Ejemplo n.º 1
0
    def _test_create_k8s_api(self, bay_uuid,
                             mock_api_client,
                             mock_bay_retrieval,
                             mock_get_bay_magnum_cert,
                             mock_get_bay_ca_cert):
        bay_obj = mock.MagicMock()
        bay_obj.uuid = 'bay-uuid'
        bay_obj.api_address = 'fake-k8s-api-endpoint'
        bay_obj.magnum_cert_ref = 'fake-magnum-cert-ref'
        bay_obj.ca_cert_ref = 'fake-ca-cert-ref'
        mock_bay_retrieval.return_value = bay_obj

        mock_get_bay_magnum_cert.return_value = self._mock_cert_mgr_get_cert(
            'fake-magnum-cert-ref')
        mock_get_bay_ca_cert.return_value = self._mock_cert_mgr_get_cert(
            'fake-ca-cert-ref')

        file_dict = TestK8sAPI.file_dict
        for content in file_dict.keys():
            file_hdl = file_dict[content]
            file_hdl.name = TestK8sAPI.file_name[content]

        context = 'context'
        with patch(
            'magnum.conductor.k8s_api.K8sAPI._create_temp_file_with_content',
                side_effect=self._mock_named_file_creation):
            k8s_api.create_k8s_api(context, bay_uuid)

        mock_bay_retrieval.assert_called_once_with(context, bay_uuid)

        mock_api_client.assert_called_once_with(
            bay_obj.api_address,
            key_file='priv-key-temp-file-name',
            cert_file='cert-temp-file-name',
            ca_certs='ca-cert-temp-file-name')
Ejemplo n.º 2
0
    def _test_create_k8s_api(self, cls,
                             mock_api_vapi,
                             mock_api_client,
                             mock_bay_retrieval,
                             mock_load_pem_private_key):
        bay_obj = mock.MagicMock()
        bay_obj.uuid = 'bay-uuid'
        bay_obj.api_address = 'fake-k8s-api-endpoint'
        bay_obj.magnum_cert_ref = 'fake-magnum-cert-ref'
        bay_obj.ca_cert_ref = 'fake-ca-cert-ref'
        mock_bay_retrieval.return_value = bay_obj
        mock_private_bytes = mock.MagicMock()
        mock_load_pem_private_key.return_value = mock_private_bytes
        mock_private_bytes.private_bytes = mock.MagicMock(
            return_value='private-key-content')

        file_dict = TestK8sAPI.file_dict
        for content in file_dict.keys():
            file_hdl = file_dict[content]
            file_hdl.name = TestK8sAPI.file_name[content]

        context = 'context'

        obj = getattr(objects, cls)({})
        if cls is not 'Bay':
            self.assertFalse(hasattr(obj, 'bay_uuid'))
            obj.bay_uuid = 'bay-uuid'
        else:
            obj = bay_obj

        with patch(
            'magnum.conductor.k8s_api.K8sAPI._create_temp_file_with_content',
                side_effect=self._mock_named_file_creation):
            with patch(
                'magnum.common.cert_manager.local_cert_manager'
                    '.CertManager.get_cert',
                    side_effect=self._mock_cert_mgr_get_cert):
                with patch(
                    'magnum.common.cert_manager.barbican_cert_manager'
                        '.CertManager.get_cert',
                        side_effect=self._mock_cert_mgr_get_cert):
                    k8s_api.create_k8s_api(context, obj)

        if cls is not 'Bay':
            mock_bay_retrieval.assert_called_once_with(context, obj)

        mock_api_client.assert_called_once_with(
            bay_obj.api_address,
            key_file='priv-key-temp-file-name',
            cert_file='cert-temp-file-name',
            ca_certs='ca-cert-temp-file-name')
