Commit 028c6b76 authored by Oleksiy Mishchenko's avatar Oleksiy Mishchenko
Browse files

RAPI:Fix root list and unittest for it.

Reviewed-by: imsnah
parent a0dcf7c2
......@@ -125,11 +125,11 @@ CONNECTOR.update({
"/tags": rlib1.R_tags,
"/info": rlib1.R_info,
"/nodes": rlib2.R_2_nodes,
"/nodes": rlib2.R_nodes,
re.compile(r'^/nodes/([\w\._-]+)$'): rlib1.R_nodes_name,
re.compile(r'^/nodes/([\w\._-]+)/tags$'): rlib1.R_nodes_name_tags,
"/instances": rlib2.R_2_instances,
"/instances": rlib2.R_instances,
re.compile(r'^/instances/([\w\._-]+)$'): rlib1.R_instances_name,
re.compile(r'^/instances/([\w\._-]+)/tags$'): rlib1.R_instances_name_tags,
......
......@@ -104,60 +104,6 @@ class R_info(baserlib.R_Generic):
return ganeti.cli.SubmitOpCode(op)
class R_nodes(baserlib.R_Generic):
"""/nodes resource.
"""
DOC_URI = "/nodes"
def GET(self):
"""Returns a list of all nodes.
Returns:
A dictionary with 'name' and 'uri' keys for each of them.
Example: [
{
"name": "node1.example.com",
"uri": "\/instances\/node1.example.com"
},
{
"name": "node2.example.com",
"uri": "\/instances\/node2.example.com"
}]
If the optional 'bulk' argument is provided and set to 'true'
value (i.e '?bulk=1'), the output contains detailed
information about nodes as a list.
Example: [
{
"pinst_cnt": 1,
"mfree": 31280,
"mtotal": 32763,
"name": "www.example.com",
"tags": [],
"mnode": 512,
"dtotal": 5246208,
"sinst_cnt": 2,
"dfree": 5171712
},
...
]
"""
op = ganeti.opcodes.OpQueryNodes(output_fields=["name"], names=[])
nodeslist = baserlib.ExtractField(ganeti.cli.SubmitOpCode(op), 0)
if 'bulk' in self.queryargs:
op = ganeti.opcodes.OpQueryNodes(output_fields=N_FIELDS,
names=nodeslist)
result = ganeti.cli.SubmitOpCode(op)
return baserlib.MapBulkFields(result, N_FIELDS)
return baserlib.BuildUriList(nodeslist, "/nodes/%s")
class R_nodes_name(baserlib.R_Generic):
"""/nodes/[node_name] resources.
......@@ -193,70 +139,6 @@ class R_nodes_name_tags(baserlib.R_Generic):
return baserlib._Tags_GET(constants.TAG_NODE, name=self.items[0])
class R_instances(baserlib.R_Generic):
"""/instances resource.
"""
DOC_URI = "/instances"
def GET(self):
"""Returns a list of all available instances.
Returns:
A dictionary with 'name' and 'uri' keys for each of them.
Example: [
{
"name": "web.example.com",
"uri": "\/instances\/web.example.com"
},
{
"name": "mail.example.com",
"uri": "\/instances\/mail.example.com"
}]
If the optional 'bulk' argument is provided and set to 'true'
value (i.e '?bulk=1'), the output contains detailed
information about instances as a list.
Example: [
{
"status": "running",
"bridge": "xen-br0",
"name": "web.example.com",
"tags": ["tag1", "tag2"],
"admin_ram": 512,
"sda_size": 20480,
"pnode": "node1.example.com",
"mac": "01:23:45:67:89:01",
"sdb_size": 4096,
"snodes": ["node2.example.com"],
"disk_template": "drbd",
"ip": null,
"admin_state": true,
"os": "debian-etch",
"vcpus": 2,
"oper_state": true
},
...
]
"""
op = ganeti.opcodes.OpQueryInstances(output_fields=["name"], names=[])
instanceslist = baserlib.ExtractField(ganeti.cli.SubmitOpCode(op), 0)
if 'bulk' in self.queryargs:
op = ganeti.opcodes.OpQueryInstances(output_fields=I_FIELDS,
names=instanceslist)
result = ganeti.cli.SubmitOpCode(op)
return baserlib.MapBulkFields(result, I_FIELDS)
else:
return baserlib.BuildUriList(instanceslist, "/instances/%s")
class R_instances_name(baserlib.R_Generic):
"""/instances/[instance_name] resources.
......
......@@ -140,6 +140,14 @@ class R_2_nodes(baserlib.R_Generic):
uri_fields=("id", "uri"))
class R_nodes(R_2_nodes):
"""/nodes resource
"""
# TODO: Temporary resource will be deprecated
DOC_URI = "/nodes"
class R_2_instances(baserlib.R_Generic):
"""/2/instances resource.
......@@ -241,6 +249,14 @@ class R_2_instances(baserlib.R_Generic):
return job_id
class R_instances(R_2_instances):
"""/instances resource.
"""
# TODO: Temporary resource will be deprecated
DOC_URI = "/instances"
class R_2_instances_name_reboot(baserlib.R_Generic):
"""/2/instances/[instance_name]/reboot resource.
......
......@@ -30,6 +30,7 @@ from ganeti import http
from ganeti.rapi import connector
from ganeti.rapi import rlib1
from ganeti.rapi import rlib2
class MapperTests(unittest.TestCase):
......@@ -48,7 +49,7 @@ class MapperTests(unittest.TestCase):
"""Testing Mapper"""
self._TestUri("/tags", (rlib1.R_tags, [], {}))
self._TestUri("/instances", (rlib1.R_instances, [], {}))
self._TestUri("/instances", (rlib2.R_instances, [], {}))
self._TestUri('/instances/www.test.com',
(rlib1.R_instances_name,
......
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