Skip to content

Commit

Permalink
detect config_host when running from bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
karmab committed Apr 17, 2020
1 parent 77ee0b8 commit fcef009
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions kvirt/kvm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt'
iftype = 'network'
sourcexml = "<source network='%s'/>" % netname
elif netname in bridges or ovs:
if 'ip' in allnetworks[netname] and 'config_host' not in overrides:
overrides['config_host'] = allnetworks[netname]['ip']
iftype = 'bridge'
sourcexml = "<source bridge='%s'/>" % netname
guestagent = True
Expand Down Expand Up @@ -2547,8 +2549,10 @@ def list_networks(self):
netmask = attributes.get('netmask')
netmask = attributes.get('prefix') if netmask is None else netmask
ipnet = '%s/%s' % (firstip, netmask) if netmask is not None else firstip
ip = IPNetwork(ipnet)
cidr = ip.cidr
ipnet = IPNetwork(ipnet)
cidr = ipnet.cidr
else:
ip = None
dhcp = list(root.getiterator('dhcp'))
if dhcp:
dhcp = True
Expand All @@ -2567,6 +2571,8 @@ def list_networks(self):
else:
mode = 'isolated'
networks[networkname] = {'cidr': cidr, 'dhcp': dhcp, 'domain': domainname, 'type': 'routed', 'mode': mode}
if ip is not None:
networks[networkname]['ip'] = ip
plan = 'N/A'
for element in list(root.getiterator('{kvirt}info')):
e = element.find('{kvirt}plan')
Expand All @@ -2587,11 +2593,14 @@ def list_networks(self):
attributes = ip[0].attrib
ip = attributes.get('address')
prefix = attributes.get('prefix')
ip = IPNetwork('%s/%s' % (ip, prefix))
cidr = ip.cidr
ipnet = IPNetwork('%s/%s' % (ip, prefix))
cidr = ipnet.cidr
else:
ip = None
cidr = 'N/A'
networks[interfacename] = {'cidr': cidr, 'dhcp': 'N/A', 'type': 'bridged', 'mode': 'N/A'}
if ip is not None:
networks[interfacename]['ip'] = ip
plan = 'N/A'
for element in list(root.getiterator('{kvirt}info')):
e = element.find('{kvirt}plan')
Expand Down

0 comments on commit fcef009

Please sign in to comment.