Ejemplo n.º 3
0
    def _test_create_k8s_api(self, cls,
                             mock_api_vapi,
                             mock_api_client,
                             mock_bay_retrieval,
                             mock_load_pem_private_key):
        bay_obj = mock.MagicMock()
        bay_obj.uuid = 'bay-uuid'
        bay_obj.api_address = 'fake-k8s-api-endpoint'
        bay_obj.magnum_cert_ref = 'fake-magnum-cert-ref'
        bay_obj.ca_cert_ref = 'fake-ca-cert-ref'
        mock_bay_retrieval.return_value = bay_obj
        mock_private_bytes = mock.MagicMock()
        mock_load_pem_private_key.return_value = mock_private_bytes
        mock_private_bytes.private_bytes = mock.MagicMock(
            return_value='private-key-content')

        file_dict = TestK8sAPI.file_dict
        for content in file_dict.keys():
            file_hdl = file_dict[content]
            file_hdl.name = TestK8sAPI.file_name[content]

        context = 'context'

        obj = getattr(objects, cls)({})
        if cls is not 'Bay':
            self.assertFalse(hasattr(obj, 'bay_uuid'))
            obj.bay_uuid = 'bay-uuid'
        else:
            obj = bay_obj

        with patch(
            'magnum.conductor.k8s_api.K8sAPI._create_temp_file_with_content',
                side_effect=self._mock_named_file_creation):
            with patch(
                'magnum.common.cert_manager.local_cert_manager'
                    '.CertManager.get_cert',
                    side_effect=self._mock_cert_mgr_get_cert):
                with patch(
                    'magnum.common.cert_manager.barbican_cert_manager'
                        '.CertManager.get_cert',
                        side_effect=self._mock_cert_mgr_get_cert):
                    k8s_api.create_k8s_api(context, obj)

        if cls is not 'Bay':
            mock_bay_retrieval.assert_called_once_with(context, obj.bay_uuid)

        mock_api_client.assert_called_once_with(
            bay_obj.api_address,
            key_file='priv-key-temp-file-name',
            cert_file='cert-temp-file-name',
            ca_certs='ca-cert-temp-file-name')
Ejemplo n.º 4
0
    def _get_hosts_with_container(self, context, cluster):
        k8s_api = k8s.create_k8s_api(self.context, cluster)
        hosts = set()
        for pod in k8s_api.list_namespaced_pod(namespace='default').items:
            hosts.add(pod.spec.node_name)

        return hosts
Ejemplo n.º 5
0
    def service_create(self, context, service):
        LOG.debug("service_create")
        bay = conductor_utils.retrieve_bay(context, service.bay_uuid)
        self.k8s_api = k8s.create_k8s_api(context, bay)
        manifest = k8s_manifest.parse(service.manifest)
        try:
            resp = self.k8s_api.create_namespaced_service(body=manifest,
                                                          namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

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

        service['uuid'] = resp.metadata.uid
        service['name'] = resp.metadata.name
        service['labels'] = ast.literal_eval(resp.metadata.labels)
        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
Ejemplo n.º 6
0
    def pod_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_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
Ejemplo n.º 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
Ejemplo n.º 8
0
    def pod_update(self, context, pod_ident, bay_ident, manifest):
        LOG.debug("pod_update %s", pod_ident)
        bay = conductor_utils.retrieve_bay(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay)
        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
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
    def service_create(self, context, service):
        LOG.debug("service_create")
        self.k8s_api = k8s.create_k8s_api(context, service.bay_uuid)
        manifest = k8s_manifest.parse(service.manifest)
        try:
            resp = self.k8s_api.create_namespaced_service(body=manifest,
                                                          namespace='default')
        except rest.ApiException as err:
            raise exception.KubernetesAPIFailed(err=err)

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

        service['uuid'] = resp.metadata.uid
        service['name'] = resp.metadata.name
        service['labels'] = ast.literal_eval(resp.metadata.labels)
        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
Ejemplo n.º 11
0
    def _get_hosts_with_container(self, context, cluster):
        k8s_api = k8s.create_k8s_api(self.context, cluster)
        hosts = set()
        for pod in k8s_api.list_namespaced_pod(namespace='default').items:
            hosts.add(pod.spec.node_name)

        return hosts
Ejemplo n.º 12
0
    def pod_update(self, context, pod_ident, bay_ident, manifest):
        LOG.debug("pod_update %s", pod_ident)
        bay = conductor_utils.retrieve_bay(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay)
        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
Ejemplo n.º 13
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
Ejemplo n.º 14
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
Ejemplo n.º 15
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 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
Ejemplo n.º 16
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
Ejemplo n.º 17
0
    def poll_health_status(self):
        k8s_api = k8s.create_k8s_api(self.context, self.cluster)
        if self._is_cluster_accessible():
            status, reason = self._poll_health_status(k8s_api)
        else:
            status = m_fields.ClusterHealthStatus.UNKNOWN
            reason = {"api": "The cluster %s is not accessible." %
                      self.cluster.name}

        self.data['health_status'] = status
        self.data['health_status_reason'] = reason
Ejemplo n.º 18
0
    def pod_show(self, context, pod_ident, bay_ident):
        LOG.debug("pod_show %s", pod_ident)
        bay = conductor_utils.retrieve_bay(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay)
        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
Ejemplo n.º 19
0
    def service_show(self, context, service_ident, bay_ident):
        LOG.debug("service_show %s", service_ident)
        bay = conductor_utils.retrieve_bay(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay)
        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)

        return service
