Skip to content

Commit

Permalink
Only update if there are networks to update
Browse files Browse the repository at this point in the history
Fixes bug 917812

Change-Id: Ibb59e2ae634590fe57e777b720a84580c6ed64cc
  • Loading branch information
Johannes Erdfelt committed Jan 17, 2012
1 parent 8c1e002 commit 7397d8f
Showing 1 changed file with 58 additions and 52 deletions.
Expand Up @@ -139,6 +139,57 @@ def _create_subnet(version, network, vif):

return subnet

def _update_network(vif, network):
# vifs have a network which has subnets, so create the subnets
# subnets contain all of the ip information
network['subnets'] = []

network['dns1'] = _ip_dict_from_string(network['dns1'], 'dns')
network['dns2'] = _ip_dict_from_string(network['dns2'], 'dns')

# nova networks can only have 2 subnets
if network['cidr']:
network['subnets'].append(_create_subnet(4, network, vif))
if network['cidr_v6']:
network['subnets'].append(_create_subnet(6, network, vif))

# put network together to fit model
network['id'] = network.pop('uuid')
network['meta'] = {}

# NOTE(tr3buchet) this isn't absolutely necessary as hydration
# would still work with these as keys, but cache generated by
# the model would show these keys as a part of meta. i went
# ahead and set it up the same way just so it looks the same
if network['project_id']:
network['meta']['project_id'] = network['project_id']
del network['project_id']
if network['injected']:
network['meta']['injected'] = network['injected']
del network['injected']
if network['multi_host']:
network['meta']['multi_host'] = network['multi_host']
del network['multi_host']
if network['bridge_interface']:
network['meta']['bridge_interface'] = \
network['bridge_interface']
del network['bridge_interface']
if network['vlan']:
network['meta']['vlan'] = network['vlan']
del network['vlan']

# ip information now lives in the subnet, pull them out of network
del network['dns1']
del network['dns2']
del network['cidr']
del network['cidr_v6']
del network['gateway']
del network['gateway_v6']

# don't need meta if it's empty
if not network['meta']:
del network['meta']

# preload caches table
# list is made up of a row(instance_id, nw_info_json) for each instance
for instance in get_instances():
Expand All @@ -152,59 +203,14 @@ def _create_subnet(version, network, vif):
logging.info("VIFs for Instance %s: \n %s" % \
(instance['uuid'], nw_info))
for vif in nw_info:
network = get_network_by_id(vif['network_id'])[0]
logging.info("Network for Instance %s: \n %s" % \
networks_ = get_network_by_id(vif['network_id'])
if networks_:
network = networks_[0]
logging.info("Network for Instance %s: \n %s" % \
(instance['uuid'], network))

# vifs have a network which has subnets, so create the subnets
# subnets contain all of the ip information
network['subnets'] = []

network['dns1'] = _ip_dict_from_string(network['dns1'], 'dns')
network['dns2'] = _ip_dict_from_string(network['dns2'], 'dns')

# nova networks can only have 2 subnets
if network['cidr']:
network['subnets'].append(_create_subnet(4, network, vif))
if network['cidr_v6']:
network['subnets'].append(_create_subnet(6, network, vif))

# put network together to fit model
network['id'] = network.pop('uuid')
network['meta'] = {}

# NOTE(tr3buchet) this isn't absolutely necessary as hydration
# would still work with these as keys, but cache generated by
# the model would show these keys as a part of meta. i went
# ahead and set it up the same way just so it looks the same
if network['project_id']:
network['meta']['project_id'] = network['project_id']
del network['project_id']
if network['injected']:
network['meta']['injected'] = network['injected']
del network['injected']
if network['multi_host']:
network['meta']['multi_host'] = network['multi_host']
del network['multi_host']
if network['bridge_interface']:
network['meta']['bridge_interface'] = \
network['bridge_interface']
del network['bridge_interface']
if network['vlan']:
network['meta']['vlan'] = network['vlan']
del network['vlan']

# ip information now lives in the subnet, pull them out of network
del network['dns1']
del network['dns2']
del network['cidr']
del network['cidr_v6']
del network['gateway']
del network['gateway_v6']

# don't need meta if it's empty
if not network['meta']:
del network['meta']
_update_network(vif, network)
else:
network = None

# put vif together to fit model
del vif['network_id']
Expand Down

0 comments on commit 7397d8f

Please sign in to comment.