Merge lp:~sidnei/golxc/clone-with-backing-store into lp:golxc

Proposed by Sidnei da Silva
Status: Needs review
Proposed branch: lp:~sidnei/golxc/clone-with-backing-store
Merge into: lp:golxc
Diff against target: 169 lines (+70/-10)
3 files modified
golxc.go (+42/-6)
golxc_test.go (+27/-3)
network.go (+1/-1)
To merge this branch: bzr merge lp:~sidnei/golxc/clone-with-backing-store
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+180444@code.launchpad.net

Description of the change

Suport extra args for lxc-clone in lxc 1.0alpha2

Allow using snapshots for cloning, selecting a specific backing store and also
passing template arguments to whatever template was used when cloning.

To post a comment you must log in.
Revision history for this message
Sidnei da Silva (sidnei) wrote :

Please take a look.

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2013-10-23 2:29, Sidnei da Silva wrote:
> Sidnei da Silva has proposed merging
> lp:~sidnei/golxc/clone-with-backing-store into lp:golxc.
>
> Requested reviews: juju hackers (juju) Related bugs: Bug #1203291
> in juju-core: "local provider moar awesome with lxc-clone"
> https://bugs.launchpad.net/juju-core/+bug/1203291
>
> For more details, see:
> https://code.launchpad.net/~sidnei/golxc/clone-with-backing-store/+merge/180444
>
> Suport extra args for lxc-clone in lxc 0.9
>
> Allow using snapshots for cloning, selecting a specific backing
> store and also passing template arguments to whatever template was
> used when cloning.
>

Is this backwards compatible for the version of LXC that is default
installed in Precise?

