Example #1
0
 def get_cluster_template_by_uuid(self, context, cluster_template_uuid):
     query = model_query(models.ClusterTemplate)
     query = self._add_tenant_filters(context, query)
     public_q = model_query(models.ClusterTemplate).filter_by(public=True)
     query = query.union(public_q)
     query = query.filter_by(uuid=cluster_template_uuid)
     try:
         return query.one()
     except NoResultFound:
         raise exception.ClusterTemplateNotFound(
             clustertemplate=cluster_template_uuid)
Example #2
0
 def get_baymodel_by_name(self, context, baymodel_name):
     query = model_query(models.BayModel)
     query = self._add_tenant_filters(context, query)
     public_q = model_query(models.BayModel).filter_by(public=True)
     query = query.union(public_q)
     query = query.filter_by(name=baymodel_name)
     try:
         return query.one()
     except MultipleResultsFound:
         raise exception.Conflict('Multiple baymodels exist with same name.'
                                  ' Please use the baymodel uuid instead.')
     except NoResultFound:
         raise exception.ClusterTemplateNotFound(
             clustertemplate=baymodel_name)
Example #3
0
 def get_cluster_template_by_name(self, context, cluster_template_name):
     query = model_query(models.ClusterTemplate)
     query = self._add_tenant_filters(context, query)
     public_q = model_query(models.ClusterTemplate).filter_by(public=True)
     query = query.union(public_q)
     query = query.filter_by(name=cluster_template_name)
     try:
         return query.one()
     except MultipleResultsFound:
         raise exception.Conflict('Multiple ClusterTemplates exist with'
                                  ' same name. Please use the '
                                  'ClusterTemplate uuid instead.')
     except NoResultFound:
         raise exception.ClusterTemplateNotFound(
             clustertemplate=cluster_template_name)
Example #4
0
    def destroy_baymodel(self, baymodel_id):
        session = get_session()
        with session.begin():
            query = model_query(models.BayModel, session=session)
            query = add_identity_filter(query, baymodel_id)

            try:
                baymodel_ref = query.one()
            except NoResultFound:
                raise exception.ClusterTemplateNotFound(
                    clustertemplate=baymodel_id)

            if self._is_baymodel_referenced(session, baymodel_ref['uuid']):
                raise exception.ClusterTemplateReferenced(
                    clustertemplate=baymodel_id)

            query.delete()
Example #5
0
    def _do_update_cluster_template(self, cluster_template_id, values):
        session = get_session()
        with session.begin():
            query = model_query(models.ClusterTemplate, session=session)
            query = add_identity_filter(query, cluster_template_id)
            try:
                ref = query.with_lockmode('update').one()
            except NoResultFound:
                raise exception.ClusterTemplateNotFound(
                    clustertemplate=cluster_template_id)

            if self._is_cluster_template_referenced(session, ref['uuid']):
                # we only allow to update ClusterTemplate to be public
                if not self._is_publishing_cluster_template(values):
                    raise exception.ClusterTemplateReferenced(
                        clustertemplate=cluster_template_id)

            ref.update(values)
        return ref
Example #6
0
    def _do_update_cluster_template(self, cluster_template_id, values):
        session = get_session()
        with session.begin():
            query = model_query(models.ClusterTemplate, session=session)
            query = add_identity_filter(query, cluster_template_id)
            try:
                ref = query.with_for_update().one()
            except NoResultFound:
                raise exception.ClusterTemplateNotFound(
                    clustertemplate=cluster_template_id)

            if self._is_cluster_template_referenced(session, ref['uuid']):
                # NOTE(flwang): We only allow to update ClusterTemplate to be
                # public, hidden and rename
                if (not self._is_publishing_cluster_template(values) and
                        list(six.viewkeys(values)) != ["name"]):
                    raise exception.ClusterTemplateReferenced(
                        clustertemplate=cluster_template_id)

            ref.update(values)
        return ref