Ejemplo n.º 20
0
 def service_create(self, context, service):
     LOG.debug("service_create")
     self.k8s_api = k8s.create_k8s_api(context, service)
     manifest = k8s_manifest.parse(service.manifest)
     try:
         self.k8s_api.create_namespaced_service(body=manifest,
                                                namespace='default')
     except rest.ApiException as err:
         raise exception.KubernetesAPIFailed(err=err)
     # call the service object to persist in db
     service.create(context)
     return service
Ejemplo n.º 21
0
    def pod_show(self, context, pod_ident, bay_ident):
        LOG.debug("pod_show %s", pod_ident)
        bay = conductor_utils.retrieve_bay(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay)
        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
Ejemplo n.º 22
0
 def rc_create(self, context, rc):
     LOG.debug("rc_create")
     self.k8s_api = k8s.create_k8s_api(context, rc)
     manifest = k8s_manifest.parse(rc.manifest)
     try:
         self.k8s_api.create_namespaced_replication_controller(
             body=manifest, namespace='default')
     except rest.ApiException as err:
         raise exception.KubernetesAPIFailed(err=err)
     # call the rc object to persist in db
     rc.create(context)
     return rc
Ejemplo n.º 23
0
 def service_create(self, context, service):
     LOG.debug("service_create")
     self.k8s_api = k8s.create_k8s_api(context, service)
     manifest = k8s_manifest.parse(service.manifest)
     try:
         self.k8s_api.create_namespaced_service(body=manifest,
                                                namespace='default')
     except rest.ApiException as err:
         raise exception.KubernetesAPIFailed(err=err)
     # call the service object to persist in db
     service.create(context)
     return service
Ejemplo n.º 24
0
 def service_create(self, context, service):
     LOG.debug("service_create")
     self.k8s_api = k8s.create_k8s_api(context, service)
     manifest = k8s_manifest.parse(service.manifest)
     try:
         self.k8s_api.createService(body=manifest, namespaces='default')
     except error.HTTPError as err:
         message = ast.literal_eval(err.read())['message']
         raise exception.KubernetesAPIFailed(code=err.code, message=message)
     # call the service object to persist in db
     service.create(context)
     return service
Ejemplo n.º 25
0
 def rc_create(self, context, rc):
     LOG.debug("rc_create")
     self.k8s_api = k8s.create_k8s_api(context, rc)
     manifest = k8s_manifest.parse(rc.manifest)
     try:
         self.k8s_api.create_namespaced_replication_controller(
             body=manifest, namespace='default')
     except rest.ApiException as err:
         raise exception.KubernetesAPIFailed(err=err)
     # call the rc object to persist in db
     rc.create(context)
     return rc
Ejemplo n.º 26
0
    def service_show(self, context, service_ident, bay_ident):
        LOG.debug("service_show %s", service_ident)
        bay = conductor_utils.retrieve_bay(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay)
        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)

        return service
Ejemplo n.º 27
0
    def rc_show(self, context, rc_ident, bay_ident):
        LOG.debug("rc_show %s", rc_ident)
        bay = conductor_utils.retrieve_bay(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay)
        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
Ejemplo n.º 28
0
 def rc_create(self, context, rc):
     LOG.debug("rc_create")
     self.k8s_api = k8s.create_k8s_api(context, rc)
     manifest = k8s_manifest.parse(rc.manifest)
     try:
         self.k8s_api.createReplicationController(body=manifest,
                                                  namespaces='default')
     except error.HTTPError as err:
         message = ast.literal_eval(err.read())['message']
         raise exception.KubernetesAPIFailed(code=err.code, message=message)
     # call the rc object to persist in db
     rc.create(context)
     return rc
Ejemplo n.º 29
0
 def rc_create(self, context, rc):
     LOG.debug("rc_create")
     self.k8s_api = k8s.create_k8s_api(context, rc)
     manifest = k8s_manifest.parse(rc.manifest)
     try:
         self.k8s_api.createReplicationController(body=manifest,
                                                  namespaces='default')
     except error.HTTPError as err:
         message = ast.literal_eval(err.read())['message']
         raise exception.KubernetesAPIFailed(code=err.code, message=message)
     # call the rc object to persist in db
     rc.create(context)
     return rc
