Commit 7eac4a4d authored by Michael Hanselmann's avatar Michael Hanselmann

Add new /2/features RAPI resource

The /2/features RAPI resource can be used to detect optional
features implemented by the RAPI server. This will be used
to recognize servers implementing a new request format for
instance creation requests.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 565083ef
......@@ -280,6 +280,19 @@ It supports the following commands: ``PUT``.
Redistribute configuration to all nodes. The result will be a job id.
``/2/features``
+++++++++++++++
``GET``
~~~~~~~
Returns a list of features supported by the RAPI server. Available
features:
``instance-create-reqv1``
Instance creation request data version 1 supported.
``/2/instances``
++++++++++++++++
......
......@@ -39,6 +39,7 @@ HTTP_GET = "GET"
HTTP_PUT = "PUT"
HTTP_POST = "POST"
HTTP_OK = 200
HTTP_NOT_FOUND = 404
HTTP_APP_JSON = "application/json"
REPLACE_DISK_PRI = "replace_on_primary"
......@@ -433,6 +434,23 @@ class GanetiRapiClient(object):
"""
return self._SendRequest(HTTP_GET, "/version", None, None)
def GetFeatures(self):
"""Gets the list of optional features supported by RAPI server.
@rtype: list
@return: List of optional features
"""
try:
return self._SendRequest(HTTP_GET, "/%s/features" % GANETI_RAPI_VERSION,
None, None)
except GanetiApiError, err:
# Older RAPI servers don't support this resource
if err.code == HTTP_NOT_FOUND:
return []
raise
def GetOperatingSystems(self):
"""Gets the Operating Systems running in the Ganeti cluster.
......
......@@ -216,6 +216,7 @@ def GetHandlers(node_name_pattern, instance_name_pattern, job_id_pattern):
"/2/info": rlib2.R_2_info,
"/2/os": rlib2.R_2_os,
"/2/redistribute-config": rlib2.R_2_redist_config,
"/2/features": rlib2.R_2_features,
}
......
......@@ -118,6 +118,18 @@ class R_2_info(baserlib.R_Generic):
return client.QueryClusterInfo()
class R_2_features(baserlib.R_Generic):
"""/2/features resource.
"""
@staticmethod
def GET():
"""Returns list of optional RAPI features implemented.
"""
return []
class R_2_os(baserlib.R_Generic):
"""/2/os resource.
......
......@@ -190,6 +190,12 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
self.assertEqual(2, self.client.GetVersion())
self.assertHandler(rlib2.R_version)
def testGetFeatures(self):
for features in [[], ["foo", "bar", "baz"]]:
self.rapi.AddResponse(serializer.DumpJson(features))
self.assertEqual(features, self.client.GetFeatures())
self.assertHandler(rlib2.R_2_features)
def testGetOperatingSystems(self):
self.rapi.AddResponse("[\"beos\"]")
self.assertEqual(["beos"], self.client.GetOperatingSystems())
......
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