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))
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]
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):
import base64
import pycurl
import threading
+import copy
from ganeti import utils
from ganeti import objects
rpc_defs.ED_INST_DICT: self._InstDict,
rpc_defs.ED_INST_DICT_HVP_BEP: self._InstDictHvpBep,
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,
_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.
nic["nicparams"] = objects.FillDict(
cluster.nicparams[constants.PP_DEFAULT],
nic["nicparams"])
+ 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 _InstDictHvpBep(self, (instance, hvp, bep)):
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):