[lxc-devel] [PATCH] python: Various fixes to the python scripts
Serge Hallyn
serge.hallyn at ubuntu.com
Thu Apr 18 20:33:16 UTC 2013
Quoting Stéphane Graber (stgraber at ubuntu.com):
> This fixes a few issues uncovered by the recent C module fix.
>
> In lxc-start-ephemeral, the hwaddr code wasn't actually working.
> Replace by code that properly iterates through the network interfaces
> and sets a new MAC address for each entry.
>
> In the python overlay, catch the newly emitted KeyError when in
> set_config_item (or setting any previously unset variable would fail).
>
> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>
> ---
> src/lxc/lxc-start-ephemeral.in | 4 +++-
> src/python-lxc/lxc/__init__.py | 5 ++++-
> 2 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/src/lxc/lxc-start-ephemeral.in b/src/lxc/lxc-start-ephemeral.in
> index bed86e6..b5cad9a 100644
> --- a/src/lxc/lxc-start-ephemeral.in
> +++ b/src/lxc/lxc-start-ephemeral.in
> @@ -134,7 +134,9 @@ dest = lxc.Container(os.path.basename(dest_path), args.lxcpath)
> dest.load_config(orig.config_file_name)
> dest.set_config_item("lxc.utsname", dest.name)
> dest.set_config_item("lxc.rootfs", os.path.join(dest_path, "rootfs"))
> -dest.set_config_item("lxc.network.hwaddr", randomMAC())
> +for nic in dest.network:
> + if hasattr(nic, 'hwaddr'):
> + nic.hwaddr = randomMAC()
>
> overlay_dirs = [(orig.get_config_item("lxc.rootfs"), "%s/rootfs/" % dest_path)]
>
> diff --git a/src/python-lxc/lxc/__init__.py b/src/python-lxc/lxc/__init__.py
> index 118a081..e3ce8eb 100644
> --- a/src/python-lxc/lxc/__init__.py
> +++ b/src/python-lxc/lxc/__init__.py
> @@ -412,7 +412,10 @@ class Container(_lxc.Container):
> Set a config key to a provided value.
> The value can be a list for the keys supporting multiple values.
> """
> - old_value = self.get_config_item(key)
> + try:
> + old_value = self.get_config_item(key)
> + except KeyError:
> + old_value = None
>
> # Check if it's a list
> def set_key(key, value):
> --
> 1.8.1.2
>
>
> ------------------------------------------------------------------------------
> Precog is a next-generation analytics platform capable of advanced
> analytics on semi-structured data. The platform includes APIs for building
> apps and a phenomenal toolset for data science. Developers can use
> our toolset for easy data analysis & visualization. Get a free account!
> http://www2.precog.com/precogplatform/slashdotnewsletter
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel
More information about the lxc-devel
mailing list