Commit 4e5a68f8 authored by Oleksiy Mishchenko's avatar Oleksiy Mishchenko
Browse files

RAPI: rlib1 removal

The resources we still need moved to rlib2.

Reviewed-by: iustinp
parent fc72a3a3
......@@ -97,7 +97,6 @@ rapi_PYTHON = \
lib/rapi/__init__.py \
lib/rapi/baserlib.py \
lib/rapi/connector.py \
lib/rapi/rlib1.py \
lib/rapi/rlib2.py
http_PYTHON = \
......
......@@ -26,7 +26,6 @@ import re
import cgi
import inspect
from ganeti.rapi import rlib1
from ganeti.rapi import rlib2
from ganeti.rapi import connector
......@@ -38,7 +37,7 @@ def main():
# Get list of all resources
all = list(connector.CONNECTOR.itervalues())
# Sort rlib1 by URI
# Sort rlib by URI
all.sort(cmp=lambda a, b: cmp(a.DOC_URI, b.DOC_URI))
print "<!-- Automatically generated, do not edit -->"
......
......@@ -29,7 +29,6 @@ from ganeti import constants
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
......@@ -152,13 +151,14 @@ class R_2(baserlib.R_Generic):
CONNECTOR.update({
"/": R_root,
"/version": rlib1.R_version,
"/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,
"/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,
......@@ -167,4 +167,7 @@ CONNECTOR.update({
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,
})
#
#
# Copyright (C) 2006, 2007, 2008 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Remote API version 1 resources library.
"""
import ganeti.cli
import ganeti.errors
import ganeti.opcodes
from ganeti import constants
from ganeti import http
from ganeti.rapi import baserlib
I_FIELDS = ["name", "os", "pnode", "snodes", "admin_state", "disk_template",
"ip", "mac", "bridge", "sda_size", "sdb_size", "beparams",
"oper_state", "status", "tags"]
N_FIELDS = ["name", "dtotal", "dfree",
"mtotal", "mnode", "mfree",
"pinst_cnt", "sinst_cnt", "tags"]
class R_version(baserlib.R_Generic):
"""/version resource.
This resource should be used to determine the remote API version and
to adapt clients accordingly.
"""
DOC_URI = "/version"
def GET(self):
"""Returns the remote API version.
"""
return constants.RAPI_VERSION
class R_tags(baserlib.R_Generic):
"""/tags resource.
Manages cluster tags.
"""
DOC_URI = "/tags"
def GET(self):
"""Returns a list of all cluster tags.
Example: ["tag1", "tag2", "tag3"]
"""
return baserlib._Tags_GET(constants.TAG_CLUSTER)
class R_info(baserlib.R_Generic):
"""Cluster info.
"""
DOC_URI = "/info"
def GET(self):
"""Returns cluster information.
Example::
{
"config_version": 3,
"name": "cluster1.example.com",
"software_version": "1.2.4",
"os_api_version": 5,
"export_version": 0,
"master": "node1.example.com",
"architecture": [
"64bit",
"x86_64"
],
"hypervisor_type": "xen-pvm",
"protocol_version": 12
}
"""
op = ganeti.opcodes.OpQueryClusterInfo()
return ganeti.cli.SubmitOpCode(op)
class R_nodes_name(baserlib.R_Generic):
"""/nodes/[node_name] resources.
"""
DOC_URI = "/nodes/[node_name]"
def GET(self):
"""Send information about a node.
"""
node_name = self.items[0]
op = ganeti.opcodes.OpQueryNodes(output_fields=N_FIELDS,
names=[node_name])
result = ganeti.cli.SubmitOpCode(op)
return baserlib.MapFields(N_FIELDS, result[0])
class R_nodes_name_tags(baserlib.R_Generic):
"""/nodes/[node_name]/tags resource.
Manages per-node tags.
"""
DOC_URI = "/nodes/[node_name]/tags"
def GET(self):
"""Returns a list of node tags.
Example: ["tag1", "tag2", "tag3"]
"""
return baserlib._Tags_GET(constants.TAG_NODE, name=self.items[0])
class R_instances_name(baserlib.R_Generic):
"""/instances/[instance_name] resources.
"""
DOC_URI = "/instances/[instance_name]"
def GET(self):
"""Send information about an instance.
"""
instance_name = self.items[0]
op = ganeti.opcodes.OpQueryInstances(output_fields=I_FIELDS,
names=[instance_name])
result = ganeti.cli.SubmitOpCode(op)
return baserlib.MapFields(I_FIELDS, result[0])
def DELETE(self):
"""Removes an instance.
"""
instance_name = self.items[0]
op = ganeti.opcodes.OpRemoveInstance(instance_name=instance_name,
ignore_failures=True)
job_id = ganeti.cli.SendJob([op])
return job_id
def PUT(self):
"""Modify an instance.
"""
instance_name = self.items[0]
opts = {}
for key in self.queryargs:
opts[key] = self.queryargs[key][0]
beparams = baserlib.MakeParamsDict(opts, constants.BES_PARAMETERS)
hvparams = baserlib.MakeParamsDict(opts, constants.HVS_PARAMETERS)
op = ganeti.opcodes.OpSetInstanceParams(
instance_name=instance_name,
ip=opts.get('ip', None),
bridge=opts.get('bridge', None),
mac=opts.get('mac', None),
hvparams=hvparams,
beparams=beparams,
force=opts.get('force', None))
job_id = ganeti.cli.SendJob([op])
return job_id
class R_instances_name_tags(baserlib.R_Generic):
"""/instances/[instance_name]/tags resource.
Manages per-instance tags.
"""
DOC_URI = "/instances/[instance_name]/tags"
def GET(self):
"""Returns a list of instance tags.
Example: ["tag1", "tag2", "tag3"]
"""
return baserlib._Tags_GET(constants.TAG_INSTANCE, name=self.items[0])
class R_os(baserlib.R_Generic):
"""/os resource.
"""
DOC_URI = "/os"
def GET(self):
"""Return a list of all OSes.
Can return error 500 in case of a problem.
Example: ["debian-etch"]
"""
op = ganeti.opcodes.OpDiagnoseOS(output_fields=["name", "valid"],
names=[])
diagnose_data = ganeti.cli.SubmitOpCode(op)
if not isinstance(diagnose_data, list):
raise http.HttpInternalServerError(message="Can't get OS list")
return [row[0] for row in diagnose_data if row[1]]
......@@ -29,7 +29,102 @@ from ganeti import luxi
from ganeti import constants
from ganeti.rapi import baserlib
from ganeti.rapi.rlib1 import I_FIELDS, N_FIELDS
I_FIELDS = ["name", "os", "pnode", "snodes", "admin_state", "disk_template",
"ip", "mac", "bridge", "sda_size", "sdb_size", "beparams",
"oper_state", "status", "tags"]
N_FIELDS = ["name", "dtotal", "dfree",
"mtotal", "mnode", "mfree",
"pinst_cnt", "sinst_cnt", "tags"]
class R_version(baserlib.R_Generic):
"""/version resource.
This resource should be used to determine the remote API version and
to adapt clients accordingly.
"""
DOC_URI = "/version"
def GET(self):
"""Returns the remote API version.
"""
return constants.RAPI_VERSION
class R_2_info(baserlib.R_Generic):
"""Cluster info.
"""
DOC_URI = "/2/info"
def GET(self):
"""Returns cluster information.
Example::
{
"config_version": 3,
"name": "cluster1.example.com",
"software_version": "1.2.4",
"os_api_version": 5,
"export_version": 0,
"master": "node1.example.com",
"architecture": [
"64bit",
"x86_64"
],
"hypervisor_type": "xen-pvm",
"protocol_version": 12
}
"""
op = ganeti.opcodes.OpQueryClusterInfo()
return ganeti.cli.SubmitOpCode(op)
class R_2_tags(baserlib.R_Generic):
"""/2/tags resource.
Manages cluster tags.
"""
DOC_URI = "/2/tags"
def GET(self):
"""Returns a list of all cluster tags.
Example: ["tag1", "tag2", "tag3"]
"""
return baserlib._Tags_GET(constants.TAG_CLUSTER)
class R_2_os(baserlib.R_Generic):
"""/2/os resource.
"""
DOC_URI = "/2/os"
def GET(self):
"""Return a list of all OSes.
Can return error 500 in case of a problem.
Example: ["debian-etch"]
"""
op = ganeti.opcodes.OpDiagnoseOS(output_fields=["name", "valid"],
names=[])
diagnose_data = ganeti.cli.SubmitOpCode(op)
if not isinstance(diagnose_data, list):
raise http.HttpInternalServerError(message="Can't get OS list")
return [row[0] for row in diagnose_data if row[1]]
class R_2_jobs(baserlib.R_Generic):
......@@ -141,12 +236,22 @@ class R_2_nodes(baserlib.R_Generic):
uri_fields=("id", "uri"))
class R_nodes(R_2_nodes):
"""/nodes resource
class R_2_nodes_name(baserlib.R_Generic):
"""/2/nodes/[node_name] resources.
"""
# TODO: Temporary resource will be deprecated
DOC_URI = "/nodes"
DOC_URI = "/nodes/[node_name]"
def GET(self):
"""Send information about a node.
"""
node_name = self.items[0]
op = ganeti.opcodes.OpQueryNodes(output_fields=N_FIELDS,
names=[node_name])
result = ganeti.cli.SubmitOpCode(op)
return baserlib.MapFields(N_FIELDS, result[0])
class R_2_instances(baserlib.R_Generic):
......@@ -254,12 +359,22 @@ class R_2_instances(baserlib.R_Generic):
return job_id
class R_instances(R_2_instances):
"""/instances resource.
class R_2_instances_name(baserlib.R_Generic):
"""/2/instances/[instance_name] resources.
"""
# TODO: Temporary resource will be deprecated
DOC_URI = "/instances"
DOC_URI = "/2/instances/[instance_name]"
def GET(self):
"""Send information about an instance.
"""
instance_name = self.items[0]
op = ganeti.opcodes.OpQueryInstances(output_fields=I_FIELDS,
names=[instance_name])
result = ganeti.cli.SubmitOpCode(op)
return baserlib.MapFields(I_FIELDS, result[0])
class R_2_instances_name_reboot(baserlib.R_Generic):
......
......@@ -29,7 +29,6 @@ from ganeti import errors
from ganeti import http
from ganeti.rapi import connector
from ganeti.rapi import rlib1
from ganeti.rapi import rlib2
......@@ -50,10 +49,10 @@ class MapperTests(unittest.TestCase):
self._TestFailingUri("/tags")
self._TestFailingUri("/instances")
self._TestUri("/version", (rlib1.R_version, [], {}))
self._TestUri("/version", (rlib2.R_version, [], {}))
self._TestUri('/2/instances/www.test.com',
(rlib1.R_instances_name,
(rlib2.R_2_instances_name,
['www.test.com'],
{}))
......
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