Commit 6e8091f9 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Iustin Pop

Fixes to pass unittests (make check)

Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 77aab207
......@@ -214,6 +214,69 @@ Evacuates a node group.
:pre-execution: master node and all nodes in the group
:post-execution: master node and all nodes in the group
Network operations
~~~~~~~~~~~~~~~~~~
OP_NETWORK_ADD
++++++++++++++
Adds a network to the cluster.
:directory: network-add
:env. vars: NETWORK_NAME, NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6,
NETWORK_GATEWAY6, NETWORK_TYPE, NETWORK_MAC_PREFIX, NETWORK_TAGS
:pre-execution: master node
:post-execution: master node
OP_NETWORK_REMOVE
+++++++++++++++++
Removes a network from the cluster.
:directory: network-remove
:env. vars: NETWORK_NAME
:pre-execution: master node
:post-execution: master node
OP_NETWORK_CONNECT
++++++++++++++++++
Connects a network to a nodegroup.
:directory: network-connect
:env. vars: GROUP_NAME, NETWORK_NAME,
GROUP_NETWORK_MODE, GROUP_NETWORK_LINK,
NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6,
NETWORK_GATEWAY6, NETWORK_TYPE, NETWORK_MAC_PREFIX, NETWORK_TAGS
:pre-execution: nodegroup nodes
:post-execution: nodegroup nodes
OP_NETWORK_DISCONNECT
+++++++++++++++++++++
Disconnects a network from a nodegroup.
:directory: network-disconnect
:env. vars: GROUP_NAME, NETWORK_NAME,
GROUP_NETWORK_MODE, GROUP_NETWORK_LINK,
NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6,
NETWORK_GATEWAY6, NETWORK_TYPE, NETWORK_MAC_PREFIX, NETWORK_TAGS
:pre-execution: nodegroup nodes
:post-execution: nodegroup nodes
OP_NETWORK_SET_PARAMS
+++++++++++++++++++++
Modifies a network.
:directory: network-modify
:env. vars: NETWORK_NAME, NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6,
NETWORK_GATEWAY6, NETWORK_TYPE, NETWORK_MAC_PREFIX, NETWORK_TAGS
:pre-execution: master node
:post-execution: master node
Instance operations
~~~~~~~~~~~~~~~~~~~
......
......@@ -646,6 +646,207 @@ to URI like::
It supports the ``dry-run`` argument.
``/2/networks``
+++++++++++++++
The networks resource.
It supports the following commands: ``GET``, ``POST``.
``GET``
~~~~~~~
Returns a list of all existing networks.
Example::
[
{
"name": "network1",
"uri": "\/2\/networks\/network1"
},
{
"name": "network2",
"uri": "\/2\/networks\/network2"
}
]
If the optional bool *bulk* argument is provided and set to a true value
(i.e ``?bulk=1``), the output contains detailed information about networks
as a list.
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.NET_FIELDS))`.
Example::
[
{
'external_reservations': '10.0.0.0, 10.0.0.1, 10.0.0.15',
'free_count': 13,
'gateway': '10.0.0.1',
'gateway6': None,
'group_list': ['default(bridged, prv0)'],
'inst_list': [],
'mac_prefix': None,
'map': 'XX.............X',
'name': 'nat',
'network': '10.0.0.0/28',
'network6': None,
'network_type': 'private',
'reserved_count': 3,
'tags': ['nfdhcpd']
},
]
``POST``
~~~~~~~~
Creates a network.
If the optional bool *dry-run* argument is provided, the job will not be
actually executed, only the pre-execution checks will be done.
Returns: a job ID that can be used later for polling.
Body parameters:
.. opcode_params:: OP_NETWORK_ADD
Job result:
.. opcode_result:: OP_NETWORK_ADD
``/2/networks/[network_name]``
++++++++++++++++++++++++++++++
Returns information about a network.
It supports the following commands: ``GET``, ``DELETE``.
``GET``
~~~~~~~
Returns information about a network, similar to the bulk output from
the network list.
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.NET_FIELDS))`.
``DELETE``
~~~~~~~~~~
Deletes a network.
It supports the ``dry-run`` argument.
Job result:
.. opcode_result:: OP_NETWORK_REMOVE
``/2/networks/[network_name]/modify``
+++++++++++++++++++++++++++++++++++++
Modifies the parameters of a network.
Supports the following commands: ``PUT``.
``PUT``
~~~~~~~
Returns a job ID.
Body parameters:
.. opcode_params:: OP_NETWORK_SET_PARAMS
Job result:
.. opcode_result:: OP_NETWORK_SET_PARAMS
``/2/networks/[network_name]/connect``
++++++++++++++++++++++++++++++++++++++
Connects a network to a nodegroup.
Supports the following commands: ``PUT``.
``PUT``
~~~~~~~
Returns a job ID. It supports the ``dry-run`` arguments.
Body parameters:
.. opcode_params:: OP_NETWORK_CONNECT
Job result:
.. opcode_result:: OP_NETWORK_CONNECT
``/2/networks/[network_name]/disconnect``
+++++++++++++++++++++++++++++++++++++++++
Disonnects a network from a nodegroup.
Supports the following commands: ``PUT``.
``PUT``
~~~~~~~
Returns a job ID. It supports the ``dry-run`` arguments.
Body parameters:
.. opcode_params:: OP_NETWORK_DISCONNECT
Job result:
.. opcode_result:: OP_NETWORK_DISCONNECT
``/2/networks/[network_name]/tags``
+++++++++++++++++++++++++++++++++++
Manages per-network tags.
Supports the following commands: ``GET``, ``PUT``, ``DELETE``.
``GET``
~~~~~~~
Returns a list of tags.
Example::
["tag1", "tag2", "tag3"]
``PUT``
~~~~~~~
Add a set of tags.
The request as a list of strings should be ``PUT`` to this URI. The
result will be a job id.
It supports the ``dry-run`` argument.
``DELETE``
~~~~~~~~~~
Delete a tag.
In order to delete a set of tags, the DELETE request should be addressed
to URI like::
/tags?tag=[tag]&tag=[tag]
It supports the ``dry-run`` argument.
``/2/instances-multi-alloc``
++++++++++++++++++++++++++++
......
......@@ -115,7 +115,8 @@ class AddressPool(object):
assert self.net.family == 4
assert len(self.reservations) == self._GetSize()
assert len(self.ext_reservations) == self._GetSize()
assert not (self.reservations & self.ext_reservations).any()
all_res = self.reservations & self.ext_reservations
assert not all_res.any()
if self.gateway is not None:
assert self.net.family == self.gateway.version
......
......@@ -2011,15 +2011,22 @@ class OpNetworkAdd(OpCode):
OP_PARAMS = [
_PNetworkName,
_PNetworkType,
("network", None, ht.TAnd(ht.TString ,_CheckCIDRNetNotation), None),
("gateway", None, ht.TOr(ht.TNone, _CheckCIDRAddrNotation), None),
("network6", None, ht.TOr(ht.TNone, _CheckCIDR6NetNotation), None),
("gateway6", None, ht.TOr(ht.TNone, _CheckCIDR6AddrNotation), None),
("mac_prefix", None, ht.TMaybeString, None),
("network", None, ht.TAnd(ht.TString ,_CheckCIDRNetNotation),
"IPv4 Subnet"),
("gateway", None, ht.TOr(ht.TNone, _CheckCIDRAddrNotation),
"IPv4 Gateway"),
("network6", None, ht.TOr(ht.TNone, _CheckCIDR6NetNotation),
"IPv6 Subnet"),
("gateway6", None, ht.TOr(ht.TNone, _CheckCIDR6AddrNotation),
"IPv6 Gateway"),
("mac_prefix", None, ht.TMaybeString,
"Mac prefix that overrides cluster one"),
("add_reserved_ips", None,
ht.TOr(ht.TNone, ht.TListOf(_CheckCIDRAddrNotation)), None),
ht.TOr(ht.TNone, ht.TListOf(_CheckCIDRAddrNotation)),
"Which IPs to reserve"),
("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Network tags"),
]
OP_RESULT = ht.TNone
class OpNetworkRemove(OpCode):
"""Remove an existing network from the cluster.
......@@ -2031,6 +2038,7 @@ class OpNetworkRemove(OpCode):
_PNetworkName,
_PForce,
]
OP_RESULT = ht.TNone
class OpNetworkSetParams(OpCode):
"""Modify Network's parameters except for IPv4 subnet"""
......@@ -2038,15 +2046,22 @@ class OpNetworkSetParams(OpCode):
OP_PARAMS = [
_PNetworkName,
_PNetworkType,
("gateway", None, ht.TOr(ht.TNone, _CheckCIDRAddrNotation), None),
("network6", None, ht.TOr(ht.TNone, _CheckCIDR6NetNotation), None),
("gateway6", None, ht.TOr(ht.TNone, _CheckCIDR6AddrNotation), None),
("mac_prefix", None, ht.TMaybeString, None),
("gateway", None, ht.TOr(ht.TNone, _CheckCIDRAddrNotation),
"IPv4 Gateway"),
("network6", None, ht.TOr(ht.TNone, _CheckCIDR6NetNotation),
"IPv6 Subnet"),
("gateway6", None, ht.TOr(ht.TNone, _CheckCIDR6AddrNotation),
"IPv6 Gateway"),
("mac_prefix", None, ht.TMaybeString,
"Mac prefix that overrides cluster one"),
("add_reserved_ips", None,
ht.TOr(ht.TNone, ht.TListOf(_CheckCIDRAddrNotation)), None),
ht.TOr(ht.TNone, ht.TListOf(_CheckCIDRAddrNotation)),
"Which external IPs to reserve"),
("remove_reserved_ips", None,
ht.TOr(ht.TNone, ht.TListOf(_CheckCIDRAddrNotation)), None),
ht.TOr(ht.TNone, ht.TListOf(_CheckCIDRAddrNotation)),
"Which external IPs to release"),
]
OP_RESULT = ht.TNone
class OpNetworkConnect(OpCode):
"""Connect a Network to a specific Nodegroup with the defined netparams
......@@ -2060,10 +2075,11 @@ class OpNetworkConnect(OpCode):
OP_PARAMS = [
_PGroupName,
_PNetworkName,
("network_mode", None, ht.TString, None),
("network_link", None, ht.TString, None),
("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
("network_mode", None, ht.TString, "Connectivity mode"),
("network_link", None, ht.TString, "Connectivity link"),
("conflicts_check", True, ht.TBool, "Whether to check for conflicting IPs"),
]
OP_RESULT = ht.TNone
class OpNetworkDisconnect(OpCode):
"""Disconnect a Network from a Nodegroup. Produce errors if NICs are
......@@ -2074,8 +2090,9 @@ class OpNetworkDisconnect(OpCode):
OP_PARAMS = [
_PGroupName,
_PNetworkName,
("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
("conflicts_check", True, ht.TBool, "Whether to check for conflicting IPs"),
]
OP_RESULT = ht.TNone
class OpNetworkQuery(OpCode):
"""Compute the list of networks."""
......@@ -2084,6 +2101,7 @@ class OpNetworkQuery(OpCode):
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
"Empty list to query all groups, group names otherwise"),
]
OP_RESULT = ht.TNone
def _GetOpList():
......
......@@ -760,7 +760,7 @@ class OVFWriter(object):
SubElementText(nic, "gnt:MACAddress", network["mac"])
SubElementText(nic, "gnt:IPAddress", network["ip"])
SubElementText(nic, "gnt:Link", network["link"])
SubElementText(nic, "gnt:Network", network["network"])
SubElementText(nic, "gnt:Net", network["network"])
def SaveVirtualSystemData(self, name, vcpus, memory):
"""Convert virtual system information to OVF sections.
......@@ -1665,7 +1665,8 @@ class OVFExporter(Converter):
counter = 0
while True:
data_link = \
self.config_parser.get(constants.INISECT_INS, "nic%s_network" % counter)
self.config_parser.get(constants.INISECT_INS,
"nic%s_link" % counter)
if data_link is None:
break
results.append({
......@@ -1675,9 +1676,9 @@ class OVFExporter(Converter):
"nic%s_mac" % counter),
"ip": self.config_parser.get(constants.INISECT_INS,
"nic%s_ip" % counter),
"link": self.config_parser.get(constants.INISECT_INS,
"nic%s_link" % counter),
"network": data_link,
"network": self.config_parser.get(constants.INISECT_INS,
"nic%s_network" % counter),
"link": data_link,
})
if results[counter]["mode"] not in constants.NIC_VALID_MODES:
raise errors.OpPrereqError("Network mode %s not recognized"
......
......@@ -1761,7 +1761,7 @@ 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):
def ConnectNetwork(self, network_name, group_name, mode, link, dry_run=False):
"""Connects a Network to a NodeGroup with the given netparams
"""
......@@ -1771,22 +1771,44 @@ class GanetiRapiClient(object): # pylint: disable=R0904
"network_link": link
}
query = []
_AppendDryRunIf(query, dry_run)
return self._SendRequest(HTTP_PUT,
("/%s/networks/%s/connect" %
(GANETI_RAPI_VERSION, network_name)), None, body)
(GANETI_RAPI_VERSION, network_name)), query, body)
def DisconnectNetwork(self, network_name, group_name):
def DisconnectNetwork(self, network_name, group_name, dry_run=False):
"""Connects a Network to a NodeGroup with the given netparams
"""
body = {
"group_name": group_name
}
query = []
_AppendDryRunIf(query, dry_run)
return self._SendRequest(HTTP_PUT,
("/%s/networks/%s/disconnect" %
(GANETI_RAPI_VERSION, network_name)), None, body)
(GANETI_RAPI_VERSION, network_name)), query, body)
def ModifyNetwork(self, network, **kwargs):
"""Modifies a network.
More details for parameters can be found in the RAPI documentation.
@type network: string
@param network: Network name
@rtype: string
@return: job id
"""
return self._SendRequest(HTTP_PUT,
("/%s/networks/%s/modify" %
(GANETI_RAPI_VERSION, network)), None, kwargs)
def DeleteNetwork(self, network, dry_run=False):
"""Deletes a network.
......@@ -1806,6 +1828,62 @@ class GanetiRapiClient(object): # pylint: disable=R0904
("/%s/networks/%s" %
(GANETI_RAPI_VERSION, network)), query, None)
def GetNetworkTags(self, network):
"""Gets tags for a network.
@type network: string
@param network: Node group whose tags to return
@rtype: list of strings
@return: tags for the network
"""
return self._SendRequest(HTTP_GET,
("/%s/networks/%s/tags" %
(GANETI_RAPI_VERSION, network)), None, None)
def AddNetworkTags(self, network, tags, dry_run=False):
"""Adds tags to a network.
@type network: str
@param network: network to add tags to
@type tags: list of string
@param tags: tags to add to the network
@type dry_run: bool
@param dry_run: whether to perform a dry run
@rtype: string
@return: job id
"""
query = [("tag", t) for t in tags]
_AppendDryRunIf(query, dry_run)
return self._SendRequest(HTTP_PUT,
("/%s/networks/%s/tags" %
(GANETI_RAPI_VERSION, network)), query, None)
def DeleteNetworkTags(self, network, tags, dry_run=False):
"""Deletes tags from a network.
@type network: str
@param network: network to delete tags from
@type tags: list of string
@param tags: tags to delete
@type dry_run: bool
@param dry_run: whether to perform a dry run
@rtype: string
@return: job id
"""
query = [("tag", t) for t in tags]
_AppendDryRunIf(query, dry_run)
return self._SendRequest(HTTP_DELETE,
("/%s/networks/%s/tags" %
(GANETI_RAPI_VERSION, network)), query, None)
def GetGroups(self, bulk=False):
"""Gets all node groups in the cluster.
......
......@@ -175,6 +175,10 @@ def GetHandlers(node_name_pattern, instance_name_pattern,
rlib2.R_2_networks_name_connect,
re.compile(r"^/2/networks/(%s)/disconnect$" % network_name_pattern):
rlib2.R_2_networks_name_disconnect,
re.compile(r"^/2/networks/(%s)/modify$" % network_name_pattern):
rlib2.R_2_networks_name_modify,
re.compile(r"^/2/networks/(%s)/tags$" % network_name_pattern):
rlib2.R_2_networks_name_tags,
"/2/groups": rlib2.R_2_groups,
re.compile(r"^/2/groups/(%s)$" % group_name_pattern):
......
......@@ -688,7 +688,7 @@ class R_2_networks(baserlib.OpcodeResource):
class R_2_networks_name(baserlib.OpcodeResource):
"""/2/network/[network_name] resource.
"""/2/networks/[network_name] resource.
"""
DELETE_OPCODE = opcodes.OpNetworkRemove
......@@ -718,7 +718,7 @@ class R_2_networks_name(baserlib.OpcodeResource):
})
class R_2_networks_name_connect(baserlib.OpcodeResource):
"""/2/network/[network_name]/connect.
"""/2/networks/[network_name]/connect resource.
"""
PUT_OPCODE = opcodes.OpNetworkConnect
......@@ -730,10 +730,11 @@ class R_2_networks_name_connect(baserlib.OpcodeResource):
assert self.items
return (self.request_body, {
"network_name": self.items[0],
"dry_run": self.dryRun(),
})
class R_2_networks_name_disconnect(baserlib.OpcodeResource):
"""/2/network/[network_name]/disconnect.
"""/2/networks/[network_name]/disconnect resource.
"""
PUT_OPCODE = opcodes.OpNetworkDisconnect
......@@ -741,12 +742,29 @@ class R_2_networks_name_disconnect(baserlib.OpcodeResource):
def GetPutOpInput(self):
"""Changes some parameters of node group.
"""
assert self.items
return (self.request_body, {
"network_name": self.items[0],
"dry_run": self.dryRun(),
})
class R_2_networks_name_modify(baserlib.OpcodeResource):
"""/2/networks/[network_name]/modify resource.
"""
PUT_OPCODE = opcodes.OpNetworkSetParams
def GetPutOpInput(self):
"""Changes some parameters of network.
"""
assert self.items
return (self.request_body, {
"network_name": self.items[0],
})
class R_2_groups(baserlib.OpcodeResource):
"""/2/groups resource.
......@@ -1546,6 +1564,14 @@ class R_2_groups_name_tags(_R_Tags):
"""
TAG_LEVEL = constants.TAG_NODEGROUP
class R_2_networks_name_tags(_R_Tags):
""" /2/networks/[network_name]/tags resource.
Manages per-network tags.
"""
TAG_LEVEL = constants.TAG_NETWORK
class R_2_tags(_R_Tags):
""" /2/tags resource.
......
......@@ -158,6 +158,45 @@ RENAME
Renames a given network from *oldname* to *newname*. NOT implemeted yet
TAGS
~~~
ADD-TAGS
^^^^^^^^
**add-tags** [\--from *file*] {*networkname*} {*tag*...}
Add tags to the given network. If any of the tags contains invalid
characters, the entire operation will abort.
If the ``--from`` option is given, the list of tags will be extended
with the contents of that file (each line becomes a tag). In this case,
there is not need to pass tags on the command line (if you do, both
sources will be used). A file name of ``-`` will be interpreted as
stdin.
LIST-TAGS
^^^^^^^^^
**list-tags** {*networkname*}
List the tags of the given network.
REMOVE-TAGS
^^^^^^^^^^^
**remove-tags** [\--from *file*] {*networkname*} {*tag*...}
Remove tags from the given network. If any of the tags are not
existing on the network, the entire operation will abort.