def _create_hosts_list(ctx, node_ids, node_instance_ids):
    if node_ids or node_instance_ids:
        filtered_node_instances = _filter_node_instances(
            ctx=ctx,
            node_ids=node_ids,
            node_instance_ids=node_instance_ids,
            type_names=[])
        error = False
        for node_instance in filtered_node_instances:
            if not lifecycle.is_host_node(node_instance):
                msg = 'Node instance {0} is not host.'.format(node_instance.id)
                ctx.logger.error(msg)
                error = True
            elif utils.internal.get_install_method(
                    node_instance.node.properties) \
                    == constants.AGENT_INSTALL_METHOD_NONE:
                msg = ('Agent should not be installed on '
                       'node instance {0}').format(node_instance.id)
                ctx.logger.error(msg)
                error = True
        if error:
            raise ValueError('Specified filters are not correct.')
        else:
            hosts = filtered_node_instances
    else:
        hosts = [host for host in _get_all_host_instances(ctx)
                 if utils.internal.get_install_method(host.node.properties) !=
                 constants.AGENT_INSTALL_METHOD_NONE]
    return hosts
示例#2
0
def _create_hosts_list(ctx, node_ids, node_instance_ids, install_methods=None):
    if install_methods is None:
        install_methods = constants.AGENT_INSTALL_METHODS_INSTALLED
    if node_ids or node_instance_ids:
        filtered_node_instances = _filter_node_instances(
            ctx=ctx,
            node_ids=node_ids,
            node_instance_ids=node_instance_ids,
            type_names=[])
        errors = list()
        for node_instance in filtered_node_instances:
            if not lifecycle.is_host_node(node_instance):
                errors.append('Node instance {0} is not host.'.format(
                    node_instance.id))
            elif utils.internal.get_install_method(
                    node_instance.node.properties) \
                    == constants.AGENT_INSTALL_METHOD_NONE:
                errors.append('Agent should not be installed on node instance '
                              '{0}').format(node_instance.id)
        if errors:
            raise ValueError('Specified filters are not correct:\n{0}'.format(
                '\n'.join(errors)))
        hosts = filtered_node_instances
    else:
        hosts = [
            host for host in _get_all_host_instances(ctx)
            if utils.internal.get_install_method(host.node.properties) in
            install_methods
        ]
    return hosts
def refresh_snapshots(ctx, **_):
    '''
        Executes a complex, graph-based set of lifecycle events
        to stop all host (compute) instances, delete all
        existing instance snapshots, take new snapshots
        of all attached volumes, and start the instances
        back up when complete.
    '''
    graph = ctx.graph_mode()
    # Find all compute hosts and build a sequence graph
    for node in ctx.nodes:
        if not REQUIRED_OPS.issubset(node.operations):
            ctx.logger.warn(
                'Skipping refresh_snapshots workflow for node "%s" because '
                'it does not have all required operations defined' % node.id)
            continue
        # Iterate over each node instance
        for instance in node.instances:
            if not lifecycle.is_host_node(instance):
                ctx.logger.warn(
                    'Skipping refresh_snapshots workflow for node instance '
                    '"%s" because it is not a compute host' % instance.id)
                continue
            build_instance_subgraph(instance, graph)
    # Execute the sequences
    return graph.execute()
def _create_hosts_list(ctx, node_ids, node_instance_ids, install_methods=None):
    if install_methods is None:
        install_methods = constants.AGENT_INSTALL_METHODS_INSTALLED
    if node_ids or node_instance_ids:
        filtered_node_instances = _filter_node_instances(
            ctx=ctx,
            node_ids=node_ids,
            node_instance_ids=node_instance_ids,
            type_names=[])
        error = False
        for node_instance in filtered_node_instances:
            if not lifecycle.is_host_node(node_instance):
                msg = 'Node instance {0} is not host.'.format(node_instance.id)
                ctx.logger.error(msg)
                error = True
            elif utils.internal.get_install_method(
                    node_instance.node.properties) \
                    == constants.AGENT_INSTALL_METHOD_NONE:
                msg = ('Agent should not be installed on '
                       'node instance {0}').format(node_instance.id)
                ctx.logger.error(msg)
                error = True
        if error:
            raise ValueError('Specified filters are not correct.')
        else:
            hosts = filtered_node_instances
    else:
        hosts = [
            host for host in _get_all_host_instances(ctx)
            if utils.internal.get_install_method(host.node.properties) in
            install_methods
        ]
    return hosts
