Index: net/cloud-init-azure/files/patch-frbsd-azure.txt =================================================================== --- net/cloud-init-azure/files/patch-frbsd-azure.txt +++ net/cloud-init-azure/files/patch-frbsd-azure.txt @@ -126,15 +126,23 @@ # This method is preferred to apply_network which only takes --- cloudinit/distros/freebsd.py.orig 2016-12-23 16:37:45 UTC +++ cloudinit/distros/freebsd.py -@@ -30,6 +30,7 @@ class Distro(distros.Distro): +@@ -30,6 +30,15 @@ class Distro(distros.Distro): login_conf_fn_bak = '/etc/login.conf.orig' resolv_conf_fn = '/etc/resolv.conf' ci_sudoers_fn = '/usr/local/etc/sudoers.d/90-cloud-init-users' + default_primary_nic = 'hn0' ++ # check whether VF is enabled, which will override "hn0" to "mlx0" ++ try: ++ out, err = util.subp(['sysctl', '-n', 'dev.hn.0.vf']) ++ hnvf = out.strip() ++ if len(hnvf) > 0: ++ default_primary_nic = hnvf ++ except util.ProcessExecutionError: ++ pass def __init__(self, name, cfg, paths): distros.Distro.__init__(self, name, cfg, paths) -@@ -38,6 +39,8 @@ class Distro(distros.Distro): +@@ -38,6 +47,8 @@ class Distro(distros.Distro): # should only happen say once per instance...) self._runner = helpers.Runners(paths) self.osfamily = 'freebsd' @@ -143,7 +151,7 @@ # Updates a key in /etc/rc.conf. def updatercconf(self, key, value): -@@ -183,7 +186,6 @@ class Distro(distros.Distro): +@@ -183,7 +194,6 @@ class Distro(distros.Distro): "gecos": '-c', "primary_group": '-g', "groups": '-G', @@ -151,7 +159,7 @@ "shell": '-s', "inactive": '-E', } -@@ -193,19 +195,11 @@ class Distro(distros.Distro): +@@ -193,19 +203,11 @@ class Distro(distros.Distro): "no_log_init": '--no-log-init', } @@ -171,7 +179,7 @@ elif key in adduser_flags and val: adduser_cmd.append(adduser_flags[key]) log_adduser_cmd.append(adduser_flags[key]) -@@ -226,19 +220,21 @@ class Distro(distros.Distro): +@@ -226,19 +228,21 @@ class Distro(distros.Distro): except Exception as e: util.logexc(LOG, "Failed to create user %s", name) raise e @@ -189,10 +197,10 @@ + hash_opt = "-H" else: - cmd.append('-h') +- +- cmd.append('0') + hash_opt = "-h" -- cmd.append('0') -- try: - util.subp(cmd, passwd, logstring="chpasswd for %s" % user) + util.subp(['pw', 'usermod', user, hash_opt, '0'], @@ -200,11 +208,10 @@ except Exception as e: util.logexc(LOG, "Failed to set password for %s", user) raise e -@@ -270,6 +266,255 @@ class Distro(distros.Distro): - if 'ssh_authorized_keys' in kwargs: +@@ -271,6 +275,255 @@ class Distro(distros.Distro): keys = set(kwargs['ssh_authorized_keys']) or [] ssh_util.setup_user_keys(keys, name, options=None) -+ + + @staticmethod + def get_ifconfig_list(): + cmd = ['ifconfig', '-l'] @@ -453,9 +460,10 @@ + return nconf + else: + return None - ++ def _write_network(self, settings): entries = net_util.translate_network(settings) + nameservers = [] --- cloudinit/settings.py.orig 2016-12-23 16:37:45 UTC +++ cloudinit/settings.py @@ -37,7 +37,7 @@ CFG_BUILTIN = { @@ -477,14 +485,21 @@ import time from xml.dom import minidom import xml.etree.ElementTree as ET -@@ -32,19 +33,160 @@ BOUNCE_COMMAND = [ +@@ -27,24 +28,175 @@ AGENT_START = ['service', 'walinuxagent', 'start'] + AGENT_START_BUILTIN = "__builtin__" + BOUNCE_COMMAND = [ + 'sh', '-xc', +- "i=$interface; x=0; ifdown $i || x=$?; ifup $i || x=$?; exit $x" ++ "i=$interface; x=0; ", ++ "ifconfig down $i || x=$?; ifconfig up $i || x=$?; exit $x" + ] # azure systems will always have a resource disk, and 66-azure-ephemeral.rules # ensures that it gets linked to this path. RESOURCE_DISK_PATH = '/dev/disk/cloud/azure_resource' +DEFAULT_PRIMARY_NIC = 'eth0' +LEASE_FILE = '/var/lib/dhcp/dhclient.eth0.leases' +DEFAULT_FS = 'ext4' - ++ + +def find_storvscid_from_sysctl_pnpinfo(sysctl_out, deviceid): + # extract the 'X' from dev.storvsc.X. if deviceid matches @@ -614,7 +629,16 @@ +# update the FreeBSD specific information +if util.is_FreeBSD(): + DEFAULT_PRIMARY_NIC = 'hn0' -+ LEASE_FILE = '/var/db/dhclient.leases.hn0' ++ # check whether VF is enabled, which will override "hn0" to "mlx0" ++ try: ++ out, err = util.subp(['sysctl', '-n', 'dev.hn.0.vf']) ++ hnvf = out.strip() ++ if len(hnvf) > 0: ++ DEFAULT_PRIMARY_NIC = hnvf ++ except util.ProcessExecutionError: ++ pass ++ ++ LEASE_FILE = '/var/db/dhclient.leases.{0}'.format(DEFAULT_PRIMARY_NIC) + DEFAULT_FS = 'freebsd-ufs' + res_disk = get_resource_disk_on_freebsd(1) + if res_disk is not None: @@ -622,7 +646,7 @@ + RESOURCE_DISK_PATH = "/dev/" + res_disk + else: + LOG.debug("resource disk is None") -+ + BUILTIN_DS_CONFIG = { 'agent_command': AGENT_START_BUILTIN, 'data_dir': "/var/lib/waagent", @@ -640,7 +664,7 @@ } BUILTIN_CLOUD_CONFIG = { -@@ -53,7 +195,7 @@ BUILTIN_CLOUD_CONFIG = { +@@ -53,7 +205,7 @@ BUILTIN_CLOUD_CONFIG = { 'layout': [100], 'overwrite': True}, }, @@ -649,7 +673,7 @@ 'device': 'ephemeral0.1', 'replace_fs': 'ntfs'}], } -@@ -178,7 +320,11 @@ class DataSourceAzureNet(sources.DataSource): +@@ -178,7 +330,11 @@ class DataSourceAzureNet(sources.DataSource): for cdev in candidates: try: if cdev.startswith("/dev/"): @@ -662,7 +686,7 @@ else: ret = load_azure_ds_dir(cdev) -@@ -206,11 +352,13 @@ class DataSourceAzureNet(sources.DataSource): +@@ -206,11 +362,13 @@ class DataSourceAzureNet(sources.DataSource): LOG.debug("using files cached in %s", ddir) # azure / hyper-v provides random data here @@ -680,7 +704,7 @@ # now update ds_cfg to reflect contents pass in config user_ds_cfg = util.get_cfg_by_path(self.cfg, DS_CFG_PATH, {}) self.ds_cfg = util.mergemanydict([user_ds_cfg, self.ds_cfg]) -@@ -619,8 +767,19 @@ def encrypt_pass(password, salt_id="$6$"): +@@ -619,8 +777,17 @@ def encrypt_pass(password, salt_id="$6$"): def list_possible_azure_ds_devs(): # return a sorted list of devices that might have a azure datasource devlist = [] @@ -689,13 +713,11 @@ + if util.is_FreeBSD(): + cdrom_dev = "/dev/cd0" + try: -+ util.subp(["mount", "-o", "ro", "-t", "udf", cdrom_dev, -+ "/mnt/cdrom/secure"]) -+ except util.ProcessExecutionError: -+ LOG.debug("Fail to mount cd") -+ return devlist -+ util.subp(["umount", "/mnt/cdrom/secure"]) -+ devlist.append(cdrom_dev) ++ with open(cdrom_dev) as fp: ++ fp.read(1024) ++ devlist.append(cdrom_dev) ++ except IOError: ++ LOG.debug("cdrom (%s) is not configured", cdrom_dev) + else: + for fstype in ("iso9660", "udf"): + devlist.extend(util.find_devs_with("TYPE=%s" % fstype))