Ejemplo n.º 30
0
 def service_create(self, context, service):
     LOG.debug("service_create")
     self.k8s_api = k8s.create_k8s_api(context, service)
     manifest = k8s_manifest.parse(service.manifest)
     try:
         self.k8s_api.createService(body=manifest,
                                    namespaces='default')
     except error.HTTPError as err:
         message = ast.literal_eval(err.read())['message']
         raise exception.KubernetesAPIFailed(code=err.code, message=message)
     # call the service object to persist in db
     service.create(context)
     return service
Ejemplo n.º 31
0
    def rc_show(self, context, rc_ident, bay_ident):
        LOG.debug("rc_show %s", rc_ident)
        bay = conductor_utils.retrieve_bay(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay)
        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
Ejemplo n.º 32
0
 def service_update(self, context, service):
     LOG.debug("service_update %s", service.uuid)
     self.k8s_api = k8s.create_k8s_api(context, service)
     manifest = k8s_manifest.parse(service.manifest)
     try:
         self.k8s_api.replace_namespaced_service(name=str(service.name),
                                                 body=manifest,
                                                 namespace='default')
     except rest.ApiException as err:
         raise exception.KubernetesAPIFailed(err=err)
     # call the service object to persist in db
     service.refresh(context)
     service.save()
     return service
Ejemplo n.º 33
0
 def pod_update(self, context, pod):
     LOG.debug("pod_update %s", pod.uuid)
     self.k8s_api = k8s.create_k8s_api(context, pod)
     manifest = k8s_manifest.parse(pod.manifest)
     try:
         self.k8s_api.replace_namespaced_pod(name=str(pod.name),
                                             body=manifest,
                                             namespace='default')
     except rest.ApiException as err:
         raise exception.KubernetesAPIFailed(err=err)
     # call the pod object to persist in db
     pod.refresh(context)
     pod.save()
     return pod
Ejemplo n.º 34
0
 def pod_update(self, context, pod):
     LOG.debug("pod_update %s", pod.uuid)
     self.k8s_api = k8s.create_k8s_api(context, pod)
     manifest = k8s_manifest.parse(pod.manifest)
     try:
         self.k8s_api.replace_namespaced_pod(name=str(pod.name),
                                             body=manifest,
                                             namespace='default')
     except rest.ApiException as err:
         raise exception.KubernetesAPIFailed(err=err)
     # call the pod object to persist in db
     pod.refresh(context)
     pod.save()
     return pod
Ejemplo n.º 35
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
Ejemplo n.º 36
0
 def service_update(self, context, service):
     LOG.debug("service_update %s", service.uuid)
     self.k8s_api = k8s.create_k8s_api(context, service)
     manifest = k8s_manifest.parse(service.manifest)
     try:
         self.k8s_api.replace_namespaced_service(name=str(service.name),
                                                 body=manifest,
                                                 namespace='default')
     except rest.ApiException as err:
         raise exception.KubernetesAPIFailed(err=err)
     # call the service object to persist in db
     service.refresh(context)
     service.save()
     return service
Ejemplo n.º 37
0
 def pod_update(self, context, pod):
     LOG.debug("pod_update %s", pod.uuid)
     self.k8s_api = k8s.create_k8s_api(context, pod)
     manifest = k8s_manifest.parse(pod.manifest)
     try:
         self.k8s_api.replacePod(name=pod.name, body=manifest,
                                 namespaces='default')
     except error.HTTPError as err:
         message = ast.literal_eval(err.read())['message']
         raise exception.KubernetesAPIFailed(code=err.code, message=message)
     # call the pod object to persist in db
     pod.refresh(context)
     pod.save()
     return pod
Ejemplo n.º 38
0
 def pod_delete(self, context, uuid):
     LOG.debug("pod_delete %s", uuid)
     pod = objects.Pod.get_by_uuid(context, uuid)
     self.k8s_api = k8s.create_k8s_api(context, pod)
     if conductor_utils.object_has_stack(context, pod):
         try:
             self.k8s_api.delete_namespaced_pod(name=str(pod.name), body={},
                                                namespace='default')
         except rest.ApiException as err:
             if err.status == 404:
                 pass
             else:
                 raise exception.KubernetesAPIFailed(err=err)
     # call the pod object to persist in db
     pod.destroy(context)
