diff --git a/lib/rapi/connector.py b/lib/rapi/connector.py index 1ce02ad26f8de75bff09802b54440be863677ff3..99a00cec404b56bbec5436927c3778039b421eba 100644 --- a/lib/rapi/connector.py +++ b/lib/rapi/connector.py @@ -140,5 +140,7 @@ CONNECTOR.update({ "/2/instances": rlib2.R_2_instances, re.compile(r'^/2/instances/([\w\._-]+)$'): rlib1.R_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/jobs/(%s)$' % constants.JOB_ID_TEMPLATE): rlib2.R_2_jobs_id, }) diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py index 832fe456feb8864313d5b33183e6af2a63767226..1556cfbf98b0ec0c0e905d90e6514ffb50f500e8 100644 --- a/lib/rapi/rlib2.py +++ b/lib/rapi/rlib2.py @@ -245,6 +245,33 @@ class R_2_instances(baserlib.R_Generic): return job_id +class R_2_instances_name_reboot(baserlib.R_Generic): + """/2/instances/[instance_name]/reboot resource. + + Implements an instance reboot. + + """ + + DOC_URI = "/2/instances/[instance_name]/reboot" + + def GET(self): + """Reboot an instance. + + """ + instance_name = self.items[0] + reboot_type = self.queryargs.get('reboot_type', + constants.INSTANCE_REBOOT_HARD) + ignore_secondaries = self.queryargs.get('ignore_secondaries', False) + op = ganeti.opcodes.OpRebootInstance( + instance_name=instance_name, + reboot_type=reboot_type, + ignore_secondaries=ignore_secondaries) + + job_id = ganeti.cli.SendJob([op]) + + return job_id + + class R_2_instances_name_tags(baserlib.R_Generic): """/2/instances/[instance_name]/tags resource.