def test_list_resources(self, mokc_image_list):
     plugin = ImageProtectablePlugin(self._context)
     mokc_image_list.return_value = \
         [
             image_info(id='123', name='name123', owner='abcd'),
             image_info(id='456', name='name456', owner='efgh'),
         ]
     self.assertEqual(plugin.list_resources(self._context), [
         resource.Resource(
             type=constants.IMAGE_RESOURCE_TYPE, id='123', name='name123'),
         resource.Resource(
             type=constants.IMAGE_RESOURCE_TYPE, id='456', name='name456')
     ])
예제 #2
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)
            ]
예제 #3
0
 def list_resources(self, context):
     # TODO(yuvalbr) handle admin context for multiple projects?
     return [
         resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                           id=context.project_id,
                           name=context.project_name)
     ]
 def test_show_resource(self, mock_image_get):
     image_info = namedtuple('image_info', field_names=['id', 'name'])
     plugin = ImageProtectablePlugin(self._context)
     mock_image_get.return_value = \
         image_info(id='123', name='name123')
     self.assertEqual(
         plugin.show_resource(self._context, '123'),
         resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                           id='123',
                           name='name123'))
예제 #5
0
 def resource_graph(self):
     packed_graph = self._md_cache.get("resource_graph", None)
     if packed_graph is not None:
         nodes = packed_graph[0]
         for sid, value in nodes.items():
             nodes[sid] = resource.Resource(type=value[0],
                                            id=value[1],
                                            name=value[2])
         return graph.unpack_graph(packed_graph)
     else:
         return None
예제 #6
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)
예제 #7
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)
 def test_get_server_dependent_resources(self, mock_server_get):
     vm = server_info(id='server1',
                      type=constants.SERVER_RESOURCE_TYPE,
                      name='nameserver1',
                      image=dict(id='123', name='name123'))
     plugin = ImageProtectablePlugin(self._context)
     mock_server_get.return_value = vm
     self.assertEqual(plugin.get_dependent_resources(self._context, vm), [
         resource.Resource(
             type=constants.IMAGE_RESOURCE_TYPE, id='123', name='name123')
     ])
예제 #9
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)
예제 #10
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'])
         ]
예제 #11
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
         ]
예제 #12
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]
예제 #13
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
         ]
 def test_get_project_dependent_resources(self, mock_image_list):
     project = project_info(id='abcd',
                            type=constants.PROJECT_RESOURCE_TYPE,
                            name='nameabcd')
     plugin = ImageProtectablePlugin(self._context)
     mock_image_list.return_value = \
         [
             image_info('123', 'abcd', 'nameabcd'),
             image_info('456', 'efgh', 'nameefgh'),
         ]
     self.assertEqual(
         plugin.get_dependent_resources(self._context, project), [
             resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                               name='nameabcd',
                               id='123')
         ])
예제 #15
0
 def show_resource(self, context, resource_id):
     # TODO(yinwei) get project name through keystone client
     return resource.Resource(type=self._SUPPORT_RESOURCE_TYPE,
                              id=resource_id,
                              name=context.project_name)