예제 #1
0
    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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(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
예제 #2
0
 def test_retrieve_bay_uuid_from_uuid(self, mock_bay_get_by_name,
                                      mock_uuid_like):
     bay_uuid = utils.retrieve_bay_uuid(
         'context', '5d12f6fd-a196-4bf0-ae4c-1f639a523a52')
     self.assertEqual('5d12f6fd-a196-4bf0-ae4c-1f639a523a52', bay_uuid)
     mock_uuid_like.return_value = True
     mock_bay_get_by_name.assert_not_called()
예제 #3
0
 def rc_delete(self, context, rc_ident, bay_ident):
     LOG.debug("rc_delete %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.
     bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
     self.k8s_api = k8s.create_k8s_api(context, bay_uuid)
     if utils.is_uuid_like(rc_ident):
         rc = objects.ReplicationController.get_by_uuid(context, rc_ident,
                                                        bay_uuid,
                                                        self.k8s_api)
         rc_name = rc.name
     else:
         rc_name = rc_ident
     if conductor_utils.object_has_stack(context, bay_uuid):
         try:
             self.k8s_api.delete_namespaced_replication_controller(
                 name=str(rc_name),
                 body={},
                 namespace='default')
         except rest.ApiException as err:
             if err.status == 404:
                 pass
             else:
                 raise exception.KubernetesAPIFailed(err=err)
예제 #4
0
    def pod_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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay_uuid)
        try:
            resp = self.k8s_api.list_namespaced_pod(namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

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

        pods = []
        for pod_entry in resp.items:
            pod = {}
            pod['uuid'] = pod_entry.metadata.uid
            pod['name'] = pod_entry.metadata.name
            pod['project_id'] = context.project_id
            pod['user_id'] = context.user_id
            pod['bay_uuid'] = bay_uuid
            pod['images'] = [c.image for c in pod_entry.spec.containers]
            if not pod_entry.metadata.labels:
                pod['labels'] = {}
            else:
                pod['labels'] = ast.literal_eval(pod_entry.metadata.labels)
            pod['status'] = pod_entry.status.phase
            pod['host'] = pod_entry.spec.node_name

            pod_obj = objects.Pod(context, **pod)
            pods.append(pod_obj)

        return pods
예제 #5
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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(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
예제 #6
0
    def pod_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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay_uuid)
        try:
            resp = self.k8s_api.list_namespaced_pod(namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

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

        pods = []
        for pod_entry in resp.items:
            pod = {}
            pod['uuid'] = pod_entry.metadata.uid
            pod['name'] = pod_entry.metadata.name
            pod['project_id'] = context.project_id
            pod['user_id'] = context.user_id
            pod['bay_uuid'] = bay_uuid
            pod['images'] = [c.image for c in pod_entry.spec.containers]
            if not pod_entry.metadata.labels:
                pod['labels'] = {}
            else:
                pod['labels'] = ast.literal_eval(pod_entry.metadata.labels)
            pod['status'] = pod_entry.status.phase
            pod['host'] = pod_entry.spec.node_name

            pod_obj = objects.Pod(context, **pod)
            pods.append(pod_obj)

        return pods
예제 #7
0
    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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(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
예제 #8
0
 def test_retrieve_bay_uuid_from_uuid(self, mock_bay_get_by_name,
                                      mock_uuid_like):
     bay_uuid = utils.retrieve_bay_uuid(
         'context',
         '5d12f6fd-a196-4bf0-ae4c-1f639a523a52')
     self.assertEqual('5d12f6fd-a196-4bf0-ae4c-1f639a523a52', bay_uuid)
     mock_uuid_like.return_value = True
     mock_bay_get_by_name.assert_not_called()
예제 #9
0
 def container_list(self, context, limit, marker, sort_key, sort_dir,
                    bay_ident):
     filters = None
     if bay_ident is not None:
         bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
         filters = {'bay_uuid': bay_uuid}
     return objects.Container.list(context, limit, marker, sort_key,
                                   sort_dir, filters=filters)
예제 #10
0
파일: test_utils.py 프로젝트: baikai/magnum
    def test_retrieve_bay_uuid_from_name(self, mock_bay_get_by_name,
                                         mock_uuid_like):
        bay = objects.Bay(uuid=1)
        mock_uuid_like.return_value = False
        mock_bay_get_by_name.return_value = bay
        bay_uuid = utils.retrieve_bay_uuid('context', 'fake_name')
        self.assertEqual('1', bay_uuid)

        mock_uuid_like.assert_called_once_with('fake_name')
        mock_bay_get_by_name.assert_called_once_with('context', 'fake_name')
예제 #11
0
    def test_retrieve_bay_uuid_from_name(self, mock_bay_get_by_name,
                                         mock_uuid_like):
        bay = objects.Bay(uuid=1)
        mock_uuid_like.return_value = False
        mock_bay_get_by_name.return_value = bay
        bay_uuid = utils.retrieve_bay_uuid('context', 'fake_name')
        self.assertEqual('1', bay_uuid)

        mock_uuid_like.assert_called_once_with('fake_name')
        mock_bay_get_by_name.assert_called_once_with('context', 'fake_name')
예제 #12
0
    def test_retrieve_bay_uuid_from_name(self, mock_bay_get_by_name,
                                         mock_uuid_like):
        bay = objects.Bay(uuid='5d12f6fd-a196-4bf0-ae4c-1f639a523a52')
        mock_uuid_like.return_value = False
        mock_bay_get_by_name.return_value = bay
        bay_uuid = utils.retrieve_bay_uuid('context', 'fake_name')
        self.assertEqual('5d12f6fd-a196-4bf0-ae4c-1f639a523a52', bay_uuid)

        mock_uuid_like.assert_called_once_with('fake_name')
        mock_bay_get_by_name.assert_called_once_with('context', 'fake_name')
예제 #13
0
    def test_retrieve_bay_uuid_from_name(self, mock_bay_get_by_name,
                                         mock_uuid_like):
        bay = objects.Bay(uuid='5d12f6fd-a196-4bf0-ae4c-1f639a523a52')
        mock_uuid_like.return_value = False
        mock_bay_get_by_name.return_value = bay
        bay_uuid = utils.retrieve_bay_uuid('context', 'fake_name')
        self.assertEqual('5d12f6fd-a196-4bf0-ae4c-1f639a523a52', bay_uuid)

        mock_uuid_like.assert_called_once_with('fake_name')
        mock_bay_get_by_name.assert_called_once_with('context', 'fake_name')
예제 #14
0
    def service_update(self, context, service_ident, bay_ident, manifest):
        LOG.debug("service_update %s", service_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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay_uuid)
        if utils.is_uuid_like(service_ident):
            service = objects.Service.get_by_uuid(context,
                                                  service_ident,
                                                  bay_uuid,
                                                  self.k8s_api)
        else:
            service = objects.Service.get_by_name(context,
                                                  service_ident,
                                                  bay_uuid,
                                                  self.k8s_api)
        service_ident = service.name
        try:
            resp = self.k8s_api.replace_namespaced_service(
                name=str(service_ident),
                body=manifest,
                namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.ServiceNotFound(service=service.uuid)

        service['uuid'] = resp.metadata.uid
        service['name'] = resp.metadata.name
        service['project_id'] = context.project_id
        service['user_id'] = context.user_id
        service['bay_uuid'] = bay_uuid
        service['labels'] = ast.literal_eval(resp.metadata.labels)
        if not resp.spec.selector:
            service['selector'] = {}
        else:
            service['selector'] = ast.literal_eval(resp.spec.selector)
        service['ip'] = resp.spec.cluster_ip
        service_value = []
        for p in resp.spec.ports:
            ports = p.to_dict()
            if not ports['name']:
                ports['name'] = 'k8s-service'
            service_value.append(ports)

        service['ports'] = service_value

        return service
예제 #15
0
    def pod_show(self, context, pod_ident, bay_ident):
        LOG.debug("pod_show %s", pod_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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay_uuid)
        if utils.is_uuid_like(pod_ident):
            pod = objects.Pod.get_by_uuid(context, pod_ident, bay_uuid,
                                          self.k8s_api)
        else:
            pod = objects.Pod.get_by_name(context, pod_ident, bay_uuid,
                                          self.k8s_api)

        return pod
예제 #16
0
    def rc_show(self, context, rc_ident, bay_ident):
        LOG.debug("rc_show %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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(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)

        return rc
예제 #17
0
    def pod_show(self, context, pod_ident, bay_ident):
        LOG.debug("pod_show %s", pod_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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay_uuid)
        if utils.is_uuid_like(pod_ident):
            pod = objects.Pod.get_by_uuid(context, pod_ident,
                                          bay_uuid, self.k8s_api)
        else:
            pod = objects.Pod.get_by_name(context, pod_ident,
                                          bay_uuid, self.k8s_api)

        return pod
예제 #18
0
    def rc_show(self, context, rc_ident, bay_ident):
        LOG.debug("rc_show %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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(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)

        return rc
예제 #19
0
    def service_update(self, context, service_ident, bay_ident, manifest):
        LOG.debug("service_update %s", service_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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay_uuid)
        if utils.is_uuid_like(service_ident):
            service = objects.Service.get_by_uuid(context, service_ident,
                                                  bay_uuid, self.k8s_api)
        else:
            service = objects.Service.get_by_name(context, service_ident,
                                                  bay_uuid, self.k8s_api)
        service_ident = service.name
        try:
            resp = self.k8s_api.replace_namespaced_service(
                name=str(service_ident), body=manifest, namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.ServiceNotFound(service=service.uuid)

        service['uuid'] = resp.metadata.uid
        service['name'] = resp.metadata.name
        service['project_id'] = context.project_id
        service['user_id'] = context.user_id
        service['bay_uuid'] = bay_uuid
        service['labels'] = ast.literal_eval(resp.metadata.labels)
        if not resp.spec.selector:
            service['selector'] = {}
        else:
            service['selector'] = ast.literal_eval(resp.spec.selector)
        service['ip'] = resp.spec.cluster_ip
        service_value = []
        for p in resp.spec.ports:
            ports = p.to_dict()
            if not ports['name']:
                ports['name'] = 'k8s-service'
            service_value.append(ports)

        service['ports'] = service_value

        return service
예제 #20
0
    def service_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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay_uuid)
        try:
            resp = self.k8s_api.list_namespaced_service(namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

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

        services = []
        for service_entry in resp.items:
            service = {}
            service['uuid'] = service_entry.metadata.uid
            service['name'] = service_entry.metadata.name
            service['project_id'] = context.project_id
            service['user_id'] = context.user_id
            service['bay_uuid'] = bay_uuid
            service['labels'] = ast.literal_eval(
                service_entry.metadata.labels)
            if not service_entry.spec.selector:
                service['selector'] = {}
            else:
                service['selector'] = ast.literal_eval(
                    service_entry.spec.selector)
            service['ip'] = service_entry.spec.cluster_ip
            service_value = []
            for p in service_entry.spec.ports:
                ports = p.to_dict()
                if not ports['name']:
                    ports['name'] = 'k8s-service'
                service_value.append(ports)

            service['ports'] = service_value

            service_obj = objects.Service(context, **service)
            services.append(service_obj)

        return services
예제 #21
0
    def service_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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay_uuid)
        try:
            resp = self.k8s_api.list_namespaced_service(namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

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

        services = []
        for service_entry in resp.items:
            service = {}
            service['uuid'] = service_entry.metadata.uid
            service['name'] = service_entry.metadata.name
            service['project_id'] = context.project_id
            service['user_id'] = context.user_id
            service['bay_uuid'] = bay_uuid
            service['labels'] = ast.literal_eval(service_entry.metadata.labels)
            if not service_entry.spec.selector:
                service['selector'] = {}
            else:
                service['selector'] = ast.literal_eval(
                    service_entry.spec.selector)
            service['ip'] = service_entry.spec.cluster_ip
            service_value = []
            for p in service_entry.spec.ports:
                ports = p.to_dict()
                if not ports['name']:
                    ports['name'] = 'k8s-service'
                service_value.append(ports)

            service['ports'] = service_value

            service_obj = objects.Service(context, **service)
            services.append(service_obj)

        return services
예제 #22
0
 def rc_delete(self, context, rc_ident, bay_ident):
     LOG.debug("rc_delete %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.
     bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
     self.k8s_api = k8s.create_k8s_api(context, bay_uuid)
     if utils.is_uuid_like(rc_ident):
         rc = objects.ReplicationController.get_by_uuid(
             context, rc_ident, bay_uuid, self.k8s_api)
         rc_name = rc.name
     else:
         rc_name = rc_ident
     if conductor_utils.object_has_stack(context, bay_uuid):
         try:
             self.k8s_api.delete_namespaced_replication_controller(
                 name=str(rc_name), body={}, namespace='default')
         except rest.ApiException as err:
             if err.status == 404:
                 pass
             else:
                 raise exception.KubernetesAPIFailed(err=err)
예제 #23
0
    def pod_update(self, context, pod_ident, bay_ident, manifest):
        LOG.debug("pod_update %s", pod_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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay_uuid)
        if utils.is_uuid_like(pod_ident):
            pod = objects.Pod.get_by_uuid(context, pod_ident,
                                          bay_uuid, self.k8s_api)
        else:
            pod = objects.Pod.get_by_name(context, pod_ident,
                                          bay_uuid, self.k8s_api)
        pod_ident = pod.name
        try:
            resp = self.k8s_api.replace_namespaced_pod(name=str(pod_ident),
                                                       body=manifest,
                                                       namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.PodNotFound(pod=pod.uuid)

        pod['uuid'] = resp.metadata.uid
        pod['name'] = resp.metadata.name
        pod['project_id'] = context.project_id
        pod['user_id'] = context.user_id
        pod['bay_uuid'] = bay_uuid
        pod['images'] = [c.image for c in resp.spec.containers]
        if not resp.metadata.labels:
            pod['labels'] = {}
        else:
            pod['labels'] = ast.literal_eval(resp.metadata.labels)
        pod['status'] = resp.status.phase
        pod['host'] = resp.spec.node_name

        return pod
예제 #24
0
    def pod_update(self, context, pod_ident, bay_ident, manifest):
        LOG.debug("pod_update %s", pod_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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay_uuid)
        if utils.is_uuid_like(pod_ident):
            pod = objects.Pod.get_by_uuid(context, pod_ident, bay_uuid,
                                          self.k8s_api)
        else:
            pod = objects.Pod.get_by_name(context, pod_ident, bay_uuid,
                                          self.k8s_api)
        pod_ident = pod.name
        try:
            resp = self.k8s_api.replace_namespaced_pod(name=str(pod_ident),
                                                       body=manifest,
                                                       namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

        if resp is None:
            raise exception.PodNotFound(pod=pod.uuid)

        pod['uuid'] = resp.metadata.uid
        pod['name'] = resp.metadata.name
        pod['project_id'] = context.project_id
        pod['user_id'] = context.user_id
        pod['bay_uuid'] = bay_uuid
        pod['images'] = [c.image for c in resp.spec.containers]
        if not resp.metadata.labels:
            pod['labels'] = {}
        else:
            pod['labels'] = ast.literal_eval(resp.metadata.labels)
        pod['status'] = resp.status.phase
        pod['host'] = resp.spec.node_name

        return pod
예제 #25
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.
        bay_uuid = conductor_utils.retrieve_bay_uuid(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(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
예제 #26
0
파일: test_utils.py 프로젝트: baikai/magnum
 def test_retrieve_bay_uuid_from_uuid(self, mock_bay_get_by_name,
                                      mock_uuid_like):
     bay_uuid = utils.retrieve_bay_uuid('context', '1')
     self.assertEqual('1', bay_uuid)
     mock_uuid_like.return_value = True
     mock_bay_get_by_name.assert_not_called()
예제 #27
0
 def test_retrieve_bay_uuid_from_uuid(self, mock_bay_get_by_name,
                                      mock_uuid_like):
     bay_uuid = utils.retrieve_bay_uuid('context', '1')
     self.assertEqual('1', bay_uuid)
     mock_uuid_like.return_value = True
     mock_bay_get_by_name.assert_not_called()