Exemplo n.º 1
0
    def _get_dependent_resources_by_server(self, context, parent_resource):
        def _is_attached_to(vol):
            if parent_resource.type == constants.SERVER_RESOURCE_TYPE:
                return any([
                    s.get('server_id') == parent_resource.id
                    for s in vol.attachments
                ])
            if parent_resource.type == constants.PROJECT_RESOURCE_TYPE:
                return getattr(
                    vol, 'os-vol-tenant-attr:tenant_id') == parent_resource.id

        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 _is_attached_to(vol)
            ]
Exemplo n.º 2
0
    def _get_dependent_resources_by_server(self, context, parent_resource):
        try:
            # get metadata about network from neutron
            net_client = self._neutron_client(context)
            network_infos = net_client.list_networks().get('networks')
            neutron_networks = {network["id"] for network in network_infos}

            # get interface info from server
            nova_networks = set()
            serverid = parent_resource.id
            nova_client = ClientFactory.create_client("nova", context)
            interface_list = nova_client.servers.interface_list(serverid)

            # check net_id in interface
            for iface in interface_list:
                net_id = iface.net_id
                if net_id not in nova_networks:
                    nova_networks.add(net_id)

            # get the exsited networks
            valid_networks = nova_networks.intersection(neutron_networks)
            if valid_networks:
                return [
                    resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                                      id=self._get_network_id(),
                                      name="Network Topology")
                ]
            return []
        except Exception as e:
            LOG.exception("List all interfaces from nova failed.")
            raise exception.ListProtectableResourceFailed(
                type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e))
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(_LE("Show a image from glance failed."))
         raise exception.ListProtectableResourceFailed(
             type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e))
     else:
         return resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                                  id=image.id,
                                  name=image.name)
Exemplo n.º 4
0
 def show_resource(self, context, resource_id, parameters=None):
     try:
         server = self._client(context).servers.get(resource_id)
     except Exception as e:
         LOG.exception(_LE("Show a server from nova failed."))
         raise exception.ListProtectableResourceFailed(
             type=self._SUPPORT_RESOURCE_TYPE,
             reason=six.text_type(e))
     else:
         return resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                                  id=server.id,
                                  name=server.name)
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(_LE("Show a summary volume "
                           "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=volume.id, name=volume.name)
Exemplo n.º 6
0
 def list_resources(self, context, parameters=None):
     try:
         servers = self._client(context).servers.list(detailed=False)
     except Exception as e:
         LOG.exception(_LE("List all servers from nova failed."))
         raise exception.ListProtectableResourceFailed(
             type=self._SUPPORT_RESOURCE_TYPE,
             reason=six.text_type(e))
     else:
         return [resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                                   id=server.id,
                                   name=server.name)
                 for server in servers]
Exemplo n.º 7
0
 def list_resources(self, context, parameters=None):
     try:
         volumes = self._client(context).volumes.list(detailed=False)
     except Exception as e:
         LOG.exception(_LE("List all summary 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)
                 for vol in volumes]
Exemplo n.º 8
0
 def list_resources(self, context, parameters=None):
     try:
         images = self._glance_client(context).images.list()
     except Exception as e:
         LOG.exception(_LE("List all images from glance failed."))
         raise exception.ListProtectableResourceFailed(
             type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e))
     else:
         return [
             resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                               id=image.id,
                               name=image.name) for image in images
         ]
Exemplo n.º 9
0
 def list_resources(self, context, parameters=None):
     try:
         shares = self._client(context).shares.list(detailed=True)
     except Exception as e:
         LOG.exception("List all summary shares from manila failed.")
         raise exception.ListProtectableResourceFailed(
             type=self._SUPPORT_RESOURCE_TYPE,
             reason=six.text_type(e))
     else:
         return [resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                                   id=share.id, name=share.name)
                 for share in shares
                 if share.status not in INVALID_SHARE_STATUS]
