from ganeti import http
from ganeti.rapi import baserlib
-from ganeti.rapi import rlib1
from ganeti.rapi import rlib2
# the connection map is created at the end of this file
def __init__(self, connector=CONNECTOR):
"""Resource mapper constructor.
- Args:
- con: a dictionary, mapping method name with URL path regexp
+ @param connector: a dictionary, mapping method name with URL path regexp
"""
self._connector = connector
def getController(self, uri):
"""Find method for a given URI.
- Args:
- uri: string with URI
+ @param uri: string with URI
- Returns:
- None if no method is found or a tuple containing the following fields:
- methd: name of method mapped to URI
- items: a list of variable intems in the path
- args: a dictionary with additional parameters from URL
+ @return: None if no method is found or a tuple containing
+ the following fields:
+ - method: name of method mapped to URI
+ - items: a list of variable intems in the path
+ - args: a dictionary with additional parameters from URL
"""
if '?' in uri:
def GET(self):
"""Show the list of mapped resources.
- Returns:
- A dictionary with 'name' and 'uri' keys for each of them.
+ @return: a dictionary with 'name' and 'uri' keys for each of them.
"""
root_pattern = re.compile('^R_([a-zA-Z0-9]+)$')
return baserlib.BuildUriList(rootlist, "/%s")
-CONNECTOR.update({
- "/": R_root,
+def _getResources(id):
+ """Return a list of resources underneath given id.
+
+ This is to generalize querying of version resources lists.
+
+ @return: a list of resources names.
+
+ """
+ r_pattern = re.compile('^R_%s_([a-zA-Z0-9]+)$' % id)
+
+ rlist = []
+ for handler in CONNECTOR.values():
+ m = r_pattern.match(handler.__name__)
+ if m:
+ name = m.group(1)
+ rlist.append(name)
+
+ return rlist
+
- "/version": rlib1.R_version,
+class R_2(baserlib.R_Generic):
+ """ /2 resourse.
- "/tags": rlib1.R_tags,
- "/info": rlib1.R_info,
+ """
+ DOC_URI = "/2"
- "/nodes": rlib2.R_nodes,
- re.compile(r'^/nodes/([\w\._-]+)$'): rlib1.R_nodes_name,
- re.compile(r'^/nodes/([\w\._-]+)/tags$'): rlib1.R_nodes_name_tags,
+ def GET(self):
+ """Show the list of mapped resources.
- "/instances": rlib2.R_instances,
- re.compile(r'^/instances/([\w\._-]+)$'): rlib1.R_instances_name,
- re.compile(r'^/instances/([\w\._-]+)/tags$'): rlib1.R_instances_name_tags,
+ @return: a dictionary with 'name' and 'uri' keys for each of them.
+
+ """
+ return baserlib.BuildUriList(_getResources("2"), "/2/%s")
+
+
+CONNECTOR.update({
+ "/": R_root,
- "/os": rlib1.R_os,
+ "/version": rlib2.R_version,
+ "/2": R_2,
"/2/jobs": rlib2.R_2_jobs,
"/2/nodes": rlib2.R_2_nodes,
+ re.compile(r'^/2/nodes/([\w\._-]+)$'): rlib2.R_2_nodes_name,
+ re.compile(r'^/2/nodes/([\w\._-]+)/tags$'): rlib2.R_2_nodes_name_tags,
"/2/instances": rlib2.R_2_instances,
- re.compile(r'^/2/instances/([\w\._-]+)$'): rlib1.R_instances_name,
+ re.compile(r'^/2/instances/([\w\._-]+)$'): rlib2.R_2_instances_name,
re.compile(r'^/2/instances/([\w\._-]+)/tags$'): rlib2.R_2_instances_name_tags,
re.compile(r'^/2/instances/([\w\._-]+)/reboot$'):
rlib2.R_2_instances_name_reboot,
re.compile(r'^/2/instances/([\w\._-]+)/startup$'):
rlib2.R_2_instances_name_startup,
re.compile(r'/2/jobs/(%s)$' % constants.JOB_ID_TEMPLATE): rlib2.R_2_jobs_id,
+ "/2/tags": rlib2.R_2_tags,
+ "/2/info": rlib2.R_2_info,
+ "/2/os": rlib2.R_2_os,
})