Commit 7e8f03e3 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Guido Trotter
Browse files

Make use of HooksDict() for networks



This can be used in hypervisor code as well. For consistency
export *NETWORK_NAME and not *NETWORK throughout the code.
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 48616625
...@@ -1512,7 +1512,7 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status, ...@@ -1512,7 +1512,7 @@ def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status,
# FIXME: broken network reference: the instance NIC specifies a # FIXME: broken network reference: the instance NIC specifies a
# network, but the relevant network entry was not in the config. This # network, but the relevant network entry was not in the config. This
# should be made impossible. # should be made impossible.
env["INSTANCE_NIC%d_NETWORK" % idx] = net env["INSTANCE_NIC%d_NETWORK_NAME" % idx] = net
if mode == constants.NIC_MODE_BRIDGED: if mode == constants.NIC_MODE_BRIDGED:
env["INSTANCE_NIC%d_BRIDGE" % idx] = link env["INSTANCE_NIC%d_BRIDGE" % idx] = link
else: else:
......
...@@ -148,29 +148,6 @@ def _OpenTap(vnet_hdr=True): ...@@ -148,29 +148,6 @@ def _OpenTap(vnet_hdr=True):
return (ifname, tapfd) return (ifname, tapfd)
def _BuildNetworkEnv(name, network, gateway, network6, gateway6,
mac_prefix, tags, env):
"""Build environment variables concerning a Network.
"""
if name:
env["NETWORK_NAME"] = name
if network:
env["NETWORK_SUBNET"] = network
if gateway:
env["NETWORK_GATEWAY"] = gateway
if network6:
env["NETWORK_SUBNET6"] = network6
if gateway6:
env["NETWORK_GATEWAY6"] = gateway6
if mac_prefix:
env["NETWORK_MAC_PREFIX"] = mac_prefix
if tags:
env["NETWORK_TAGS"] = " ".join(tags)
return env
class QmpMessage: class QmpMessage:
"""QEMU Messaging Protocol (QMP) message. """QEMU Messaging Protocol (QMP) message.
...@@ -854,9 +831,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -854,9 +831,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
if nic.network: if nic.network:
n = objects.Network.FromDict(nic.netinfo) n = objects.Network.FromDict(nic.netinfo)
_BuildNetworkEnv(nic.network, n.network, n.gateway, env.update(n.HooksDict())
n.network6, n.gateway6,
n.mac_prefix, n.tags, env)
if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED: if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
env["BRIDGE"] = nic.nicparams[constants.NIC_LINK] env["BRIDGE"] = nic.nicparams[constants.NIC_LINK]
......
...@@ -2043,7 +2043,7 @@ class Network(TaggableObject): ...@@ -2043,7 +2043,7 @@ class Network(TaggableObject):
"ext_reservations", "ext_reservations",
] + _TIMESTAMPS + _UUID ] + _TIMESTAMPS + _UUID
def HooksDict(self, prefix): def HooksDict(self, prefix=""):
"""Export a dictionary used by hooks with a network's information. """Export a dictionary used by hooks with a network's information.
@type prefix: String @type prefix: String
...@@ -2051,7 +2051,7 @@ class Network(TaggableObject): ...@@ -2051,7 +2051,7 @@ class Network(TaggableObject):
""" """
result = { result = {
"%sNETWORK" % prefix: self.name, "%sNETWORK_NAME" % prefix: self.name,
"%sNETWORK_UUID" % prefix: self.uuid, "%sNETWORK_UUID" % prefix: self.uuid,
"%sNETWORK_TAGS" % prefix: " ".join(self.tags), "%sNETWORK_TAGS" % prefix: " ".join(self.tags),
} }
......
...@@ -118,7 +118,7 @@ NIC_%N_FRONTEND_TYPE ...@@ -118,7 +118,7 @@ NIC_%N_FRONTEND_TYPE
instance, this can be one of: ``rtl8139``, ``ne2k_pci``, instance, this can be one of: ``rtl8139``, ``ne2k_pci``,
``ne2k_isa``, ``paravirtual``. ``ne2k_isa``, ``paravirtual``.
NIC_%d_NETWORK NIC_%d_NETWORK_NAME
(Optional) If a NIC network is specified, the network's name. (Optional) If a NIC network is specified, the network's name.
NIC_%d_NETWORK_UUID NIC_%d_NETWORK_UUID
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment