diff --git a/lib/client/gnt_instance.py b/lib/client/gnt_instance.py index 4a9458dab7dd7aeebaecd2d555f7b6f1fc9d8eb8..8b35427e28543738c8d12809c0c7be2cc1a57e1b 100644 --- a/lib/client/gnt_instance.py +++ b/lib/client/gnt_instance.py @@ -1178,7 +1178,7 @@ def ShowInstanceConfig(opts, args): FormatParameterDict(buf, instance["be_instance"], be_actual, level=2) # TODO(ganeti 2.7) rework the NICs as well buf.write(" - NICs:\n") - for idx, (ip, mac, mode, link, network) in enumerate(instance["nics"]): + for idx, (ip, mac, mode, link, network, _) in enumerate(instance["nics"]): buf.write(" - nic/%d: MAC: %s, IP: %s," " mode: %s, link: %s, network: %s\n" % (idx, mac, ip, mode, link, network)) diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py index 71f3e925e2d01d67dda17502ec7c93719f65fff0..576d1c2253f402e4c34370a9a4ce18d6f84e2c40 100644 --- a/lib/hypervisor/hv_kvm.py +++ b/lib/hypervisor/hv_kvm.py @@ -775,8 +775,33 @@ class KVMHypervisor(hv_base.BaseHypervisor): if nic.nicparams[constants.NIC_LINK]: env["LINK"] = nic.nicparams[constants.NIC_LINK] + def _BuildNetworkEnv(name, network, gateway, network6, gateway6, + network_type, mac_prefix, tags, env): + 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 network_type: + env["NETWORK_TYPE"] = network_type + if tags: + env["NETWORK_TAGS"] = " ".join(tags) + + return env + + if nic.network: - env["NETWORK"] = nic.network + n = objects.Network.FromDict(nic.netinfo) + _BuildNetworkEnv(nic.network, n.network, n.gateway, + n.network6, n.gateway6, n.network_type, + n.mac_prefix, n.tags, env) if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED: env["BRIDGE"] = nic.nicparams[constants.NIC_LINK] diff --git a/lib/objects.py b/lib/objects.py index a31b2a54269ca0fab8c9c24fde0a92b36b82c237..df7ac7ea8816bb73996050343ee27def0dc70e57 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -503,7 +503,7 @@ class ConfigData(ConfigObject): class NIC(ConfigObject): """Config object representing a network card.""" - __slots__ = ["mac", "ip", "network", "nicparams"] + __slots__ = ["mac", "ip", "network", "nicparams", "netinfo"] @classmethod def CheckParameterSyntax(cls, nicparams): diff --git a/lib/rpc.py b/lib/rpc.py index 87fd81fbddf7d1e408b7f5f4933d4680c9f7095f..6f8326c6518e629720ac84d04efaa3947248e261 100644 --- a/lib/rpc.py +++ b/lib/rpc.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc. +# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -35,6 +35,7 @@ import zlib import base64 import pycurl import threading +import copy from ganeti import utils from ganeti import objects @@ -666,6 +667,7 @@ class RpcRunner(_RpcClientBase, rpc_defs.ED_INST_DICT: self._InstDict, rpc_defs.ED_INST_DICT_HVP_BEP_DP: self._InstDictHvpBepDp, rpc_defs.ED_INST_DICT_OSP_DP: self._InstDictOspDp, + rpc_defs.ED_NIC_DICT: self._NicDict, # Encoders annotating disk parameters rpc_defs.ED_DISKS_DICT_DP: self._DisksDictDP, @@ -691,6 +693,18 @@ class RpcRunner(_RpcClientBase, _generated_rpc.RpcClientDnsOnly.__init__(self) _generated_rpc.RpcClientDefault.__init__(self) + def _NicDict(self, nic): + """Convert the given nic to a dict and encapsulate netinfo + + """ + n = copy.deepcopy(nic) + if n.network: + net_uuid = self._cfg.LookupNetwork(n.network) + if net_uuid: + nobj = self._cfg.GetNetwork(net_uuid) + n.netinfo = objects.Network.ToDict(nobj) + return n.ToDict() + def _InstDict(self, instance, hvp=None, bep=None, osp=None): """Convert the given instance to a dict. @@ -721,11 +735,17 @@ class RpcRunner(_RpcClientBase, idict["osparams"] = cluster.SimpleFillOS(instance.os, instance.osparams) if osp is not None: idict["osparams"].update(osp) + idict["disks"] = self._DisksDictDP((instance.disks, instance)) for nic in idict["nics"]: nic["nicparams"] = objects.FillDict( cluster.nicparams[constants.PP_DEFAULT], nic["nicparams"]) - idict["disks"] = self._DisksDictDP((instance.disks, instance)) + network = nic.get("network", None) + if network: + net_uuid = self._cfg.LookupNetwork(network) + if net_uuid: + nobj = self._cfg.GetNetwork(net_uuid) + nic["netinfo"] = objects.Network.ToDict(nobj) return idict def _InstDictHvpBepDp(self, (instance, hvp, bep)): diff --git a/lib/rpc_defs.py b/lib/rpc_defs.py index 9e167c40defa77ac96a5386e7d45097e12230c4e..6ecd2b26fc8b74364d8f173c31be1a768f82efcb 100644 --- a/lib/rpc_defs.py +++ b/lib/rpc_defs.py @@ -70,7 +70,8 @@ ACCEPT_OFFLINE_NODE = object() ED_COMPRESS, ED_BLOCKDEV_RENAME, ED_DISKS_DICT_DP, - ED_SINGLE_DISK_DICT_DP) = range(1, 14) + ED_SINGLE_DISK_DICT_DP, + ED_NIC_DICT) = range(1, 15) def _Prepare(calls):