def check_create_complete(self, data): attributes = self._show_resource() status = attributes['status'] if status == 'PENDING_CREATE': return False elif status == 'ACTIVE': vip_attributes = self.client().show_vip( self.metadata_get()['vip'])['vip'] vip_status = vip_attributes['status'] if vip_status == 'PENDING_CREATE': return False if vip_status == 'ACTIVE': return True if vip_status == 'ERROR': raise exception.ResourceInError( resource_status=vip_status, status_reason=_('error in vip')) raise exception.ResourceUnknownStatus( resource_status=vip_status, result=_('Pool creation failed due to vip')) elif status == 'ERROR': raise exception.ResourceInError(resource_status=status, status_reason=_('error in pool')) else: raise exception.ResourceUnknownStatus( resource_status=status, result=_('Pool creation failed'))
def check_create_complete(self, id): container = self.client().containers.get(id) if container.status in ('Creating', 'Created'): return False elif container.status == 'Running': return True elif container.status == 'Stopped': if container.interactive: msg = (_("Error in creating container '%(name)s' - " "interactive mode was enabled but the container " "has stopped running") % { 'name': self.name }) raise exception.ResourceInError( status_reason=msg, resource_status=container.status) return True elif container.status == 'Error': msg = (_("Error in creating container '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': container.status_reason }) raise exception.ResourceInError(status_reason=msg, resource_status=container.status) else: msg = (_("Unknown status Container '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': container.status_reason }) raise exception.ResourceUnknownStatus( status_reason=msg, resource_status=container.status)
def check_create_complete(self, *args): share_status = self._request_share().status if share_status == self.STATUS_CREATING: return False elif share_status == self.STATUS_AVAILABLE: LOG.info(_LI('Applying access rules to created Share.')) # apply access rules to created share. please note that it is not # possible to define rules for share with share_status = creating access_rules = self.properties.get(self.ACCESS_RULES) try: if access_rules: for rule in access_rules: self.client().shares.allow( share=self.resource_id, access_type=rule.get(self.ACCESS_TYPE), access=rule.get(self.ACCESS_TO), access_level=rule.get(self.ACCESS_LEVEL)) return True except Exception as ex: reason = _( 'Error during applying access rules to share "{0}". ' 'The root cause of the problem is the following: {1}.' ).format(self.resource_id, ex.message) raise exception.ResourceInError(status_reason=reason) elif share_status == self.STATUS_ERROR: reason = _('Error during creation of share "{0}"').format( self.resource_id) raise exception.ResourceInError(status_reason=reason, resource_status=share_status) else: reason = _('Unknown share_status during creation of share "{0}"' ).format(self.resource_id) raise exception.ResourceUnknownStatus( status_reason=reason, resource_status=share_status)
def check_update_complete(self, id): cluster = self.client().clusters.get(id) # Check update complete request might get status before the status # got changed to update in progress, so we allow `CREATE_COMPLETE` # for it. # TODO(ricolin): we should find way to make sure status check will # only perform after action really started. if cluster.status in ['UPDATE_IN_PROGRESS', 'CREATE_COMPLETE']: return False elif cluster.status == 'UPDATE_COMPLETE': return True elif cluster.status == 'UPDATE_FAILED': msg = (_("Failed to update Cluster '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': cluster.status_reason }) raise exception.ResourceInError(status_reason=msg, resource_status=cluster.status) else: msg = ( _("Unknown status updating Cluster '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': cluster.status_reason }) raise exception.ResourceUnknownStatus( status_reason=msg, resource_status=cluster.status)
def check_create_complete(self, id): print("111111111111") container = self.client().containers.get(id) if container.status == 'Creating': return False elif container.status is None: return False elif container.status in ('Running', 'Created'): print("container: " + repr(container)) return True elif container.status == 'Error': msg = (_("Failed to create Container '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': container.status_reason }) raise exception.ResourceInError(status_reason=msg, resource_status=container.status) else: msg = ( _("Unknown status creating Container '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': container.status_reason }) raise exception.ResourceUnknownStatus( status_reason=msg, resource_status=container.status)
def check_delete_complete(self, *args): if not self.resource_id: return True try: share = self._request_share() except Exception as ex: self.client_plugin().ignore_not_found(ex) return True else: # when share creation is not finished proceed listening if share.status == self.STATUS_DELETING: return False elif share.status in (self.STATUS_ERROR, self.STATUS_ERROR_DELETING): raise exception.ResourceInError( status_reason=_( 'Error during deleting share "{0}".' ).format(self.resource_id), resource_status=share.status) else: reason = _('Unknown status during deleting share ' '"{0}"').format(self.resource_id) raise exception.ResourceUnknownStatus( status_reason=reason, resource_status=share.status)
def check_update_complete(self, id): bay = self.client().bays.get(id) if bay.status == 'UPDATE_IN_PROGRESS': return False # check for None due to Magnum bug # https://bugs.launchpad.net/magnum/+bug/1507598 elif bay.status is None: return False elif bay.status == 'UPDATE_COMPLETE': return True elif bay.status == 'UPDATE_FAILED': msg = (_("Failed to update Bay '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': bay.status_reason }) raise exception.ResourceInError(status_reason=msg, resource_status=bay.status) else: msg = (_("Unknown status updating Bay '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': bay.status_reason }) raise exception.ResourceUnknownStatus(status_reason=msg, resource_status=bay.status)
def check_delete_server_complete(self, server_id): """Wait for server to disappear from Nova.""" try: server = self.fetch_server(server_id) except Exception as exc: self.ignore_not_found(exc) return True if not server: return False task_state_in_nova = getattr(server, 'OS-EXT-STS:task_state', None) # the status of server won't change until the delete task has done if task_state_in_nova == 'deleting': return False status = self.get_status(server) if status in ("DELETED", "SOFT_DELETED"): return True if status == 'ERROR': fault = getattr(server, 'fault', {}) message = fault.get('message', 'Unknown') code = fault.get('code') errmsg = _("Server %(name)s delete failed: (%(code)s) " "%(message)s") % dict( name=server.name, code=code, message=message) raise exception.ResourceInError(resource_status=status, status_reason=errmsg) return False
def check_update_complete(self, updaters): def start_action(action, params): if action == 'cluster_resize': resp = self.client().cluster_resize(self.resource_id, **params) return resp['action'] elif action == 'cluster_update': resp = self.client().update_cluster(self.resource_id, **params) return resp.location.split('/')[-1] if not updaters: return True for k, updater in list(updaters.items()): if not updater['start']: action_id = start_action(k, updater['params']) updater['action'] = action_id updater['start'] = True else: action = self.client().get_action(updater['action']) if action.status == self.ACTION_SUCCEEDED: del updaters[k] elif action.status == self.ACTION_FAILED: raise exception.ResourceInError( status_reason=action.status_reason, resource_status=self.FAILED, ) return False
def check_update_complete(self, updates): instance = self.client().instances.get(self.resource_id) if instance.status in self.BAD_STATUSES: raise exception.ResourceInError( resource_status=instance.status, status_reason=self.TROVE_STATUS_REASON.get( instance.status, _("Unknown"))) if updates: if instance.status != self.ACTIVE: dmsg = ("Instance is in status %(now)s. Waiting on status" " %(stat)s") LOG.debug(dmsg % {"now": instance.status, "stat": self.ACTIVE}) return False try: return ( self._update_name(instance, updates.get(self.NAME)) and self._update_flavor(instance, updates.get(self.FLAVOR)) and self._update_size(instance, updates.get(self.SIZE)) and self._update_databases(instance, updates.get(self.DATABASES)) and self._update_users(instance, updates.get(self.USERS))) except Exception as exc: if self.client_plugin().is_client_exception(exc): # the instance could have updated between the time # we retrieve it and try to update it so check again if self.client_plugin().is_over_limit(exc): LOG.debug("API rate limit: %(ex)s. Retrying.", {'ex': six.text_type(exc)}) return False if "No change was requested" in six.text_type(exc): LOG.warning("Unexpected instance state change " "during update. Retrying.") return False raise return True
def check_delete_complete(self, prg): if not prg.backup['called']: prg.backup_id = self._create_backup() prg.backup['called'] = True return False if not prg.backup['complete']: prg.backup['complete'] = self._check_create_backup_complete(prg) return False if not prg.delete['called']: prg.delete['complete'] = self._delete_volume() prg.delete['called'] = True return False if not prg.delete['complete']: try: vol = self.client().volumes.get(self.resource_id) except Exception as ex: self.client_plugin().ignore_not_found(ex) prg.delete['complete'] = True return True if vol.status.lower() == 'error_deleting': raise exception.ResourceInError(status_reason='delete', resource_status=vol.status) else: return False return True
def handle_create(self): client = self.getClient() vnets = JsonVNet(self.properties[self.NETWORK_NAME]) vswitches = self.properties[self.SWITCHES] or [] self._addVSwitches(vnets, vswitches) vports = self.properties[self.PORTS] or [] self._addVPorts(vnets, vports) vlinks = self.properties[self.LINKS] or [] self._addVLinks(vnets, vlinks) vhosts = self.properties[self.HOSTS] or [] self._addVHosts(vnets, vhosts) networkName = client.createVNet(vnets.getJson()) if (networkName is False) or (networkName is None): raise exception.ResourceInError(resource_status=self.FAILED, status_reason="REST server error") self.resource_id_set(networkName) return networkName
def check_create_complete(self, instance_id): """Check if cloud DB instance creation is complete.""" instance = self._refresh_instance(instance_id) # refresh attributes if instance is None: return False if instance.status in self.BAD_STATUSES: raise exception.ResourceInError( resource_status=instance.status, status_reason=self.TROVE_STATUS_REASON.get( instance.status, _("Unknown"))) if instance.status != self.ACTIVE: return False LOG.info( "Database instance %(database)s created " "(flavor:%(flavor)s, volume:%(volume)s, " "datastore:%(datastore_type)s, " "datastore_version:%(datastore_version)s)", { 'database': self._dbinstance_name(), 'flavor': self.flavor, 'volume': self.volume, 'datastore_type': self.datastore_type, 'datastore_version': self.datastore_version }) return True
def check_delete_complete(self, prg): if not prg.backup['called']: prg.backup_id = self._create_backup() prg.backup['called'] = True return False if not prg.backup['complete']: prg.backup['complete'] = self._check_create_backup_complete(prg) return False if not prg.delete['called']: prg.delete['complete'] = self._delete_volume() prg.delete['called'] = True return False if not prg.delete['complete']: try: vol = self.client().volumes.get(self.resource_id) except Exception as ex: self.client_plugin().ignore_not_found(ex) prg.delete['complete'] = True return True if vol.status.lower() == 'error_deleting': raise exception.ResourceInError(status_reason='delete', resource_status=vol.status) else: # WRS enhancement. if wrs-background-delete is 'True' # HEAT will not wait for it to complete if vol.metadata.get('wrs-background-delete', False) == 'True': prg.delete['complete'] = True return True return False return True
def check_create_complete(self, container_id): status = self._get_container_status(container_id) exit_status = status.get('ExitCode') if exit_status is not None and exit_status != 0: logs = self.get_client().logs(self.resource_id) raise exception.ResourceInError(resource_status=self.FAILED, status_reason=logs) return status['Running']
def _check_status_complete(self): zone = self.client().zones.get(self.resource_id) if zone['status'] == 'ERROR': raise exception.ResourceInError(resource_status=zone['status'], status_reason=_('Error in zone')) return zone['status'] != 'PENDING'
def check_action(updater, set_key): action = self.client().get_action(updater['action']) if action.status == self.ACTION_SUCCEEDED: updater[set_key] = True elif action.status == self.ACTION_FAILED: raise exception.ResourceInError( status_reason=action.status_reason, resource_status=action.status, )
def check_create_complete(self, resource_id): cluster = self.client().get_cluster(resource_id) if cluster.status in [self.CLUSTER_ACTIVE, self.CLUSTER_WARNING]: return True elif cluster.status in [self.CLUSTER_INIT, self.CLUSTER_CREATING]: return False else: raise exception.ResourceInError( status_reason=cluster.status_reason, resource_status=cluster.status)
def cluster_is_active(self, cluster_id): cluster = self.client().get_cluster(cluster_id) if cluster.status == 'ACTIVE': return True elif cluster.status == 'ERROR': raise exception.ResourceInError( status_reason=cluster.status_reason, resource_status=cluster.status, ) return False
def check_create_complete(self, cluster_id): cluster = self.client().clusters.get(cluster_id) if cluster.status == self.CLUSTER_ERROR: raise exception.ResourceInError(resource_status=cluster.status) if cluster.status != self.CLUSTER_ACTIVE: return False LOG.info(_LI("Cluster '%s' has been created"), cluster.name) return True
def check_action_status(self, action_id): action = self.client().get_action(action_id) if action.status == 'SUCCEEDED': return True elif action.status == 'FAILED': raise exception.ResourceInError( status_reason=action.status_reason, resource_status=action.status, ) return False
def _check_status_complete(self): recordset = self.client().recordsets.get( recordset=self.resource_id, zone=self.properties[self.ZONE]) if recordset['status'] == 'ERROR': raise exception.ResourceInError( resource_status=recordset['status'], status_reason=_('Error in RecordSet')) return recordset['status'] != 'PENDING'
def is_built(attributes): status = attributes['status'] if status == 'BUILD': return False if status in ('ACTIVE', 'DOWN'): return True elif status == 'ERROR': raise exception.ResourceInError(resource_status=status) else: raise exception.ResourceUnknownStatus( resource_status=status, result=_('Resource is not built'))
def check_create_complete(self, resource_id): node = self.client().get_node(resource_id) if node.status == self.ACTIVE: return True elif node.status in [self.INIT, self.CREATING]: return False else: raise exception.ResourceInError( status_reason=node.status_reason, resource_status=node.status, )
def check_create_complete(self, vol_id): vol = self.client().volumes.get(vol_id) if vol.status == 'available': return True if vol.status in self._volume_creating_status: return False if vol.status == 'error': raise exception.ResourceInError(resource_status=vol.status) else: raise exception.ResourceUnknownStatus( resource_status=vol.status, result=_('Volume create failed'))
def check_create_complete(self, data): attributes = self._show_resource() status = attributes['status'] if status == 'PENDING_CREATE': return False elif status == 'ACTIVE': return True elif status == 'ERROR': raise exception.ResourceInError( resource_status=status, status_reason=_('Error in Firewall')) else: raise exception.ResourceUnknownStatus( resource_status=status, result=_('Firewall creation failed'))
def check_create_complete(self, container_href): container = self.client().containers.get(container_href) if container.status == 'ERROR': reason = container.error_reason code = container.error_status_code msg = (_("Container '%(name)s' creation failed: " "%(code)s - %(reason)s") % {'name': self.name, 'code': code, 'reason': reason}) raise exception.ResourceInError( status_reason=msg, resource_status=container.status) return container.status == 'ACTIVE'
def check_delete_complete(self, resource_id): if not resource_id: return True try: cluster = self.client().clusters.get(resource_id) except Exception as ex: self.client_plugin().ignore_not_found(ex) LOG.info("Cluster '%s' has been deleted", self._cluster_name()) return True else: if cluster.status == self.CLUSTER_ERROR: raise exception.ResourceInError(resource_status=cluster.status) return False
def check_create_complete(self, id): cluster = self.client().clusters.get(id) if cluster.status == 'CREATE_IN_PROGRESS': return False elif cluster.status == 'CREATE_COMPLETE': return True elif cluster.status == 'CREATE_FAILED': msg = (_("Failed to create Cluster '%(name)s' - %(reason)s") % {'name': self.name, 'reason': cluster.status_reason}) raise exception.ResourceInError(status_reason=msg, resource_status=cluster.status) else: msg = (_("Unknown status creating Cluster '%(name)s' - %(reason)s") % {'name': self.name, 'reason': cluster.status_reason}) raise exception.ResourceUnknownStatus( status_reason=msg, resource_status=cluster.status)
def check_update_complete(self, id): bay = self.client().bays.get(id) if bay.status == 'UPDATE_IN_PROGRESS': return False elif bay.status == 'UPDATE_COMPLETE': return True elif bay.status == 'UPDATE_FAILED': msg = (_("Failed to update Bay '%(name)s' - %(reason)s") % {'name': self.name, 'reason': bay.status_reason}) raise exception.ResourceInError(status_reason=msg, resource_status=bay.status) else: msg = (_("Unknown status updating Bay '%(name)s' - %(reason)s") % {'name': self.name, 'reason': bay.status_reason}) raise exception.ResourceUnknownStatus(status_reason=msg, resource_status=bay.status)