当前位置: 首页>>代码示例>>Python>>正文


Python block.Block类代码示例

本文整理汇总了Python中ansible.playbook.block.Block的典型用法代码示例。如果您正苦于以下问题:Python Block类的具体用法?Python Block怎么用?Python Block使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Block类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _create_noop_block_from

    def _create_noop_block_from(self, original_block, parent):
        noop_block = Block(parent_block=parent)
        noop_block.block = self._replace_with_noop(original_block.block)
        noop_block.always = self._replace_with_noop(original_block.always)
        noop_block.rescue = self._replace_with_noop(original_block.rescue)

        return noop_block
开发者ID:awiddersheim,项目名称:ansible,代码行数:7,代码来源:linear.py

示例2: deserialize

    def deserialize(self, data):

        # import is here to avoid import loops
        #from ansible.playbook.task_include import TaskInclude

        block_data = data.get('block')

        if block_data:
            b = Block()
            b.deserialize(block_data)
            self._block = b
            del data['block']

        role_data = data.get('role')
        if role_data:
            r = Role()
            r.deserialize(role_data)
            self._role = r
            del data['role']

        ti_data = data.get('task_include')
        if ti_data:
            #ti = TaskInclude()
            ti = Task()
            ti.deserialize(ti_data)
            self._task_include = ti
            del data['task_include']

        super(Task, self).deserialize(data)
开发者ID:RajeevNambiar,项目名称:temp,代码行数:29,代码来源:task.py

示例3: deserialize

    def deserialize(self, data):

        # import is here to avoid import loops
        from ansible.playbook.task_include import TaskInclude
        from ansible.playbook.handler_task_include import HandlerTaskInclude

        parent_data = data.get('parent', None)
        if parent_data:
            parent_type = data.get('parent_type')
            if parent_type == 'Block':
                p = Block()
            elif parent_type == 'TaskInclude':
                p = TaskInclude()
            elif parent_type == 'HandlerTaskInclude':
                p = HandlerTaskInclude()
            p.deserialize(parent_data)
            self._parent = p
            del data['parent']

        role_data = data.get('role')
        if role_data:
            r = Role()
            r.deserialize(role_data)
            self._role = r
            del data['role']

        super(Task, self).deserialize(data)
开发者ID:KMK-ONLINE,项目名称:ansible,代码行数:27,代码来源:task.py

示例4: test_block__load_list_of_tasks

 def test_block__load_list_of_tasks(self):
     task = dict(action='test')
     b = Block()
     self.assertEqual(b._load_list_of_tasks([]), [])
     res = b._load_list_of_tasks([task])
     self.assertEqual(len(res), 1)
     assert isinstance(res[0], Task)
     res = b._load_list_of_tasks([task,task,task])
     self.assertEqual(len(res), 3)
开发者ID:conlini,项目名称:frozen-ansible,代码行数:9,代码来源:test_block.py

示例5: __init__

    def __init__(self, inventory, play, play_context, variable_manager, all_vars, start_at_done=False):
        self._play = play
        self._blocks = []

        setup_block = Block(play=self._play)
        setup_task = Task(block=setup_block)
        setup_task.action = 'setup'
        setup_task.tags   = ['always']
        setup_task.args   = {}
        setup_task.set_loader(self._play._loader)
        setup_block.block = [setup_task]

        setup_block = setup_block.filter_tagged_tasks(play_context, all_vars)
        self._blocks.append(setup_block)

        for block in self._play.compile():
            new_block = block.filter_tagged_tasks(play_context, all_vars)
            if new_block.has_tasks():
                self._blocks.append(new_block)

        self._host_states = {}
        start_at_matched = False
        for host in inventory.get_hosts(self._play.hosts):
            self._host_states[host.name] = HostState(blocks=self._blocks)
            # if the host's name is in the variable manager's fact cache, then set
            # its _gathered_facts flag to true for smart gathering tests later
            if host.name in variable_manager._fact_cache:
                host._gathered_facts = True
            # if we're looking to start at a specific task, iterate through
            # the tasks for this host until we find the specified task
            if play_context.start_at_task is not None and not start_at_done:
                while True:
                    (s, task) = self.get_next_task_for_host(host, peek=True)
                    if s.run_state == self.ITERATING_COMPLETE:
                        break
                    if task.name == play_context.start_at_task or fnmatch.fnmatch(task.name, play_context.start_at_task) or \
                       task.get_name() == play_context.start_at_task or fnmatch.fnmatch(task.get_name(), play_context.start_at_task):
                        start_at_matched = True
                        break
                    else:
                        self.get_next_task_for_host(host)

                # finally, reset the host's state to ITERATING_SETUP
                if start_at_matched:
                    self._host_states[host.name].did_start_at_task = True
                    self._host_states[host.name].run_state = self.ITERATING_SETUP

        if start_at_matched:
            # we have our match, so clear the start_at_task field on the
            # play context to flag that we've started at a task (and future
            # plays won't try to advance)
            play_context.start_at_task = None

        # Extend the play handlers list to include the handlers defined in roles
        self._play.handlers.extend(play.compile_roles_handlers())
开发者ID:matthewbga,项目名称:blargotron,代码行数:55,代码来源:play_iterator.py

示例6: load_list_of_blocks

def load_list_of_blocks(ds, play, parent_block=None, role=None, task_include=None, use_handlers=False, variable_manager=None, loader=None):
    '''
    Given a list of mixed task/block data (parsed from YAML),
    return a list of Block() objects, where implicit blocks
    are created for each bare Task.
    '''
 
    # we import here to prevent a circular dependency with imports
    from ansible.playbook.block import Block

    if not isinstance(ds, (list, type(None))):
        raise AnsibleParserError('block has bad type: "%s". Expecting "list"' % type(ds).__name__, obj=ds)

    block_list = []
    if ds:
        for block in ds:
            b = Block.load(
                block,
                play=play,
                parent_block=parent_block,
                role=role,
                task_include=task_include,
                use_handlers=use_handlers,
                variable_manager=variable_manager,
                loader=loader
            )
            # Implicit blocks are created by bare tasks listed in a play withou
            # an explicit block statement. If we have two implicit blocks in a row,
            # squash them down to a single block to save processing time later.
            if b._implicit and len(block_list) > 0 and block_list[-1]._implicit:
                block_list[-1].block.extend(b.block)
            else:
                block_list.append(b)

    return block_list
开发者ID:thebeefcake,项目名称:masterless,代码行数:35,代码来源:helpers.py

示例7: load_list_of_blocks

def load_list_of_blocks(ds, play, parent_block=None, role=None, task_include=None, use_handlers=False, variable_manager=None, loader=None):
    '''
    Given a list of mixed task/block data (parsed from YAML),
    return a list of Block() objects, where implicit blocks
    are created for each bare Task.
    '''
 
    # we import here to prevent a circular dependency with imports
    from ansible.playbook.block import Block

    if not isinstance(ds, (list, type(None))):
        raise AnsibleParserError('block has bad type: "%s". Expecting "list"' % type(ds).__name__, obj=ds)

    block_list = []
    if ds:
        for block in ds:
            b = Block.load(
                block,
                play=play,
                parent_block=parent_block,
                role=role,
                task_include=task_include,
                use_handlers=use_handlers,
                variable_manager=variable_manager,
                loader=loader
            )
            block_list.append(b)

    return block_list
开发者ID:ferhaty,项目名称:ansible,代码行数:29,代码来源:helpers.py

示例8: compile

    def compile(self):
        '''
        Compiles and returns the task list for this play, compiled from the
        roles (which are themselves compiled recursively) and/or the list of
        tasks specified in the play.
        '''

        # create a block containing a single flush handlers meta
        # task, so we can be sure to run handlers at certain points
        # of the playbook execution
        flush_block = Block.load(
            data={'meta': 'flush_handlers'},
            play=self,
            variable_manager=self._variable_manager,
            loader=self._loader
        )

        block_list = []

        block_list.extend(self.pre_tasks)
        block_list.append(flush_block)
        block_list.extend(self._compile_roles())
        block_list.extend(self.tasks)
        block_list.append(flush_block)
        block_list.extend(self.post_tasks)
        block_list.append(flush_block)

        return block_list
开发者ID:2ndQuadrant,项目名称:ansible,代码行数:28,代码来源:play.py

示例9: load_list_of_blocks

