Commit cbe4a0a5 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Iustin Pop
Browse files

Pass netinfo in rpcs



If a nic has a network field then encapsulate a network object in
netinfo slot for every rpc. This is needed to pass network info to
scripts managing nics (kvm-vif-bridge).

Introduce _BuildNetworkEnv().
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 58bf877f
......@@ -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))
......
......@@ -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]
......
......@@ -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):
......
#
#
# 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)):
......
......@@ -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):
......
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