Commit 2f7635f4 authored by Oleksiy Mishchenko's avatar Oleksiy Mishchenko
Browse files

RAPI: Instance add/delete implementation.

Reviewed-by: iustinp
parent 29fc6636
...@@ -33,10 +33,9 @@ from ganeti import http ...@@ -33,10 +33,9 @@ from ganeti import http
from ganeti.rapi import baserlib from ganeti.rapi import baserlib
I_FIELDS = ["name", "os", "pnode", "snodes", I_FIELDS = ["name", "os", "pnode", "snodes", "admin_state", "disk_template",
"admin_state", "admin_ram", "ip", "mac", "bridge", "sda_size", "sdb_size", "be/vcpus",
"disk_template", "ip", "mac", "bridge", "be/memory", "be/auto_balance",
"sda_size", "sdb_size", "vcpus",
"oper_state", "status", "tags"] "oper_state", "status", "tags"]
N_FIELDS = ["name", "dtotal", "dfree", N_FIELDS = ["name", "dtotal", "dfree",
...@@ -276,6 +275,17 @@ class R_instances_name(baserlib.R_Generic): ...@@ -276,6 +275,17 @@ class R_instances_name(baserlib.R_Generic):
return baserlib.MapFields(I_FIELDS, result[0]) 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
class R_instances_name_tags(baserlib.R_Generic): class R_instances_name_tags(baserlib.R_Generic):
"""/instances/[instance_name]/tags resource. """/instances/[instance_name]/tags resource.
......
...@@ -139,7 +139,6 @@ class R_2_instances(baserlib.R_Generic): ...@@ -139,7 +139,6 @@ class R_2_instances(baserlib.R_Generic):
""" """
DOC_URI = "/2/instances" DOC_URI = "/2/instances"
def GET(self): def GET(self):
"""Returns a list of all available instances. """Returns a list of all available instances.
...@@ -197,6 +196,54 @@ class R_2_instances(baserlib.R_Generic): ...@@ -197,6 +196,54 @@ class R_2_instances(baserlib.R_Generic):
return baserlib.BuildUriList(instanceslist, "/2/instances/%s", return baserlib.BuildUriList(instanceslist, "/2/instances/%s",
uri_fields=("id", "uri")) uri_fields=("id", "uri"))
def PUT(self):
"""Create an instance.
Returns:
A job id.
"""
opts = self.post_data
# beparams
mem = opts.get('mem', None)
vcpus = opts.get('vcpus', None)
auto_balance = opts.get('auto_balance', None)
beparams = {}
for key, const in [(mem, constants.BE_MEMORY),
(vcpus, constants.BE_VCPUS),
(auto_balance, constants.BE_AUTO_BALANCE)]:
if key is not None:
beparams[const] = key
op = ganeti.opcodes.OpCreateInstance(
instance_name=opts.get('name'),
disk_size=opts.get('size', 20 * 1024),
swap_size=opts.get('swap', 4 * 1024),
disk_template=opts.get('disk_template', None),
mode=constants.INSTANCE_CREATE,
os_type=opts.get('os'),
pnode=opts.get('pnode'),
snode=opts.get('snode'),
ip=opts.get('ip', 'none'),
bridge=opts.get('bridge', None),
start=opts.get('start', True),
ip_check=opts.get('ip_check', True),
wait_for_sync=opts.get('wait_for_sync', True),
mac=opts.get('mac', 'auto'),
hypervisor=opts.get('hypervisor', None),
hvparams=opts.get('hvparams', {}),
beparams=beparams,
iallocator=opts.get('iallocator', None),
file_storage_dir=opts.get('file_storage_dir', None),
file_driver=opts.get('file_driver', 'loop'),
)
job_id = ganeti.cli.SendJob([op])
return job_id
class R_2_instances_name_tags(baserlib.R_Generic): class R_2_instances_name_tags(baserlib.R_Generic):
"""/2/instances/[instance_name]/tags resource. """/2/instances/[instance_name]/tags resource.
......
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