Пример #1
0
 def __init__(self,
              app_name,
              action_name,
              arguments=None,
              transforms=None,
              uid=None):
     """Initializes a new Condition object.
     
     Args:
         app_name (str): The name of the app which contains this condition
         action_name (str): The action name for the Condition. Defaults to an empty string.
         arguments (list[Argument], optional): Dictionary of Argument keys to Argument values.
             This dictionary will be converted to a dictionary of str:Argument. Defaults to None.
         transforms(list[Transform], optional): A list of Transform objects for the Condition object.
             Defaults to None.
         uid (str, optional): A universally unique identifier for this object.
             Created from uuid.uuid4() in Python
     """
     ExecutionElement.__init__(self, uid)
     self.app_name = app_name
     self.action_name = action_name
     self._data_param_name, self._run, self._api = get_condition_api(
         self.app_name, self.action_name)
     self._condition_executable = get_condition(self.app_name, self._run)
     arguments = {arg.name: arg
                  for arg in arguments} if arguments is not None else {}
     tmp_api = split_api_params(self._api, self._data_param_name)
     validate_condition_parameters(tmp_api, arguments, self.action_name)
     self.arguments = arguments
     self.transforms = transforms if transforms is not None else []
Пример #2
0
 def __init__(self,
              source_uid,
              destination_uid,
              status='Success',
              conditions=None,
              priority=999,
              uid=None):
     """Initializes a new Branch object.
     
     Args:
         source_uid (str): The UID of the source action that will be sending inputs to this Branch.
         destination_uid (str): The UID of the destination action that will be returned if the conditions for this
             Branch are met.
         status (str, optional): Optional field to keep track of the status of the Branch. Defaults to
             "Success".
         conditions (list[Condition], optional): A list of Condition objects for the Branch object.
             Defaults to None.
         priority (int, optional): Optional priority parameter to specify which Branch in the Workflow's
             list of Branches should be executed if multiple have conditions resulting to True.
             Defaults to 999 (lowest priority).
         uid (str, optional): A universally unique identifier for this object. Created from uuid.uuid4() in Python.
     """
     ExecutionElement.__init__(self, uid)
     self.source_uid = source_uid
     self.destination_uid = destination_uid
     self.status = status
     self.conditions = conditions if conditions is not None else []
     self.priority = priority
Пример #3
0
    def __init__(self, name, workflows=None, uid=None,
                 walkoff_version=walkoff.__version__):
        """Creates a Playbook object.

        Args:
            name (str): The name of the Playbook
            workflows (list[Workflow], optional): An optional list of Workflows associated with this Playbook
            uid (str, optional): An optional UID to specify for this Playbook
        """
        ExecutionElement.__init__(self, uid)
        self.name = name
        # TODO: When playbook endpoints use UIDs, this should store UIDS
        self.workflows = {workflow.name: workflow for workflow in workflows} if workflows is not None else {}
        self.walkoff_version = walkoff_version
Пример #4
0
 def __init__(self, app_name, action_name, arguments=None, uid=None):
     """Initializes a new Transform object. A Transform is used to transform input into a workflow.
     
     Args:
         app_name (str): The app name associated with this transform
         action_name (str): The action name for the transform.
         arguments (list[Argument], optional): Dictionary of Argument keys to Argument values.
             This dictionary will be converted to a dictionary of str:Argument. Defaults to None.
         uid (str, optional): A universally unique identifier for this object.
             Created from uuid.uuid4() in Python
     """
     ExecutionElement.__init__(self, uid)
     self.app_name = app_name
     self.action_name = action_name
     self._data_param_name, self._run, self._api = get_transform_api(self.app_name, self.action_name)
     self._transform_executable = get_transform(self.app_name, self._run)
     arguments = {arg.name: arg for arg in arguments} if arguments is not None else {}
     tmp_api = split_api_params(self._api, self._data_param_name)
     validate_transform_parameters(tmp_api, arguments, self.action_name)
     self.arguments = arguments
