Re: [Cloud-init-dev] [Merge] ~daniel-thewatkins/cloud-init/+git/cloud-init:dracut into cloud-init:master

2019-08-22 Thread Dan Watkins



Diff comments:

> diff --git a/cloudinit/net/cmdline.py b/cloudinit/net/cmdline.py
> index 556a10f..c05d36c 100755
> --- a/cloudinit/net/cmdline.py
> +++ b/cloudinit/net/cmdline.py
> @@ -137,6 +203,24 @@ def config_from_klibc_net_cfg(files=None, 
> mac_addrs=None):
>  return {'config': entries, 'version': 1}
>  
>  
> +def read_initramfs_config():
> +"""
> +Return v1 network config for initramfs-configured networking (or None)
> +
> +This will consider each _INITRAMFS_CONFIG_SOURCES entry in turn, and 
> return
> +v1 network configuration for the first one that is applicable.  If none 
> are
> +applicable, return None.
> +"""
> +for src_cls in _INITRAMFS_CONFIG_SOURCES:

Yeah, good thinking.  I'll refactor bits up as I find them in the dracut work.  
(Because, for example, the open-iscsi check _doesn't_ apply to dracut.  They do 
use open-iscsi, but that file isn't present.)

> +cfg_source = src_cls()
> +
> +if not cfg_source.is_applicable():
> +continue
> +
> +return cfg_source.render_config()
> +return None
> +
> +
>  def _decomp_gzip(blob, strict=True):
>  # decompress blob. raise exception if not compressed unless strict=False.
>  with io.BytesIO(blob) as iobuf:


-- 
https://code.launchpad.net/~daniel-thewatkins/cloud-init/+git/cloud-init/+merge/371673
Your team cloud-init commiters is requested to review the proposed merge of 
~daniel-thewatkins/cloud-init/+git/cloud-init:dracut into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Cloud-init-dev] [Merge] ~daniel-thewatkins/cloud-init/+git/cloud-init:dracut into cloud-init:master

2019-08-22 Thread Ryan Harper



Diff comments:

> diff --git a/cloudinit/net/cmdline.py b/cloudinit/net/cmdline.py
> index 556a10f..c05d36c 100755
> --- a/cloudinit/net/cmdline.py
> +++ b/cloudinit/net/cmdline.py
> @@ -137,6 +203,24 @@ def config_from_klibc_net_cfg(files=None, 
> mac_addrs=None):
>  return {'config': entries, 'version': 1}
>  
>  
> +def read_initramfs_config():
> +"""
> +Return v1 network config for initramfs-configured networking (or None)

OK.

> +
> +This will consider each _INITRAMFS_CONFIG_SOURCES entry in turn, and 
> return
> +v1 network configuration for the first one that is applicable.  If none 
> are
> +applicable, return None.
> +"""
> +for src_cls in _INITRAMFS_CONFIG_SOURCES:

I see it now.  You're right.  I wonder if the the command line bits ought to be 
factored out of the "am I klibc, or dracut or. ..." path?  Checking if the 
commandline has ip= is duplicate code between initramfs applicables, as will 
the open-iscsi check,  the only things that are initramfs format specific are 
the file locations they know about.  Maybe a base class implementation with the 
common bits ?

> +cfg_source = src_cls()
> +
> +if not cfg_source.is_applicable():
> +continue
> +
> +return cfg_source.render_config()
> +return None
> +
> +
>  def _decomp_gzip(blob, strict=True):
>  # decompress blob. raise exception if not compressed unless strict=False.
>  with io.BytesIO(blob) as iobuf:


-- 
https://code.launchpad.net/~daniel-thewatkins/cloud-init/+git/cloud-init/+merge/371673
Your team cloud-init commiters is requested to review the proposed merge of 
~daniel-thewatkins/cloud-init/+git/cloud-init:dracut into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Cloud-init-dev] [Merge] ~daniel-thewatkins/cloud-init/+git/cloud-init:dracut into cloud-init:master

2019-08-22 Thread Server Team CI bot
Review: Approve continuous-integration

PASSED: Continuous integration, rev:b4772d90e58e24b96b39a4c5a4ddfbc048febd62
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1067/
Executed test runs:
SUCCESS: Checkout
SUCCESS: Unit & Style Tests
SUCCESS: Ubuntu LTS: Build
SUCCESS: Ubuntu LTS: Integration
IN_PROGRESS: Declarative: Post Actions


Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1067//rebuild
-- 
https://code.launchpad.net/~daniel-thewatkins/cloud-init/+git/cloud-init/+merge/371673
Your team cloud-init commiters is requested to review the proposed merge of 
~daniel-thewatkins/cloud-init/+git/cloud-init:dracut into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Cloud-init-dev] [Merge] ~daniel-thewatkins/cloud-init/+git/cloud-init:dracut into cloud-init:master

