summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Alekseyev <ialekseev@griddynamics.com>2011-03-17 18:06:05 +0300
committerIlya Alekseyev <ialekseev@griddynamics.com>2011-03-17 18:06:05 +0300
commitba0160cacac1c7db71eadd6624ee75a014c18378 (patch)
tree655e3a6bb3420e8c0d60f087dd3930cac3c64401
parentaf754e3bba9b2ee93147a3533319ac5a5e199f45 (diff)
refactored: network_info creation extracted to method
-rw-r--r--nova/virt/libvirt_conn.py74
1 files changed, 40 insertions, 34 deletions
diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py
index c122ac8d4..90bd5421c 100644
--- a/nova/virt/libvirt_conn.py
+++ b/nova/virt/libvirt_conn.py
@@ -154,6 +154,45 @@ def _get_ip_version(cidr):
return int(net.version())
+def _get_network_info(instance):
+ admin_context = context.get_admin_context()
+
+ ip_addresses = db.fixed_ip_get_all_by_instance(admin_context,
+ instance['id'])
+
+ networks = db.network_get_all_by_instance(admin_context,
+ instance['id'])
+ network_info = []
+
+ def ip_dict(ip):
+ return {
+ "ip": ip.address,
+ "netmask": network["netmask"],
+ "enabled": "1"}
+
+ def ip6_dict(ip6):
+ return {
+ "ip": ip6.addressV6,
+ "netmask": ip6.netmaskV6,
+ "gateway": ip6.gatewayV6,
+ "enabled": "1"}
+
+ for network in networks:
+ network_ips = [ip for ip in ip_addresses
+ if ip.network_id == network.id]
+
+ mapping = {
+ 'label': network['label'],
+ 'gateway': network['gateway'],
+ 'mac': instance.mac_address,
+ 'dns': [network['dns']],
+ 'ips': [ip_dict(ip) for ip in network_ips],
+ 'ip6s': [ip6_dict(ip) for ip in network_ips]}
+
+ network_info.append((network, mapping))
+ return network_info
+
+
class LibvirtConnection(object):
def __init__(self, read_only):
@@ -742,43 +781,10 @@ class LibvirtConnection(object):
# TODO(termie): cache?
LOG.debug(_('instance %s: starting toXML method'), instance['name'])
- ip_addresses = db.fixed_ip_get_all_by_instance(admin_context,
- instance['id'])
-
- networks = db.network_get_all_by_instance(admin_context,
- instance['id'])
-
#TODO(ilyaalekseyev) remove network_info creation code
# when multinics will be completed
if network_info is None:
- network_info = []
-
- def ip_dict(ip):
- return {
- "ip": ip.address,
- "netmask": network["netmask"],
- "enabled": "1"}
-
- def ip6_dict(ip6):
- return {
- "ip": ip6.addressV6,
- "netmask": ip6.netmaskV6,
- "gateway": ip6.gatewayV6,
- "enabled": "1"}
-
- for network in networks:
- network_ips = [ip for ip in ip_addresses
- if ip.network_id == network.id]
-
- mapping = {
- 'label': network['label'],
- 'gateway': network['gateway'],
- 'mac': instance.mac_address,
- 'dns': [network['dns']],
- 'ips': [ip_dict(ip) for ip in network_ips],
- 'ip6s': [ip6_dict(ip) for ip in network_ips]}
-
- network_info.append((network, mapping))
+ network_info = _get_network_info(instance)
nics = []
for (network, mapping) in network_info: