Commit e5b7c4ca authored by Iustin Pop's avatar Iustin Pop
Browse files

RAPI: implement instance reinstall



This patch adds instance reinstall to RAPI, with two optional parameters:
  - ‘os', in order to change the OS on reinstall
  - ‘nostartup’, in order to leave the instance down after reinstall

The call will first shutdown the instance, the reinstall it, and unless
‘nostartup’ has been passed and is equal to 1, it will be started
automatically.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 8e2524c3
......@@ -252,6 +252,18 @@ class R_Generic(object):
" '%s' parameter" % (name,))
return val
def _checkStringVariable(self, name, default=None):
"""Return the parsed value of an int argument.
"""
val = self.queryargs.get(name, default)
if isinstance(val, list):
if val:
val = val[0]
else:
val = default
return val
def getBodyParameter(self, name, *args):
"""Check and return the value for a given parameter.
......
......@@ -163,6 +163,8 @@ CONNECTOR.update({
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\._-]+)/reinstall$'):
rlib2.R_2_instances_name_reinstall,
re.compile(r'^/2/instances/([\w\._-]+)/shutdown$'):
rlib2.R_2_instances_name_shutdown,
re.compile(r'^/2/instances/([\w\._-]+)/startup$'):
......
......@@ -493,6 +493,36 @@ class R_2_instances_name_shutdown(baserlib.R_Generic):
return baserlib.SubmitJob([op])
class R_2_instances_name_reinstall(baserlib.R_Generic):
"""/2/instances/[instance_name]/reinstall resource.
Implements an instance reinstall.
"""
DOC_URI = "/2/instances/[instance_name]/reinstall"
def POST(self):
"""Reinstall an instance.
The URI takes os=name and nostartup=[0|1] optional
parameters. By default, the instance will be started
automatically.
"""
instance_name = self.items[0]
ostype = self._checkStringVariable('os')
nostartup = self._checkIntVariable('nostartup')
ops = [
opcodes.OpShutdownInstance(instance_name=instance_name),
opcodes.OpReinstallInstance(instance_name=instance_name, os_type=ostype),
]
if not nostartup:
ops.append(opcodes.OpStartupInstance(instance_name=instance_name,
force=False))
return baserlib.SubmitJob(ops)
class _R_Tags(baserlib.R_Generic):
""" Quasiclass for tagging resources
......
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