From e2f708a2527816a845ca1048f5ad5c58fdb506e0 Mon Sep 17 00:00:00 2001 From: spisarski Date: Fri, 1 Dec 2017 11:06:23 -0700 Subject: Added the ability to reboot OpenStack server instances JIRA: SNAPS-243 Change-Id: I7232ee14cac81d39d86e7391a4e006b8276ed536 Signed-off-by: spisarski --- snaps/openstack/utils/nova_utils.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'snaps/openstack/utils/nova_utils.py') diff --git a/snaps/openstack/utils/nova_utils.py b/snaps/openstack/utils/nova_utils.py index b735ee2..2d569e6 100644 --- a/snaps/openstack/utils/nova_utils.py +++ b/snaps/openstack/utils/nova_utils.py @@ -15,6 +15,7 @@ import logging +import enum import os import time from cryptography.hazmat.backends import default_backend @@ -281,6 +282,21 @@ def get_server_info(nova, server): return vm._info return None +def reboot_server(nova, server, reboot_type=None): + """ + Returns a dictionary of a VMs info as returned by OpenStack + :param nova: the Nova client + :param server: the old server object + :param reboot_type: Acceptable values 'SOFT', 'HARD' + (api uses SOFT as the default) + :return: a dict of the info if VM exists else None + """ + vm = __get_latest_server_os_object(nova, server) + if vm: + vm.reboot(reboot_type=reboot_type.value) + else: + raise ServerNotFoundError('Cannot locate server') + def create_keys(key_size=2048): """ @@ -730,7 +746,22 @@ def detach_volume(nova, server, volume, timeout=None): return get_server_object_by_id(nova, server.id) +class RebootType(enum.Enum): + """ + A rule's direction + """ + soft = 'SOFT' + hard = 'HARD' + + class NovaException(Exception): """ Exception when calls to the Keystone client cannot be served properly """ + + +class ServerNotFoundError(Exception): + """ + Exception when operations to a VM/Server is requested and the OpenStack + Server instance cannot be located + """ -- cgit 1.2.3-korg