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

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,
# FIXME: broken network reference: the instance NIC specifies a
# network, but the relevant network entry was not in the config. This
# 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:
env["INSTANCE_NIC%d_BRIDGE" % idx] = link
else:
......
......@@ -148,29 +148,6 @@ def _OpenTap(vnet_hdr=True):
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:
"""QEMU Messaging Protocol (QMP) message.
......@@ -854,9 +831,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
if nic.network:
n = objects.Network.FromDict(nic.netinfo)
_BuildNetworkEnv(nic.network, n.network, n.gateway,
n.network6, n.gateway6,
n.mac_prefix, n.tags, env)
env.update(n.HooksDict())
if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
env["BRIDGE"] = nic.nicparams[constants.NIC_LINK]
......
......@@ -2043,7 +2043,7 @@ class Network(TaggableObject):
"ext_reservations",
] + _TIMESTAMPS + _UUID
def HooksDict(self, prefix):
def HooksDict(self, prefix=""):
"""Export a dictionary used by hooks with a network's information.
@type prefix: String
......@@ -2051,7 +2051,7 @@ class Network(TaggableObject):
"""
result = {
"%sNETWORK" % prefix: self.name,
"%sNETWORK_NAME" % prefix: self.name,
"%sNETWORK_UUID" % prefix: self.uuid,
"%sNETWORK_TAGS" % prefix: " ".join(self.tags),
}
......
......@@ -118,7 +118,7 @@ NIC_%N_FRONTEND_TYPE
instance, this can be one of: ``rtl8139``, ``ne2k_pci``,
``ne2k_isa``, ``paravirtual``.
NIC_%d_NETWORK
NIC_%d_NETWORK_NAME
(Optional) If a NIC network is specified, the network's name.
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