Пример #1
0
    def get_dependent_resources(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(
                _LE("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) for vol in volumes
                if _is_attached_to(vol)
            ]
Пример #2
0
 def show_resource(self, context, resource_id):
     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)
Пример #3
0
 def show_resource(self, context, resource_id):
     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)
Пример #4
0
 def show_resource(self, context, resource_id):
     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)
Пример #5
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))
     else:
         return [
             resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                               id=server.image['id'],
                               name=server.image['name'])
         ]
Пример #6
0
 def list_resources(self, context):
     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
         ]
Пример #7
0
 def list_resources(self, context):
     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]
Пример #8
0
 def list_resources(self, context):
     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
         ]