def _log_and_raise(self, exc, message, task_status): LOG.error(message) LOG.error(exc) tb = traceback.format_exc() for line in tb: LOG.error(line) LOG.error(traceback.format_exc()) self.update_db(task_status=task_status) raise ReddwarfError(message=message)
def ip_is_available(server): LOG.info("Polling for ip addresses: $%s " % server.addresses) if server.addresses != {}: return True elif (server.addresses == {} and server.status != InstanceStatus.ERROR): return False elif (server.addresses == {} and server.status == InstanceStatus.ERROR): msg = _("Instance IP not available, instance (%s): " "server had status (%s).") LOG.error(msg % (self.id, server.status)) raise ReddwarfError(status=server.status)
def _service_is_active(self): """ Check that the database guest is active. This function is meant to be called with poll_until to check that the guest is alive before sending a 'create' message. This prevents over billing a customer for a instance that they can never use. Returns: boolean if the service is active. Raises: ReddwarfError if the service is in a failure state. """ service = InstanceServiceStatus.find_by(instance_id=self.id) status = service.get_status() if status == ServiceStatuses.RUNNING: return True elif status not in [ServiceStatuses.NEW, ServiceStatuses.BUILDING]: raise ReddwarfError("Service not active, status: %s" % status) c_id = self.db_info.compute_instance_id nova_status = self.nova_client.servers.get(c_id).status if nova_status in [InstanceStatus.ERROR, InstanceStatus.FAILED]: raise ReddwarfError("Server not active, status: %s" % nova_status) return False
def resize_flavor(self, new_flavor_id, old_memory_size, new_memory_size): def resize_status_msg(): return "instance_id=%s, status=%s, flavor_id=%s, "\ "dest. flavor id=%s)" % (self.db_info.id, self.server.status, str(self.flavor['id']), str(new_flavor_id)) try: LOG.debug("Instance %s calling stop_mysql..." % self.db_info.id) self.guest.stop_mysql() try: LOG.debug("Instance %s calling Compute resize..." % self.db_info.id) self.server.resize(new_flavor_id) # Do initial check and confirm the status is appropriate. self._refresh_compute_server_info() if (self.server.status != "RESIZE" and self.server.status != "VERIFY_RESIZE"): msg = "Unexpected status after call to resize! : %s" raise ReddwarfError(msg % resize_status_msg()) # Wait for the flavor to change. def update_server_info(): self._refresh_compute_server_info() return self.server.status != 'RESIZE' utils.poll_until(update_server_info, sleep_time=2, time_out=60 * 2) # Do check to make sure the status and flavor id are correct. if (str(self.server.flavor['id']) != str(new_flavor_id) or self.server.status != "VERIFY_RESIZE"): msg = "Assertion failed! flavor_id=%s and not %s" actual_flavor = self.server.flavor['id'] expected_flavor = new_flavor_id raise ReddwarfError(msg % (actual_flavor, expected_flavor)) # Confirm the resize with Nova. LOG.debug("Instance %s calling Compute confirm resize..." % self.db_info.id) self.server.confirm_resize() # Record the new flavor_id in our database. LOG.debug("Updating instance %s to flavor_id %s." % (self.id, new_flavor_id)) self.update_db(flavor_id=new_flavor_id) except PollTimeOut as pto: LOG.error("Timeout trying to resize the flavor for instance " " %s" % self.db_info.id) except Exception as ex: new_memory_size = old_memory_size LOG.error("Error during resize compute! Aborting action.") LOG.error(ex) finally: # Tell the guest to restart MySQL with the new RAM size. # This is in the finally because we have to call this, or # else MySQL could stay turned off on an otherwise usable # instance. LOG.debug("Instance %s starting mysql..." % self.db_info.id) self.guest.start_mysql_with_conf_changes(new_memory_size) finally: self.update_db(task_status=inst_models.InstanceTasks.NONE)
def _assert_nova_action_was_successful(self): # Do check to make sure the status and flavor id are correct. if str(self.instance.server.flavor['id']) != str(self.new_flavor_id): msg = "Assertion failed! flavor_id=%s and not %s" \ % (self.instance.server.flavor['id'], self.new_flavor_id) raise ReddwarfError(msg)
def _assert_nova_status_is_ok(self): # Make sure Nova thinks things went well. if self.instance.server.status != "VERIFY_RESIZE": msg = "Migration failed! status=%s and not %s" \ % (self.instance.server.status, 'VERIFY_RESIZE') raise ReddwarfError(msg)