示例#1
0
 def get_resource(self, key, extras):
     """
     Retrieve one resource
     """
     context = extras['nova_ctx']
     try:
         (loc, identifier) = key.rsplit('/', 1)
     except ValueError:
         raise AttributeError("Unexpected format for key %s" % key)
     loc = loc + '/'
     LOG.debug("Getting resource at %s with id: %s", loc, identifier)
     try:
         # XXX should use regular expressions?
         if loc == infrastructure.COMPUTE.location:
             compute_vm = vm.get_vm(identifier, context)
             return self._construct_occi_compute(compute_vm, extras)
         elif loc == infrastructure.STORAGE.location:
             vol = storage.get_storage(identifier, context)
             return self._construct_occi_storage(vol, extras)
         elif loc in [infrastructure.STORAGELINK.location,
                      infrastructure.NETWORKINTERFACE.location]:
             (compute_id, other_id) = identifier.split('_', 1)
             compute_vm = vm.get_vm(compute_id, context)
             occi_vm = self._construct_occi_compute(compute_vm, extras)
             # look for the link
             for link in occi_vm.links:
                 if link.identifier == key:
                     return link
         elif loc == infrastructure.NETWORK.location:
             return self.nets[identifier]
     except exceptions.HTTPError:
         # the nova_glue did not find the resource, just ignore
         pass
     # not found!
     raise KeyError(key)
示例#2
0
文件: storage.py 项目: IFCA/occi-os
    def create(self, entity, extras):
        """
        Creates a new volume.
        """
        context = extras['nova_ctx']
        if 'occi.storage.size' not in entity.attributes:
            raise AttributeError('size attribute not found!')
        size = entity.attributes['occi.storage.size']

        name = ''
        if 'occi.core.title' not in entity.attributes:
            name = str(uuid.uuid4())
        else:
            name = entity.attributes['occi.core.title']

        new_volume = storage.create_storage(size, name, context)
        vol_id = new_volume['id']

        # Work around problem that instance is lazy-loaded...
        new_volume = storage.get_storage(vol_id, context)

        if new_volume['status'] == 'error':
            raise exceptions.HTTPError(500, 'There was an error creating the '
                                       'volume')
        entity.attributes['occi.core.id'] = str(vol_id)
        entity.identifier = infrastructure.STORAGE.location + vol_id

        if new_volume['status'] == 'available':
            entity.attributes['occi.storage.state'] = 'active'

        entity.actions = [infrastructure.OFFLINE, infrastructure.BACKUP,
                          infrastructure.SNAPSHOT, infrastructure.RESIZE]
示例#3
0
    def create(self, entity, extras):
        """
        Creates a new volume.
        """
        context = extras['nova_ctx']
        if 'occi.storage.size' not in entity.attributes:
            raise AttributeError('size attribute not found!')

        new_volume = storage.create_storage(
            entity.attributes['occi.storage'
                              '.size'], context)
        vol_id = new_volume['id']

        # Work around problem that instance is lazy-loaded...
        new_volume = storage.get_storage(vol_id, context)

        if new_volume['status'] == 'error':
            raise exceptions.HTTPError(
                500, 'There was an error creating the '
                'volume')
        entity.attributes['occi.core.id'] = str(vol_id)
        entity.identifier = infrastructure.STORAGE.location + vol_id

        if new_volume['status'] == 'available':
            entity.attributes['occi.storage.state'] = 'active'

        entity.actions = [
            infrastructure.OFFLINE, infrastructure.BACKUP,
            infrastructure.SNAPSHOT, infrastructure.RESIZE
        ]
示例#4
0
文件: storage.py 项目: IFCA/occi-os
    def delete(self, link, extras):
        """
        Unlinks the the compute from the storage resource.
        """
        instance_id = link.source.attributes['occi.core.id']
        volume_id = link.target.attributes['occi.core.id']

        volume = storage.get_storage(volume_id, extras['nova_ctx'])
        vm.detach_volume(instance_id, volume, extras['nova_ctx'])
示例#5
0
    def delete(self, link, extras):
        """
        Unlinks the the compute from the storage resource.
        """
        instance_id = link.source.attributes['occi.core.id']
        volume_id = link.target.attributes['occi.core.id']

        volume = storage.get_storage(volume_id, extras['nova_ctx'])
        vm.detach_volume(instance_id, volume, extras['nova_ctx'])