2019-08-22 Thread Dan Watkins



Diff comments:

> diff --git a/cloudinit/net/cmdline.py b/cloudinit/net/cmdline.py
> index 556a10f..c05d36c 100755
> --- a/cloudinit/net/cmdline.py
> +++ b/cloudinit/net/cmdline.py
> @@ -137,6 +203,24 @@ def config_from_klibc_net_cfg(files=None, 
> mac_addrs=None):
>  return {'config': entries, 'version': 1}
>  
>  
> +def read_initramfs_config():
> +"""
> +Return v1 network config for initramfs-configured networking (or None)

At the very least the Oracle DS is relying on this being v1, so it can merge 
secondary NIC config into it.  So this _does_ need to be v1 until we lift up 
everything to v2 (and even then it will always need to be consistent across 
InitramfsNetworkConfigSources).

> +
> +This will consider each _INITRAMFS_CONFIG_SOURCES entry in turn, and 
> return
> +v1 network configuration for the first one that is applicable.  If none 
> are
> +applicable, return None.
> +"""
> +for src_cls in _INITRAMFS_CONFIG_SOURCES:

In KlibcNetworkConfigSource.is_applicable, we check for the klibc-written files 
before we even look at the kernel cmdline.  So if there aren't any 
/run/{net,net6}-*.conf files, we won't select KlibcNetworkConfigSource.

(I'll improve the docstring on KlibcNetworkConfigSource.is_applicable, because 
I _also_ thought this was going to be a problem for a while and clearly it 
wasn't just me. :)

> +cfg_source = src_cls()
> +
> +if not cfg_source.is_applicable():
> +continue
> +
> +return cfg_source.render_config()
> +return None
> +
> +
>  def _decomp_gzip(blob, strict=True):
>  # decompress blob. raise exception if not compressed unless strict=False.
>  with io.BytesIO(blob) as iobuf:


-- 
https://code.launchpad.net/~daniel-thewatkins/cloud-init/+git/cloud-init/+merge/371673
Your team cloud-init commiters is requested to review the proposed merge of 
~daniel-thewatkins/cloud-init/+git/cloud-init:dracut into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Cloud-init-dev] [Merge] ~daniel-thewatkins/cloud-init/+git/cloud-init:dracut into cloud-init:master

2019-08-22 Thread Ryan Harper



Diff comments:

> diff --git a/cloudinit/net/cmdline.py b/cloudinit/net/cmdline.py
> index 556a10f..c05d36c 100755
> --- a/cloudinit/net/cmdline.py
> +++ b/cloudinit/net/cmdline.py
> @@ -137,6 +203,24 @@ def config_from_klibc_net_cfg(files=None, 
> mac_addrs=None):
>  return {'config': entries, 'version': 1}
>  
>  
> +def read_initramfs_config():
> +"""
> +Return v1 network config for initramfs-configured networking (or None)

remove v1;  that'll be initramfs-config obj method specific.  In practice it is 
but
that can change.

> +
> +This will consider each _INITRAMFS_CONFIG_SOURCES entry in turn, and 
> return
> +v1 network configuration for the first one that is applicable.  If none 
> are
> +applicable, return None.
> +"""
> +for src_cls in _INITRAMFS_CONFIG_SOURCES:

Hrm, how we are going to distinguish the klibc one from dracut where the user 
has passed an ip= parameter?  

https://fedoraproject.org/wiki/Dracut/Options#Network  suggests that it also 
handles the same parameters as kblic will.

I suspect we'll want/need some what to positively identify which 
initramfs_config_sources are present via some
distro specific path/tool/exec and include that in the applicable check such 
that even if using ip=, the
klibc source won't be used since it's not on the right distro.

> +cfg_source = src_cls()
> +
> +if not cfg_source.is_applicable():
> +continue
> +
> +return cfg_source.render_config()
> +return None
> +
> +
>  def _decomp_gzip(blob, strict=True):
>  # decompress blob. raise exception if not compressed unless strict=False.
>  with io.BytesIO(blob) as iobuf:


-- 
https://code.launchpad.net/~daniel-thewatkins/cloud-init/+git/cloud-init/+merge/371673
Your team cloud-init commiters is requested to review the proposed merge of 
~daniel-thewatkins/cloud-init/+git/cloud-init:dracut into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


[Cloud-init-dev] [Merge] ~daniel-thewatkins/cloud-init/+git/cloud-init:dracut into cloud-init:master

2019-08-22 Thread Dan Watkins
Dan Watkins has proposed merging 
~daniel-thewatkins/cloud-init/+git/cloud-init:dracut into cloud-init:master.

Commit message:
net/cmdline: refactor to allow multiple initramfs network config sources

