Beispiel #1
0
 def _check_type_name(self, type_name):
     """Check that type name and type versions were specified."""
     type_name = type_name or self.type_name
     if type_name is None:
         msg = "Type name must be specified"
         raise exc.HTTPBadRequest(msg)
     return type_name
    def _validate_sort_param(self, sort):
        """Validates sorting argument for invalid keys and directions values.

        :param sort: comma-separated list of sort keys with optional <:dir>
        after each key
        """
        for sort_param in sort.strip().split(','):
            key, _sep, dir = sort_param.partition(':')
            if dir and dir not in self.sort_dir_values:
                msg = ('Invalid sort direction: %(sort_dir)s.'
                       ' It must be one of the following: %(available)s.'
                       ) % {'sort_dir': dir,
                            'available': ', '.join(self.sort_dir_values)}
                raise exc.HTTPBadRequest(msg)
        return sort
    def add_external_location(self, artifact_id, blob_property, data,
                              type_name=None):
        """Add external location.

        :param artifact_id: ID of the artifact to download a blob
        :param blob_property: blob property name
        """
        content_type = 'application/vnd+openstack.glare-custom-location+json'

        type_name = self._check_type_name(type_name)
        hdrs = {'Content-Type': content_type}
        url = '/artifacts/%s/%s/%s' % (type_name, artifact_id, blob_property)
        try:
            data = jsonutils.dumps(data)
        except TypeError:
            raise exc.HTTPBadRequest("json is malformed.")
        self.http_client.put(url, headers=hdrs, data=data)