Exemplo n.º 1
0
 def show_resource(self, context, resource_id, parameters=None):
     try:
         if not parameters:
             raise
         name = parameters.get("name", None)
         if ":" in name:
             pod_namespace, pod_name = name.split(":")
         else:
             pod_namespace = self.namespace
             pod_name = name
         pod = self._client(context).read_namespaced_pod(
             pod_name, pod_namespace)
     except Exception as e:
         LOG.exception("Show a summary pod from kubernetes failed.")
         raise exception.ProtectableResourceNotFound(
             id=resource_id,
             type=self._SUPPORT_RESOURCE_TYPE,
             reason=six.text_type(e))
     else:
         if pod.status.phase in INVALID_POD_STATUS:
             raise exception.ProtectableResourceInvalidStatus(
                 id=resource_id,
                 type=self._SUPPORT_RESOURCE_TYPE,
                 status=pod.status.phase)
         return resource.Resource(
             type=self._SUPPORT_RESOURCE_TYPE,
             id=uuid.uuid5(uuid.NAMESPACE_OID,
                           "%s:%s" % (self.namespace, pod.metadata.name)),
             name="%s:%s" % (pod_namespace, pod.metadata.name),
             extra_info={'namespace': pod_namespace})
Exemplo n.º 2
0
 def show_resource(self, context, resource_id, parameters=None):
     try:
         share = self._client(context).shares.get(resource_id)
     except Exception as e:
         LOG.exception("Show a summary share from manila failed.")
         raise exception.ProtectableResourceNotFound(
             id=resource_id,
             type=self._SUPPORT_RESOURCE_TYPE,
             reason=six.text_type(e))
     else:
         if share.status in INVALID_SHARE_STATUS:
             raise exception.ProtectableResourceInvalidStatus(
                 id=resource_id, type=self._SUPPORT_RESOURCE_TYPE,
                 status=share.status)
         return resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                                  id=share.id, name=share.name)
Exemplo n.º 3
0
 def show_resource(self, context, resource_id, parameters=None):
     try:
         image = self._glance_client(context).images.get(resource_id)
     except Exception as e:
         LOG.exception("Show a image from glance failed.")
         raise exception.ProtectableResourceNotFound(
             id=resource_id,
             type=self._SUPPORT_RESOURCE_TYPE,
             reason=six.text_type(e))
     else:
         if image.status in INVALID_IMAGE_STATUS:
             raise exception.ProtectableResourceInvalidStatus(
                 id=image.id, type=self._SUPPORT_RESOURCE_TYPE,
                 status=image.status)
         return resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                                  id=image.id, name=image.name)
Exemplo n.º 4
0
    def _get_dependent_resources_by_pod(self, context, parent_resource):
        try:
            name = parent_resource.name
            pod_namespace, pod_name = name.split(":")
            pod = self._k8s_client(context).read_namespaced_pod(
                pod_name, pod_namespace)
            if not pod.spec.volumes:
                return []
            mounted_vol_list = []
            for volume in pod.spec.volumes:
                volume_pvc = volume.persistent_volume_claim
                volume_cinder = volume.cinder
                if volume_pvc:
                    pvc_name = volume_pvc.claim_name
                    pvc = self._k8s_client(
                        context).read_namespaced_persistent_volume_claim(
                            pvc_name, pod_namespace)
                    pv_name = pvc.spec.volume_name
                    if pv_name:
                        pv = self._k8s_client(context).read_persistent_volume(
                            pv_name)
                        if pv.spec.cinder:
                            mounted_vol_list.append(pv.spec.cinder.volume_id)
                elif volume_cinder:
                    mounted_vol_list.append(volume_cinder.volume_id)

        except Exception as e:
            LOG.exception("Get mounted volumes from kubernetes " "pod failed.")
            raise exception.ProtectableResourceNotFound(
                id=parent_resource.id,
                type=parent_resource.type,
                reason=six.text_type(e))
        try:
            volumes = self._client(context).volumes.list(detailed=True)
        except Exception as e:
            LOG.exception("List all detailed volumes from cinder failed.")
            raise exception.ListProtectableResourceFailed(
                type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e))
        else:
            return [
                resource.Resource(
                    type=self._SUPPORT_RESOURCE_TYPE,
                    id=vol.id,
                    name=vol.name,
                    extra_info={'availability_zone': vol.availability_zone})
                for vol in volumes if (vol.id in mounted_vol_list)
            ]
Exemplo n.º 5
0
 def show_resource(self, context, resource_id, parameters=None):
     try:
         volume = self._client(context).volumes.get(resource_id)
     except Exception as e:
         LOG.exception("Show a summary volume from cinder failed.")
         raise exception.ProtectableResourceNotFound(
             id=resource_id,
             type=self._SUPPORT_RESOURCE_TYPE,
             reason=six.text_type(e))
     else:
         if volume.status in INVALID_VOLUME_STATUS:
             raise exception.ProtectableResourceInvalidStatus(
                 id=resource_id,
                 type=self._SUPPORT_RESOURCE_TYPE,
                 status=volume.status)
         return resource.Resource(
             type=self._SUPPORT_RESOURCE_TYPE,
             id=volume.id,
             name=volume.name,
             extra_info={'availability_zone': volume.availability_zone})