Beispiel #1
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 = vol.create_storage(entity.attributes['occi.storage' \
                                                          '.size'], context)
        vol_id = new_volume['id']

        # Work around problem that instance is lazy-loaded...
        new_volume = vol.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)

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

        entity.actions = [infrastructure.OFFLINE, infrastructure.BACKUP,
                            infrastructure.SNAPSHOT, infrastructure.RESIZE]
Beispiel #2
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 = vol.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'