This creates the /2/groups/<name>/modify resource; at the moment, only the "alloc_policy" attribute can be modified.
Signed-off-by: Adeodato Simo <[email protected]> --- doc/rapi.rst | 18 ++++++++++++++++++ lib/rapi/client.py | 15 +++++++++++++++ lib/rapi/connector.py | 2 ++ lib/rapi/rlib2.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 0 deletions(-) diff --git a/doc/rapi.rst b/doc/rapi.rst index 67e1e6f..0226089 100644 --- a/doc/rapi.rst +++ b/doc/rapi.rst @@ -420,6 +420,24 @@ Deletes a node group. It supports the ``dry-run`` argument. +``/2/groups/[group_name]/modify`` ++++++++++++++++++++++++++++++++++ + +Modifies the parameters of a node group. + +Supports the following commands: ``PUT``. + +``PUT`` +~~~~~~~ + +Returns a job ID. + +Body parameters: + +``alloc_policy`` (string) + If present, the new allocation policy for the node group. + + ``/2/groups/[group_name]/rename`` +++++++++++++++++++++++++++++++++ diff --git a/lib/rapi/client.py b/lib/rapi/client.py index 096463e..b129d65 100644 --- a/lib/rapi/client.py +++ b/lib/rapi/client.py @@ -1434,6 +1434,21 @@ class GanetiRapiClient(object): return self._SendRequest(HTTP_POST, "/%s/groups" % GANETI_RAPI_VERSION, query, body) + def ModifyGroup(self, group, **kwargs): + """Modifies a node group. + + More details for parameters can be found in the RAPI documentation. + + @type group: string + @param group: Node group name + @rtype: int + @return: job id + + """ + return self._SendRequest(HTTP_PUT, + ("/%s/groups/%s/modify" % + (GANETI_RAPI_VERSION, group)), None, kwargs) + def DeleteGroup(self, group, dry_run=False): """Deletes a node group. diff --git a/lib/rapi/connector.py b/lib/rapi/connector.py index 9f3a314..c1deeef 100644 --- a/lib/rapi/connector.py +++ b/lib/rapi/connector.py @@ -215,6 +215,8 @@ def GetHandlers(node_name_pattern, instance_name_pattern, "/2/groups": rlib2.R_2_groups, re.compile(r'^/2/groups/(%s)$' % group_name_pattern): rlib2.R_2_groups_name, + re.compile(r'^/2/groups/(%s)/modify$' % group_name_pattern): + rlib2.R_2_groups_name_modify, re.compile(r'^/2/groups/(%s)/rename$' % group_name_pattern): rlib2.R_2_groups_name_rename, diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py index 418c003..73eabb6 100644 --- a/lib/rapi/rlib2.py +++ b/lib/rapi/rlib2.py @@ -604,6 +604,34 @@ class R_2_groups_name(baserlib.R_Generic): return baserlib.SubmitJob([op]) +def _ParseModifyGroupRequest(name, data): + """Parses a request for modifying a node group. + + @rtype: L{opcodes.OpSetGroupParams} + @return: Group modify opcode + + """ + alloc_policy = baserlib.CheckParameter(data, "alloc_policy", default=None) + return opcodes.OpSetGroupParams(group_name=name, alloc_policy=alloc_policy) + + +class R_2_groups_name_modify(baserlib.R_Generic): + """/2/groups/[group_name]/modify resource. + + """ + def PUT(self): + """Changes some parameters of node group. + + @return: a job id + + """ + baserlib.CheckType(self.request_body, dict, "Body contents") + + op = _ParseModifyGroupRequest(self.items[0], self.request_body) + + return baserlib.SubmitJob([op]) + + def _ParseRenameGroupRequest(name, data, dry_run): """Parses a request for renaming a node group. -- 1.7.3.1
