diff --git a/cloudinit/config/cc_vyos.py b/cloudinit/config/cc_vyos.py index d01f1fc1..0f1289ac 100644 --- a/cloudinit/config/cc_vyos.py +++ b/cloudinit/config/cc_vyos.py @@ -137,10 +137,55 @@ def set_config_ovf(config, hostname, metadata): config.set(['system', 'host-name'], value=hostname, replace=True) +def set_config_nocloud(config, hostname, metadata, _network_config): + if _network_config["version"] == 1: + for interface in _network_config["config"]: + if interface["type"] == "physical": + name = interface["name"] + for subnet in interface["subnets"]: + if subnet["type"] == "static": + ip = subnet["address"] + mask = subnet["netmask"] + gateway = subnet["gateway"] + cidr = str(IPv4Network('0.0.0.0/' + mask).prefixlen) + ipcidr = ip + '/' + cidr + config.set(['interfaces', 'ethernet', name, 'address'], value=ipcidr, replace=True) + config.set_tag(['interfaces', 'ethernet']) + if gateway != '': + config.set(['protocols', 'static', 'route', '0.0.0.0/0', 'next-hop'], value=gateway, replace=True) + config.set_tag(['protocols', 'static', 'route']) + config.set_tag(['protocols', 'static', 'route', '0.0.0.0/0', 'next-hop']) + continue + if subnet["type"] == "dhcp4": + config.set(['interfaces', 'ethernet', name, 'address'], value='dhcp', replace=True) + config.set_tag(['interfaces', 'ethernet']) + continue + else: + continue + continue + if interface["type"] == "nameserver": + DNS = interface["address"] + if DNS: + for server in DNS: + config.set(['system', 'name-server'], value=server, replace=False) + search = interface["search"] + if search: + for domain in search: + config.set(['system', 'domain-name'], value=domain, replace=True) + continue + else: + continue + if hostname != '': + config.set(['system', 'host-name'], value=hostname, replace=True) + config.set(['service', 'ssh'], replace=True) + config.set(['service', 'ssh', 'port'], value='22', replace=True) + + def handle(name, cfg, cloud, log, _args): cfg_file_name = '/opt/vyatta/etc/config/config.boot' bak_file_name = '/opt/vyatta/etc/config.boot.default' metadata = cloud.datasource.metadata + _network_config = cloud.datasource._network_config (users, groups) = ug_util.normalize_users_groups(cfg, cloud.distro) (hostname, fqdn) = util.get_hostname_fqdn(cfg, cloud) encrypted_pass = False @@ -183,6 +225,21 @@ def handle(name, cfg, cloud, log, _args): set_ssh_login(config, log, user, ssh_key, key_x) key_x = key_x + 1 set_config_ovf(config, hostname, metadata) + elif 'NoCloud' in str(cloud.datasource): + for user in users: + password = util.get_cfg_option_str(cfg, 'passwd', None) + if password: + set_pass_login(config, user, password, encrypted_pass) + + vyos_keys = cloud.get_public_ssh_keys() or [] + if 'ssh_authorized_keys' in cfg: + cfgkeys = cfg['ssh_authorized_keys'] + vyos_keys.extend(cfgkeys) + + for ssh_key in vyos_keys: + set_ssh_login(config, log, user, ssh_key, key_x) + key_x = key_x + 1 + set_config_nocloud(config, hostname, metadata, _network_config) else: for user in users: password = util.get_cfg_option_str(cfg, 'passwd', None)