if block:
if not self.vm_active(block=True):
- raise Exception(
+ raise VmInstanceCreationError(
'Fatal error, VM did not become ACTIVE within the alloted '
'time')
nova_utils.add_security_group(self.__nova, self.__vm,
sec_grp_name)
else:
- raise Exception(
+ raise VmInstanceCreationError(
'Cannot applying security group with name ' +
sec_grp_name +
' to VM that did not activate with name - ' +
port = port_dict.get(floating_ip_setting.port_name)
if not port:
- raise Exception(
+ raise VmInstanceCreationError(
'Cannot find port object with name - ' +
floating_ip_setting.port_name)
floating_ip_setting.router_name)
self.__add_floating_ip(floating_ip, port, subnet)
else:
- raise Exception('Unable to add floating IP to port,'
- ' cannot locate router with an external '
- 'gateway ')
+ raise VmInstanceCreationError(
+ 'Unable to add floating IP to port, cannot locate router '
+ 'with an external gateway ')
def __ext_gateway_by_router(self, router_name):
"""
count -= 1
pass
else:
- raise Exception(
+ raise VmInstanceCreationError(
'Unable find IP address on which to place the floating IP')
logger.error('Timeout attempting to add the floating IP to instance.')
- raise Exception('Timeout while attempting add floating IP to instance')
+ raise VmInstanceCreationError(
+ 'Timeout while attempting add floating IP to instance')
def get_os_creds(self):
"""
"""
return self.__vm
- def get_os_vm_server_obj(self):
+ def get_console_output(self):
"""
- Returns the OpenStack server object
- :return: the server object
+ Returns the vm console object for parsing logs
+ :return: the console output object
"""
- return nova_utils.get_latest_server_os_object(self.__nova, self.__vm)
+ return nova_utils.get_server_console_output(self.__nova, self.__vm)
def get_port_ip(self, port_name, subnet_name=None):
"""
logger.warning('Cannot find port with name - ' + port_name)
return None
+ def get_vm_info(self):
+ """
+ Returns a dictionary of a VMs info as returned by OpenStack
+ :return: a dict()
+ """
+ return nova_utils.get_server_info(self.__nova, self.__vm)
+
def config_nics(self):
"""
Responsible for configuring NICs on RPM systems where the instance has
if not self.__vm:
return False
- instance = nova_utils.get_latest_server_os_object(
- self.__nova, self.__vm)
- if not instance:
+ status = nova_utils.get_server_status(self.__nova, self.__vm)
+ if not status:
logger.warning('Cannot find instance with id - ' + self.__vm.id)
return False
- if instance.status == 'ERROR':
- raise Exception('Instance had an error during deployment')
+ if status == 'ERROR':
+ raise VmInstanceCreationError(
+ 'Instance had an error during deployment')
logger.debug(
'Instance status [%s] is - %s', self.instance_settings.name,
- instance.status)
- return instance.status == expected_status_code
+ status)
+ return status == expected_status_code
def vm_ssh_active(self, block=False, poll_interval=POLL_INTERVAL):
"""
elif isinstance(kwargs['security_group_names'], str):
self.security_group_names = [kwargs['security_group_names']]
else:
- raise Exception(
+ raise VmInstanceSettingsError(
'Invalid data type for security_group_names attribute')
else:
self.security_group_names = set()
self.availability_zone = None
if not self.name or not self.flavor:
- raise Exception(
+ raise VmInstanceSettingsError(
'Instance configuration requires the attributes: name, flavor')
if len(self.port_settings) == 0:
- raise Exception(
+ raise VmInstanceSettingsError(
'Instance configuration requires port settings (aka. NICS)')
self.provisioning = True
if not self.name or not self.port_name or not self.router_name:
- raise Exception(
+ raise FloatingIpSettingsError(
'The attributes name, port_name and router_name are required '
'for FloatingIPSettings')
+
+
+class VmInstanceSettingsError(Exception):
+ """
+ Exception to be thrown when an VM instance settings are incorrect
+ """
+
+
+class FloatingIpSettingsError(Exception):
+ """
+ Exception to be thrown when an VM instance settings are incorrect
+ """
+
+
+class VmInstanceCreationError(Exception):
+ """
+ Exception to be thrown when an VM instance cannot be created
+ """