def get_by_name(cls, context, name, bay_uuid, k8s_api):
        """Return a :class:`ReplicationController` object based on name.

        :param context: Security context
        :param name: the name of a ReplicationController.
        :param bay_uuid: the UUID of the Bay.

        :returns: a :class:`ReplicationController` object.
        """
        try:
            resp = k8s_api.read_namespaced_replication_controller(
                name=name,
                namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.ReplicationControllerNotFound(rc=name)

        rc = {}
        rc['uuid'] = resp.metadata.uid
        rc['name'] = resp.metadata.name
        rc['project_id'] = context.project_id
        rc['user_id'] = context.user_id
        rc['images'] = [c.image for c in resp.spec.template.spec.containers]
        rc['bay_uuid'] = bay_uuid
        # Convert string to dictionary
        rc['labels'] = ast.literal_eval(resp.metadata.labels)
        rc['replicas'] = resp.status.replicas

        rc_obj = ReplicationController(context, **rc)
        return rc_obj
Пример #2
0
 def get_rcs_by_bay_uuid(self, bay_uuid):
     query = model_query(
         models.ReplicationController).filter_by(bay_uuid=bay_uuid)
     try:
         return query.all()
     except NoResultFound:
         raise exception.ReplicationControllerNotFound(bay=bay_uuid)
Пример #3
0
    def rc_update(self, context, rc_ident, bay_ident, manifest):
        LOG.debug("rc_update %s", rc_ident)
        bay = conductor_utils.retrieve_bay(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay)
        if uuidutils.is_uuid_like(rc_ident):
            rc = objects.ReplicationController.get_by_uuid(context, rc_ident,
                                                           bay.uuid,
                                                           self.k8s_api)
        else:
            rc = objects.ReplicationController.get_by_name(context, rc_ident,
                                                           bay.uuid,
                                                           self.k8s_api)
        try:
            resp = self.k8s_api.replace_namespaced_replication_controller(
                name=str(rc.name),
                body=manifest,
                namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.ReplicationControllerNotFound(rc=rc.uuid)

        rc['uuid'] = resp.metadata.uid
        rc['name'] = resp.metadata.name
        rc['project_id'] = context.project_id
        rc['user_id'] = context.user_id
        rc['images'] = [c.image for c in resp.spec.template.spec.containers]
        rc['bay_uuid'] = bay.uuid
        rc['labels'] = ast.literal_eval(resp.metadata.labels)
        rc['replicas'] = resp.status.replicas

        return rc
Пример #4
0
 def destroy_rc(self, rc_id):
     session = get_session()
     with session.begin():
         query = model_query(models.ReplicationController, session=session)
         query = add_identity_filter(query, rc_id)
         count = query.delete()
         if count != 1:
             raise exception.ReplicationControllerNotFound(rc_id)
Пример #5
0
 def get_rc_by_uuid(self, context, rc_uuid):
     query = model_query(models.ReplicationController)
     query = self._add_tenant_filters(context, query)
     query = query.filter_by(uuid=rc_uuid)
     try:
         return query.one()
     except NoResultFound:
         raise exception.ReplicationControllerNotFound(rc=rc_uuid)
Пример #6
0
 def get_rcs_by_bay_uuid(self, context, bay_uuid):
     # First verify whether the Bay exists
     self.get_bay_by_uuid(context, bay_uuid)
     query = model_query(
         models.ReplicationController).filter_by(bay_uuid=bay_uuid)
     try:
         return query.all()
     except NoResultFound:
         raise exception.ReplicationControllerNotFound(bay=bay_uuid)
Пример #7
0
 def get_rc_by_name(self, rc_name):
     query = model_query(
         models.ReplicationController).filter_by(name=rc_name)
     try:
         return query.one()
     except MultipleResultsFound:
         raise exception.Conflict('Multiple rcs exist with same name.'
                                  ' Please use the rc uuid instead.')
     except NoResultFound:
         raise exception.ReplicationControllerNotFound(rc=rc_name)
Пример #8
0
    def _do_update_rc(self, rc_id, values):
        session = get_session()
        with session.begin():
            query = model_query(models.ReplicationController, session=session)
            query = add_identity_filter(query, rc_id)
            try:
                ref = query.with_lockmode('update').one()
            except NoResultFound:
                raise exception.ReplicationControllerNotFound(rc=rc_id)

            ref.update(values)
        return ref
Пример #9
0
    def rc_update(self, context, rc_ident, bay_ident, manifest):
        LOG.debug("rc_update %s", rc_ident)
        # Since bay identifier is specified verify whether its a UUID
        # or Name. If name is specified as bay identifier need to extract
        # the bay uuid since its needed to get the k8s_api object.
        if not utils.is_uuid_like(bay_ident):
            bay = objects.Bay.get_by_name(context, bay_ident)
            bay_ident = bay.uuid

        bay_uuid = bay_ident
        self.k8s_api = k8s.create_k8s_api_rc(context, bay_uuid)
        if utils.is_uuid_like(rc_ident):
            rc = objects.ReplicationController.get_by_uuid(context, rc_ident,
                                                           bay_uuid,
                                                           self.k8s_api)
        else:
            rc = objects.ReplicationController.get_by_name(context, rc_ident,
                                                           bay_uuid,
                                                           self.k8s_api)
        try:
            resp = self.k8s_api.replace_namespaced_replication_controller(
                name=str(rc.name),
                body=manifest,
                namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.ReplicationControllerNotFound(rc=rc.uuid)

        rc['uuid'] = resp.metadata.uid
        rc['name'] = resp.metadata.name
        rc['project_id'] = context.project_id
        rc['user_id'] = context.user_id
        rc['images'] = [c.image for c in resp.spec.template.spec.containers]
        rc['bay_uuid'] = bay_uuid
        rc['labels'] = ast.literal_eval(resp.metadata.labels)
        rc['replicas'] = resp.status.replicas

        return rc
Пример #10
0
 def test_ReplicationControllerNotFound(self):
     self.assertRaises(
         exception.ReplicationControllerNotFound,
         lambda: self.raise_(exception.ReplicationControllerNotFound()))