def install_new_agents(ctx, install_agent_timeout, node_ids,
                       node_instance_ids, **_):
    if node_ids or node_instance_ids:
        filtered_node_instances = _filter_node_instances(
            ctx=ctx,
            node_ids=node_ids,
            node_instance_ids=node_instance_ids,
            type_names=[])
        error = False
        for node_instance in filtered_node_instances:
            if not lifecycle.is_host_node(node_instance):
                msg = 'Node instance {0} is not host.'.format(node_instance.id)
                ctx.logger.error(msg)
                error = True
            elif utils.internal.get_install_method(
                    node_instance.node.properties) \
                    == constants.AGENT_INSTALL_METHOD_NONE:
                msg = ('Agent should not be installed on '
                       'node instance {0}').format(node_instance.id)
                ctx.logger.error(msg)
                error = True
        if error:
            raise ValueError('Specified filters are not correct.')
        else:
            hosts = filtered_node_instances
    else:
        hosts = (host for host in _get_all_host_instances(ctx)
                 if utils.internal.get_install_method(host.node.properties)
                 != constants.AGENT_INSTALL_METHOD_NONE)

    graph = ctx.graph_mode()
    for host in hosts:
        seq = graph.sequence()
        seq.add(
            host.send_event('Installing new agent.'),
            host.execute_operation(
                'cloudify.interfaces.cloudify_agent.create_amqp',
                kwargs={'install_agent_timeout': install_agent_timeout},
                allow_kwargs_override=True),
            host.send_event('New agent installed.'),
            *lifecycle.prepare_running_agent(host)
        )
        for subnode in host.get_contained_subgraph():
            seq.add(subnode.execute_operation(
                'cloudify.interfaces.monitoring.start'))
    graph.execute()
示例#6
0
def install_new_agents(ctx, install_agent_timeout, node_ids, node_instance_ids,
                       **_):
    if node_ids or node_instance_ids:
        filtered_node_instances = _filter_node_instances(
            ctx=ctx,
            node_ids=node_ids,
            node_instance_ids=node_instance_ids,
            type_names=[])
        error = False
        for node_instance in filtered_node_instances:
            if not lifecycle.is_host_node(node_instance):
                msg = 'Node instance {0} is not host.'.format(node_instance.id)
                ctx.logger.error(msg)
                error = True
            elif utils.internal.get_install_method(
                    node_instance.node.properties) \
                    == constants.AGENT_INSTALL_METHOD_NONE:
                msg = ('Agent should not be installed on '
                       'node instance {0}').format(node_instance.id)
                ctx.logger.error(msg)
                error = True
        if error:
            raise ValueError('Specified filters are not correct.')
        else:
            hosts = filtered_node_instances
    else:
        hosts = (host for host in _get_all_host_instances(ctx)
                 if utils.internal.get_install_method(host.node.properties) !=
                 constants.AGENT_INSTALL_METHOD_NONE)

    graph = ctx.graph_mode()
    for host in hosts:
        seq = graph.sequence()
        seq.add(
            host.send_event('Installing new agent.'),
            host.execute_operation(
                'cloudify.interfaces.cloudify_agent.create_amqp',
                kwargs={'install_agent_timeout': install_agent_timeout},
                allow_kwargs_override=True),
            host.send_event('New agent installed.'),
            *lifecycle.prepare_running_agent(host))
        for subnode in host.get_contained_subgraph():
            seq.add(
                subnode.execute_operation(
                    'cloudify.interfaces.monitoring.start'))
    graph.execute()
def _get_all_host_instances(ctx):
    node_instances = set()
    for node_instance in ctx.node_instances:
        if lifecycle.is_host_node(node_instance):
            node_instances.add(node_instance)
    return node_instances
示例#8
0
def _get_all_host_instances(ctx):
    node_instances = set()
    for node_instance in ctx.node_instances:
        if lifecycle.is_host_node(node_instance):
            node_instances.add(node_instance)
    return node_instances
