コード例 #1
0
    def rc_list(self, context, bay_ident):
        bay = conductor_utils.retrieve_bay(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay)
        try:
            resp = self.k8s_api.list_namespaced_replication_controller(
                namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.ReplicationControllerListNotFound(
                bay_uuid=bay.uuid)

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

            rc_obj = objects.ReplicationController(context, **rc)
            rcs.append(rc_obj)

        return rcs
コード例 #2
0
 def test_create(self):
     with mock.patch.object(self.dbapi, 'create_rc',
                            autospec=True) as mock_create_rc:
         mock_create_rc.return_value = self.fake_rc
         rc = objects.ReplicationController(self.context, **self.fake_rc)
         rc.create()
         mock_create_rc.assert_called_once_with(self.fake_rc)
         self.assertEqual(self.context, rc._context)
コード例 #3
0
def get_test_rc(context, **kw):
    """Return a ReplicationController object with appropriate attributes.

    NOTE: The object leaves the attributes marked as changed, such
    that a create() could be used to commit it to the DB.
    """
    db_rc = db_utils.get_test_rc(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del db_rc['id']
    rc = objects.ReplicationController(context)
    for key in db_rc:
        setattr(rc, key, db_rc[key])
    return rc
コード例 #4
0
    def post(self, rc):
        """Create a new ReplicationController.

        :param rc: a ReplicationController within the request body.
        """
        rc.parse_manifest()
        rc_dict = rc.as_dict()
        context = pecan.request.context
        rc_dict['project_id'] = context.project_id
        rc_dict['user_id'] = context.user_id
        rc_obj = objects.ReplicationController(context, **rc_dict)
        new_rc = pecan.request.rpcapi.rc_create(rc_obj)
        if not new_rc:
            raise exception.InvalidState()

        # Set the HTTP Location Header
        pecan.response.location = link.build_url('rcs', new_rc.uuid)
        return ReplicationController.convert_with_links(new_rc)
コード例 #5
0
    def post(self, rc):
        """Create a new ReplicationController.

        :param rc: a ReplicationController within the request body.
        """
        if self.from_rcs:
            raise exception.OperationNotPermitted

        rc.parse_manifest()
        rc_dict = rc.as_dict()
        context = pecan.request.context
        auth_token = context.auth_token_info['token']
        rc_dict['project_id'] = auth_token['project']['id']
        rc_dict['user_id'] = auth_token['user']['id']
        rc_obj = objects.ReplicationController(context, **rc_dict)
        new_rc = pecan.request.rpcapi.rc_create(rc_obj)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('rcs', new_rc.uuid)
        return ReplicationController.convert_with_links(new_rc)
コード例 #6
0
ファイル: k8s_conductor.py プロジェクト: leader716/magnum
    def rc_list(self, context, bay_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)
        try:
            resp = self.k8s_api.list_namespaced_replication_controller(
                namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.ReplicationControllerListNotFound(
                bay_uuid=bay_uuid)

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

            rc_obj = objects.ReplicationController(context, **rc)
            rcs.append(rc_obj)

        return rcs
コード例 #7
0
 def test_retrieve_bay_from_rc(self, mock_bay_get_by_uuid):
     rc = objects.ReplicationController({})
     rc.bay_uuid = '5d12f6fd-a196-4bf0-ae4c-1f639a523a52'
     self._test_retrieve_bay(rc.bay_uuid, mock_bay_get_by_uuid)
コード例 #8
0
 def mock_rc(self):
     return objects.ReplicationController({})
コード例 #9
0
 def test_retrieve_bay_from_rc(self,
                               mock_bay_get_by_uuid):
     self._test_retrieve_bay(objects.ReplicationController({}),
                             mock_bay_get_by_uuid)