diff options
author | Vlastimil Holer <vlastimil.holer@gmail.com> | 2013-01-04 15:26:11 +0100 |
---|---|---|
committer | Vlastimil Holer <vlastimil.holer@gmail.com> | 2013-01-04 15:26:11 +0100 |
commit | 5bfbf7a81872afd426271b0ed3ed65e76b9a584e (patch) | |
tree | a5a8a6aa94e845986d1ecb89f89aace82a2f23ff | |
parent | 5aab64f71c1f07670b59dd7be18d704611dc0ab5 (diff) | |
download | vyos-cloud-init-5bfbf7a81872afd426271b0ed3ed65e76b9a584e.tar.gz vyos-cloud-init-5bfbf7a81872afd426271b0ed3ed65e76b9a584e.zip |
Append DNS related stuff to network interfaces configuration. Minor cleanups.
-rw-r--r-- | cloudinit/sources/DataSourceOpenNebula.py | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/cloudinit/sources/DataSourceOpenNebula.py b/cloudinit/sources/DataSourceOpenNebula.py index 57b0c62c..52474675 100644 --- a/cloudinit/sources/DataSourceOpenNebula.py +++ b/cloudinit/sources/DataSourceOpenNebula.py @@ -103,12 +103,11 @@ class DataSourceOpenNebula(sources.DataSource): self.metadata = md self.userdata_raw = results.get('userdata') - if 'network-interfaces' in results: + # apply static network configuration only in 'local' dsmode + if ('network-interfaces' in results and self.dsmode == "local"): + LOG.debug("Updating network interfaces from %s", self) self.distro.apply_network(results['network-interfaces']) - if 'dns' in results: - self.distro.apply_resolv_conf(results['dns']) - return True def get_hostname(self, fqdn=False, resolve_ip=None): @@ -175,7 +174,25 @@ class OpenNebulaNetwork(object): else: None + def get_dns(self, dev, components): + var_name=dev+'_dns' + if var_name in self.context_sh: + return self.context_sh[var_name] + else: + None + + def get_domain(self, dev, components): + var_name=dev+'_domain' + if var_name in self.context_sh: + return self.context_sh[var_name] + else: + None + def gen_conf(self): + global_dns=[] + if 'dns' in self.context_sh: + global_dns.append(self.context_sh['dns']) + conf=[] conf.append('auto lo') conf.append('iface lo inet loopback') @@ -196,25 +213,21 @@ class OpenNebulaNetwork(object): if gateway: conf.append(' gateway '+gateway) - conf.append('') - - return "\n".join(conf) - - def gen_dns(self): - dnss=[] + domain=self.get_domain(dev, ip_components) + if domain: + conf.append(' dns-search '+domain) - if 'dns' in self.context_sh: - dnss.append('nameserver '+self.context_sh['dns']) + # add global DNS servers to all interfaces + dns=self.get_dns(dev, ip_components) + if global_dns or dns: + all_dns=global_dns + if dns: + all_dns.append(dns) + conf.append(' dns-nameservers '+' '.join(all_dns)) - keys=[d for d in self.context_sh.keys() if re.match('^eth\d+_dns$', d)] - - for k in sorted(keys): - dnss.append('nameserver '+self.context_sh[k]) + conf.append('') - if not dnss: - return None - else: - return "\n".join(dnss)+"\n" + return "\n".join(conf) def find_candidate_devs(): @@ -280,10 +293,8 @@ def read_context_disk_dir(source_dir): 'comm -23 <(set | sort -u) <(echo "$VARS") | egrep -v "^(VARS|PIPESTATUS|_)="' (out,err) = util.subp(['bash', - '--noprofile', - '--norc', - '-c', - BASH_CMD % (source_dir) ]) + '--noprofile', '--norc', + '-c', BASH_CMD % (source_dir) ]) for (key,value) in [ l.split('=',1) for l in out.rstrip().split("\n") ]: # with backslash escapes @@ -317,13 +328,12 @@ def read_context_disk_dir(source_dir): results['metadata']['public-keys'] = [l for l in lines if len(l) and not l.startswith("#")] - # custom hostname - if 'hostname' in context_sh: - results['metadata']['local-hostname'] = context_sh['hostname'] - elif 'public_ip'in context_sh: - results['metadata']['local-hostname'] = context_sh['public_ip'] - elif 'eth0_ip' in context_sh: - results['metadata']['local-hostname'] = context_sh['eth0_ip'] + # custom hostname -- try hostname or leave cloud-init + # itself create hostname from IP address later + for k in ('hostname','public_ip','ip_public','eth0_ip'): + if k in context_sh: + results['metadata']['local-hostname'] = context_sh[k] + break # raw user data if "user_data" in context_sh: @@ -335,10 +345,6 @@ def read_context_disk_dir(source_dir): net=OpenNebulaNetwork(out, context_sh) results['network-interfaces']=net.gen_conf() - dns=net.gen_dns() - if dns: - results['dns']=dns - return results |