Commit cd748cde authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis
Browse files

Update rapi client



Get rapi client from snf-ganeti. Add depends argument (for chain jobs)
where needed.

Argument tags must be a list of strings and arguments add_reserved_ips and
remove_reserved_ips must be None or a list of strings.
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
parent 2c0ad54e
...@@ -256,6 +256,9 @@ def GenericCurlConfig(verbose=False, use_signal=False, ...@@ -256,6 +256,9 @@ def GenericCurlConfig(verbose=False, use_signal=False,
lcsslver = sslver.lower() lcsslver = sslver.lower()
if lcsslver.startswith("openssl/"): if lcsslver.startswith("openssl/"):
pass pass
elif lcsslver.startswith("nss/"):
# TODO: investigate compatibility beyond a simple test
pass
elif lcsslver.startswith("gnutls/"): elif lcsslver.startswith("gnutls/"):
if capath: if capath:
raise Error("cURL linked against GnuTLS has no support for a" raise Error("cURL linked against GnuTLS has no support for a"
...@@ -1659,7 +1662,8 @@ class GanetiRapiClient(object): # pylint: disable=R0904 ...@@ -1659,7 +1662,8 @@ class GanetiRapiClient(object): # pylint: disable=R0904
def CreateNetwork(self, network_name, network, gateway=None, network6=None, def CreateNetwork(self, network_name, network, gateway=None, network6=None,
gateway6=None, mac_prefix=None, network_type=None, gateway6=None, mac_prefix=None, network_type=None,
tags=None, conflicts_check=False, dry_run=False): add_reserved_ips=None, tags=[],
conflicts_check=False, dry_run=False):
"""Creates a new network. """Creates a new network.
@type name: str @type name: str
...@@ -1674,12 +1678,6 @@ class GanetiRapiClient(object): # pylint: disable=R0904 ...@@ -1674,12 +1678,6 @@ class GanetiRapiClient(object): # pylint: disable=R0904
query = [] query = []
_AppendDryRunIf(query, dry_run) _AppendDryRunIf(query, dry_run)
if tags:
tags = tags.split(',')
else:
tags = []
body = { body = {
"network_name": network_name, "network_name": network_name,
"gateway": gateway, "gateway": gateway,
...@@ -1688,15 +1686,16 @@ class GanetiRapiClient(object): # pylint: disable=R0904 ...@@ -1688,15 +1686,16 @@ class GanetiRapiClient(object): # pylint: disable=R0904
"network6": network6, "network6": network6,
"mac_prefix": mac_prefix, "mac_prefix": mac_prefix,
"network_type": network_type, "network_type": network_type,
"tags": tags, "add_reserved_ips": add_reserved_ips,
"conflicts_check": conflicts_check, "conflicts_check": conflicts_check,
"tags": tags,
} }
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, def ConnectNetwork(self, network_name, group_name, mode, link,
conflicts_check=False, depends=None): conflicts_check=False, depends=None, dry_run=False):
"""Connects a Network to a NodeGroup with the given netparams """Connects a Network to a NodeGroup with the given netparams
""" """
...@@ -1712,12 +1711,15 @@ class GanetiRapiClient(object): # pylint: disable=R0904 ...@@ -1712,12 +1711,15 @@ class GanetiRapiClient(object): # pylint: disable=R0904
for d in depends: for d in depends:
body['depends'].append([d, ["success"]]) body['depends'].append([d, ["success"]])
query = []
_AppendDryRunIf(query, dry_run)
return self._SendRequest(HTTP_PUT, return self._SendRequest(HTTP_PUT,
("/%s/networks/%s/connect" % ("/%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, depends=None): def DisconnectNetwork(self, network_name, group_name,
depends=None, dry_run=False):
"""Connects a Network to a NodeGroup with the given netparams """Connects a Network to a NodeGroup with the given netparams
""" """
...@@ -1730,12 +1732,30 @@ class GanetiRapiClient(object): # pylint: disable=R0904 ...@@ -1730,12 +1732,30 @@ class GanetiRapiClient(object): # pylint: disable=R0904
for d in depends: for d in depends:
body['depends'].append([d, ["success"]]) body['depends'].append([d, ["success"]])
query = []
_AppendDryRunIf(query, dry_run)
return self._SendRequest(HTTP_PUT, return self._SendRequest(HTTP_PUT,
("/%s/networks/%s/disconnect" % ("/%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.
def DeleteNetwork(self, network, depends=None): 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, depends=None, dry_run=False):
"""Deletes a network. """Deletes a network.
@type group: str @type group: str
...@@ -1753,10 +1773,68 @@ class GanetiRapiClient(object): # pylint: disable=R0904 ...@@ -1753,10 +1773,68 @@ class GanetiRapiClient(object): # pylint: disable=R0904
for d in depends: for d in depends:
body['depends'].append([d, ["success"]]) body['depends'].append([d, ["success"]])
query = []
_AppendDryRunIf(query, dry_run)
return self._SendRequest(HTTP_DELETE, return self._SendRequest(HTTP_DELETE,
("/%s/networks/%s" % ("/%s/networks/%s" %
(GANETI_RAPI_VERSION, network)), None, body) (GANETI_RAPI_VERSION, network)), query, body)
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): def GetGroups(self, bulk=False):
"""Gets all node groups in the cluster. """Gets all node groups in the cluster.
......
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