def save(self): if not self.is_valid(): raise exception.InvalidModelError(errors=self.errors) self['updated'] = utils.utcnow() LOG.debug(_("Saving %(name)s: %(dict)s") % {'name': self.__class__.__name__, 'dict': self.__dict__}) return self.db_api.save(self)
def validate_action(context, action_str, tenant_id, auto_apply, visible, priority_apply, full_access): admin_options_str = None option_strs = [] if tenant_id is None: option_strs.append(_("Tenant: %s") % Modules.MATCH_ALL_NAME) if auto_apply: option_strs.append(_("Auto: %s") % auto_apply) if not visible: option_strs.append(_("Visible: %s") % visible) if priority_apply: option_strs.append(_("Priority: %s") % priority_apply) if full_access is not None: if full_access and option_strs: admin_options_str = "(" + ", ".join(option_strs) + ")" raise exception.InvalidModelError( errors=_('Cannot make module full access: %s') % admin_options_str) option_strs.append(_("Full Access: %s") % full_access) if option_strs: admin_options_str = "(" + ", ".join(option_strs) + ")" if not context.is_admin and admin_options_str: raise exception.ModuleAccessForbidden( action=action_str, options=admin_options_str) return admin_options_str
def save(self): if not self.is_valid(): raise exception.InvalidModelError(errors=self.errors) self['updated_at'] = utils.utcnow() LOG.debug( _("Saving %s: %s") % (self.__class__.__name__, self.__dict__)) return get_db_api().save(self)
def save(self): if not self.is_valid(): raise exception.InvalidModelError(errors=self.errors) LOG.debug("Saving %(name)s: %(dict)s" % { 'name': self.__class__.__name__, 'dict': self.__dict__ }) return get_db_api().save(self)
def __init__(self, security_group=None, id=None, context=None): if id is None and security_group is None: msg = _("Security Group does not have id defined!") raise exception.InvalidModelError(msg) elif security_group is None: driver = self.get_driver(context) self._data_object = driver.get_sec_group_by_id(group_id=id) else: self._data_object = security_group
def create(cls, **values): if 'id' not in values: values['id'] = utils.generate_uuid() if hasattr(cls, 'deleted') and 'deleted' not in values: values['deleted'] = False values['created'] = utils.utcnow() instance = cls(**values).save() if not instance.is_valid(): raise exception.InvalidModelError(errors=instance.errors) return instance
def create(cls, **values): init_vals = { 'id': utils.generate_uuid(), 'created': utils.utcnow(), } if hasattr(cls, 'deleted'): init_vals['deleted'] = False init_vals.update(values) instance = cls(**init_vals) if not instance.is_valid(): raise exception.InvalidModelError(errors=instance.errors) return instance.save()
def load(cls, volume_type_id, context=None, client=None): if not (client or context): raise trove_exception.InvalidModelError( "client or context must be provided to load a volume_type") if not client: client = clients.create_cinder_client(context) try: volume_type = client.volume_types.get(volume_type_id) except cinder_exception.NotFound: raise trove_exception.NotFound(uuid=volume_type_id) except cinder_exception.ClientException as ce: raise trove_exception.TroveError(str(ce)) return cls(volume_type)
def __init__(self, security_group=None, id=None, context=None, region_name=None): if id is None and security_group is None: msg = _("Security Group does not have id defined!") raise exception.InvalidModelError(msg) elif security_group is None: region = region_name or CONF.service_credentials.region_name driver = self.get_driver(context, region) self._data_object = driver.get_sec_group_by_id(group_id=id) else: self._data_object = security_group
def __init__(self, security_group=None, id=None, context=None): if id is None and security_group is None: msg = "Security Group does not have id defined!" raise exception.InvalidModelError(msg) elif security_group is None: try: client = trove.common.remote.create_nova_client(context) self._data_object = client.security_groups.get(id) except nova_exceptions.NotFound as e: raise exception.NotFound(id=id) except nova_exceptions.ClientException as e: raise exception.TroveError(str(e)) else: self._data_object = security_group
def __init__(self, flavor=None, context=None, flavor_id=None): if flavor: self.flavor = flavor return if flavor_id and context: try: client = create_nova_client(context) self.flavor = client.flavors.get(flavor_id) except nova_exceptions.NotFound: raise exception.NotFound(uuid=flavor_id) except nova_exceptions.ClientException as e: raise exception.TroveError(str(e)) return msg = ("Flavor is not defined, and" " context and flavor_id were not specified.") raise exception.InvalidModelError(errors=msg)
def __init__(self, volume_type=None, context=None, volume_type_id=None): """ Initialize the volume type either from the volume_type parameter, or by querying cinder using the context provided. """ if volume_type and not (volume_type_id or context): self.volume_type = volume_type elif volume_type_id and context: try: client = create_cinder_client(context) self.volume_type = client.volume_types.get(volume_type_id) except cinder_exception.NotFound: raise trove_exception.NotFound(uuid=volume_type_id) except cinder_exception.ClientException as ce: raise trove_exception.TroveError(str(ce)) return else: raise trove_exception.InvalidModelError( errors="An invalid set of arguments were provided.")
def __init__(self, **kwargs): self.merge_attributes(kwargs) if not self.is_valid(): raise exception.InvalidModelError(errors=self.errors)
def create(cls, **values): record = cls(**values).save() if not record.is_valid(): raise exception.InvalidModelError(errors=record.errors) return record
def create(cls, **values): values['id'] = utils.generate_uuid() heartbeat = cls(**values).save() if not heartbeat.is_valid(): raise exception.InvalidModelError(errors=heartbeat.errors) return heartbeat