|
Karanbir Singh |
2fc45d |
diff -uNr cloud-init-0.7.5__orig/cloudinit/sources/DataSourceOpenNebula.py cloud-init-0.7.5/cloudinit/sources/DataSourceOpenNebula.py
|
|
Karanbir Singh |
2fc45d |
--- cloud-init-0.7.5__orig/cloudinit/sources/DataSourceOpenNebula.py 2014-04-01 19:26:07.000000000 +0100
|
|
Karanbir Singh |
2fc45d |
+++ cloud-init-0.7.5/cloudinit/sources/DataSourceOpenNebula.py 2014-07-29 20:20:20.286992747 +0100
|
|
Karanbir Singh |
2fc45d |
@@ -29,6 +29,7 @@
|
|
Karanbir Singh |
2fc45d |
import pwd
|
|
Karanbir Singh |
2fc45d |
import re
|
|
Karanbir Singh |
2fc45d |
import string # pylint: disable=W0402
|
|
Karanbir Singh |
2fc45d |
+#import sys
|
|
Karanbir Singh |
2fc45d |
|
|
Karanbir Singh |
2fc45d |
from cloudinit import log as logging
|
|
Karanbir Singh |
2fc45d |
from cloudinit import sources
|
|
Karanbir Singh |
2fc45d |
@@ -149,7 +150,7 @@
|
|
Karanbir Singh |
2fc45d |
|
|
Karanbir Singh |
2fc45d |
class OpenNebulaNetwork(object):
|
|
Karanbir Singh |
2fc45d |
REG_DEV_MAC = re.compile(
|
|
Karanbir Singh |
2fc45d |
- r'^\d+: (eth\d+):.*?link\/ether (..:..:..:..:..:..) ?',
|
|
Karanbir Singh |
2fc45d |
+ r'^\d+: (\w+):.*?link\/\w+ (..:..:..:..:..:..) ?',
|
|
Karanbir Singh |
2fc45d |
re.MULTILINE | re.DOTALL)
|
|
Karanbir Singh |
2fc45d |
|
|
Karanbir Singh |
2fc45d |
def __init__(self, ip, context):
|
|
Karanbir Singh |
2fc45d |
@@ -158,7 +159,11 @@
|
|
Karanbir Singh |
2fc45d |
self.ifaces = self.get_ifaces()
|
|
Karanbir Singh |
2fc45d |
|
|
Karanbir Singh |
2fc45d |
def get_ifaces(self):
|
|
Karanbir Singh |
2fc45d |
- return self.REG_DEV_MAC.findall(self.ip)
|
|
Karanbir Singh |
2fc45d |
+ list = self.REG_DEV_MAC.findall(self.ip)
|
|
Karanbir Singh |
2fc45d |
+ ifaces = dict()
|
|
Karanbir Singh |
2fc45d |
+ for l in list:
|
|
Karanbir Singh |
2fc45d |
+ ifaces[l[1]] = l[0]
|
|
Karanbir Singh |
2fc45d |
+ return ifaces
|
|
Karanbir Singh |
2fc45d |
|
|
Karanbir Singh |
2fc45d |
def mac2ip(self, mac):
|
|
Karanbir Singh |
2fc45d |
components = mac.split(':')[2:]
|
|
Karanbir Singh |
2fc45d |
@@ -206,6 +211,15 @@
|
|
Karanbir Singh |
2fc45d |
else:
|
|
Karanbir Singh |
2fc45d |
return None
|
|
Karanbir Singh |
2fc45d |
|
|
Karanbir Singh |
2fc45d |
+ def get_context_interfaces(self):
|
|
Karanbir Singh |
2fc45d |
+
|
|
Karanbir Singh |
2fc45d |
+ def device_mac(t): return re.match(r"ETH\d+_MAC", t)
|
|
Karanbir Singh |
2fc45d |
+
|
|
Karanbir Singh |
2fc45d |
+ mac_vars = filter(device_mac, self.context.keys())
|
|
Karanbir Singh |
2fc45d |
+
|
|
Karanbir Singh |
2fc45d |
+ context_interfaces = [v.split('_')[0] for v in mac_vars]
|
|
Karanbir Singh |
2fc45d |
+ return context_interfaces
|
|
Karanbir Singh |
2fc45d |
+
|
|
Karanbir Singh |
2fc45d |
def gen_conf(self):
|
|
Karanbir Singh |
2fc45d |
global_dns = []
|
|
Karanbir Singh |
2fc45d |
if 'DNS' in self.context:
|
|
Karanbir Singh |
2fc45d |
@@ -216,27 +230,37 @@
|
|
Karanbir Singh |
2fc45d |
conf.append('iface lo inet loopback')
|
|
Karanbir Singh |
2fc45d |
conf.append('')
|
|
Karanbir Singh |
2fc45d |
|
|
Karanbir Singh |
2fc45d |
- for i in self.ifaces:
|
|
Karanbir Singh |
2fc45d |
- dev = i[0]
|
|
Karanbir Singh |
2fc45d |
- mac = i[1]
|
|
Karanbir Singh |
2fc45d |
+ context_interfaces = self.get_context_interfaces()
|
|
Karanbir Singh |
2fc45d |
+
|
|
Karanbir Singh |
2fc45d |
+ if len(context_interfaces):
|
|
Karanbir Singh |
2fc45d |
+ try:
|
|
Karanbir Singh |
2fc45d |
+ (out, _err) = util.subp(["systemctl", "stop", "NetworkManager"])
|
|
Karanbir Singh |
2fc45d |
+ (out, _err) = util.subp(["systemctl", "disable", "NetworkManager"])
|
|
Karanbir Singh |
2fc45d |
+ except util.ProcessExecutionError:
|
|
Karanbir Singh |
2fc45d |
+ util.logexc(LOG, "Disable NetworkManager command failed")
|
|
Karanbir Singh |
2fc45d |
+
|
|
Karanbir Singh |
2fc45d |
+ for interface in context_interfaces:
|
|
Karanbir Singh |
2fc45d |
+ mac = self.context[interface+"_MAC"]
|
|
Karanbir Singh |
2fc45d |
+ dev = self.ifaces[mac]
|
|
Karanbir Singh |
2fc45d |
+
|
|
Karanbir Singh |
2fc45d |
ip_components = self.mac2ip(mac)
|
|
Karanbir Singh |
2fc45d |
|
|
Karanbir Singh |
2fc45d |
conf.append('auto ' + dev)
|
|
Karanbir Singh |
2fc45d |
conf.append('iface ' + dev + ' inet static')
|
|
Karanbir Singh |
2fc45d |
- conf.append(' address ' + self.get_ip(dev, ip_components))
|
|
Karanbir Singh |
2fc45d |
- conf.append(' network ' + self.get_network(dev, ip_components))
|
|
Karanbir Singh |
2fc45d |
- conf.append(' netmask ' + self.get_mask(dev))
|
|
Karanbir Singh |
2fc45d |
+ conf.append(' address ' + self.get_ip(interface, ip_components))
|
|
Karanbir Singh |
2fc45d |
+ conf.append(' network ' + self.get_network(interface, ip_components))
|
|
Karanbir Singh |
2fc45d |
+ conf.append(' netmask ' + self.get_mask(interface))
|
|
Karanbir Singh |
2fc45d |
|
|
Karanbir Singh |
2fc45d |
- gateway = self.get_gateway(dev)
|
|
Karanbir Singh |
2fc45d |
+ gateway = self.get_gateway(interface)
|
|
Karanbir Singh |
2fc45d |
if gateway:
|
|
Karanbir Singh |
2fc45d |
conf.append(' gateway ' + gateway)
|
|
Karanbir Singh |
2fc45d |
|
|
Karanbir Singh |
2fc45d |
- domain = self.get_domain(dev)
|
|
Karanbir Singh |
2fc45d |
+ domain = self.get_domain(interface)
|
|
Karanbir Singh |
2fc45d |
if domain:
|
|
Karanbir Singh |
2fc45d |
conf.append(' dns-search ' + domain)
|
|
Karanbir Singh |
2fc45d |
|
|
Karanbir Singh |
2fc45d |
# add global DNS servers to all interfaces
|
|
Karanbir Singh |
2fc45d |
- dns = self.get_dns(dev)
|
|
Karanbir Singh |
2fc45d |
+ dns = self.get_dns(interface)
|
|
Karanbir Singh |
2fc45d |
if global_dns or dns:
|
|
Karanbir Singh |
2fc45d |
all_dns = global_dns
|
|
Karanbir Singh |
2fc45d |
if dns:
|
|
Karanbir Singh |
2fc45d |
@@ -404,8 +428,8 @@
|
|
Karanbir Singh |
2fc45d |
|
|
Karanbir Singh |
2fc45d |
if ssh_key_var:
|
|
Karanbir Singh |
2fc45d |
lines = context.get(ssh_key_var).splitlines()
|
|
Karanbir Singh |
2fc45d |
- results['metadata']['public-keys'] = [l for l in lines
|
|
Karanbir Singh |
2fc45d |
- if len(l) and not l.startswith("#")]
|
|
Karanbir Singh |
2fc45d |
+ ssh_keys = [l for l in lines if len(l) and not l.startswith("#")]
|
|
Karanbir Singh |
2fc45d |
+ results['metadata']['public-keys'] = ssh_keys
|
|
Karanbir Singh |
2fc45d |
|
|
Karanbir Singh |
2fc45d |
# custom hostname -- try hostname or leave cloud-init
|
|
Karanbir Singh |
2fc45d |
# itself create hostname from IP address later
|
|
Karanbir Singh |
2fc45d |
@@ -453,3 +477,4 @@
|
|
Karanbir Singh |
2fc45d |
# Return a list of data sources that match this set of dependencies
|
|
Karanbir Singh |
2fc45d |
def get_datasource_list(depends):
|
|
Karanbir Singh |
2fc45d |
return sources.list_from_depends(depends, datasources)
|
|
Karanbir Singh |
2fc45d |
+
|