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: Dimitris Aragiorgis <[email protected]>
---
 lib/client/gnt_network.py      |   16 +++++++++-------
 lib/cmdlib/network.py          |    2 +-
 lib/rapi/client.py             |    5 +++--
 man/gnt-network.rst            |   10 +++++++---
 qa/qa_network.py               |    5 ++++-
 src/Ganeti/OpCodes.hs          |    1 +
 src/Ganeti/OpParams.hs         |    6 ++++++
 test/hs/Test/Ganeti/OpCodes.hs |    2 +-
 8 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/lib/client/gnt_network.py b/lib/client/gnt_network.py
index aff0b59..6f67091 100644
--- a/lib/client/gnt_network.py
+++ b/lib/client/gnt_network.py
@@ -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}
@@ -112,15 +113,18 @@ def ConnectNetwork(opts, args):
   """
   cl = GetClient()
 
-  (network, mode, link) = args[:3]
-  groups = _GetDefaultGroups(cl, 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)
 
@@ -340,10 +344,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)"),
diff --git a/lib/cmdlib/network.py b/lib/cmdlib/network.py
index 3596adb..d93f2dd 100644
--- a/lib/cmdlib/network.py
+++ b/lib/cmdlib/network.py
@@ -572,7 +572,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.network_vlan = self.op.network_vlan
 
     self.network_uuid = self.cfg.LookupNetwork(self.network_name)
     self.group_uuid = self.cfg.LookupNodeGroup(self.group_name)
diff --git a/lib/rapi/client.py b/lib/rapi/client.py
index 4b4969d..cfb7e05 100644
--- a/lib/rapi/client.py
+++ b/lib/rapi/client.py
@@ -2017,8 +2017,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
 
     """
@@ -2026,6 +2026,7 @@ class GanetiRapiClient(object): # pylint: disable=R0904
       "group_name": group_name,
       "network_mode": mode,
       "network_link": link,
+      "network_vlan": vlan,
       }
 
     query = []
diff --git a/man/gnt-network.rst b/man/gnt-network.rst
index 3d71663..5b2b088 100644
--- a/man/gnt-network.rst
+++ b/man/gnt-network.rst
@@ -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
 ~~~~~~~~~~
 
diff --git a/qa/qa_network.py b/qa/qa_network.py
index aac83d5..63919e0 100644
--- a/qa/qa_network.py
+++ b/qa/qa_network.py
@@ -80,10 +80,13 @@ 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])
 
-  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-group", "remove", group1])
diff --git a/src/Ganeti/OpCodes.hs b/src/Ganeti/OpCodes.hs
index 9b60a61..97efc1a 100644
--- a/src/Ganeti/OpCodes.hs
+++ b/src/Ganeti/OpCodes.hs
@@ -919,6 +919,7 @@ $(genOpCode "OpCode"
      , pNetworkName
      , pNetworkMode
      , pNetworkLink
+     , pNetworkVlan
      , pIpConflictsCheck
      ],
      "network_name")
diff --git a/src/Ganeti/OpParams.hs b/src/Ganeti/OpParams.hs
index 7122372..ae00822 100644
--- a/src/Ganeti/OpParams.hs
+++ b/src/Ganeti/OpParams.hs
@@ -247,6 +247,7 @@ module Ganeti.OpParams
   , pNetworkRemoveRsvdIps
   , pNetworkMode
   , pNetworkLink
+  , pNetworkVlan
   , pDryRun
   , pDebugLevel
   , pOpPriority
@@ -1630,3 +1631,8 @@ pNetworkLink :: Field
 pNetworkLink =
   withDoc "Network link when connecting to a group" $
   simpleField "network_link" [t| NonEmptyString |]
+
+pNetworkVlan :: Field
+pNetworkVlan =
+  withDoc "Network vlan when connecting to a group" $
+  simpleField "network_vlan" [t| String |]
diff --git a/test/hs/Test/Ganeti/OpCodes.hs b/test/hs/Test/Ganeti/OpCodes.hs
index 50d7ee2..383a621 100644
--- a/test/hs/Test/Ganeti/OpCodes.hs
+++ b/test/hs/Test/Ganeti/OpCodes.hs
@@ -361,7 +361,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_NETWORK_QUERY" ->
-- 
1.7.10.4

Reply via email to