daemon: added support to set <address> 'iface' attribute with interface name in XML written by CORE so different interface addresses can be discriminated on <testHost> instances
This commit is contained in:
parent
139b495982
commit
46cd65c821
1 changed files with 36 additions and 7 deletions
|
@ -34,7 +34,28 @@ class CoreDeploymentWriter(object):
|
||||||
else:
|
else:
|
||||||
# TODO: handle other hosts
|
# TODO: handle other hosts
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_interface_names(hostname):
|
||||||
|
'''Uses same methodology of get_ipv4_addresses() to get
|
||||||
|
parallel list of interface names to go with ...'''
|
||||||
|
if hostname == 'localhost':
|
||||||
|
iface_list = []
|
||||||
|
cmd = (constants.IP_BIN, '-o', '-f', 'inet', 'addr', 'show')
|
||||||
|
output = subprocess.check_output(cmd)
|
||||||
|
for line in output.split(os.linesep):
|
||||||
|
split = line.split()
|
||||||
|
if not split:
|
||||||
|
continue
|
||||||
|
ifaceName = split[1]
|
||||||
|
addr = split[3]
|
||||||
|
if not addr.startswith('127.'):
|
||||||
|
iface_list.append(ifaceName)
|
||||||
|
return iface_list
|
||||||
|
else:
|
||||||
|
# TODO: handle other hosts
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def find_device(scenario, name):
|
def find_device(scenario, name):
|
||||||
tagName = ('device', 'host', 'router')
|
tagName = ('device', 'host', 'router')
|
||||||
|
@ -61,7 +82,8 @@ class CoreDeploymentWriter(object):
|
||||||
nodelist.append(obj)
|
nodelist.append(obj)
|
||||||
name = self.hostname
|
name = self.hostname
|
||||||
ipv4_addresses = self.get_ipv4_addresses('localhost')
|
ipv4_addresses = self.get_ipv4_addresses('localhost')
|
||||||
testhost = self.add_physical_host(testbed, name, ipv4_addresses)
|
iface_names = self.get_interface_names('localhost')
|
||||||
|
testhost = self.add_physical_host(testbed, name, ipv4_addresses, iface_names)
|
||||||
for n in nodelist:
|
for n in nodelist:
|
||||||
self.add_virtual_host(testhost, n)
|
self.add_virtual_host(testhost, n)
|
||||||
# TODO: handle other servers
|
# TODO: handle other servers
|
||||||
|
@ -81,9 +103,11 @@ class CoreDeploymentWriter(object):
|
||||||
el.setAttribute('id', '%s/%s' % (parent.getAttribute('id'), name))
|
el.setAttribute('id', '%s/%s' % (parent.getAttribute('id'), name))
|
||||||
return el
|
return el
|
||||||
|
|
||||||
def add_address(self, parent, address_type, address_str):
|
def add_address(self, parent, address_type, address_str, address_iface=None):
|
||||||
el = self.add_child_element(parent, 'address')
|
el = self.add_child_element(parent, 'address')
|
||||||
el.setAttribute('type', address_type)
|
el.setAttribute('type', address_type)
|
||||||
|
if address_iface is not None:
|
||||||
|
el.setAttribute('iface', address_iface)
|
||||||
el.appendChild(self.dom.createTextNode(address_str))
|
el.appendChild(self.dom.createTextNode(address_str))
|
||||||
return el
|
return el
|
||||||
|
|
||||||
|
@ -121,11 +145,16 @@ class CoreDeploymentWriter(object):
|
||||||
el = self.add_child_element_with_nameattr(parent, 'testHost', name)
|
el = self.add_child_element_with_nameattr(parent, 'testHost', name)
|
||||||
return el
|
return el
|
||||||
|
|
||||||
def add_physical_host(self, parent, name, ipv4_addresses):
|
def add_physical_host(self, parent, name, ipv4_addresses, iface_names):
|
||||||
el = self.add_host(parent, name)
|
el = self.add_host(parent, name)
|
||||||
self.add_type(el, 'physical')
|
self.add_type(el, 'physical')
|
||||||
for addr in ipv4_addresses:
|
for i in range(0, len(ipv4_addresses)):
|
||||||
self.add_address(el, 'IPv4', addr)
|
addr = ipv4_addresses[i]
|
||||||
|
if iface_names:
|
||||||
|
ifaceName = iface_names[i]
|
||||||
|
else:
|
||||||
|
ifaceName = None
|
||||||
|
self.add_address(el, 'IPv4', addr, ifaceName)
|
||||||
return el
|
return el
|
||||||
|
|
||||||
def add_virtual_host(self, parent, obj):
|
def add_virtual_host(self, parent, obj):
|
||||||
|
@ -147,7 +176,7 @@ class CoreDeploymentWriter(object):
|
||||||
addr_type = 'IPv6'
|
addr_type = 'IPv6'
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
self.add_address(el, addr_type, address)
|
self.add_address(el, addr_type, address, netif.name)
|
||||||
if isinstance(netif.net, nodes.EmaneNode):
|
if isinstance(netif.net, nodes.EmaneNode):
|
||||||
nem = self.add_emane_interface(parent, el, netif)
|
nem = self.add_emane_interface(parent, el, netif)
|
||||||
interface = self.find_interface(device, netif.name)
|
interface = self.find_interface(device, netif.name)
|
||||||
|
|
Loading…
Reference in a new issue