Ejemplo n.º 39
0
 def service_delete(self, context, uuid):
     LOG.debug("service_delete %s", uuid)
     service = objects.Service.get_by_uuid(context, uuid)
     self.k8s_api = k8s.create_k8s_api(context, service)
     if conductor_utils.object_has_stack(context, service):
         try:
             self.k8s_api.delete_namespaced_service(name=str(service.name),
                                                    namespace='default')
         except rest.ApiException as err:
             if err.status == 404:
                 pass
             else:
                 raise exception.KubernetesAPIFailed(err=err)
     # call the service object to persist in db
     service.destroy(context)
Ejemplo n.º 40
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
Ejemplo n.º 41
0
 def rc_delete(self, context, uuid):
     LOG.debug("rc_delete %s", uuid)
     rc = objects.ReplicationController.get_by_uuid(context, uuid)
     self.k8s_api = k8s.create_k8s_api(context, rc)
     if conductor_utils.object_has_stack(context, rc):
         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)
     # call the rc object to persist in db
     rc.destroy(context)
Ejemplo n.º 42
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
Ejemplo n.º 43
0
 def pod_update(self, context, pod):
     LOG.debug("pod_update %s", pod.uuid)
     self.k8s_api = k8s.create_k8s_api(context, pod)
     manifest = k8s_manifest.parse(pod.manifest)
     try:
         self.k8s_api.replacePod(name=pod.name,
                                 body=manifest,
                                 namespaces='default')
     except error.HTTPError as err:
         message = ast.literal_eval(err.read())['message']
         raise exception.KubernetesAPIFailed(code=err.code, message=message)
     # call the pod object to persist in db
     pod.refresh(context)
     pod.save()
     return pod
Ejemplo n.º 44
0
 def service_delete(self, context, uuid):
     LOG.debug("service_delete %s", uuid)
     service = objects.Service.get_by_uuid(context, uuid)
     self.k8s_api = k8s.create_k8s_api(context, service)
     if conductor_utils.object_has_stack(context, service):
         try:
             self.k8s_api.delete_namespaced_service(name=str(service.name),
                                                    namespace='default')
         except rest.ApiException as err:
             if err.status == 404:
                 pass
             else:
                 raise exception.KubernetesAPIFailed(err=err)
     # call the service object to persist in db
     service.destroy(context)
Ejemplo n.º 45
0
 def rc_delete(self, context, uuid):
     LOG.debug("rc_delete %s", uuid)
     rc = objects.ReplicationController.get_by_uuid(context, uuid)
     self.k8s_api = k8s.create_k8s_api(context, rc)
     if conductor_utils.object_has_stack(context, rc):
         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)
     # call the rc object to persist in db
     rc.destroy(context)
Ejemplo n.º 46
0
 def pod_delete(self, context, uuid):
     LOG.debug("pod_delete %s", uuid)
     pod = objects.Pod.get_by_uuid(context, uuid)
     self.k8s_api = k8s.create_k8s_api(context, pod)
     if conductor_utils.object_has_stack(context, pod):
         try:
             self.k8s_api.delete_namespaced_pod(name=str(pod.name), body={},
                                                namespace='default')
         except rest.ApiException as err:
             if err.status == 404:
                 pass
             else:
                 raise exception.KubernetesAPIFailed(err=err)
     # call the pod object to persist in db
     pod.destroy(context)
Ejemplo n.º 47
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
Ejemplo n.º 48
0
 def pod_delete(self, context, uuid):
     LOG.debug("pod_delete %s", uuid)
     pod = objects.Pod.get_by_uuid(context, uuid)
     self.k8s_api = k8s.create_k8s_api(context, pod)
     if conductor_utils.object_has_stack(context, pod):
         try:
             self.k8s_api.deletePod(name=pod.name, namespaces='default')
         except error.HTTPError as err:
             if err.code == 404:
                 pass
             else:
                 message = ast.literal_eval(err.read())['message']
                 raise exception.KubernetesAPIFailed(code=err.code,
                                                     message=message)
     # call the pod object to persist in db
     pod.destroy(context)
Ejemplo n.º 49
0
 def rc_delete(self, context, uuid):
     LOG.debug("rc_delete %s", uuid)
     rc = objects.ReplicationController.get_by_uuid(context, uuid)
     self.k8s_api = k8s.create_k8s_api(context, rc)
     if conductor_utils.object_has_stack(context, rc):
         try:
             self.k8s_api.deleteReplicationController(name=rc.name,
                                                      namespaces='default')
         except error.HTTPError as err:
             if err.code == 404:
                 pass
             else:
                 message = ast.literal_eval(err.read())['message']
                 raise exception.KubernetesAPIFailed(code=err.code,
                                                     message=message)
     # call the rc object to persist in db
     rc.destroy(context)
