Пример #1
0
 def get_capsule_by_uuid(self, context, capsule_uuid):
     try:
         res = self.client.read('/capsules/' + capsule_uuid)
         capsule = translate_etcd_result(res, 'capsule')
         filtered_capsules = self._filter_resources(
             [capsule], self._add_project_filters(context, {}))
         if len(filtered_capsules) > 0:
             return filtered_capsules[0]
         else:
             raise exception.CapsuleNotFound(capsule=capsule_uuid)
     except etcd.EtcdKeyNotFound:
         raise exception.CapsuleNotFound(capsule=capsule_uuid)
     except Exception as e:
         LOG.error('Error occurred while retrieving capsule: %s',
                   six.text_type(e))
         raise
Пример #2
0
 def destroy_capsule(self, context, capsule_id):
     session = get_session()
     with session.begin():
         query = model_query(models.Capsule, session=session)
         query = add_identity_filter(query, capsule_id)
         count = query.delete()
         if count != 1:
             raise exception.CapsuleNotFound(capsule_id)
Пример #3
0
 def get_capsule_by_uuid(self, context, capsule_uuid):
     query = model_query(models.Capsule)
     query = self._add_tenant_filters(context, query)
     query = query.filter_by(uuid=capsule_uuid)
     try:
         return query.one()
     except NoResultFound:
         raise exception.CapsuleNotFound(capsule=capsule_uuid)
Пример #4
0
    def get_capsule_by_meta_name(self, context, capsule_meta_name):
        try:
            filters = self._add_project_filters(
                context, {'meta_name': capsule_meta_name})
            capsules = self.list_capsules(context, filters=filters)
        except etcd.EtcdKeyNotFound:
            raise exception.CapsuleNotFound(capsule=capsule_meta_name)
        except Exception as e:
            LOG.error('Error occurred while retrieving capsule: %s',
                      six.text_type(e))
            raise

        if len(capsules) > 1:
            raise exception.Conflict('Multiple capsules exist with same '
                                     'meta name. Please use the capsule uuid '
                                     'instead.')
        elif len(capsules) == 0:
            raise exception.CapsuleNotFound(capsule=capsule_meta_name)

        return capsules[0]
Пример #5
0
    def _do_update_capsule_id(self, capsule_id, values):
        session = get_session()
        with session.begin():
            query = model_query(models.Capsule, session=session)
            query = add_identity_filter(query, capsule_id)
            try:
                ref = query.with_lockmode('update').one()
            except NoResultFound:
                raise exception.CapsuleNotFound(capsule=capsule_id)

            ref.update(values)
        return ref
Пример #6
0
 def get_capsule_by_meta_name(self, context, capsule_name):
     query = model_query(models.Capsule)
     query = self._add_tenant_filters(context, query)
     query = query.filter_by(meta_name=capsule_name)
     try:
         return query.one()
     except NoResultFound:
         raise exception.CapsuleNotFound(capsule=capsule_name)
     except MultipleResultsFound:
         raise exception.Conflict('Multiple capsules exist with same '
                                  'name. Please use the capsule uuid '
                                  'instead.')
Пример #7
0
    def update_capsule(self, context, capsule_id, values):
        if 'uuid' in values:
            msg = _("Cannot overwrite UUID for an existing Capsule.")
            raise exception.InvalidParameterValue(err=msg)

        try:
            target_uuid = self.get_capsule_by_uuid(context, capsule_id).uuid
            target = self.client.read('/capsules/' + target_uuid)
            target_value = json.loads(target.value)
            target_value.update(values)
            target.value = json.dump_as_bytes(target_value)
            self.client.update(target)
        except etcd.EtcdKeyNotFound:
            raise exception.CapsuleNotFound(capsule=capsule_id)
        except Exception as e:
            LOG.error('Error occurred while updating capsule: %s',
                      six.text_type(e))
            raise

        return translate_etcd_result(target, 'capsule')