summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-01-17 23:31:14 +0000
committerGerrit Code Review <review@openstack.org>2012-01-17 23:31:14 +0000
commit7bb9f3413a2bc6ef56ab3c384d0624f193e58e34 (patch)
tree59b2a44a8f251ef024125cbb8614c5f6666a4abe
parent8d010cacb520786fa12794801bc31eddd23b2af7 (diff)
parent7397d8fc1dab0fed2a069af670f37f3002ae1d1d (diff)
downloadnova-7bb9f3413a2bc6ef56ab3c384d0624f193e58e34.tar.gz
nova-7bb9f3413a2bc6ef56ab3c384d0624f193e58e34.tar.xz
nova-7bb9f3413a2bc6ef56ab3c384d0624f193e58e34.zip
Merge "Only update if there are networks to update"
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/066_preload_instance_info_cache_table.py110
1 files changed, 58 insertions, 52 deletions
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/066_preload_instance_info_cache_table.py b/nova/db/sqlalchemy/migrate_repo/versions/066_preload_instance_info_cache_table.py
index 67a618e0c..a9a9db96e 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/066_preload_instance_info_cache_table.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/066_preload_instance_info_cache_table.py
@@ -139,6 +139,57 @@ def upgrade(migrate_engine):
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():
@@ -152,59 +203,14 @@ def upgrade(migrate_engine):
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']