Exemplo n.º 10
0
    def _get_dependent_resources_by_server(self, context, parent_resource):
        try:
            server = self._nova_client(context).servers.get(parent_resource.id)
        except Exception as e:
            LOG.exception(_LE("List all server from nova failed."))
            raise exception.ListProtectableResourceFailed(
                type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e))

        if not server.image:
            return []
        try:
            image = self._glance_client(context).images.get(server.image['id'])
        except Exception as e:
            LOG.exception(_LE("Getting image from glance failed."))
            raise exception.ListProtectableResourceFailed(
                type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e))

        return [
            resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                              id=server.image['id'],
                              name=image.name)
        ]
Exemplo n.º 11
0
 def list_resources(self, context, parameters=None):
     try:
         instances = self._client(context).instances.list()
     except Exception as e:
         LOG.exception("List all database instances from trove failed.")
         raise exception.ListProtectableResourceFailed(
             type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e))
     else:
         return [
             resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                               id=instance.id,
                               name=instance.name) for instance in instances
             if instance.status not in INVALID_INSTANCE_STATUS
         ]
Exemplo n.º 12
0
 def _get_dependent_resources_by_project(self, context, parent_resource):
     try:
         images = self._glance_client(context).images.list()
     except Exception as e:
         LOG.exception(_LE("List all images from glance failed."))
         raise exception.ListProtectableResourceFailed(
             type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e))
     else:
         return [
             resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                               id=image.id,
                               name=image.name) for image in images
             if image.owner == parent_resource.id
         ]
Exemplo n.º 13
0
 def get_dependent_resources(self, context, parent_resource):
     try:
         shares = self._client(context).shares.list()
     except Exception as e:
         LOG.exception("List all shares from manila failed.")
         raise exception.ListProtectableResourceFailed(
             type=self._SUPPORT_RESOURCE_TYPE,
             reason=six.text_type(e))
     else:
         return [resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                                   id=share.id,
                                   name=share.name)
                 for share in shares
                 if share.project_id == parent_resource.id
                 and share.status not in INVALID_SHARE_STATUS]
Exemplo n.º 14
0
 def list_resources(self, context, parameters=None):
     try:
         netclient = self._neutron_client(context)
         networks = netclient.list_networks(
             project_id=context.project_id).get('networks')
     except Exception as e:
         LOG.exception("List all summary networks from neutron failed.")
         raise exception.ListProtectableResourceFailed(
             type=self._SUPPORT_RESOURCE_TYPE,
             reason=six.text_type(e))
     else:
         if networks:
             return [resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                                       id=self._get_network_id(),
                                       name="Network Topology")]
         return []
Exemplo n.º 15
0
 def list_resources(self, context, parameters=None):
     try:
         volumes = self._client(context).volumes.list(detailed=True)
     except Exception as e:
         LOG.exception("List all summary 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.status not in INVALID_VOLUME_STATUS
         ]
Exemplo n.º 16
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.º 17
0
 def list_resources(self, context, parameters=None):
     try:
         pods = self._client(context).list_namespaced_pod(self.namespace)
     except Exception as e:
         LOG.exception("List all summary pods from kubernetes failed.")
         raise exception.ListProtectableResourceFailed(
             type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e))
     else:
         return [
             resource.Resource(
                 type=self._SUPPORT_RESOURCE_TYPE,
                 id=uuid.uuid5(
                     uuid.NAMESPACE_OID,
                     "%s:%s" % (self.namespace, pod.metadata.name)),
                 name="%s:%s" % (self.namespace, pod.metadata.name),
                 extra_info={'namespace': self.namespace})
             for pod in pods.items
             if pod.status.phase not in INVALID_POD_STATUS
         ]
Exemplo n.º 18
0
    def _get_dependent_resources_by_project(self, context, parent_resource):
        try:
            tid = parent_resource.id
            netclient = self._neutron_client(context)
            networks = netclient.list_networks(tenant_id=tid).get('networks')

            if networks:
                return [
                    resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                                      id=self._get_network_id(),
                                      name="Network Topology")
                ]
            else:
                return []

        except Exception as e:
            LOG.exception("List all summary networks from neutron failed.")
            raise exception.ListProtectableResourceFailed(
                type=self._SUPPORT_RESOURCE_TYPE, reason=six.text_type(e))