From 69049a9321757680831f802180399f46403527c8 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 12 May 2019 19:21:52 +0200 Subject: [PATCH] Add poweroff and resume methods --- opennebula_api/models.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/opennebula_api/models.py b/opennebula_api/models.py index 01bd065a..3a74ad63 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -363,6 +363,40 @@ class OpenNebulaManager(): return vm_terminated + def power_off_vm(self, vm_id): + vm = None + try: + vm = self.get_vm(vm_id) + vm.poweroff() + except socket.timeout as socket_err: + logger.error("Socket timeout error: {0}".format(socket_err)) + except OpenNebulaException as opennebula_err: + logger.error( + "OpenNebulaException error: {0}".format(opennebula_err)) + except OSError as os_err: + logger.error("OSError : {0}".format(os_err)) + except ValueError as value_err: + logger.error("ValueError : {0}".format(value_err)) + + return vm + + def resume(self, vm_id): + vm = None + try: + vm = self.get_vm(vm_id) + vm.resume() + except socket.timeout as socket_err: + logger.error("Socket timeout error: {0}".format(socket_err)) + except OpenNebulaException as opennebula_err: + logger.error( + "OpenNebulaException error: {0}".format(opennebula_err)) + except OSError as os_err: + logger.error("OSError : {0}".format(os_err)) + except ValueError as value_err: + logger.error("ValueError : {0}".format(value_err)) + + return vm + def save_key_in_vm_template(self, vm_id, ssh_key): """ Update the template of a given VM and set the ssh key of the user @@ -385,7 +419,7 @@ class OpenNebulaManager(): logger.error( "Could not save the key in VM Template. %s" % return_value) - return + return return_value def save_key_in_opennebula_user(self, ssh_key): """