Beispiel #1
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_vm_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 "method" not 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)
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_vm_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)
Beispiel #3
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)

        # set state and applicable actions!
        # TODO: map to OCCI state!
        state, actions = vm.get_vm_state(uid, context)
        entity.attributes["occi.compute.state"] = state
        entity.actions = actions

        # set up to date attributes
        entity.attributes["occi.compute.hostname"] = instance["hostname"]
        # TODO: check to get arch from OS!
        entity.attributes["occi.compute.architecture"] = "x86"
        entity.attributes["occi.compute.cores"] = str(instance["vcpus"])
        entity.attributes["occi.compute.speed"] = str(0.0)  # N/A in instance
        value = str(float(instance["memory_mb"]) / 1024)
        entity.attributes["occi.compute.memory"] = value
Beispiel #4
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)

        # set state and applicable actions!
        # TODO: map to OCCI state!
        state, actions = vm.get_vm_state(uid, context)
        entity.attributes['occi.compute.state'] = state
        entity.actions = actions

        # set up to date attributes
        entity.attributes['occi.compute.hostname'] = instance['hostname']
        # TODO: check to get arch from OS!
        entity.attributes['occi.compute.architecture'] = 'x86'
        entity.attributes['occi.compute.cores'] = str(instance['vcpus'])
        entity.attributes['occi.compute.speed'] = str(0.0)  # N/A in instance
        value = str(float(instance['memory_mb']) / 1024)
        entity.attributes['occi.compute.memory'] = value
Beispiel #5
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)

        # set state and applicable actions!
        # TODO: map to OCCI state!
        state, actions = vm.get_vm_state(uid, context)
        entity.attributes['occi.compute.state'] = state
        entity.actions = actions

        # set up to date attributes
        entity.attributes['occi.compute.hostname'] = instance['hostname']
        # TODO: check to get arch from OS!
        entity.attributes['occi.compute.architecture'] = 'x86'
        entity.attributes['occi.compute.cores'] = str(instance['vcpus'])
        entity.attributes['occi.compute.speed'] = str(0.0)  # N/A in instance
        value = str(float(instance['memory_mb']) / 1024)
        entity.attributes['occi.compute.memory'] = value