Пример #5
0
    def __init__(self,
                 name='',
                 uid=None,
                 actions=None,
                 branches=None,
                 start=None):
        """Initializes a Workflow object. A Workflow falls under a Playbook, and has many associated Actions
            within it that get executed.
            
        Args:
            name (str, optional): The name of the Workflow object. Defaults to an empty string.
            uid (str, optional): Optional UID to pass in for the workflow. Defaults to uuid.uuid4().
            actions (dict, optional): Optional Action objects. Defaults to None.
            branches (list[Branch], optional): A list of Branch objects for the Action object. Defaults to None.
            start (str, optional): Optional UID of the starting Action. Defaults to None.
        """
        ExecutionElement.__init__(self, uid)
        self.name = name
        self.actions = {action.uid: action
                        for action in actions} if actions is not None else {}

        self.branches = {}
        if actions:
            for action in actions:
                self.branches[action.uid] = []

        if branches:
            for branch in branches:
                if branch.source_uid in self.branches:
                    self.branches[branch.source_uid].append(branch)

        self.start = start if start is not None else 'start'

        self._is_paused = False
        self._resume = threading.Event()
        self._accumulator = {}
        self._execution_uid = 'default'
Пример #6
0
 def __init__(self):
     ExecutionElement.__init__(self)
     self.a = 42
     self.b = B('a')
     self.c = [B(i) for i in range(3)]
     self.d = {i: B(i) for i in range(3)}
Пример #7
0
 def __init__(self, b):
     ExecutionElement.__init__(self)
     self.b = b
Пример #8
0
 def __init__(self):
     ExecutionElement.__init__(self)
     self.a = 42
     self.d = [B(i) for i in range(3)]
Пример #9
0
 def __init__(self):
     ExecutionElement.__init__(self)
     self.a = 42
     self.d = B('something')
Пример #10
0
 def test_init_with_uid(self):
     uid = uuid.uuid4().hex
     elem = ExecutionElement(uid=uid)
     self.assertEqual(elem.uid, uid)
Пример #11
0
 def test_init_default(self):
     elem = ExecutionElement()
     self.assertIsNotNone(elem.uid)
Пример #12
0
    def __init__(self,
                 app_name,
                 action_name,
                 name='',
                 device_id=None,
                 arguments=None,
                 triggers=None,
                 position=None,
                 uid=None,
                 templated=False,
                 raw_representation=None):
        """Initializes a new Action object. A Workflow has many actions that it executes.

        Args:
            app_name (str): The name of the app associated with the Action
            action_name (str): The name of the action associated with a Action
            name (str, optional): The name of the Action object. Defaults to an empty string.
            device_id (int, optional): The id of the device associated with the app associated with the Action. Defaults
                to None.
            arguments ([Argument], optional): A list of Argument objects that are parameters to the action.
                Defaults to None.
            triggers (list[Flag], optional): A list of Flag objects for the Action. If a Action should wait for data
                before continuing, then include these Trigger objects in the Action init. Defaults to None.
            position (dict, optional): A dictionary with the x and y coordinates of the Action object. This is used
                for UI display purposes. Defaults to None.
            uid (str, optional): A universally unique identifier for this object.
                Created from uuid.uuid4().hex in Python
            templated (bool, optional): Whether or not the Action is templated. Used for Jinja templating.
            raw_representation (dict, optional): JSON representation of this object. Used for Jinja templating.
        """
        ExecutionElement.__init__(self, uid)

        self.triggers = triggers if triggers is not None else []
        self._incoming_data = None
        self._event = threading.Event()

        self.name = name
        self.device_id = device_id
        self.app_name = app_name
        self.action_name = action_name
        self._run, self._arguments_api = get_app_action_api(
            self.app_name, self.action_name)

        if is_app_action_bound(self.app_name,
                               self._run) and not self.device_id:
            raise InvalidArgument(
                "Cannot initialize Action {}. App action is bound but no device ID was provided."
                .format(self.name))

        self._action_executable = get_app_action(self.app_name, self._run)

        arguments = {argument.name: argument
                     for argument in arguments
                     } if arguments is not None else {}

        self.templated = templated
        if not self.templated:
            validate_app_action_parameters(self._arguments_api, arguments,
                                           self.app_name, self.action_name)
        self.arguments = arguments
        self.position = position if position is not None else {}

        self._output = None
        self._raw_representation = raw_representation if raw_representation is not None else {}
        self._execution_uid = 'default'