Beispiel #1
0
    def retrieve(self, entity, extras):
        """
        Retrieve a VM.
        """
        uid = entity.attributes['occi.core.id']
        context = extras['nova_ctx']
        instance = vm.get_vm(uid, context)

        LOG.debug('Retrieving an Virtual machine: ', uid)

        # set state and applicable actions!
        state, actions = vm.get_occi_state(uid, context)
        entity.attributes['occi.compute.state'] = state
        entity.actions = actions

        # set up to date attributes
        entity.attributes['occi.compute.cores'] = str(instance['vcpus'])
        value = str(float(instance['memory_mb']) / 1024)
        entity.attributes['occi.compute.memory'] = value

        #Now we have the instance state, get its updated network info
        net_info = net.get_adapter_info(uid, context)
        attach_to_default_network(net_info, entity, extras)

        # add consoles and storage links
        set_console_info(entity, uid, extras)
Beispiel #2
0
    def action(self, entity, action, attributes, extras):
        """
        Perform an action.
        """
        # As there is no callback mechanism to update the state
        # of computes known by occi, a call to get the latest representation
        # must be made.
        context = extras['nova_ctx']
        uid = entity.attributes['occi.core.id']

        # set state and applicable actions - so even if the user hasn't done
        # a GET het can still the most applicable action now...
        state, actions = vm.get_occi_state(uid, context)
        entity.attributes['occi.compute.state'] = state
        entity.actions = actions

        if action not in entity.actions:
            raise AttributeError("This action is currently not applicable.")
        elif action == infrastructure.START:
            vm.start_vm(uid, context)
        elif action == infrastructure.STOP:
            vm.stop_vm(uid, context)
        elif action == infrastructure.RESTART:
            if not 'method' in attributes:
                raise AttributeError('Please provide a method!')
            method = attributes['method']
            vm.restart_vm(uid, method, context)
        elif action == infrastructure.SUSPEND:
            vm.suspend_vm(uid, context)