Added the ability to reboot OpenStack server instances
[snaps.git] / snaps / openstack / utils / nova_utils.py
1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 #                    and others.  All rights reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import logging
17
18 import enum
19 import os
20 import time
21 from cryptography.hazmat.backends import default_backend
22 from cryptography.hazmat.primitives import serialization
23 from cryptography.hazmat.primitives.asymmetric import rsa
24 from novaclient.client import Client
25 from novaclient.exceptions import NotFound, ClientException
26
27 from snaps import file_utils
28 from snaps.domain.flavor import Flavor
29 from snaps.domain.keypair import Keypair
30 from snaps.domain.project import ComputeQuotas
31 from snaps.domain.vm_inst import VmInst
32 from snaps.openstack.utils import keystone_utils, glance_utils, neutron_utils
33
34 __author__ = 'spisarski'
35
36 logger = logging.getLogger('nova_utils')
37
38 """
39 Utilities for basic OpenStack Nova API calls
40 """
41
42
43 def nova_client(os_creds):
44     """
45     Instantiates and returns a client for communications with OpenStack's Nova
46     server
47     :param os_creds: The connection credentials to the OpenStack API
48     :return: the client object
49     """
50     logger.debug('Retrieving Nova Client')
51     return Client(os_creds.compute_api_version,
52                   session=keystone_utils.keystone_session(os_creds),
53                   region_name=os_creds.region_name)
54
55
56 def create_server(nova, neutron, glance, instance_config, image_config,
57                   keypair_config=None):
58     """
59     Creates a VM instance
60     :param nova: the nova client (required)
61     :param neutron: the neutron client for retrieving ports (required)
62     :param glance: the glance client (required)
63     :param instance_config: the VMInstConfig object (required)
64     :param image_config: the VM's ImageConfig object (required)
65     :param keypair_config: the VM's KeypairConfig object (optional)
66     :return: a snaps.domain.VmInst object
67     """
68
69     ports = list()
70
71     for port_setting in instance_config.port_settings:
72         ports.append(neutron_utils.get_port(
73             neutron, port_settings=port_setting))
74     nics = []
75     for port in ports:
76         kv = dict()
77         kv['port-id'] = port.id
78         nics.append(kv)
79
80     logger.info('Creating VM with name - ' + instance_config.name)
81     keypair_name = None
82     if keypair_config:
83         keypair_name = keypair_config.name
84
85     flavor = get_flavor_by_name(nova, instance_config.flavor)
86     if not flavor:
87         raise NovaException(
88             'Flavor not found with name - %s', instance_config.flavor)
89
90     image = glance_utils.get_image(glance, image_settings=image_config)
91     if image:
92         userdata = None
93         if instance_config.userdata:
94             if isinstance(instance_config.userdata, str):
95                 userdata = instance_config.userdata + '\n'
96             elif (isinstance(instance_config.userdata, dict) and
97                   'script_file' in instance_config.userdata):
98                 try:
99                     userdata = file_utils.read_file(
100                         instance_config.userdata['script_file'])
101                 except Exception as e:
102                     logger.warn('error reading userdata file %s - %s',
103                                 instance_config.userdata, e)
104         args = {'name': instance_config.name,
105                 'flavor': flavor,
106                 'image': image,
107                 'nics': nics,
108                 'key_name': keypair_name,
109                 'security_groups':
110                     instance_config.security_group_names,
111                 'userdata': userdata}
112
113         if instance_config.availability_zone:
114             args['availability_zone'] = instance_config.availability_zone
115
116         server = nova.servers.create(**args)
117
118         return __map_os_server_obj_to_vm_inst(server)
119     else:
120         raise NovaException(
121             'Cannot create instance, image cannot be located with name %s',
122             image_config.name)
123
124
125 def get_server(nova, vm_inst_settings=None, server_name=None):
126     """
127     Returns a VmInst object for the first server instance found.
128     :param nova: the Nova client
129     :param vm_inst_settings: the VmInstanceConfig object from which to build
130                              the query if not None
131     :param server_name: the server with this name to return if vm_inst_settings
132                         is not None
133     :return: a snaps.domain.VmInst object or None if not found
134     """
135     search_opts = dict()
136     if vm_inst_settings:
137         search_opts['name'] = vm_inst_settings.name
138     elif server_name:
139         search_opts['name'] = server_name
140
141     servers = nova.servers.list(search_opts=search_opts)
142     for server in servers:
143         return __map_os_server_obj_to_vm_inst(server)
144
145
146 def get_server_connection(nova, vm_inst_settings=None, server_name=None):
147     """
148     Returns a VmInst object for the first server instance found.
149     :param nova: the Nova client
150     :param vm_inst_settings: the VmInstanceConfig object from which to build
151                              the query if not None
152     :param server_name: the server with this name to return if vm_inst_settings
153                         is not None
154     :return: a snaps.domain.VmInst object or None if not found
155     """
156     search_opts = dict()
157     if vm_inst_settings:
158         search_opts['name'] = vm_inst_settings.name
159     elif server_name:
160         search_opts['name'] = server_name
161
162     servers = nova.servers.list(search_opts=search_opts)
163     for server in servers:
164         return server.links[0]
165
166
167 def __map_os_server_obj_to_vm_inst(os_server):
168     """
169     Returns a VmInst object for an OpenStack Server object
170     :param os_server: the OpenStack server object
171     :return: an equivalent SNAPS-OO VmInst domain object
172     """
173     sec_grp_names = list()
174     # VM must be active for 'security_groups' attr to be initialized
175     if hasattr(os_server, 'security_groups'):
176         for sec_group in os_server.security_groups:
177             if sec_group.get('name'):
178                 sec_grp_names.append(sec_group.get('name'))
179
180     volumes = None
181     if hasattr(os_server, 'os-extended-volumes:volumes_attached'):
182         volumes = getattr(os_server, 'os-extended-volumes:volumes_attached')
183
184     return VmInst(
185         name=os_server.name, inst_id=os_server.id,
186         image_id=os_server.image['id'], flavor_id=os_server.flavor['id'],
187         networks=os_server.networks, keypair_name=os_server.key_name,
188         sec_grp_names=sec_grp_names, volume_ids=volumes)
189
190
191 def __get_latest_server_os_object(nova, server):
192     """
193     Returns a server with a given id
194     :param nova: the Nova client
195     :param server: the domain VmInst object
196     :return: the list of servers or None if not found
197     """
198     return __get_latest_server_os_object_by_id(nova, server.id)
199
200
201 def __get_latest_server_os_object_by_id(nova, server_id):
202     """
203     Returns a server with a given id
204     :param nova: the Nova client
205     :param server_id: the server's ID
206     :return: the list of servers or None if not found
207     """
208     return nova.servers.get(server_id)
209
210
211 def get_server_status(nova, server):
212     """
213     Returns the a VM instance's status from OpenStack
214     :param nova: the Nova client
215     :param server: the domain VmInst object
216     :return: the VM's string status or None if not founc
217     """
218     server = __get_latest_server_os_object(nova, server)
219     if server:
220         return server.status
221     return None
222
223
224 def get_server_console_output(nova, server):
225     """
226     Returns the console object for parsing VM activity
227     :param nova: the Nova client
228     :param server: the domain VmInst object
229     :return: the console output object or None if server object is not found
230     """
231     server = __get_latest_server_os_object(nova, server)
232     if server:
233         return server.get_console_output()
234     return None
235
236
237 def get_latest_server_object(nova, server):
238     """
239     Returns a server with a given id
240     :param nova: the Nova client
241     :param server: the old server object
242     :return: the list of servers or None if not found
243     """
244     server = __get_latest_server_os_object(nova, server)
245     return __map_os_server_obj_to_vm_inst(server)
246
247
248 def get_server_object_by_id(nova, server_id):
249     """
250     Returns a server with a given id
251     :param nova: the Nova client
252     :param server_id: the server's id
253     :return: an SNAPS-OO VmInst object or None if not found
254     """
255     server = __get_latest_server_os_object_by_id(nova, server_id)
256     return __map_os_server_obj_to_vm_inst(server)
257
258
259 def get_server_security_group_names(nova, server):
260     """
261     Returns a server with a given id
262     :param nova: the Nova client
263     :param server: the old server object
264     :return: the list of security groups associated with a VM
265     """
266     out = list()
267     os_vm_inst = __get_latest_server_os_object(nova, server)
268     for sec_grp_dict in os_vm_inst.security_groups:
269         out.append(sec_grp_dict['name'])
270     return out
271
272
273 def get_server_info(nova, server):
274     """
275     Returns a dictionary of a VMs info as returned by OpenStack
276     :param nova: the Nova client
277     :param server: the old server object
278     :return: a dict of the info if VM exists else None
279     """
280     vm = __get_latest_server_os_object(nova, server)
281     if vm:
282         return vm._info
283     return None
284
285 def reboot_server(nova, server, reboot_type=None):
286     """
287     Returns a dictionary of a VMs info as returned by OpenStack
288     :param nova: the Nova client
289     :param server: the old server object
290     :param reboot_type: Acceptable values 'SOFT', 'HARD'
291                         (api uses SOFT as the default)
292     :return: a dict of the info if VM exists else None
293     """
294     vm = __get_latest_server_os_object(nova, server)
295     if vm:
296         vm.reboot(reboot_type=reboot_type.value)
297     else:
298         raise ServerNotFoundError('Cannot locate server')
299
300
301 def create_keys(key_size=2048):
302     """
303     Generates public and private keys
304     :param key_size: the number of bytes for the key size
305     :return: the cryptography keys
306     """
307     return rsa.generate_private_key(backend=default_backend(),
308                                     public_exponent=65537,
309                                     key_size=key_size)
310
311
312 def public_key_openssh(keys):
313     """
314     Returns the public key for OpenSSH
315     :param keys: the keys generated by create_keys() from cryptography
316     :return: the OpenSSH public key
317     """
318     return keys.public_key().public_bytes(serialization.Encoding.OpenSSH,
319                                           serialization.PublicFormat.OpenSSH)
320
321
322 def save_keys_to_files(keys=None, pub_file_path=None, priv_file_path=None):
323     """
324     Saves the generated RSA generated keys to the filesystem
325     :param keys: the keys to save generated by cryptography
326     :param pub_file_path: the path to the public keys
327     :param priv_file_path: the path to the private keys
328     """
329     if keys:
330         if pub_file_path:
331             # To support '~'
332             pub_expand_file = os.path.expanduser(pub_file_path)
333             pub_dir = os.path.dirname(pub_expand_file)
334
335             if not os.path.isdir(pub_dir):
336                 os.mkdir(pub_dir)
337
338             public_handle = None
339             try:
340                 public_handle = open(pub_expand_file, 'wb')
341                 public_bytes = keys.public_key().public_bytes(
342                     serialization.Encoding.OpenSSH,
343                     serialization.PublicFormat.OpenSSH)
344                 public_handle.write(public_bytes)
345             finally:
346                 if public_handle:
347                     public_handle.close()
348
349             os.chmod(pub_expand_file, 0o600)
350             logger.info("Saved public key to - " + pub_expand_file)
351         if priv_file_path:
352             # To support '~'
353             priv_expand_file = os.path.expanduser(priv_file_path)
354             priv_dir = os.path.dirname(priv_expand_file)
355             if not os.path.isdir(priv_dir):
356                 os.mkdir(priv_dir)
357
358             private_handle = None
359             try:
360                 private_handle = open(priv_expand_file, 'wb')
361                 private_handle.write(
362                     keys.private_bytes(
363                         encoding=serialization.Encoding.PEM,
364                         format=serialization.PrivateFormat.TraditionalOpenSSL,
365                         encryption_algorithm=serialization.NoEncryption()))
366             finally:
367                 if private_handle:
368                     private_handle.close()
369
370             os.chmod(priv_expand_file, 0o600)
371             logger.info("Saved private key to - " + priv_expand_file)
372
373
374 def upload_keypair_file(nova, name, file_path):
375     """
376     Uploads a public key from a file
377     :param nova: the Nova client
378     :param name: the keypair name
379     :param file_path: the path to the public key file
380     :return: the keypair object
381     """
382     fpubkey = None
383     try:
384         with open(os.path.expanduser(file_path), 'rb') as fpubkey:
385             logger.info('Saving keypair to - ' + file_path)
386             return upload_keypair(nova, name, fpubkey.read())
387     finally:
388         if fpubkey:
389             fpubkey.close()
390
391
392 def upload_keypair(nova, name, key):
393     """
394     Uploads a public key from a file
395     :param nova: the Nova client
396     :param name: the keypair name
397     :param key: the public key object
398     :return: the keypair object
399     """
400     logger.info('Creating keypair with name - ' + name)
401     os_kp = nova.keypairs.create(name=name, public_key=key.decode('utf-8'))
402     return Keypair(name=os_kp.name, kp_id=os_kp.id,
403                    public_key=os_kp.public_key, fingerprint=os_kp.fingerprint)
404
405
406 def keypair_exists(nova, keypair_obj):
407     """
408     Returns a copy of the keypair object if found
409     :param nova: the Nova client
410     :param keypair_obj: the keypair object
411     :return: the keypair object or None if not found
412     """
413     try:
414         os_kp = nova.keypairs.get(keypair_obj)
415         return Keypair(name=os_kp.name, kp_id=os_kp.id,
416                        public_key=os_kp.public_key)
417     except:
418         return None
419
420
421 def get_keypair_by_name(nova, name):
422     """
423     Returns a list of all available keypairs
424     :param nova: the Nova client
425     :param name: the name of the keypair to lookup
426     :return: the keypair object or None if not found
427     """
428     keypairs = nova.keypairs.list()
429
430     for keypair in keypairs:
431         if keypair.name == name:
432             return Keypair(name=keypair.name, kp_id=keypair.id,
433                            public_key=keypair.public_key)
434
435     return None
436
437
438 def get_keypair_by_id(nova, kp_id):
439     """
440     Returns a list of all available keypairs
441     :param nova: the Nova client
442     :param kp_id: the ID of the keypair to return
443     :return: the keypair object
444     """
445     keypair = nova.keypairs.get(kp_id)
446     return Keypair(name=keypair.name, kp_id=keypair.id,
447                    public_key=keypair.public_key)
448
449
450 def delete_keypair(nova, key):
451     """
452     Deletes a keypair object from OpenStack
453     :param nova: the Nova client
454     :param key: the SNAPS-OO keypair domain object to delete
455     """
456     logger.debug('Deleting keypair - ' + key.name)
457     nova.keypairs.delete(key.id)
458
459
460 def get_availability_zone_hosts(nova, zone_name='nova'):
461     """
462     Returns the names of all nova active compute servers
463     :param nova: the Nova client
464     :param zone_name: the Nova client
465     :return: a list of compute server names
466     """
467     out = list()
468     zones = nova.availability_zones.list()
469     for zone in zones:
470         if zone.zoneName == zone_name and zone.hosts:
471             for key, host in zone.hosts.items():
472                 if host['nova-compute']['available']:
473                     out.append(zone.zoneName + ':' + key)
474
475     return out
476
477
478 def delete_vm_instance(nova, vm_inst):
479     """
480     Deletes a VM instance
481     :param nova: the nova client
482     :param vm_inst: the snaps.domain.VmInst object
483     """
484     nova.servers.delete(vm_inst.id)
485
486
487 def __get_os_flavor(nova, flavor_id):
488     """
489     Returns to OpenStack flavor object by name
490     :param nova: the Nova client
491     :param flavor_id: the flavor's ID value
492     :return: the OpenStack Flavor object
493     """
494     try:
495         return nova.flavors.get(flavor_id)
496     except NotFound:
497         return None
498
499
500 def get_flavor(nova, flavor):
501     """
502     Returns to OpenStack flavor object by name
503     :param nova: the Nova client
504     :param flavor: the SNAPS flavor domain object
505     :return: the SNAPS Flavor domain object
506     """
507     os_flavor = __get_os_flavor(nova, flavor.id)
508     if os_flavor:
509         return Flavor(
510             name=os_flavor.name, id=os_flavor.id, ram=os_flavor.ram,
511             disk=os_flavor.disk, vcpus=os_flavor.vcpus,
512             ephemeral=os_flavor.ephemeral, swap=os_flavor.swap,
513             rxtx_factor=os_flavor.rxtx_factor, is_public=os_flavor.is_public)
514     try:
515         return nova.flavors.get(flavor.id)
516     except NotFound:
517         return None
518
519
520 def get_flavor_by_id(nova, flavor_id):
521     """
522     Returns to OpenStack flavor object by name
523     :param nova: the Nova client
524     :param flavor_id: the flavor ID value
525     :return: the SNAPS Flavor domain object
526     """
527     os_flavor = __get_os_flavor(nova, flavor_id)
528     if os_flavor:
529         return Flavor(
530             name=os_flavor.name, id=os_flavor.id, ram=os_flavor.ram,
531             disk=os_flavor.disk, vcpus=os_flavor.vcpus,
532             ephemeral=os_flavor.ephemeral, swap=os_flavor.swap,
533             rxtx_factor=os_flavor.rxtx_factor, is_public=os_flavor.is_public)
534
535
536 def __get_os_flavor_by_name(nova, name):
537     """
538     Returns to OpenStack flavor object by name
539     :param nova: the Nova client
540     :param name: the name of the flavor to query
541     :return: OpenStack flavor object
542     """
543     try:
544         return nova.flavors.find(name=name)
545     except NotFound:
546         return None
547
548
549 def get_flavor_by_name(nova, name):
550     """
551     Returns a flavor by name
552     :param nova: the Nova client
553     :param name: the flavor name to return
554     :return: the SNAPS flavor domain object or None if not exists
555     """
556     os_flavor = __get_os_flavor_by_name(nova, name)
557     if os_flavor:
558         return Flavor(
559             name=os_flavor.name, id=os_flavor.id, ram=os_flavor.ram,
560             disk=os_flavor.disk, vcpus=os_flavor.vcpus,
561             ephemeral=os_flavor.ephemeral, swap=os_flavor.swap,
562             rxtx_factor=os_flavor.rxtx_factor, is_public=os_flavor.is_public)
563
564
565 def create_flavor(nova, flavor_settings):
566     """
567     Creates and returns and OpenStack flavor object
568     :param nova: the Nova client
569     :param flavor_settings: the flavor settings
570     :return: the SNAPS flavor domain object
571     """
572     os_flavor = nova.flavors.create(
573         name=flavor_settings.name, flavorid=flavor_settings.flavor_id,
574         ram=flavor_settings.ram, vcpus=flavor_settings.vcpus,
575         disk=flavor_settings.disk, ephemeral=flavor_settings.ephemeral,
576         swap=flavor_settings.swap, rxtx_factor=flavor_settings.rxtx_factor,
577         is_public=flavor_settings.is_public)
578     return Flavor(
579         name=os_flavor.name, id=os_flavor.id, ram=os_flavor.ram,
580         disk=os_flavor.disk, vcpus=os_flavor.vcpus,
581         ephemeral=os_flavor.ephemeral, swap=os_flavor.swap,
582         rxtx_factor=os_flavor.rxtx_factor, is_public=os_flavor.is_public)
583
584
585 def delete_flavor(nova, flavor):
586     """
587     Deletes a flavor
588     :param nova: the Nova client
589     :param flavor: the SNAPS flavor domain object
590     """
591     nova.flavors.delete(flavor.id)
592
593
594 def set_flavor_keys(nova, flavor, metadata):
595     """
596     Sets metadata on the flavor
597     :param nova: the Nova client
598     :param flavor: the SNAPS flavor domain object
599     :param metadata: the metadata to set
600     """
601     os_flavor = __get_os_flavor(nova, flavor.id)
602     if os_flavor:
603         os_flavor.set_keys(metadata)
604
605
606 def get_flavor_keys(nova, flavor):
607     """
608     Sets metadata on the flavor
609     :param nova: the Nova client
610     :param flavor: the SNAPS flavor domain object
611     """
612     os_flavor = __get_os_flavor(nova, flavor.id)
613     if os_flavor:
614         return os_flavor.get_keys()
615
616
617 def add_security_group(nova, vm, security_group_name):
618     """
619     Adds a security group to an existing VM
620     :param nova: the nova client
621     :param vm: the OpenStack server object (VM) to alter
622     :param security_group_name: the name of the security group to add
623     """
624     try:
625         nova.servers.add_security_group(str(vm.id), security_group_name)
626     except ClientException as e:
627         sec_grp_names = get_server_security_group_names(nova, vm)
628         if security_group_name in sec_grp_names:
629             logger.warn('Security group [%s] already added to VM [%s]',
630                         security_group_name, vm.name)
631             return
632
633         logger.error('Unexpected error while adding security group [%s] - %s',
634                      security_group_name, e)
635         raise
636
637
638 def remove_security_group(nova, vm, security_group):
639     """
640     Removes a security group from an existing VM
641     :param nova: the nova client
642     :param vm: the OpenStack server object (VM) to alter
643     :param security_group: the SNAPS SecurityGroup domain object to add
644     """
645     nova.servers.remove_security_group(str(vm.id), security_group.name)
646
647
648 def add_floating_ip_to_server(nova, vm, floating_ip, ip_addr):
649     """
650     Adds a floating IP to a server instance
651     :param nova: the nova client
652     :param vm: VmInst domain object
653     :param floating_ip: FloatingIp domain object
654     :param ip_addr: the IP to which to bind the floating IP to
655     """
656     vm = __get_latest_server_os_object(nova, vm)
657     vm.add_floating_ip(floating_ip.ip, ip_addr)
658
659
660 def get_compute_quotas(nova, project_id):
661     """
662     Returns a list of all available keypairs
663     :param nova: the Nova client
664     :param project_id: the project's ID of the quotas to lookup
665     :return: an object of type ComputeQuotas or None if not found
666     """
667     quotas = nova.quotas.get(tenant_id=project_id)
668     if quotas:
669         return ComputeQuotas(quotas)
670
671
672 def update_quotas(nova, project_id, compute_quotas):
673     """
674     Updates the compute quotas for a given project
675     :param nova: the Nova client
676     :param project_id: the project's ID that requires quota updates
677     :param compute_quotas: an object of type ComputeQuotas containing the
678                            values to update
679     :return:
680     """
681     update_values = dict()
682     update_values['metadata_items'] = compute_quotas.metadata_items
683     update_values['cores'] = compute_quotas.cores
684     update_values['instances'] = compute_quotas.instances
685     update_values['injected_files'] = compute_quotas.injected_files
686     update_values['injected_file_content_bytes'] = (
687         compute_quotas.injected_file_content_bytes)
688     update_values['ram'] = compute_quotas.ram
689     update_values['fixed_ips'] = compute_quotas.fixed_ips
690     update_values['key_pairs'] = compute_quotas.key_pairs
691
692     return nova.quotas.update(project_id, **update_values)
693
694
695 def attach_volume(nova, server, volume, timeout=None):
696     """
697     Attaches a volume to a server
698     :param nova: the nova client
699     :param server: the VMInst domain object
700     :param volume: the Volume domain object
701     :param timeout: denotes the amount of time to block to determine if the
702                     has been properly attached. When None, do not wait.
703     :return: the value from the nova call
704     """
705     nova.volumes.create_server_volume(server.id, volume.id)
706
707     if timeout:
708         start_time = time.time()
709         while time.time() < start_time + timeout:
710             vm = get_server_object_by_id(nova, server.id)
711             for vol_dict in vm.volume_ids:
712                 if volume.id == vol_dict['id']:
713                     return vm
714
715         return None
716     else:
717         return get_server_object_by_id(nova, server.id)
718
719
720 def detach_volume(nova, server, volume, timeout=None):
721     """
722     Attaches a volume to a server
723     :param nova: the nova client
724     :param server: the VMInst domain object
725     :param volume: the Volume domain object
726     :param timeout: denotes the amount of time to block to determine if the
727                     has been properly detached. When None, do not wait.
728     :return: the value from the nova call
729     """
730     nova.volumes.delete_server_volume(server.id, volume.id)
731
732     if timeout:
733         start_time = time.time()
734         while time.time() < start_time + timeout:
735             vm = get_server_object_by_id(nova, server.id)
736             found = False
737             for vol_dict in vm.volume_ids:
738                 if volume.id == vol_dict['id']:
739                     found = True
740
741             if not found:
742                 return vm
743
744         return None
745     else:
746         return get_server_object_by_id(nova, server.id)
747
748
749 class RebootType(enum.Enum):
750     """
751     A rule's direction
752     """
753     soft = 'SOFT'
754     hard = 'HARD'
755
756
757 class NovaException(Exception):
758     """
759     Exception when calls to the Keystone client cannot be served properly
760     """
761
762
763 class ServerNotFoundError(Exception):
764     """
765     Exception when operations to a VM/Server is requested and the OpenStack
766     Server instance cannot be located
767     """