summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/utils/nova_utils.py
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-12-01 11:06:23 -0700
committerspisarski <s.pisarski@cablelabs.com>2017-12-04 16:00:21 -0800
commite2f708a2527816a845ca1048f5ad5c58fdb506e0 (patch)
treef965d21a4e5552795b81683474bb2bf67126f2f0 /snaps/openstack/utils/nova_utils.py
parentef454fe1c79bd5e920a34bc7d71ff56114035280 (diff)
Added the ability to reboot OpenStack server instances
JIRA: SNAPS-243 Change-Id: I7232ee14cac81d39d86e7391a4e006b8276ed536 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/utils/nova_utils.py')
-rw-r--r--snaps/openstack/utils/nova_utils.py31
1 files changed, 31 insertions, 0 deletions
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
+ """