Changeset View
Changeset View
Standalone View
Standalone View
net/cloud-init-azure/files/patch-frbsd-azure.txt
Show First 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | |||||
+ def generate_fallback_config(self): | + def generate_fallback_config(self): | ||||
+ return net.generate_fallback_config() | + return net.generate_fallback_config() | ||||
+ | + | ||||
def apply_network_config(self, netconfig, bring_up=False): | def apply_network_config(self, netconfig, bring_up=False): | ||||
# apply network config netconfig | # apply network config netconfig | ||||
# This method is preferred to apply_network which only takes | # 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.orig 2016-12-23 16:37:45 UTC | ||||
+++ cloudinit/distros/freebsd.py | +++ 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' | login_conf_fn_bak = '/etc/login.conf.orig' | ||||
resolv_conf_fn = '/etc/resolv.conf' | resolv_conf_fn = '/etc/resolv.conf' | ||||
ci_sudoers_fn = '/usr/local/etc/sudoers.d/90-cloud-init-users' | ci_sudoers_fn = '/usr/local/etc/sudoers.d/90-cloud-init-users' | ||||
+ default_primary_nic = 'hn0' | + 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): | def __init__(self, name, cfg, paths): | ||||
distros.Distro.__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...) | # should only happen say once per instance...) | ||||
self._runner = helpers.Runners(paths) | self._runner = helpers.Runners(paths) | ||||
self.osfamily = 'freebsd' | self.osfamily = 'freebsd' | ||||
+ self.ipv4_pat = re.compile(r"\s+inet\s+\d+[.]\d+[.]\d+[.]\d+") | + self.ipv4_pat = re.compile(r"\s+inet\s+\d+[.]\d+[.]\d+[.]\d+") | ||||
+ cfg['ssh_svcname'] = 'sshd' | + cfg['ssh_svcname'] = 'sshd' | ||||
# Updates a key in /etc/rc.conf. | # Updates a key in /etc/rc.conf. | ||||
def updatercconf(self, key, value): | def updatercconf(self, key, value): | ||||
@@ -183,7 +186,6 @@ class Distro(distros.Distro): | @@ -183,7 +194,6 @@ class Distro(distros.Distro): | ||||
"gecos": '-c', | "gecos": '-c', | ||||
"primary_group": '-g', | "primary_group": '-g', | ||||
"groups": '-G', | "groups": '-G', | ||||
- "passwd": '-h', | - "passwd": '-h', | ||||
"shell": '-s', | "shell": '-s', | ||||
"inactive": '-E', | "inactive": '-E', | ||||
} | } | ||||
@@ -193,19 +195,11 @@ class Distro(distros.Distro): | @@ -193,19 +203,11 @@ class Distro(distros.Distro): | ||||
"no_log_init": '--no-log-init', | "no_log_init": '--no-log-init', | ||||
} | } | ||||
- redact_opts = ['passwd'] | - redact_opts = ['passwd'] | ||||
- | - | ||||
for key, val in kwargs.items(): | for key, val in kwargs.items(): | ||||
if (key in adduser_opts and val and | if (key in adduser_opts and val and | ||||
isinstance(val, six.string_types)): | isinstance(val, six.string_types)): | ||||
adduser_cmd.extend([adduser_opts[key], val]) | adduser_cmd.extend([adduser_opts[key], val]) | ||||
- # Redact certain fields from the logs | - # Redact certain fields from the logs | ||||
- if key in redact_opts: | - if key in redact_opts: | ||||
- log_adduser_cmd.extend([adduser_opts[key], 'REDACTED']) | - log_adduser_cmd.extend([adduser_opts[key], 'REDACTED']) | ||||
- else: | - else: | ||||
- log_adduser_cmd.extend([adduser_opts[key], val]) | - log_adduser_cmd.extend([adduser_opts[key], val]) | ||||
- | - | ||||
elif key in adduser_flags and val: | elif key in adduser_flags and val: | ||||
adduser_cmd.append(adduser_flags[key]) | adduser_cmd.append(adduser_flags[key]) | ||||
log_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: | except Exception as e: | ||||
util.logexc(LOG, "Failed to create user %s", name) | util.logexc(LOG, "Failed to create user %s", name) | ||||
raise e | raise e | ||||
+ # Set the password if it is provided | + # Set the password if it is provided | ||||
+ # For security consideration, only hashed passwd is assumed | + # For security consideration, only hashed passwd is assumed | ||||
+ passwd_val = kwargs.get('passwd', None) | + passwd_val = kwargs.get('passwd', None) | ||||
+ if passwd_val is not None: | + if passwd_val is not None: | ||||
+ self.set_passwd(name, passwd_val, hashed=True) | + self.set_passwd(name, passwd_val, hashed=True) | ||||
def set_passwd(self, user, passwd, hashed=False): | def set_passwd(self, user, passwd, hashed=False): | ||||
- cmd = ['pw', 'usermod', user] | - cmd = ['pw', 'usermod', user] | ||||
- | - | ||||
if hashed: | if hashed: | ||||
- cmd.append('-H') | - cmd.append('-H') | ||||
+ hash_opt = "-H" | + hash_opt = "-H" | ||||
else: | else: | ||||
- cmd.append('-h') | - cmd.append('-h') | ||||
- | |||||
- cmd.append('0') | |||||
+ hash_opt = "-h" | + hash_opt = "-h" | ||||
- cmd.append('0') | |||||
- | |||||
try: | try: | ||||
- util.subp(cmd, passwd, logstring="chpasswd for %s" % user) | - util.subp(cmd, passwd, logstring="chpasswd for %s" % user) | ||||
+ util.subp(['pw', 'usermod', user, hash_opt, '0'], | + util.subp(['pw', 'usermod', user, hash_opt, '0'], | ||||
+ data=passwd, logstring="chpasswd for %s" % user) | + data=passwd, logstring="chpasswd for %s" % user) | ||||
except Exception as e: | except Exception as e: | ||||
util.logexc(LOG, "Failed to set password for %s", user) | util.logexc(LOG, "Failed to set password for %s", user) | ||||
raise e | raise e | ||||
@@ -270,6 +266,255 @@ class Distro(distros.Distro): | @@ -271,6 +275,255 @@ class Distro(distros.Distro): | ||||
if 'ssh_authorized_keys' in kwargs: | |||||
keys = set(kwargs['ssh_authorized_keys']) or [] | keys = set(kwargs['ssh_authorized_keys']) or [] | ||||
ssh_util.setup_user_keys(keys, name, options=None) | ssh_util.setup_user_keys(keys, name, options=None) | ||||
+ | |||||
+ @staticmethod | + @staticmethod | ||||
+ def get_ifconfig_list(): | + def get_ifconfig_list(): | ||||
+ cmd = ['ifconfig', '-l'] | + cmd = ['ifconfig', '-l'] | ||||
+ (nics, err) = util.subp(cmd, rcs=[0, 1]) | + (nics, err) = util.subp(cmd, rcs=[0, 1]) | ||||
+ if len(err): | + if len(err): | ||||
+ LOG.warn("Error running %s: %s", cmd, err) | + LOG.warn("Error running %s: %s", cmd, err) | ||||
+ return None | + return None | ||||
+ return nics | + return nics | ||||
▲ Show 20 Lines • Show All 232 Lines • ▼ Show 20 Lines | |||||
+ if target_mac and target_name: | + if target_mac and target_name: | ||||
+ nconf = {'config': [], 'version': 1} | + nconf = {'config': [], 'version': 1} | ||||
+ nconf['config'].append( | + nconf['config'].append( | ||||
+ {'type': 'physical', 'name': target_name, | + {'type': 'physical', 'name': target_name, | ||||
+ 'mac_address': target_mac, 'subnets': [{'type': 'dhcp'}]}) | + 'mac_address': target_mac, 'subnets': [{'type': 'dhcp'}]}) | ||||
+ return nconf | + return nconf | ||||
+ else: | + else: | ||||
+ return None | + return None | ||||
+ | |||||
def _write_network(self, settings): | def _write_network(self, settings): | ||||
entries = net_util.translate_network(settings) | entries = net_util.translate_network(settings) | ||||
nameservers = [] | |||||
--- cloudinit/settings.py.orig 2016-12-23 16:37:45 UTC | --- cloudinit/settings.py.orig 2016-12-23 16:37:45 UTC | ||||
+++ cloudinit/settings.py | +++ cloudinit/settings.py | ||||
@@ -37,7 +37,7 @@ CFG_BUILTIN = { | @@ -37,7 +37,7 @@ CFG_BUILTIN = { | ||||
], | ], | ||||
'def_log_file': '/var/log/cloud-init.log', | 'def_log_file': '/var/log/cloud-init.log', | ||||
'log_cfgs': [], | 'log_cfgs': [], | ||||
- 'syslog_fix_perms': ['syslog:adm', 'root:adm'], | - 'syslog_fix_perms': ['syslog:adm', 'root:adm'], | ||||
+ 'syslog_fix_perms': ['syslog:adm', 'root:adm', 'root:wheel'], | + 'syslog_fix_perms': ['syslog:adm', 'root:adm', 'root:wheel'], | ||||
'system_info': { | 'system_info': { | ||||
'paths': { | 'paths': { | ||||
'cloud_dir': '/var/lib/cloud', | 'cloud_dir': '/var/lib/cloud', | ||||
--- cloudinit/sources/DataSourceAzure.py.orig 2016-12-23 16:37:45 UTC | --- cloudinit/sources/DataSourceAzure.py.orig 2016-12-23 16:37:45 UTC | ||||
+++ cloudinit/sources/DataSourceAzure.py | +++ cloudinit/sources/DataSourceAzure.py | ||||
@@ -10,6 +10,7 @@ import crypt | @@ -10,6 +10,7 @@ import crypt | ||||
from functools import partial | from functools import partial | ||||
import os | import os | ||||
import os.path | import os.path | ||||
+import re | +import re | ||||
import time | import time | ||||
from xml.dom import minidom | from xml.dom import minidom | ||||
import xml.etree.ElementTree as ET | 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" | |||||
lifanov: This needs to be "ifconfig $i down" and "ifconfig $i up".
Interface name comes first. | |||||
] | |||||
# azure systems will always have a resource disk, and 66-azure-ephemeral.rules | # azure systems will always have a resource disk, and 66-azure-ephemeral.rules | ||||
# ensures that it gets linked to this path. | # ensures that it gets linked to this path. | ||||
RESOURCE_DISK_PATH = '/dev/disk/cloud/azure_resource' | RESOURCE_DISK_PATH = '/dev/disk/cloud/azure_resource' | ||||
+DEFAULT_PRIMARY_NIC = 'eth0' | +DEFAULT_PRIMARY_NIC = 'eth0' | ||||
+LEASE_FILE = '/var/lib/dhcp/dhclient.eth0.leases' | +LEASE_FILE = '/var/lib/dhcp/dhclient.eth0.leases' | ||||
+DEFAULT_FS = 'ext4' | +DEFAULT_FS = 'ext4' | ||||
+ | + | ||||
+ | |||||
+def find_storvscid_from_sysctl_pnpinfo(sysctl_out, deviceid): | +def find_storvscid_from_sysctl_pnpinfo(sysctl_out, deviceid): | ||||
+ # extract the 'X' from dev.storvsc.X. if deviceid matches | + # extract the 'X' from dev.storvsc.X. if deviceid matches | ||||
+ """ | + """ | ||||
+ dev.storvsc.1.%pnpinfo: | + dev.storvsc.1.%pnpinfo: | ||||
+ classid=32412632-86cb-44a2-9b5c-50d1417354f5 | + classid=32412632-86cb-44a2-9b5c-50d1417354f5 | ||||
+ deviceid=00000000-0001-8899-0000-000000000000 | + deviceid=00000000-0001-8899-0000-000000000000 | ||||
+ """ | + """ | ||||
+ for line in sysctl_out.splitlines(): | + for line in sysctl_out.splitlines(): | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | |||||
+ LOG.debug("Fail to find /dev/daX") | + LOG.debug("Fail to find /dev/daX") | ||||
+ return None | + return None | ||||
+ return devname | + return devname | ||||
+ return None | + return None | ||||
+ | + | ||||
+# update the FreeBSD specific information | +# update the FreeBSD specific information | ||||
+if util.is_FreeBSD(): | +if util.is_FreeBSD(): | ||||
+ DEFAULT_PRIMARY_NIC = 'hn0' | + 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' | + DEFAULT_FS = 'freebsd-ufs' | ||||
+ res_disk = get_resource_disk_on_freebsd(1) | + res_disk = get_resource_disk_on_freebsd(1) | ||||
+ if res_disk is not None: | + if res_disk is not None: | ||||
+ LOG.debug("resource disk is not None") | + LOG.debug("resource disk is not None") | ||||
+ RESOURCE_DISK_PATH = "/dev/" + res_disk | + RESOURCE_DISK_PATH = "/dev/" + res_disk | ||||
+ else: | + else: | ||||
+ LOG.debug("resource disk is None") | + LOG.debug("resource disk is None") | ||||
+ | |||||
BUILTIN_DS_CONFIG = { | BUILTIN_DS_CONFIG = { | ||||
'agent_command': AGENT_START_BUILTIN, | 'agent_command': AGENT_START_BUILTIN, | ||||
'data_dir': "/var/lib/waagent", | 'data_dir': "/var/lib/waagent", | ||||
'set_hostname': True, | 'set_hostname': True, | ||||
'hostname_bounce': { | 'hostname_bounce': { | ||||
- 'interface': 'eth0', | - 'interface': 'eth0', | ||||
+ 'interface': DEFAULT_PRIMARY_NIC, | + 'interface': DEFAULT_PRIMARY_NIC, | ||||
'policy': True, | 'policy': True, | ||||
'command': BOUNCE_COMMAND, | 'command': BOUNCE_COMMAND, | ||||
'hostname_command': 'hostname', | 'hostname_command': 'hostname', | ||||
}, | }, | ||||
'disk_aliases': {'ephemeral0': RESOURCE_DISK_PATH}, | 'disk_aliases': {'ephemeral0': RESOURCE_DISK_PATH}, | ||||
- 'dhclient_lease_file': '/var/lib/dhcp/dhclient.eth0.leases', | - 'dhclient_lease_file': '/var/lib/dhcp/dhclient.eth0.leases', | ||||
+ 'dhclient_lease_file': LEASE_FILE, | + 'dhclient_lease_file': LEASE_FILE, | ||||
} | } | ||||
BUILTIN_CLOUD_CONFIG = { | BUILTIN_CLOUD_CONFIG = { | ||||
@@ -53,7 +195,7 @@ BUILTIN_CLOUD_CONFIG = { | @@ -53,7 +205,7 @@ BUILTIN_CLOUD_CONFIG = { | ||||
'layout': [100], | 'layout': [100], | ||||
'overwrite': True}, | 'overwrite': True}, | ||||
}, | }, | ||||
- 'fs_setup': [{'filesystem': 'ext4', | - 'fs_setup': [{'filesystem': 'ext4', | ||||
+ 'fs_setup': [{'filesystem': DEFAULT_FS, | + 'fs_setup': [{'filesystem': DEFAULT_FS, | ||||
'device': 'ephemeral0.1', | 'device': 'ephemeral0.1', | ||||
'replace_fs': 'ntfs'}], | 'replace_fs': 'ntfs'}], | ||||
} | } | ||||
@@ -178,7 +320,11 @@ class DataSourceAzureNet(sources.DataSource): | @@ -178,7 +330,11 @@ class DataSourceAzureNet(sources.DataSource): | ||||
for cdev in candidates: | for cdev in candidates: | ||||
try: | try: | ||||
if cdev.startswith("/dev/"): | if cdev.startswith("/dev/"): | ||||
- ret = util.mount_cb(cdev, load_azure_ds_dir) | - ret = util.mount_cb(cdev, load_azure_ds_dir) | ||||
+ if util.is_FreeBSD(): | + if util.is_FreeBSD(): | ||||
+ ret = util.mount_cb(cdev, load_azure_ds_dir, | + ret = util.mount_cb(cdev, load_azure_ds_dir, | ||||
+ mtype="udf", sync=False) | + mtype="udf", sync=False) | ||||
+ else: | + else: | ||||
+ ret = util.mount_cb(cdev, load_azure_ds_dir) | + ret = util.mount_cb(cdev, load_azure_ds_dir) | ||||
else: | else: | ||||
ret = load_azure_ds_dir(cdev) | 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) | LOG.debug("using files cached in %s", ddir) | ||||
# azure / hyper-v provides random data here | # azure / hyper-v provides random data here | ||||
- seed = util.load_file("/sys/firmware/acpi/tables/OEM0", | - seed = util.load_file("/sys/firmware/acpi/tables/OEM0", | ||||
- quiet=True, decode=False) | - quiet=True, decode=False) | ||||
- if seed: | - if seed: | ||||
- self.metadata['random_seed'] = seed | - self.metadata['random_seed'] = seed | ||||
+ if not util.is_FreeBSD(): | + if not util.is_FreeBSD(): | ||||
+ seed = util.load_file("/sys/firmware/acpi/tables/OEM0", | + seed = util.load_file("/sys/firmware/acpi/tables/OEM0", | ||||
+ quiet=True, decode=False) | + quiet=True, decode=False) | ||||
+ if seed: | + if seed: | ||||
+ self.metadata['random_seed'] = seed | + self.metadata['random_seed'] = seed | ||||
+ # TODO. find the seed on FreeBSD platform | + # TODO. find the seed on FreeBSD platform | ||||
# now update ds_cfg to reflect contents pass in config | # now update ds_cfg to reflect contents pass in config | ||||
user_ds_cfg = util.get_cfg_by_path(self.cfg, DS_CFG_PATH, {}) | user_ds_cfg = util.get_cfg_by_path(self.cfg, DS_CFG_PATH, {}) | ||||
self.ds_cfg = util.mergemanydict([user_ds_cfg, self.ds_cfg]) | 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(): | def list_possible_azure_ds_devs(): | ||||
# return a sorted list of devices that might have a azure datasource | # return a sorted list of devices that might have a azure datasource | ||||
devlist = [] | devlist = [] | ||||
- for fstype in ("iso9660", "udf"): | - for fstype in ("iso9660", "udf"): | ||||
- devlist.extend(util.find_devs_with("TYPE=%s" % fstype)) | - devlist.extend(util.find_devs_with("TYPE=%s" % fstype)) | ||||
+ if util.is_FreeBSD(): | + if util.is_FreeBSD(): | ||||
+ cdrom_dev = "/dev/cd0" | + cdrom_dev = "/dev/cd0" | ||||
+ try: | + try: | ||||
+ util.subp(["mount", "-o", "ro", "-t", "udf", cdrom_dev, | + with open(cdrom_dev) as fp: | ||||
+ "/mnt/cdrom/secure"]) | + fp.read(1024) | ||||
+ except util.ProcessExecutionError: | |||||
+ LOG.debug("Fail to mount cd") | |||||
+ return devlist | |||||
+ util.subp(["umount", "/mnt/cdrom/secure"]) | |||||
+ devlist.append(cdrom_dev) | + devlist.append(cdrom_dev) | ||||
+ except IOError: | |||||
+ LOG.debug("cdrom (%s) is not configured", cdrom_dev) | |||||
+ else: | + else: | ||||
+ for fstype in ("iso9660", "udf"): | + for fstype in ("iso9660", "udf"): | ||||
+ devlist.extend(util.find_devs_with("TYPE=%s" % fstype)) | + devlist.extend(util.find_devs_with("TYPE=%s" % fstype)) | ||||
devlist.sort(reverse=True) | devlist.sort(reverse=True) | ||||
return devlist | return devlist | ||||
--- cloudinit/sources/helpers/azure.py.orig 2016-12-23 16:37:45 UTC | --- cloudinit/sources/helpers/azure.py.orig 2016-12-23 16:37:45 UTC | ||||
+++ cloudinit/sources/helpers/azure.py | +++ cloudinit/sources/helpers/azure.py | ||||
▲ Show 20 Lines • Show All 507 Lines • Show Last 20 Lines |
This needs to be "ifconfig $i down" and "ifconfig $i up".
Interface name comes first.