Commit 6af57560 authored by Klaus Aehlig's avatar Klaus Aehlig

Merge branch 'stable-2.10' into stable-2.11

* stable-2.10
  Export VLAN nicparam to NIC configuration scripts
  Fix gnt-network client to accept vlan info
  Fix query mechanism wrt networks and vlans
  Fix LUNetwork* hooks to comply with docs
  Fix LUNetworkConnect wrt vlan

Conflicts:
	lib/client/gnt_network.py
	lib/cmdlib/network.py
	qa/qa_network.py
	src/Ganeti/OpParams.hs
Resolution:
	lib/cmdlib/network.py: use stable-2.11 version
	lib/client/gnt_network.py:  use stable-2.10 version
	Rest: union of changes
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parents e4e926c2 6b47261a
......@@ -245,7 +245,7 @@ Connects a network to a nodegroup.
:directory: network-connect
:env. vars: GROUP_NAME, NETWORK_NAME,
GROUP_NETWORK_MODE, GROUP_NETWORK_LINK,
GROUP_NETWORK_MODE, GROUP_NETWORK_LINK, GROUP_NETWORK_VLAN,
NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6,
NETWORK_GATEWAY6, NETWORK_MAC_PREFIX, NETWORK_TAGS
:pre-execution: nodegroup nodes
......@@ -259,7 +259,7 @@ Disconnects a network from a nodegroup.
:directory: network-disconnect
:env. vars: GROUP_NAME, NETWORK_NAME,
GROUP_NETWORK_MODE, GROUP_NETWORK_LINK,
GROUP_NETWORK_MODE, GROUP_NETWORK_LINK, GROUP_NETWORK_VLAN,
NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6,
NETWORK_GATEWAY6, NETWORK_MAC_PREFIX, NETWORK_TAGS
:pre-execution: nodegroup nodes
......
......@@ -32,6 +32,7 @@ from ganeti import constants
from ganeti import opcodes
from ganeti import utils
from ganeti import errors
from ganeti import objects
#: default list of fields for L{ListNetworks}
......@@ -113,15 +114,18 @@ def ConnectNetwork(opts, args):
cl = GetClient()
qcl = GetClient(query=True)
(network, mode, link) = args[:3]
groups = _GetDefaultGroups(qcl, args[3:])
network = args[0]
nicparams = objects.FillDict(constants.NICC_DEFAULTS, opts.nicparams)
groups = _GetDefaultGroups(cl, args[1:])
# TODO: Change logic to support "--submit"
for group in groups:
op = opcodes.OpNetworkConnect(group_name=group,
network_name=network,
network_mode=mode,
network_link=link,
network_mode=nicparams[constants.NIC_MODE],
network_link=nicparams[constants.NIC_LINK],
network_vlan=nicparams[constants.NIC_VLAN],
conflicts_check=opts.conflicts_check)
SubmitOpCode(op, opts=opts, cl=cl)
......@@ -162,8 +166,9 @@ def ListNetworks(opts, args):
desired_fields = ParseFields(opts.output, _LIST_DEF_FIELDS)
fmtoverride = {
"group_list":
(lambda data: utils.CommaJoin("%s (%s, %s)" % (name, mode, link)
for (name, mode, link) in data),
(lambda data:
utils.CommaJoin("%s (%s, %s, %s)" % (name, mode, link, vlan)
for (name, mode, link, vlan) in data),
False),
"inst_list": (",".join, False),
"tags": (",".join, False),
......@@ -242,8 +247,9 @@ def ShowNetworkConfig(_, args):
if group_list:
ToStdout(" connected to node groups:")
for group, nic_mode, nic_link in group_list:
ToStdout(" %s (%s on %s)", group, nic_mode, nic_link)
for group, nic_mode, nic_link, nic_vlan in group_list:
ToStdout(" %s (mode:%s link:%s vlan:%s)",
group, nic_mode, nic_link, nic_vlan)
else:
ToStdout(" not connected to any node group")
......@@ -340,10 +346,8 @@ commands = {
"connect": (
ConnectNetwork,
[ArgNetwork(min=1, max=1),
ArgChoice(min=1, max=1, choices=constants.NIC_VALID_MODES),
ArgUnknown(min=1, max=1),
ArgGroup()],
[NOCONFLICTSCHECK_OPT, PRIORITY_OPT],
[NOCONFLICTSCHECK_OPT, PRIORITY_OPT, NIC_PARAMS_OPT],
"<network_name> <mode> <link> [<node_group>...]",
"Map a given network to the specified node group"
" with given mode and link (netparams)"),
......
......@@ -390,7 +390,6 @@ class LUNetworkSetParams(LogicalUnit):
self.cfg.Update(self.network, feedback_fn)
def _FmtNetworkConflict(details):
"""Utility for L{_NetworkConflictCheck}.
......@@ -449,6 +448,7 @@ class LUNetworkConnect(LogicalUnit):
self.group_name = self.op.group_name
self.network_mode = self.op.network_mode
self.network_link = self.op.network_link
self.network_vlan = self.op.network_vlan
self.network_uuid = self.cfg.LookupNetwork(self.network_name)
self.group_uuid = self.cfg.LookupNodeGroup(self.group_name)
......@@ -479,6 +479,7 @@ class LUNetworkConnect(LogicalUnit):
"GROUP_NAME": self.group_name,
"GROUP_NETWORK_MODE": self.network_mode,
"GROUP_NETWORK_LINK": self.network_link,
"GROUP_NETWORK_VLAN": self.network_vlan,
}
return ret
......@@ -499,7 +500,9 @@ class LUNetworkConnect(LogicalUnit):
self.netparams = {
constants.NIC_MODE: self.network_mode,
constants.NIC_LINK: self.network_link,
constants.NIC_VLAN: self.network_vlan,
}
objects.NIC.CheckParameterSyntax(self.netparams)
self.group = self.cfg.GetNodeGroup(self.group_uuid)
......@@ -562,6 +565,13 @@ class LUNetworkDisconnect(LogicalUnit):
ret = {
"GROUP_NAME": self.group_name,
}
if self.connected:
ret.update({
"GROUP_NETWORK_MODE": self.netparams[constants.NIC_MODE],
"GROUP_NETWORK_LINK": self.netparams[constants.NIC_LINK],
"GROUP_NETWORK_VLAN": self.netparams[constants.NIC_VLAN],
})
return ret
def BuildHooksNodes(self):
......@@ -590,6 +600,7 @@ class LUNetworkDisconnect(LogicalUnit):
self, lambda nic: nic.network == self.network_uuid, "disconnect from",
[instance_info for (_, instance_info) in
self.cfg.GetMultiInstanceInfoByName(owned_instances)])
self.netparams = self.group.networks.get(self.network_uuid)
def Exec(self, feedback_fn):
# Disconnect the network and update the group only if network is connected
......
......@@ -1098,6 +1098,9 @@ class KVMHypervisor(hv_base.BaseHypervisor):
if nic.nicparams[constants.NIC_LINK]:
env["LINK"] = nic.nicparams[constants.NIC_LINK]
if nic.nicparams[constants.NIC_VLAN]:
env["VLAN"] = nic.nicparams[constants.NIC_VLAN]
if nic.network:
n = objects.Network.FromDict(nic.netinfo)
env.update(n.HooksDict())
......
......@@ -501,6 +501,7 @@ class XenHypervisor(hv_base.BaseHypervisor):
data.write("INTERFACE_UUID=%s\n" % nic.uuid)
data.write("MODE=%s\n" % nic.nicparams[constants.NIC_MODE])
data.write("LINK=%s\n" % nic.nicparams[constants.NIC_LINK])
data.write("VLAN=%s\n" % nic.nicparams[constants.NIC_VLAN])
try:
utils.WriteFile(cfg_file, data=data.getvalue())
......
......@@ -1521,6 +1521,9 @@ class NodeGroup(TaggableObject):
if self.networks is None:
self.networks = {}
for network, netparams in self.networks.items():
self.networks[network] = FillDict(constants.NICC_DEFAULTS, netparams)
def FillND(self, node):
"""Return filled out ndparams for L{objects.Node}
......
......@@ -2018,8 +2018,8 @@ class GanetiRapiClient(object): # pylint: disable=R0904
return self._SendRequest(HTTP_POST, "/%s/networks" % GANETI_RAPI_VERSION,
query, body)
def ConnectNetwork(self, network_name, group_name, mode, link, dry_run=False,
reason=None):
def ConnectNetwork(self, network_name, group_name, mode, link,
vlan="", dry_run=False, reason=None):
"""Connects a Network to a NodeGroup with the given netparams
"""
......@@ -2027,6 +2027,7 @@ class GanetiRapiClient(object): # pylint: disable=R0904
"group_name": group_name,
"network_mode": mode,
"network_link": link,
"network_vlan": vlan,
}
query = []
......
......@@ -147,15 +147,19 @@ CONNECT
| **connect**
| [\--no-conflicts-check]
| {*network*} {*mode*} {*link*} [*groups*...]
| [{-N|\--nic-parameters} *nic-param*=*value*[,*nic-param*=*value*...]]
| {*network*} [*groups*...]
Connect a network to given node groups (all if not specified) with the
network parameters *mode* and *link*. Every network interface will
inherit those parameters if assigned in a network.
network parameters defined via the ``--nic-parameters`` option. Every
network interface will inherit those parameters if assigned to a network.
The ``--no-conflicts-check`` option can be used to skip the check for
conflicting IP addresses.
Passing *mode* and *link* as possitional arguments along with
*network* and *groups* is deprecated and not supported any more.
DISCONNECT
~~~~~~~~~~
......
......@@ -97,6 +97,8 @@ def TestNetworkConnect():
mode = default_mode
link = default_link
nicparams = "mode=%s,link=%s" % (mode, link)
AssertCommand(["gnt-group", "add", group1])
AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/24", network1])
......@@ -104,6 +106,8 @@ def TestNetworkConnect():
TestNetworkList()
AssertCommand(["gnt-network", "connect", "--nic-parameters", nicparams,
network1, group1])
AssertCommand(["gnt-network", "disconnect", network1, group1])
AssertCommand(["gnt-group", "remove", group1])
......
......@@ -901,6 +901,7 @@ $(genOpCode "OpCode"
, pNetworkName
, pNetworkMode
, pNetworkLink
, pNetworkVlan
, pIpConflictsCheck
],
"network_name")
......
......@@ -252,6 +252,7 @@ module Ganeti.OpParams
, pNetworkRemoveRsvdIps
, pNetworkMode
, pNetworkLink
, pNetworkVlan
, pDryRun
, pDebugLevel
, pOpPriority
......@@ -1685,3 +1686,8 @@ pAdminStateSource =
withDoc "Who last changed the instance admin state" .
optionalField $
simpleField "admin_state_source" [t| AdminStateSource |]
pNetworkVlan :: Field
pNetworkVlan =
withDoc "Network vlan when connecting to a group" $
simpleField "network_vlan" [t| String |]
......@@ -101,7 +101,8 @@ fieldsMap =
-- | Given a network's UUID, this function lists all connections from
-- the network to nodegroups including the respective mode and links.
getGroupConnections :: ConfigData -> String -> [(String, String, String)]
getGroupConnections ::
ConfigData -> String -> [(String, String, String, String)]
getGroupConnections cfg network_uuid =
mapMaybe (getGroupConnection network_uuid)
((Map.elems . fromContainer . configNodegroups) cfg)
......@@ -110,13 +111,14 @@ getGroupConnections cfg network_uuid =
-- a tuple of the group's name, the mode and the link by which the
-- network is connected to the group. Returns 'Nothing' if the network
-- is not connected to the group.
getGroupConnection :: String -> NodeGroup -> Maybe (String, String, String)
getGroupConnection ::
String -> NodeGroup -> Maybe (String, String, String, String)
getGroupConnection network_uuid group =
let networks = fromContainer . groupNetworks $ group
in case Map.lookup network_uuid networks of
Nothing -> Nothing
Just net ->
Just (groupName group, getNicMode net, getNicLink net)
Just (groupName group, getNicMode net, getNicLink net, getNicVlan net)
-- | Retrieves the network's mode and formats it human-readable,
-- also in case it is not available.
......@@ -124,11 +126,16 @@ getNicMode :: PartialNicParams -> String
getNicMode nic_params =
maybe "-" nICModeToRaw $ nicpModeP nic_params
-- | Retrieves the network's link and formats it human-readable, also in
-- | Retrieves the network's vlan and formats it human-readable, also in
-- case it it not available.
getNicLink :: PartialNicParams -> String
getNicLink nic_params = fromMaybe "-" (nicpLinkP nic_params)
-- | Retrieves the network's link and formats it human-readable, also in
-- case it it not available.
getNicVlan :: PartialNicParams -> String
getNicVlan nic_params = fromMaybe "-" (nicpVlanP nic_params)
-- | Retrieves the network's instances' names.
getInstances :: ConfigData -> String -> [String]
getInstances cfg network_uuid =
......
......@@ -365,7 +365,7 @@ instance Arbitrary OpCodes.OpCode where
genMaybe (listOf genIPv4Address)
"OP_NETWORK_CONNECT" ->
OpCodes.OpNetworkConnect <$> genNameNE <*> genNameNE <*>
arbitrary <*> genNameNE <*> arbitrary
arbitrary <*> genNameNE <*> arbitrary <*> arbitrary
"OP_NETWORK_DISCONNECT" ->
OpCodes.OpNetworkDisconnect <$> genNameNE <*> genNameNE
"OP_RESTRICTED_COMMAND" ->
......
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