Can it be made to be that way?

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.13 (Cygwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlJ4n0wACgkQJdeBCYSNAAMsaACfX8B3/Gz4Uh8xPXGxaTmtJJIo
sz4AoNOATEPIfLtdAa99wrnGS3WzYHk5
=VrL9
-----END PGP SIGNATURE-----

Revision history for this message
Sidnei da Silva (sidnei) wrote :

On Tue, Nov 5, 2013 at 5:36 AM, John A Meinel <email address hidden>wrote:

>
> Is this backwards compatible for the version of LXC that is default
> installed in Precise?
>
> Can it be made to be that way?
>

It isn't because there's extra arguments that weren't there before. It
could be made compatible by sniffing out valid arguments from lxc-create
--help and lxc-clone --help, but I feel that could be too fragile. My
understanding is that lxc would be backported into the cloud archive all
the way to precise, but maybe that's not the case?

--
Sidnei

Make the most of Ubuntu with Ubuntu One
http://one.ubuntu.com

Unmerged revisions

9. By Sidnei da Silva

- Don't conditionally set options

8. By Sidnei da Silva

- Expose more settings via create and clone

7. By Sidnei da Silva

- Some test tweaks

6. By Sidnei da Silva

- Initial attempt with simply modifying the interface in place, better advice to come.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'golxc.go'
--- golxc.go 2013-06-14 01:27:52 +0000
+++ golxc.go 2013-10-22 22:26:14 +0000
@@ -57,6 +57,18 @@
57 LogFatal LogLevel = "FATAL"57 LogFatal LogLevel = "FATAL"
58)58)
5959
60// BackingStore represents a container's backing store when cloning.
61type BackingStore string
62
63const (
64 BackingStoreAuto BackingStore = "auto"
65 BackingStoreLVM BackingStore = "lvm"
66 BackingStoreBTRFS BackingStore = "btrfs"
67 BackingStoreOverlayFS BackingStore = "overlayfs"
68 BackingStoreDir BackingStore = "dir"
69 BackingStoreLoop BackingStore = "loop"
70)
71
60// Container represents a linux container instance and provides72// Container represents a linux container instance and provides
61// operations to create, maintain and destroy the container.73// operations to create, maintain and destroy the container.
62type Container interface {74type Container interface {
@@ -65,16 +77,16 @@
65 Name() string77 Name() string
6678
67 // Create creates a new container based on the given template.79 // Create creates a new container based on the given template.
68 Create(configFile, template string, templateArgs ...string) error80 Create(configFile string, backingStore BackingStore, fsSize string, fsType string, template string, templateArgs ...string) error
6981
70 // Start runs the container as a daemon.82 // Start runs the container as a daemon.
71 Start(configFile, consoleFile string) error83 Start(configFile string, consoleFile string) error
7284
73 // Stop terminates the running container.85 // Stop terminates the running container.
74 Stop() error86 Stop() error
7587
76 // Clone creates a copy of the container, giving the copy the specified name.88 // Clone creates a copy of the container, giving the copy the specified name.
77 Clone(name string) (Container, error)89 Clone(name string, snapshot bool, backingStore BackingStore, fsSize string, templateArgs ...string) (Container, error)
7890
79 // Freeze freezes all the container's processes.91 // Freeze freezes all the container's processes.
80 Freeze() error92 Freeze() error
@@ -179,7 +191,7 @@
179}191}
180192
181// Create creates a new container based on the given template.193// Create creates a new container based on the given template.
182func (c *container) Create(configFile, template string, templateArgs ...string) error {194func (c *container) Create(configFile string, backingStore BackingStore, fsSize string, fsType string, template string, templateArgs ...string) error {
183 if c.IsConstructed() {195 if c.IsConstructed() {
184 return fmt.Errorf("container %q is already created", c.Name())196 return fmt.Errorf("container %q is already created", c.Name())
185 }197 }
@@ -190,8 +202,19 @@
190 if configFile != "" {202 if configFile != "" {
191 args = append(args, "-f", configFile)203 args = append(args, "-f", configFile)
192 }204 }
193 args = append(args, "--")205 if backingStore != BackingStoreAuto {
206 args = append(args, "-B", string(backingStore))
207 } else {
208 args = append(args, "-B", "best")
209 }
210 if fsSize != "" {
211 args = append(args, "--fssize", fsSize)
212 }
213 if fsType != "" {
214 args = append(args, "--fstype", fsType)
215 }
194 if len(templateArgs) != 0 {216 if len(templateArgs) != 0 {
217 args = append(args, "--")
195 args = append(args, templateArgs...)218 args = append(args, templateArgs...)
196 }219 }
197 _, err := run("lxc-create", args...)220 _, err := run("lxc-create", args...)
@@ -245,7 +268,7 @@
245}268}
246269
247// Clone creates a copy of the container, it gets the given name.270// Clone creates a copy of the container, it gets the given name.
248func (c *container) Clone(name string) (Container, error) {271func (c *container) Clone(name string, snapshot bool, backingStore BackingStore, fsSize string, templateArgs ...string) (Container, error) {
249 if !c.IsConstructed() {272 if !c.IsConstructed() {
250 return nil, fmt.Errorf("container %q is not yet created", c.name)273 return nil, fmt.Errorf("container %q is not yet created", c.name)
251 }274 }
@@ -259,6 +282,19 @@
259 "-o", c.name,282 "-o", c.name,
260 "-n", name,283 "-n", name,
261 }284 }
285 if snapshot {
286 args = append(args, "-s")
287 }
288 if backingStore != BackingStoreAuto {
289 args = append(args, "-B", string(backingStore))
290 }
291 if fsSize != "" {
292 args = append(args, "-L", fsSize)
293 }
294 if len(templateArgs) != 0 {
295 args = append(args, "--")
296 args = append(args, templateArgs...)
297 }
262 _, err := run("lxc-clone", args...)298 _, err := run("lxc-clone", args...)
263 if err != nil {299 if err != nil {
264 return nil, err300 return nil, err
265301
=== modified file 'golxc_test.go'
--- golxc_test.go 2013-06-14 03:27:43 +0000
+++ golxc_test.go 2013-10-22 22:26:14 +0000
@@ -16,7 +16,7 @@
16var lxcfile = `# MIRROR to be used by ubuntu template at container creation:16var lxcfile = `# MIRROR to be used by ubuntu template at container creation:
17# Leaving it undefined is fine17# Leaving it undefined is fine
18#MIRROR="http://archive.ubuntu.com/ubuntu"18#MIRROR="http://archive.ubuntu.com/ubuntu"
19# or 19# or
20#MIRROR="http://<host-ip-addr>:3142/archive.ubuntu.com/ubuntu"20#MIRROR="http://<host-ip-addr>:3142/archive.ubuntu.com/ubuntu"
2121
22# LXC_AUTO - whether or not to start containers symlinked under22# LXC_AUTO - whether or not to start containers symlinked under
@@ -232,7 +232,31 @@
232 }()232 }()
233 lcs, _ := s.factory.List()233 lcs, _ := s.factory.List()
234 oldLen := len(lcs)234 oldLen := len(lcs)
235 lc2, err := lc1.Clone("golxcclone")235 lc2, err := lc1.Clone("golxcclone", false, golxc.BackingStoreAuto)
236 c.Assert(err, IsNil)
237 c.Assert(lc2.IsConstructed(), Equals, true)
238 defer func() {
239 c.Assert(lc2.Destroy(), IsNil)
240 }()
241 lcs, _ = s.factory.List()
242 newLen := len(lcs)
243 c.Assert(newLen == oldLen+1, Equals, true)
244 c.Assert(contains(lcs, lc1), Equals, true)
245 c.Assert(contains(lcs, lc2), Equals, true)
246}
247
248func (s *LXCSuite) TestCloneSnapshotWithOverlayFS(c *C) {
249 // Test the cloning of an existing container.
250 lc1 := s.factory.New("golxc")
251 c.Assert(lc1.IsConstructed(), Equals, false)
252 c.Assert(lc1.Create("", "ubuntu"), IsNil)
253 c.Assert(lc1.IsConstructed(), Equals, true)
254 defer func() {
255 c.Assert(lc1.Destroy(), IsNil)
256 }()
257 lcs, _ := s.factory.List()
258 oldLen := len(lcs)
259 lc2, err := lc1.Clone("golxcclone", true, golxc.BackingStoreOverlayFS)
236 c.Assert(err, IsNil)260 c.Assert(err, IsNil)
237 c.Assert(lc2.IsConstructed(), Equals, true)261 c.Assert(lc2.IsConstructed(), Equals, true)
238 defer func() {262 defer func() {
@@ -249,7 +273,7 @@
249 // Test the cloning of a non-existing container.273 // Test the cloning of a non-existing container.
250 lc := s.factory.New("golxc")274 lc := s.factory.New("golxc")
251 c.Assert(lc.IsConstructed(), Equals, false)275 c.Assert(lc.IsConstructed(), Equals, false)
252 _, err := lc.Clone("golxcclone")276 _, err := lc.Clone("golxcclone", false, golxc.BackingStoreAuto)
253 c.Assert(err, ErrorMatches, "container .* is not yet created")277 c.Assert(err, ErrorMatches, "container .* is not yet created")
254}278}
255279
256280
=== modified file 'network.go'
--- network.go 2013-06-14 00:29:08 +0000
+++ network.go 2013-10-22 22:26:14 +0000
@@ -53,7 +53,7 @@
53 return status == "running", nil53 return status == "running", nil
54}54}
5555
56// NetworkAttributes returns the lxc network attributes: 56// NetworkAttributes returns the lxc network attributes:
57// starting IP address and bridge name.57// starting IP address and bridge name.
58func NetworkAttributes() (addr, bridge string, err error) {58func NetworkAttributes() (addr, bridge string, err error) {
59 config, err := ReadConf()59 config, err := ReadConf()

Subscribers

People subscribed via source and target branches

to all changes: