コード例 #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
ファイル: image.py プロジェクト: smile-luobin/smaug
 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
ファイル: server.py プロジェクト: smile-luobin/smaug
 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
ファイル: image.py プロジェクト: smile-luobin/smaug
 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
ファイル: image.py プロジェクト: smile-luobin/smaug
 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
ファイル: server.py プロジェクト: smile-luobin/smaug
 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
         ]