def tag_metalsmith_managed_ports(result, conn, concurrency, stack,
                                 uuid_by_hostname, hostname_role_map,
                                 instances_by_hostname, net_maps):
    # no limit on concurrency, create a worker for every instance
    if concurrency < 1:
        concurrency = len(uuid_by_hostname)

    provisioner = metalsmith.Provisioner(cloud_region=conn.config)
    provisioner.connection = conn
    provision_jobs = []
    exceptions = []
    with futures.ThreadPoolExecutor(max_workers=concurrency) as p:
        for hostname, uuid in uuid_by_hostname.items():
            role = hostname_role_map[hostname]
            default_route_network = instances_by_hostname[hostname].get(
                'network_config', {}).get(
                'default_route_network', ['ctlplane'])

            tags = {'tripleo_stack_name={}'.format(stack),
                    'tripleo_ironic_uuid={}'.format(uuid),
                    'tripleo_role={}'.format(role),
                    'tripleo_ironic_vif_port=true'}
            provision_jobs.append(
                p.submit(_tag_metalsmith_instance_ports,
                         result, conn, provisioner, uuid, hostname, tags,
                         default_route_network, net_maps)
            )

    for job in futures.as_completed(provision_jobs):
        e = job.exception()
        if e:
            exceptions.append(e)

    if exceptions:
        raise exceptions[0]
Example #2
0
def main():
    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options'])
    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=False,
                           **module_kwargs)

    sdk, cloud = openstack_cloud_from_module(module)
    provisioner = metalsmith.Provisioner(cloud_region=cloud.config)

    try:
        found, not_found = bd.check_existing(
            instances=module.params['instances'],
            provisioner=provisioner,
            baremetal=cloud.baremetal)
        msg = ''
        if found:
            msg += ('Found existing instances: %s. ' %
                    ', '.join([i.uuid for i in found]))
        if not_found:
            msg += ('Instance(s) %s do not exist. ' %
                    ', '.join(r['hostname'] for r in not_found))

        instances = [{
            'name': i.node.name or i.uuid,
            'hostname': i.hostname,
            'id': i.uuid,
        } for i in found]
        module.exit_json(changed=False,
                         msg=msg,
                         instances=instances,
                         not_found=not_found)
    except Exception as e:
        module.fail_json(msg=str(e))
def main():
    if not openstack_full_argument_spec:
        raise RuntimeError(
            'This module requires ansible-collections-openstack')

    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options'])
    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=False,
                           **module_kwargs)

    log_stream = _configure_logging(module.params['log_level'])

    try:
        sdk, cloud = openstack_cloud_from_module(module)
        provisioner = metalsmith.Provisioner(cloud_region=cloud.config)
        instances = module.params['instances']
        state = module.params['state']
        concurrency = module.params['concurrency']
        timeout = module.params['timeout']
        wait = module.params['wait']
        clean_up = module.params['clean_up']

        if state == 'present':
            changed, nodes = provision(provisioner, instances, timeout,
                                       concurrency, clean_up, wait)
            instances = [{
                'name': i.node.name or i.uuid,
                'hostname': i.hostname,
                'id': i.uuid,
            } for i in nodes]
            module.exit_json(changed=changed,
                             msg="{} instances provisioned".format(len(nodes)),
                             instances=instances,
                             logging=log_stream.getvalue())

        if state == 'reserved':
            changed, nodes = reserve(provisioner, instances, clean_up)
            module.exit_json(changed=changed,
                             msg="{} instances reserved".format(len(nodes)),
                             ids=[node.id for node in nodes],
                             instances=instances,
                             logging=log_stream.getvalue())

        if state == 'absent':
            changed = unprovision(provisioner, instances)
            module.exit_json(changed=changed,
                             msg="{} nodes unprovisioned".format(
                                 len(instances)),
                             logging=log_stream.getvalue())
    except Exception as e:
        module.fail_json(msg=str(e), logging=log_stream.getvalue())
Example #4
0
def main():
    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options'])
    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=False,
                           **module_kwargs)

    sdk, cloud = openstack_cloud_from_module(module)
    provisioner = metalsmith.Provisioner(cloud_region=cloud.config)
    instances = module.params['instances']
    state = module.params['state']
    concurrency = module.params['concurrency']
    timeout = module.params['timeout']
    wait = module.params['wait']
    clean_up = module.params['clean_up']

    if state == 'present':
        changed, nodes = provision(provisioner, instances, timeout,
                                   concurrency, clean_up, wait)
        instances = [{
            'name': i.node.name or i.uuid,
            'hostname': i.hostname,
            'id': i.uuid,
        } for i in nodes]
        module.exit_json(
            changed=changed,
            msg="{} instances provisioned".format(len(nodes)),
            instances=instances,
        )

    if state == 'reserved':
        changed, nodes = reserve(provisioner, instances, clean_up)
        module.exit_json(changed=changed,
                         msg="{} instances reserved".format(len(nodes)),
                         ids=[node.id for node in nodes],
                         instances=instances)

    if state == 'absent':
        changed = unprovision(provisioner, instances)
        module.exit_json(changed=changed,
                         msg="{} nodes unprovisioned".format(len(instances)))
def main():
    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options'])
    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=False,
                           **module_kwargs)

    sdk, cloud = openstack_cloud_from_module(module)
    provisioner = metalsmith.Provisioner(cloud_region=cloud.config)

    instance_uuids = [i['id'] for i in module.params['instances']]

    try:
        env = bd.populate_environment(
            instance_uuids=instance_uuids,
            provisioner=provisioner,
            environment=module.params['environment'],
            ctlplane_network=module.params['ctlplane_network'])
        module.exit_json(changed=False, environment=env)
    except Exception as e:
        module.fail_json(msg=str(e))
Example #6
0
def _provisioner(context):
    session = keystone.get_session(context)
    return metalsmith.Provisioner(session=session)