This refactors read_initramfs_config to support multiple different types
of initramfs network configuration.  It introduces an
InitramfsNetworkConfigSource abstract base class.  There is currently a
single sub-class, KlibcNetworkConfigSource, which contains the logic
which previously was directly within read_initramfs_config.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~daniel-thewatkins/cloud-init/+git/cloud-init/+merge/371673
-- 
Your team cloud-init commiters is requested to review the proposed merge of 
~daniel-thewatkins/cloud-init/+git/cloud-init:dracut into cloud-init:master.
diff --git a/cloudinit/net/cmdline.py b/cloudinit/net/cmdline.py
index 556a10f..c05d36c 100755
--- a/cloudinit/net/cmdline.py
+++ b/cloudinit/net/cmdline.py
@@ -5,20 +5,86 @@
 #
 # This file is part of cloud-init. See LICENSE file for license information.
 
+import abc
 import base64
 import glob
 import gzip
 import io
 import os
 
-from . import get_devicelist
-from . import read_sys_net_safe
+import six
 
 from cloudinit import util
 
+from . import get_devicelist
+from . import read_sys_net_safe
+
 _OPEN_ISCSI_INTERFACE_FILE = "/run/initramfs/open-iscsi.interface"
 
 
+@six.add_metaclass(abc.ABCMeta)
+class InitramfsNetworkConfigSource(object):
+"""ABC for net config sources that read config written by initramfses"""
+
+@abc.abstractmethod
+def is_applicable(self):
+# type: () -> bool
+"""Is this initramfs config source applicable to the current system?"""
+pass
+
+@abc.abstractmethod
+def render_config(self):
+# type: () -> dict
+"""Render a v1 network config from the initramfs configuration"""
+pass
+
+
+class KlibcNetworkConfigSource(InitramfsNetworkConfigSource):
+"""InitramfsNetworkConfigSource for klibc initramfs (i.e. Debian/Ubuntu)
+
+Has three parameters, but they are intended to make testing simpler, _not_
+for use in production code.  (This is indicated by the prepended
+underscores.)
+"""
+
+def __init__(self, _files=None, _mac_addrs=None, _cmdline=None):
+self._files = _files
+self._mac_addrs = _mac_addrs
+self._cmdline = _cmdline
+
+# Set defaults here, as they require computation that we don't want to
+# do at method definition time
+if self._files is None:
+self._files = _get_klibc_net_cfg_files()
+if self._cmdline is None:
+self._cmdline = util.get_cmdline()
+if self._mac_addrs is None:
+self._mac_addrs = {}
+for k in get_devicelist():
+mac_addr = read_sys_net_safe(k, 'address')
+if mac_addr:
+self._mac_addrs[k] = mac_addr
+
+def is_applicable(self):
+# type: () -> bool
+if self._files:
+if 'ip=' in self._cmdline or 'ip6=' in self._cmdline:
+return True
+if os.path.exists(_OPEN_ISCSI_INTERFACE_FILE):
+# iBft can configure networking without ip=
+return True
+return False
+
+def render_config(self):
+# type: () -> dict
+return config_from_klibc_net_cfg(
+files=self._files, mac_addrs=self._mac_addrs,
+)
+
+
+_INITRAMFS_CONFIG_SOURCES = [KlibcNetworkConfigSource]
+
+
 def _klibc_to_config_entry(content, mac_addrs=None):
 """Convert a klibc written shell content file to a 'config' entry
 When ip= is seen on the kernel command line in debian initramfs
@@ -137,6 +203,24 @@ def config_from_klibc_net_cfg(files=None, mac_addrs=None):
 return {'config': entries, 'version': 1}
 
 
+def read_initramfs_config():
+"""
+Return v1 network config for initramfs-configured networking (or None)
+
+This will consider each _INITRAMFS_CONFIG_SOURCES entry in turn, and return
+v1 network configuration for the first one that is applicable.  If none are
+applicable, return None.
+"""
+for src_cls in _INITRAMFS_CONFIG_SOURCES:
+cfg_source = src_cls()
+
+if not cfg_source.is_applicable():
+continue
+
+return cfg_source.render_config()
+return None
+
+
 def _decomp_gzip(blob, strict=True):
 # decompress blob. raise exception if not compressed unless strict=False.
 with io.BytesIO(blob) as iobuf:
@@ -167,36 +251,6 @@ def _b64dgz(b64str, gzipped="try"):
 return _decomp_gzip(blob, strict=gzipped != "try")
 
 
-def _is_initramfs_netconfig(files, cmdline):
-if files:
-if 'ip=' in cmdline or 'ip6=' in cmdline:
-return True
-if os.path.exists(_OPEN_ISCSI_INTERFACE_FILE):
-# iBft can configure networking without ip=
-return True
-return