def install_new_agents(ctx, install_agent_timeout, node_ids,
                       node_instance_ids, validate=True, install=True, **_):
    if node_ids or node_instance_ids:
        filtered_node_instances = _filter_node_instances(
            ctx=ctx,
            node_ids=node_ids,
            node_instance_ids=node_instance_ids,
            type_names=[])
        error = False
        for node_instance in filtered_node_instances:
            if not lifecycle.is_host_node(node_instance):
                msg = 'Node instance {0} is not host.'.format(node_instance.id)
                ctx.logger.error(msg)
                error = True
            elif utils.internal.get_install_method(
                    node_instance.node.properties) \
                    == constants.AGENT_INSTALL_METHOD_NONE:
                msg = ('Agent should not be installed on '
                       'node instance {0}').format(node_instance.id)
                ctx.logger.error(msg)
                error = True
        if error:
            raise ValueError('Specified filters are not correct.')
        else:
            hosts = filtered_node_instances
    else:
        hosts = [host for host in _get_all_host_instances(ctx)
                 if utils.internal.get_install_method(host.node.properties) !=
                 constants.AGENT_INSTALL_METHOD_NONE]

    for host in hosts:
        state = host.get_state().get()
        if state != 'started':
            raise RuntimeError('Node {0} is not started (state: {1})'.format(
                host.id,
                state))
    graph = ctx.graph_mode()
    if validate:
        validate_subgraph = graph.subgraph('validate')
        for host in hosts:
            seq = validate_subgraph.sequence()
            seq.add(
                host.send_event('Validating agent connection.'),
                host.execute_operation(
                    'cloudify.interfaces.cloudify_agent.validate_amqp',
                    kwargs={
                        'fail_on_agent_not_installable': True
                    }),
                host.send_event('Validation done'))
    if install:
        install_subgraph = graph.subgraph('install')
        for host in hosts:
            seq = install_subgraph.sequence()
            seq.add(
                host.send_event('Installing new agent'),
                host.execute_operation(
                    'cloudify.interfaces.cloudify_agent.create_amqp',
                    kwargs={'install_agent_timeout': install_agent_timeout},
                    allow_kwargs_override=True),
                host.send_event('New agent installed.'),
                host.execute_operation(
                    'cloudify.interfaces.cloudify_agent.validate_amqp',
                    kwargs={
                        'fail_on_agent_dead': True
                    }),
                *lifecycle.prepare_running_agent(host)
            )
            for subnode in host.get_contained_subgraph():
                seq.add(subnode.execute_operation(
                    'cloudify.interfaces.monitoring.start'))
    if validate and install:
        graph.add_dependency(install_subgraph, validate_subgraph)
    graph.execute()
def install_new_agents(ctx,
                       install_agent_timeout,
                       node_ids,
                       node_instance_ids,
                       validate=True,
                       install=True,
                       **_):
    if node_ids or node_instance_ids:
        filtered_node_instances = _filter_node_instances(
            ctx=ctx,
            node_ids=node_ids,
            node_instance_ids=node_instance_ids,
            type_names=[])
        error = False
        for node_instance in filtered_node_instances:
            if not lifecycle.is_host_node(node_instance):
                msg = 'Node instance {0} is not host.'.format(node_instance.id)
                ctx.logger.error(msg)
                error = True
            elif utils.internal.get_install_method(
                    node_instance.node.properties) \
                    == constants.AGENT_INSTALL_METHOD_NONE:
                msg = ('Agent should not be installed on '
                       'node instance {0}').format(node_instance.id)
                ctx.logger.error(msg)
                error = True
        if error:
            raise ValueError('Specified filters are not correct.')
        else:
            hosts = filtered_node_instances
    else:
        hosts = [
            host for host in _get_all_host_instances(ctx)
            if utils.internal.get_install_method(host.node.properties) !=
            constants.AGENT_INSTALL_METHOD_NONE
        ]

    for host in hosts:
        state = host.get_state().get()
        if state != 'started':
            raise RuntimeError('Node {0} is not started (state: {1})'.format(
                host.id, state))
    graph = ctx.graph_mode()
    if validate:
        validate_subgraph = graph.subgraph('validate')
        for host in hosts:
            seq = validate_subgraph.sequence()
            seq.add(
                host.send_event('Validating agent connection.'),
                host.execute_operation(
                    'cloudify.interfaces.cloudify_agent.validate_amqp',
                    kwargs={'fail_on_agent_not_installable': True}),
                host.send_event('Validation done'))
    if install:
        install_subgraph = graph.subgraph('install')
        for host in hosts:
            seq = install_subgraph.sequence()
            seq.add(
                host.send_event('Installing new agent'),
                host.execute_operation(
                    'cloudify.interfaces.cloudify_agent.create_amqp',
                    kwargs={'install_agent_timeout': install_agent_timeout},
                    allow_kwargs_override=True),
                host.send_event('New agent installed.'),
                host.execute_operation(
                    'cloudify.interfaces.cloudify_agent.validate_amqp',
                    kwargs={'fail_on_agent_dead': True}),
                *lifecycle.prepare_running_agent(host))
            for subnode in host.get_contained_subgraph():
                seq.add(
                    subnode.execute_operation(
                        'cloudify.interfaces.monitoring.start'))
    if validate and install:
        graph.add_dependency(install_subgraph, validate_subgraph)
    graph.execute()