예제 #1
0
    def action_toggle(self, unit_id, wait=0, uuid=None, priority=None):
        """
        toggle unit status
        
        Create unit control action to toggle its status (1->0, 0->1). if using
        OID, you can also call "toggle(..)" with the same effect.

        Args:
            unit_id: unit id

        Optional:
            value: desired unit value
            wait: wait for the completion for the specified number of seconds
            uuid: action UUID (will be auto generated if none specified)
            priority: queue priority (default is 100, lower is better)

        Returns:
            Serialized action object (dict)

        Raises:
            FunctionFailed: action is "dead"
            ResourceNotFound: unit is not found

        @var_out exitcode Exit code
        @var_out status Action status
        """
        unit = eva.lm.controller.uc_pool.get_unit(oid_to_id(unit_id, 'unit'))
        if not unit:
            raise ResourceNotFound
        return ecall(
            eva.lm.controller.uc_pool.action_toggle(unit_id=oid_to_id(unit_id),
                                                    wait=wait,
                                                    uuid=uuid,
                                                    priority=priority))
예제 #2
0
    def result(self, unit_id=None, uuid=None, group=None, status=None):
        """
        get action status

        Checks the result of the action by its UUID or returns the actions for
        the specified unit.

        Args:
            unit_id: unit id or
            uuid: action uuid

        Optional:
            group: filter by unit group
            status: filter by action status: Q for queued, R for running, F for
                finished

        Returns:
            list or single serialized action object

        Raises:
            ResourceNotFound: unit or action is not found

        @var_out exitcode Exit code
        @var_out status Action status
        """
        if unit_id:
            unit = eva.lm.controller.uc_pool.get_unit(
                oid_to_id(unit_id, 'unit'))
            if not unit:
                raise ResourceNotFound
        return ecall(
            eva.lm.controller.uc_pool.result(oid_to_id(unit_id, 'unit'), uuid,
                                             group, status))
예제 #3
0
    def deploy_device(self, controller_id, device_tpl, cfg=None, save=None):
        """
        deploy device items from template

        Deploys the :ref:`device<device>` from the specified template.

        Args:
            controller_id: controller id to deploy device on
            device_tpl: device template
                (*runtime/tpl/<TEMPLATE>.yml|yaml|json*, without extension)

        Optional:
            cfg: device config (*var=value*, comma separated or dict)
            save: save items configuration on disk immediately after
                operation

        Raises:
            ResourceNotFound: device template or controller is not found
            FunctionFailed: device deploy error
        """
        return ecall(
            eva.lm.controller.uc_pool.deploy_device(
                controller_id=controller_id,
                device_tpl=device_tpl,
                cfg=cfg,
                save=save))
예제 #4
0
    def cmd(self, controller_id, command, args=None, wait=None, timeout=None):
        """
        execute a remote system command

        Executes a :ref:`command script<cmd>` on the server where the
        controller is installed.

        Args:
            controller_id: controller id to execute command on
            command: name of the command script

        Optional:
            args: string of command arguments, separated by spaces (passed to
                the script)
            wait: wait (in seconds) before API call sends a response. This
                allows to try waiting until command finish
            timeout: maximum time of command execution. If the command fails to
                finish within the specified time (in sec), it will be terminated

        Returns:
            Serialized command action object (dict)

        Raises:
            ResourceNotFound: command script or controller is not found

        @var_out exitcode Exit code
        @var_out status Action status
        """
        return ecall(
            eva.lm.controller.uc_pool.cmd(controller_id=controller_id,
                                          command=command,
                                          args=args,
                                          wait=wait,
                                          timeout=timeout))
예제 #5
0
    def undeploy_device(self, controller_id, device_tpl, cfg=None):
        """
        undeploy device items config from template

        Args:
            controller_id: controller id to deploy device on
            device_tpl: device template
                (*runtime/tpl/<TEMPLATE>.yml|yaml|json*, without extension)

        Optional:
            cfg: device config (*var=value*, comma separated or dict)

        Raises:
            ResourceNotFound: device template or controller is not found
        """
        return ecall(
            eva.lm.controller.uc_pool.undeploy_device(
                controller_id=controller_id, device_tpl=device_tpl, cfg=cfg))
예제 #6
0
    def kill(self, unit_id):
        """
        kill unit actions

        Apart from canceling all queued commands, this function also terminates
        the current running action.

        Args:
            unit_id: unit id

        Raises:
            ResourceNotFound: unit is not found
        """
        unit = eva.lm.controller.uc_pool.get_unit(oid_to_id(unit_id, 'unit'))
        if not unit:
            raise ResourceNotFound
        return ecall(
            eva.lm.controller.uc_pool.kill(unit_id=oid_to_id(unit_id, 'unit')))
예제 #7
0
    def q_clean(self, unit_id):
        """
        clean action queue of unit

        Cancels all queued actions, keeps the current action running.

        Args:
            unit_id: unit id

        Raises:
            ResourceNotFound: unit is not found
        """
        unit = eva.lm.controller.uc_pool.get_unit(oid_to_id(unit_id, 'unit'))
        if not unit:
            raise ResourceNotFound
        return ecall(
            eva.lm.controller.uc_pool.q_clean(
                unit_id=oid_to_id(unit_id, 'unit')))
예제 #8
0
    def action(self,
               unit_id,
               status,
               value=None,
               wait=0,
               uuid=None,
               priority=None):
        """
        unit control action
        
        The call is considered successful when action is put into the action
        queue of selected unit.

        Args:
            unit_id: unit id
            status: desired unit status

        Optional:
            value: desired unit value
            wait: wait for the completion for the specified number of seconds
            uuid: action UUID (will be auto generated if none specified)
            priority: queue priority (default is 100, lower is better)

        Returns:
            Serialized action object (dict)

        Raises:
            FunctionFailed: action is "dead"
            ResourceNotFound: unit is not found

        @var_out exitcode Exit code
        @var_out status Action status
        """
        unit = eva.lm.controller.uc_pool.get_unit(oid_to_id(unit_id, 'unit'))
        if not unit:
            raise ResourceNotFound
        return ecall(
            eva.lm.controller.uc_pool.action(unit_id=oid_to_id(
                unit_id, 'unit'),
                                             status=status,
                                             value=value,
                                             wait=wait,
                                             uuid=uuid,
                                             priority=priority))
예제 #9
0
    def terminate(self, unit_id=None, uuid=None):
        """
        terminate action execution
        
        Terminates or cancel the action if it is still queued
        
        Args:
            unit_id: action uuid or
            uuid: unit id
            
        Returns:

        Raises:
            ResourceNotFound: if unit/action is not found or action is already
                finished
        """
        if unit_id:
            unit = eva.lm.controller.uc_pool.get_unit(
                oid_to_id(unit_id, 'unit'))
            if not unit:
                raise ResourceNotFound
        return ecall(
            eva.lm.controller.uc_pool.terminate(oid_to_id(unit_id, 'unit'),
                                                uuid))