Commit 2243b133 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Klaus Aehlig

Fix gnt-network client to accept vlan info

Until now gnt-network connect expected the network,
mode, link, and optionally groups as positional arguments.

To be able to pass vlan info too, use the `--nic-parameters`
option, just like gnt-cluster client to pass the desired
mode, link, and vlan. Missing values will be filled with the
default ones.

Do not support old argument passing since mode and link should
be arguments with variable length and this violates bash completion
generation rules.

Update QA to pass the new option instead of deprecated arguments.
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent b6afa809
...@@ -32,6 +32,7 @@ from ganeti import constants ...@@ -32,6 +32,7 @@ from ganeti import constants
from ganeti import opcodes from ganeti import opcodes
from ganeti import utils from ganeti import utils
from ganeti import errors from ganeti import errors
from ganeti import objects
#: default list of fields for L{ListNetworks} #: default list of fields for L{ListNetworks}
...@@ -112,15 +113,18 @@ def ConnectNetwork(opts, args): ...@@ -112,15 +113,18 @@ def ConnectNetwork(opts, args):
""" """
cl = GetClient() cl = GetClient()
(network, mode, link) = args[:3] network = args[0]
groups = _GetDefaultGroups(cl, args[3:]) nicparams = objects.FillDict(constants.NICC_DEFAULTS, opts.nicparams)
groups = _GetDefaultGroups(cl, args[1:])
# TODO: Change logic to support "--submit" # TODO: Change logic to support "--submit"
for group in groups: for group in groups:
op = opcodes.OpNetworkConnect(group_name=group, op = opcodes.OpNetworkConnect(group_name=group,
network_name=network, network_name=network,
network_mode=mode, network_mode=nicparams[constants.NIC_MODE],
network_link=link, network_link=nicparams[constants.NIC_LINK],
network_vlan=nicparams[constants.NIC_VLAN],
conflicts_check=opts.conflicts_check) conflicts_check=opts.conflicts_check)
SubmitOpCode(op, opts=opts, cl=cl) SubmitOpCode(op, opts=opts, cl=cl)
...@@ -340,10 +344,8 @@ commands = { ...@@ -340,10 +344,8 @@ commands = {
"connect": ( "connect": (
ConnectNetwork, ConnectNetwork,
[ArgNetwork(min=1, max=1), [ArgNetwork(min=1, max=1),
ArgChoice(min=1, max=1, choices=constants.NIC_VALID_MODES),
ArgUnknown(min=1, max=1),
ArgGroup()], ArgGroup()],
[NOCONFLICTSCHECK_OPT, PRIORITY_OPT], [NOCONFLICTSCHECK_OPT, PRIORITY_OPT, NIC_PARAMS_OPT],
"<network_name> <mode> <link> [<node_group>...]", "<network_name> <mode> <link> [<node_group>...]",
"Map a given network to the specified node group" "Map a given network to the specified node group"
" with given mode and link (netparams)"), " with given mode and link (netparams)"),
......
...@@ -572,7 +572,7 @@ class LUNetworkConnect(LogicalUnit): ...@@ -572,7 +572,7 @@ class LUNetworkConnect(LogicalUnit):
self.group_name = self.op.group_name self.group_name = self.op.group_name
self.network_mode = self.op.network_mode self.network_mode = self.op.network_mode
self.network_link = self.op.network_link self.network_link = self.op.network_link
self.network_vlan = "" self.network_vlan = self.op.network_vlan
self.network_uuid = self.cfg.LookupNetwork(self.network_name) self.network_uuid = self.cfg.LookupNetwork(self.network_name)
self.group_uuid = self.cfg.LookupNodeGroup(self.group_name) self.group_uuid = self.cfg.LookupNodeGroup(self.group_name)
......
...@@ -2017,8 +2017,8 @@ class GanetiRapiClient(object): # pylint: disable=R0904 ...@@ -2017,8 +2017,8 @@ class GanetiRapiClient(object): # pylint: disable=R0904
return self._SendRequest(HTTP_POST, "/%s/networks" % GANETI_RAPI_VERSION, return self._SendRequest(HTTP_POST, "/%s/networks" % GANETI_RAPI_VERSION,
query, body) query, body)
def ConnectNetwork(self, network_name, group_name, mode, link, dry_run=False, def ConnectNetwork(self, network_name, group_name, mode, link,
reason=None): vlan="", dry_run=False, reason=None):
"""Connects a Network to a NodeGroup with the given netparams """Connects a Network to a NodeGroup with the given netparams
""" """
...@@ -2026,6 +2026,7 @@ class GanetiRapiClient(object): # pylint: disable=R0904 ...@@ -2026,6 +2026,7 @@ class GanetiRapiClient(object): # pylint: disable=R0904
"group_name": group_name, "group_name": group_name,
"network_mode": mode, "network_mode": mode,
"network_link": link, "network_link": link,
"network_vlan": vlan,
} }
query = [] query = []
......
...@@ -147,15 +147,19 @@ CONNECT ...@@ -147,15 +147,19 @@ CONNECT
| **connect** | **connect**
| [\--no-conflicts-check] | [\--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 Connect a network to given node groups (all if not specified) with the
network parameters *mode* and *link*. Every network interface will network parameters defined via the ``--nic-parameters`` option. Every
inherit those parameters if assigned in a network. network interface will inherit those parameters if assigned to a network.
The ``--no-conflicts-check`` option can be used to skip the check for The ``--no-conflicts-check`` option can be used to skip the check for
conflicting IP addresses. conflicting IP addresses.
Passing *mode* and *link* as possitional arguments along with
*network* and *groups* is deprecated and not supported any more.
DISCONNECT DISCONNECT
~~~~~~~~~~ ~~~~~~~~~~
......
...@@ -80,10 +80,13 @@ def TestNetworkConnect(): ...@@ -80,10 +80,13 @@ def TestNetworkConnect():
mode = default_mode mode = default_mode
link = default_link link = default_link
nicparams = "mode=%s,link=%s" % (mode, link)
AssertCommand(["gnt-group", "add", group1]) AssertCommand(["gnt-group", "add", group1])
AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/24", network1]) AssertCommand(["gnt-network", "add", "--network", "192.0.2.0/24", network1])
AssertCommand(["gnt-network", "connect", network1, mode, link, group1]) AssertCommand(["gnt-network", "connect", "--nic-parameters", nicparams,
network1, group1])
AssertCommand(["gnt-network", "disconnect", network1, group1]) AssertCommand(["gnt-network", "disconnect", network1, group1])
AssertCommand(["gnt-group", "remove", group1]) AssertCommand(["gnt-group", "remove", group1])
......
...@@ -919,6 +919,7 @@ $(genOpCode "OpCode" ...@@ -919,6 +919,7 @@ $(genOpCode "OpCode"
, pNetworkName , pNetworkName
, pNetworkMode , pNetworkMode
, pNetworkLink , pNetworkLink
, pNetworkVlan
, pIpConflictsCheck , pIpConflictsCheck
], ],
"network_name") "network_name")
......
...@@ -247,6 +247,7 @@ module Ganeti.OpParams ...@@ -247,6 +247,7 @@ module Ganeti.OpParams
, pNetworkRemoveRsvdIps , pNetworkRemoveRsvdIps
, pNetworkMode , pNetworkMode
, pNetworkLink , pNetworkLink
, pNetworkVlan
, pDryRun , pDryRun
, pDebugLevel , pDebugLevel
, pOpPriority , pOpPriority
...@@ -1630,3 +1631,8 @@ pNetworkLink :: Field ...@@ -1630,3 +1631,8 @@ pNetworkLink :: Field
pNetworkLink = pNetworkLink =
withDoc "Network link when connecting to a group" $ withDoc "Network link when connecting to a group" $
simpleField "network_link" [t| NonEmptyString |] simpleField "network_link" [t| NonEmptyString |]
pNetworkVlan :: Field
pNetworkVlan =
withDoc "Network vlan when connecting to a group" $
simpleField "network_vlan" [t| String |]
...@@ -361,7 +361,7 @@ instance Arbitrary OpCodes.OpCode where ...@@ -361,7 +361,7 @@ instance Arbitrary OpCodes.OpCode where
genMaybe (listOf genIPv4Address) genMaybe (listOf genIPv4Address)
"OP_NETWORK_CONNECT" -> "OP_NETWORK_CONNECT" ->
OpCodes.OpNetworkConnect <$> genNameNE <*> genNameNE <*> OpCodes.OpNetworkConnect <$> genNameNE <*> genNameNE <*>
arbitrary <*> genNameNE <*> arbitrary arbitrary <*> genNameNE <*> arbitrary <*> arbitrary
"OP_NETWORK_DISCONNECT" -> "OP_NETWORK_DISCONNECT" ->
OpCodes.OpNetworkDisconnect <$> genNameNE <*> genNameNE OpCodes.OpNetworkDisconnect <$> genNameNE <*> genNameNE
"OP_NETWORK_QUERY" -> "OP_NETWORK_QUERY" ->
......
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