示例#1
0
 def __init__(self, **kwargs):
     if "type_name" in kwargs:
         raise exc.InvalidArtifactPropertyValue(
             _("Unable to specify artifact type explicitly"))
     if "type_version" in kwargs:
         raise exc.InvalidArtifactPropertyValue(
             _("Unable to specify artifact type version explicitly"))
     super(ArtifactType,
           self).__init__(type_name=self.metadata.type_name,
                          type_version=self.metadata.type_version,
                          **kwargs)
示例#2
0
    def validate(self, value, name=None):
        if value is None:
            if self.required:
                raise exc.InvalidArtifactPropertyValue(
                    name=name or self.name,
                    val=value,
                    msg=_('Value is required'))
            else:
                return

        first_error = next(
            (msg for v_func, msg in self._validators if not v_func(value)),
            None)
        if first_error:
            raise exc.InvalidArtifactPropertyValue(name=name or self.name,
                                                   val=value,
                                                   msg=first_error)
示例#3
0
 def __set__(self, instance, value, ignore_mutability=False):
     if instance:
         if self.prop.readonly:
             if hasattr(instance, '_' + self.prop.name):
                 raise exc.InvalidArtifactPropertyValue(
                     _('Attempt to set readonly property'))
         if not self.prop.mutable:
             if (hasattr(instance, '__is_mutable__') and not hasattr(
                     instance, '__suspend_mutability_checks__')):
                 mutable = instance.__is_mutable__() or ignore_mutability
                 if not mutable:
                     raise exc.InvalidArtifactPropertyValue(
                         _('Attempt to set value of immutable property'))
         if value is not None and self.collection_wrapper_class:
             value = self.collection_wrapper_class(value)
             value.property = self.prop
         self.prop.validate(value)
         setattr(instance, '_' + self.prop.name, value)
示例#4
0
    def __pre_publish__(self, context, *args, **kwargs):
        super(ImageAsAnArtifact, self).__pre_publish__(*args, **kwargs)
        if self.file is None and self.legacy_image_id is None:
            raise exception.InvalidArtifactPropertyValue(
                message=_("Either a file or a legacy_image_id has to be "
                          "specified"))
        if self.file is not None and self.legacy_image_id is not None:
            raise exception.InvalidArtifactPropertyValue(
                message=_("Both file and legacy_image_id may not be "
                          "specified at the same time"))

        if self.legacy_image_id:
            glance_endpoint = next(service['endpoints'][0]['publicURL']
                                   for service in context.service_catalog
                                   if service['name'] == 'xmonitor')
            # Ensure glanceclient is imported correctly since we are catching
            # the ImportError on initialization
            if glanceclient == None:
                raise ImportError(_("Glance client not installed"))

            try:
                client = glanceclient.Client(version=2,
                                             endpoint=glance_endpoint,
                                             token=context.auth_token)
                legacy_image = client.images.get(self.legacy_image_id)
            except Exception:
                raise exception.InvalidArtifactPropertyValue(
                    message=_('Unable to get legacy image'))
            if legacy_image is not None:
                self.file = definitions.Blob(size=legacy_image.size,
                                             locations=[{
                                                 "status":
                                                 "active",
                                                 "value":
                                                 legacy_image.direct_url
                                             }],
                                             checksum=legacy_image.checksum,
                                             item_key=legacy_image.id)
            else:
                raise exception.InvalidArtifactPropertyValue(
                    message=_("Legacy image was not found"))
示例#5
0
def _deserialize_dependencies(artifact_type, deps_from_db, artifact_properties,
                              plugins):
    """Retrieves dependencies from database"""
    for dep_name, dep_value in six.iteritems(deps_from_db):
        if not dep_value:
            continue
        if isinstance(
                artifact_type.metadata.attributes.dependencies.get(dep_name),
                declarative.ListAttributeDefinition):
            val = []
            for v in dep_value:
                val.append(deserialize_from_db(v, plugins))
        elif len(dep_value) == 1:
            val = deserialize_from_db(dep_value[0], plugins)
        else:
            raise exception.InvalidArtifactPropertyValue(
                message=_('Relation %(name)s may not have multiple values'),
                name=dep_name)
        artifact_properties[dep_name] = val
示例#6
0
def _deserialize_blobs(artifact_type, blobs_from_db, artifact_properties):
    """Retrieves blobs from database"""
    for blob_name, blob_value in six.iteritems(blobs_from_db):
        if not blob_value:
            continue
        if isinstance(artifact_type.metadata.attributes.blobs.get(blob_name),
                      declarative.ListAttributeDefinition):
            val = []
            for v in blob_value:
                b = definitions.Blob(size=v['size'],
                                     locations=v['locations'],
                                     checksum=v['checksum'],
                                     item_key=v['item_key'])
                val.append(b)
        elif len(blob_value) == 1:
            val = definitions.Blob(size=blob_value[0]['size'],
                                   locations=blob_value[0]['locations'],
                                   checksum=blob_value[0]['checksum'],
                                   item_key=blob_value[0]['item_key'])
        else:
            raise exception.InvalidArtifactPropertyValue(
                message=_('Blob %(name)s may not have multiple values'),
                name=blob_name)
        artifact_properties[blob_name] = val
示例#7
0
def _validate_required(self, attribute_dict):
    for k, v in six.iteritems(attribute_dict):
        if v.required and (not hasattr(self, k) or getattr(self, k) is None):
            raise exc.InvalidArtifactPropertyValue(name=k,
                                                   val=None,
                                                   msg=_('Value is required'))
示例#8
0
 def substitution(*args, **kwargs):
     raise exc.InvalidArtifactPropertyValue(
         _("Unable to modify collection in "
           "immutable or readonly property"))
示例#9
0
 def _validate_key(key):
     if not isinstance(key, six.string_types):
         raise exc.InvalidArtifactPropertyValue(
             _('Invalid dict property type'))