| 1 | // Copyright © 2013, 2014, The Go-LXC Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a LGPLv2.1 |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | //go:build linux && cgo |
| 6 | // +build linux,cgo |
| 7 | |
| 8 | package mainscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/ |
| 9 | |
| 10 | import ( |
| 11 | "flagscip-go gomod github.com/golang/go/src go1.20 flag/" |
| 12 | "logscip-go gomod github.com/golang/go/src go1.20 log/" |
| 13 | |
| 14 | "github.com/lxc/go-lxcscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/" |
| 15 | ) |
| 16 | |
| 17 | var ( |
| 18 | lxcpathscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/lxcpath. string |
| 19 | namescip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/name. string |
| 20 | backendscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/backend. lxcscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/.BackendStorescip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/BackendStore# |
| 21 | ) |
| 22 | |
| 23 | func initscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/init().() { |
| 24 | flagscip-go gomod github.com/golang/go/src go1.20 flag/.StringVarscip-go gomod github.com/golang/go/src go1.20 flag/StringVar().(&lxcpathscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/lxcpath., "lxcpath", lxcscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/.DefaultConfigPathscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/DefaultConfigPath().(), "Use specified container path") |
| 25 | flagscip-go gomod github.com/golang/go/src go1.20 flag/.StringVarscip-go gomod github.com/golang/go/src go1.20 flag/StringVar().(&namescip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/name., "name", "rubik", "Name of the original container") |
| 26 | flagscip-go gomod github.com/golang/go/src go1.20 flag/.Varscip-go gomod github.com/golang/go/src go1.20 flag/Var().(&backendscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/backend., "backend", "Backend type to use, possible values are [dir, zfs, btrfs, lvm, aufs, overlayfs, loopback, best]") |
| 27 | flagscip-go gomod github.com/golang/go/src go1.20 flag/.Parsescip-go gomod github.com/golang/go/src go1.20 flag/Parse().() |
| 28 | } |
| 29 | |
| 30 | func mainscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/main().() { |
| 31 | c, err := lxcscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/.NewContainerscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/NewContainer().(namescip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/name., lxcpathscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/lxcpath.) |
| 32 | if err != nil { |
| 33 | logscip-go gomod github.com/golang/go/src go1.20 log/.Fatalfscip-go gomod github.com/golang/go/src go1.20 log/Fatalf().("ERROR: %s\n", err.Error()) |
| 34 | } |
| 35 | defer c.Releasescip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/Container#Release().() |
| 36 | |
| 37 | if backendscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/backend. == 0 { |
| 38 | logscip-go gomod github.com/golang/go/src go1.20 log/.Fatalfscip-go gomod github.com/golang/go/src go1.20 log/Fatalf().("ERROR: %s\n", lxcscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/.ErrUnknownBackendStorescip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/ErrUnknownBackendStore.) |
| 39 | } |
| 40 | |
| 41 | logscip-go gomod github.com/golang/go/src go1.20 log/.Printfscip-go gomod github.com/golang/go/src go1.20 log/Printf().("Cloning the container using %s backend...\n", backendscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/backend.) |
| 42 | err = c.Clonescip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/Container#Clone().(namescip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/name.+"_"+backendscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/backend..Stringscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/BackendStore#String().(), lxcscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/.CloneOptionsscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/CloneOptions#{ |
| 43 | Backendscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc`/CloneOptions#Backend.: backendscip-go gomod github.com/lxc/go-lxc . `github.com/lxc/go-lxc/examples/clone`/backend., |
| 44 | }) |
| 45 | if err != nil { |
| 46 | logscip-go gomod github.com/golang/go/src go1.20 log/.Fatalfscip-go gomod github.com/golang/go/src go1.20 log/Fatalf().("ERROR: %s\n", err.Error()) |
| 47 | } |
| 48 | } |