def load_list_of_blocks(ds, play, parent_block=None, role=None, task_include=None, use_handlers=False, variable_manager=None, loader=None):
    '''
    Given a list of mixed task/block data (parsed from YAML),
    return a list of Block() objects, where implicit blocks
    are created for each bare Task.
    '''
 
    # we import here to prevent a circular dependency with imports
    from ansible.playbook.block import Block

    assert ds is None or isinstance(ds, list), 'block has bad type: %s' % type(ds)

    block_list = []
    if ds:
        for block in ds:
            b = Block.load(
                block,
                play=play,
                parent_block=parent_block,
                role=role,
                task_include=task_include,
                use_handlers=use_handlers,
                variable_manager=variable_manager,
                loader=loader
            )
            block_list.append(b)

    return block_list
开发者ID:victron,项目名称:paramiko_ssh-i,代码行数:28,代码来源:helpers.py

示例10: test_deserialize

 def test_deserialize(self):
     ds = dict(
         block=[dict(action='block')],
         rescue=[dict(action='rescue')],
         always=[dict(action='always')],
     )
     b = Block.load(ds)
     data = dict(parent=ds, parent_type='Block')
     b.deserialize(data)
     self.assertIsInstance(b._parent, Block)
开发者ID:awiddersheim,项目名称:ansible,代码行数:10,代码来源:test_block.py

示例11: test_load_block_simple

 def test_load_block_simple(self):
     ds = dict(
        block = [],
        rescue = [],
        always = [],
        #otherwise = [],
     )
     b = Block.load(ds)
     self.assertEqual(b.block, [])
     self.assertEqual(b.rescue, [])
     self.assertEqual(b.always, [])
开发者ID:KMK-ONLINE,项目名称:ansible,代码行数:11,代码来源:test_block.py

示例12: test_load_block_simple

 def test_load_block_simple(self):
     ds = dict(
        begin = [],
        rescue = [],
        end = [],
        otherwise = [],
     )
     b = Block.load(ds)
     self.assertEqual(b.begin, [])
     self.assertEqual(b.rescue, [])
     self.assertEqual(b.end, [])
     self.assertEqual(b.otherwise, [])
开发者ID:conlini,项目名称:frozen-ansible,代码行数:12,代码来源:test_block.py

示例13: test_load_block_with_tasks

 def test_load_block_with_tasks(self):
     ds = dict(
        block = [dict(action='block')],
        rescue = [dict(action='rescue')],
        always = [dict(action='always')],
        #otherwise = [dict(action='otherwise')],
     )
     b = Block.load(ds)
     self.assertEqual(len(b.block), 1)
     self.assertIsInstance(b.block[0], Task)
     self.assertEqual(len(b.rescue), 1)
     self.assertIsInstance(b.rescue[0], Task)
     self.assertEqual(len(b.always), 1)
     self.assertIsInstance(b.always[0], Task)
开发者ID:KMK-ONLINE,项目名称:ansible,代码行数:14,代码来源:test_block.py

示例14: test_load_block_with_tasks

 def test_load_block_with_tasks(self):
     ds = dict(
        begin = [dict(action='begin')],
        rescue = [dict(action='rescue')],
        end = [dict(action='end')],
        otherwise = [dict(action='otherwise')],
     )
     b = Block.load(ds)
     self.assertEqual(len(b.begin), 1)
     assert isinstance(b.begin[0], Task)
     self.assertEqual(len(b.rescue), 1)
     assert isinstance(b.rescue[0], Task)
     self.assertEqual(len(b.end), 1)
     assert isinstance(b.end[0], Task)
     self.assertEqual(len(b.otherwise), 1)
     assert isinstance(b.otherwise[0], Task)
开发者ID:conlini,项目名称:frozen-ansible,代码行数:16,代码来源:test_block.py

示例15: load_list_of_blocks

def load_list_of_blocks(ds, parent_block=None, role=None, task_include=None, loader=None):
    """
    Given a list of mixed task/block data (parsed from YAML),
    return a list of Block() objects, where implicit blocks
    are created for each bare Task.
    """

    # we import here to prevent a circular dependency with imports
    from ansible.playbook.block import Block

    assert type(ds) in (list, NoneType)

    block_list = []
    if ds:
        for block in ds:
            b = Block.load(block, parent_block=parent_block, role=role, task_include=task_include, loader=loader)
            block_list.append(b)

    return block_list
开发者ID:jinnko,项目名称:ansible,代码行数:19,代码来源:helpers.py


注:本文中的ansible.playbook.block.Block类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。