示例#6
0
    def retrieve(self, entity, extras):
        """
        Gets a representation of the storage volume and presents it ready for
        rendering by pyssf.
        """
        v_id = entity.attributes['occi.core.id']

        volume = storage.get_storage(v_id, extras['nova_ctx'])

        entity.attributes['occi.storage.size'] = str(float(volume['size']))

        # OS volume states:
        #       available, creating, deleting, in-use, error, error_deleting
        if volume['status'] == 'available' or volume['status'] == 'in-use':
            entity.attributes['occi.storage.state'] = 'online'
            entity.actions = [infrastructure.OFFLINE, infrastructure.BACKUP,
                              infrastructure.SNAPSHOT, infrastructure.RESIZE]
        else:
            entity.attributes['occi.storage.state'] = 'offline'
            entity.actions = [infrastructure.ONLINE]
示例#7
0
    def retrieve(self, entity, extras):
        """
        Gets a representation of the storage volume and presents it ready for
        rendering by pyssf.
        """
        v_id = entity.attributes['occi.core.id']

        volume = storage.get_storage(v_id, extras['nova_ctx'])

        entity.attributes['occi.storage.size'] = str(float(volume['size']))

        # OS volume states:
        #       available, creating, deleting, in-use, error, error_deleting
        if volume['status'] == 'available' or volume['status'] == 'in-use':
            entity.attributes['occi.storage.state'] = 'online'
            entity.actions = [
                infrastructure.OFFLINE, infrastructure.BACKUP,
                infrastructure.SNAPSHOT, infrastructure.RESIZE
            ]
        else:
            entity.attributes['occi.storage.state'] = 'offline'
            entity.actions = [infrastructure.ONLINE]
示例#8
0
    def _construct_occi_storage(self, identifier, extras):
        """
        Construct a OCCI storage instance.

        First item in result list is entity self!

        Adds it to the cache too!
        """
        result = []
        context = extras['nova_ctx']
        stor = storage.get_storage(identifier, context)

        # id, display_name, size, status
        iden = infrastructure.STORAGE.location + identifier
        entity = core_model.Resource(iden, infrastructure.STORAGE, [])
        result.append(entity)

        # core.id and cache it!
        entity.attributes['occi.core.id'] = identifier
        entity.extras = self.get_extras(extras)
        self.cache[(entity.identifier, context.user_id)] = entity

        return result
示例#9
0
    def _construct_occi_storage(self, identifier, extras):
        """
        Construct a OCCI storage instance.

        First item in result list is entity self!

        Adds it to the cache too!
        """
        result = []
        context = extras['nova_ctx']
        stor = storage.get_storage(identifier, context)

        # id, display_name, size, status
        iden = infrastructure.STORAGE.location + identifier
        entity = core_model.Resource(iden, infrastructure.STORAGE, [])
        result.append(entity)

        # create links on VM resources
        if stor['status'] == 'in-use':
            source = self.get_resource(infrastructure.COMPUTE.location +
                                       str(stor['instance_uuid']), extras)
            link = core_model.Link(infrastructure.STORAGELINK.location +
                                   str(uuid.uuid4()),
                                   infrastructure.STORAGELINK, [], source,
                                   entity)
            link.extras = self.get_extras(extras)
            source.links.append(link)
            result.append(link)
            self.cache[(link.identifier, context.user_id)] = link

        # core.id and cache it!
        entity.attributes['occi.core.id'] = identifier
        entity.extras = self.get_extras(extras)
        self.cache[(entity.identifier, context.user_id)] = entity

        return result
示例#10
0
    def _construct_occi_storage(self, identifier, extras):
        """
        Construct a OCCI storage instance.

        First item in result list is entity self!

        Adds it to the cache too!
        """
        result = []
        context = extras['nova_ctx']
        stor = storage.get_storage(identifier, context)

        # id, display_name, size, status
        iden = infrastructure.STORAGE.location + identifier
        entity = core_model.Resource(iden, infrastructure.STORAGE, [])
        result.append(entity)

        # create links on VM resources
        if stor['status'] == 'in-use':
            source = self.get_resource(
                infrastructure.COMPUTE.location + str(stor['instance_uuid']),
                extras)
            link = core_model.Link(
                infrastructure.STORAGELINK.location + str(uuid.uuid4()),
                infrastructure.STORAGELINK, [], source, entity)
            link.extras = self.get_extras(extras)
            source.links.append(link)
            result.append(link)
            self.cache[(link.identifier, context.user_id)] = link

        # core.id and cache it!
        entity.attributes['occi.core.id'] = identifier
        entity.extras = self.get_extras(extras)
        self.cache[(entity.identifier, context.user_id)] = entity

        return result