Ejemplo n.º 50
0
 def service_delete(self, context, uuid):
     LOG.debug("service_delete %s", uuid)
     service = objects.Service.get_by_uuid(context, uuid)
     self.k8s_api = k8s.create_k8s_api(context, service)
     if conductor_utils.object_has_stack(context, service):
         try:
             self.k8s_api.deleteService(name=service.name,
                                        namespaces='default')
         except error.HTTPError as err:
             if err.code == 404:
                 pass
             else:
                 message = ast.literal_eval(err.read())['message']
                 raise exception.KubernetesAPIFailed(code=err.code,
                                                     message=message)
     # call the service object to persist in db
     service.destroy(context)
Ejemplo n.º 51
0
 def rc_delete(self, context, uuid):
     LOG.debug("rc_delete %s", uuid)
     rc = objects.ReplicationController.get_by_uuid(context, uuid)
     self.k8s_api = k8s.create_k8s_api(context, rc)
     if conductor_utils.object_has_stack(context, rc):
         try:
             self.k8s_api.deleteReplicationController(name=rc.name,
                                                      namespaces='default')
         except error.HTTPError as err:
             if err.code == 404:
                 pass
             else:
                 message = ast.literal_eval(err.read())['message']
                 raise exception.KubernetesAPIFailed(code=err.code,
                                                     message=message)
     # call the rc object to persist in db
     rc.destroy(context)
Ejemplo n.º 52
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
Ejemplo n.º 53
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
Ejemplo n.º 54
0
 def rc_delete(self, context, rc_ident, bay_ident):
     LOG.debug("rc_delete %s", rc_ident)
     bay = conductor_utils.retrieve_bay(context, bay_ident)
     self.k8s_api = k8s.create_k8s_api(context, bay)
     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)
Ejemplo n.º 55
0
 def pod_delete(self, context, pod_ident, bay_ident):
     LOG.debug("pod_delete %s", pod_ident)
     bay = conductor_utils.retrieve_bay(context, bay_ident)
     self.k8s_api = k8s.create_k8s_api(context, bay)
     if utils.is_uuid_like(pod_ident):
         pod = objects.Pod.get_by_uuid(context, pod_ident,
                                       bay.uuid, self.k8s_api)
         pod_name = pod.name
     else:
         pod_name = pod_ident
     if conductor_utils.object_has_stack(context, bay.uuid):
         try:
             self.k8s_api.delete_namespaced_pod(name=str(pod_name), body={},
                                                namespace='default')
         except rest.ApiException as err:
             if err.status == 404:
                 pass
             else:
                 raise exception.KubernetesAPIFailed(err=err)
Ejemplo n.º 56
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
Ejemplo n.º 57
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
Ejemplo n.º 58
0
    def service_delete(self, context, service_ident, bay_ident):
        LOG.debug("service_delete %s", service_ident)
        bay = conductor_utils.retrieve_bay(context, bay_ident)
        self.k8s_api = k8s.create_k8s_api(context, bay)
        if utils.is_uuid_like(service_ident):
            service = objects.Service.get_by_uuid(context, service_ident,
                                                  bay.uuid, self.k8s_api)
            service_name = service.name
        else:
            service_name = service_ident
        if conductor_utils.object_has_stack(context, bay.uuid):
            try:

                self.k8s_api.delete_namespaced_service(name=str(service_name),
                                                       namespace='default')
            except rest.ApiException as err:
                if err.status == 404:
                    pass
                else:
                    raise exception.KubernetesAPIFailed(err=err)
Ejemplo n.º 59
0
 def pod_delete(self, context, pod_ident, bay_ident):
     LOG.debug("pod_delete %s", pod_ident)
     bay = conductor_utils.retrieve_bay(context, bay_ident)
     self.k8s_api = k8s.create_k8s_api(context, bay)
     if utils.is_uuid_like(pod_ident):
         pod = objects.Pod.get_by_uuid(context, pod_ident, bay.uuid,
                                       self.k8s_api)
         pod_name = pod.name
     else:
         pod_name = pod_ident
     if conductor_utils.object_has_stack(context, bay.uuid):
         try:
             self.k8s_api.delete_namespaced_pod(name=str(pod_name),
                                                body={},
                                                namespace='default')
         except rest.ApiException as err:
             if err.status == 404:
                 pass
             else:
                 raise exception.KubernetesAPIFailed(err=err)