def main():
    result = dict(
        success=False,
        changed=False,
        error=None,
    )
    module = AnsibleModule(
        openstack_full_argument_spec(
            **yaml.safe_load(DOCUMENTATION)['options']),
        **openstack_module_kwargs())
    _, conn = openstack_cloud_from_module(module)
    tripleo = tc.TripleOCommon(session=conn.session)
    try:
        result['profile'] = tripleo.return_flavor_profile(
            module.params["flavor_name"])
    except exception.DeriveParamsError:
        result['profile'] = None
        result['success'] = True
        module.exit_json(**result)
    except Exception as exp:
        result['error'] = str(exp)
        result['msg'] = 'Error pulling flavor properties for {}: {}'.format(
            module.params["flavor_name"], exp)
        module.fail_json(**result)
    else:
        result['success'] = True
        module.exit_json(**result)
def run_module():
    result = dict(
        success=False,
        changed=False,
        error="",
    )

    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options'])

    module = AnsibleModule(argument_spec,
                           supports_check_mode=False,
                           **openstack_module_kwargs())

    try:
        _, conn = openstack_cloud_from_module(module)

        tripleo = tc.TripleOCommon(session=conn.session)
        heat_client = tripleo.get_orchestration_client()

        result['stacks'] = list(get_overclouds(heat_client))
        result['success'] = True
        result['changed'] = False
    except Exception as err:
        result['error'] = str(err)
        result['msg'] = ("Error getting overclouds: %s" % err)
        module.fail_json(**result)

    # in the event of a successful module execution, you will want to
    # simple AnsibleModule.exit_json(), passing the key/value results
    module.exit_json(**result)
def main():
    result = dict(
        success=False,
        changed=False,
        error=None,
        environment={}
    )
    module = AnsibleModule(
        openstack_full_argument_spec(
            **yaml.safe_load(DOCUMENTATION)['options']
        ),
        **openstack_module_kwargs()
    )
    container = module.params.get('container')
    env_files = module.params.get('env_files')
    try:
        if container:
            _, conn = openstack_cloud_from_module(module)
            tripleo = tc.TripleOCommon(session=conn.session)
            heat = tripleo.get_orchestration_client()
            env = heat.environment(container)
        else:
            _, env = template_utils.process_multiple_environments_and_files(
                env_paths=env_files)
        result['environment'] = env
        result['changed'] = True
        result['success'] = True
    except Exception as ex:
        result['error'] = str(ex)
        result['msg'] = 'Error buiding environment: {}'.format(
            ex)
        module.fail_json(**result)

    module.exit_json(**result)
예제 #4
0
def main():
    result = dict(
        success=False,
        changed=False,
        error=None,
    )
    module = AnsibleModule(
        openstack_full_argument_spec(
            **yaml.safe_load(DOCUMENTATION)['options']
        ),
        **openstack_module_kwargs()
    )
    _, conn = openstack_cloud_from_module(module)
    tripleo = tc.TripleOCommon(session=conn.session)
    try:
        stack_param_utils.reset_parameters(
            swift=tripleo.get_object_client(),
            container=module.params["container"],
            key=module.params["parameter_key"]
        )
        result['changed'] = True
    except Exception as exp:
        result['error'] = str(exp)
        result['msg'] = 'Error resetting params for plan {}: {}'.format(
            module.params["container"],
            exp
        )
        module.fail_json(**result)
    else:
        result['success'] = True
        module.exit_json(**result)
def run_module():
    result = dict(
        success=False,
        changed=False,
        error="",
    )

    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options'])

    module = AnsibleModule(argument_spec,
                           supports_check_mode=False,
                           **openstack_module_kwargs())

    try:
        container = module.params.get('container')
        with_roledata = module.params.get('with_roledata')
        _, conn = openstack_cloud_from_module(module)
        tripleo = tc.TripleOCommon(session=conn.session)
        swift = tripleo.get_object_client()
        plan_utils.update_plan_environment_with_image_parameters(
            swift, container, with_roledata=with_roledata)
        result['success'] = True
        result['changed'] = True
    except Exception as err:
        result['error'] = str(err)
        result['msg'] = ("Error updating image parms for plan %s: %s" %
                         (container, err))
        module.fail_json(**result)

    # in the event of a successful module execution, you will want to
    # simple AnsibleModule.exit_json(), passing the key/value results
    module.exit_json(**result)
def main():
    result = dict(
        success=False,
        changed=False,
        error=None,
    )
    module = AnsibleModule(
        openstack_full_argument_spec(
            **yaml.safe_load(DOCUMENTATION)['options']),
        **openstack_module_kwargs())
    _, conn = openstack_cloud_from_module(module)
    tripleo = tc.TripleOCommon(session=conn.session)
    object_client = tripleo.get_object_client()
    try:
        result['roles'] = roles_utils.get_roles_from_plan(
            object_client,
            container=module.params['container'],
            role_file_name=module.params['role_file_name'],
            detail=module.params['detail'],
            valid=module.params['valid'])
    except Exception as exp:
        result['error'] = str(exp)
        result['msg'] = 'Error listing roles: {}'.format(exp)
        module.fail_json(**result)
    else:
        result['success'] = True
        module.exit_json(**result)
예제 #7
0
def main():
    result = dict(
        success=False,
        changed=False,
        error=None,
    )
    module = AnsibleModule(
        openstack_full_argument_spec(
            **yaml.safe_load(DOCUMENTATION)['options']
        ),
        **openstack_module_kwargs()
    )
    _, conn = openstack_cloud_from_module(module)
    tripleo = tc.TripleOCommon(session=conn.session)
    object_client = tripleo.get_object_client()
    heat = tripleo.get_orchestration_client()
    try:
        result['stack_data'] = stack_param_utils.get_flattened_parameters(
            swift=object_client,
            heat=heat,
            container=module.params["container"]
        )
    except Exception as exp:
        result['error'] = str(exp)
        result['msg'] = 'Error flattening stack data for plan {}: {}'.format(
            module.params["container"],
            exp
        )
        module.fail_json(**result)
    else:
        result['success'] = True
        module.exit_json(**result)
예제 #8
0
def run_module():
    result = dict(success=False, error="", fernet_keys={})

    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options'])

    module = AnsibleModule(argument_spec,
                           supports_check_mode=True,
                           **openstack_module_kwargs())

    try:
        container = module.params.get('container')
        _, conn = openstack_cloud_from_module(module)
        tripleo = tc.TripleOCommon(session=conn.session)

        heat = tripleo.get_orchestration_client()
        # if the user is working with this module in only check mode we do not
        # want to make any changes to the environment, just return the current
        # state with no modifications
        if module.check_mode:
            module.exit_json(**result)
        fernet_keys = plan_utils.rotate_fernet_keys(heat, container)
        result['success'] = True
        result['fernet_keys'] = fernet_keys
    except Exception as err:
        result['error'] = str(err)
        result['msg'] = ("Error rotating fernet keys for plan %s: %s" %
                         (container, err))
        module.fail_json(**result)

    # in the event of a successful module execution, you will want to
    # simple AnsibleModule.exit_json(), passing the key/value results
    module.exit_json(**result)
예제 #9
0
def run_module():
    result = dict(success=False, error="", changed=False, tempurl="")

    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options'])

    module = AnsibleModule(argument_spec,
                           supports_check_mode=False,
                           **openstack_module_kwargs())

    try:
        container = module.params.get('container')
        obj = module.params.get('object')
        method = module.params.get('method')
        _, conn = openstack_cloud_from_module(module)
        tripleo = tc.TripleOCommon(session=conn.session)
        swift = tripleo.get_object_client()
        tempurl = swift_utils.get_temp_url(swift, container, obj, method)
        result['success'] = True
        result['changed'] = True
        result['tempurl'] = tempurl
    except Exception as err:
        result['error'] = str(err)
        result['msg'] = ("Error getting %s tempurl for %s/%s: %s" %
                         (method, container, obj, err))
        module.fail_json(**result)

    # in the event of a successful module execution, you will want to
    # simple AnsibleModule.exit_json(), passing the key/value results
    module.exit_json(**result)
def run_module():
    result = dict(
        success=False,
        changed=False,
        error="",
        passwords={}
    )

    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options']
    )

    module = AnsibleModule(
        argument_spec,
        supports_check_mode=False,
        **openstack_module_kwargs()
    )

    try:
        container = module.params.get('container')
        rotate_passwords = module.params.get('rotate_passwords')
        password_list = module.params.get('password_list')
        password_file = module.params.get('password_file')
        _, conn = openstack_cloud_from_module(module)
        tripleo = tc.TripleOCommon(session=conn.session)
        swift = tripleo.get_object_client()
        heat = tripleo.get_orchestration_client()

        # Which file to look for passwords
        if not password_file:
            password_file = os.path.join(
                constants.DEFAULT_WORKING_DIR_FORMAT.format(container),
                constants.PASSWORDS_ENV_FORMAT.format(container))
        # Check whether the password file exists
        if os.path.exists(password_file):
            with open(password_file, 'r') as f:
                passwords_env = yaml.safe_load(f.read())
        else:
            passwords_env = None

        rotated_passwords = plan_utils.generate_passwords(
            swift, heat, container=container,
            rotate_passwords=rotate_passwords,
            rotate_pw_list=password_list,
            passwords_env=passwords_env
        )
        result['success'] = True
        result['passwords'] = rotated_passwords
        result['changed'] = True
    except Exception as err:
        result['error'] = str(err)
        result['msg'] = ("Error rotating passwords for plan %s: %s" % (
            container, err))
        module.fail_json(**result)

    # in the event of a successful module execution, you will want to
    # simple AnsibleModule.exit_json(), passing the key/value results
    module.exit_json(**result)
def run_module():
    result = dict(
        success=False,
        changed=False,
        error="",
    )

    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options']
    )

    module = AnsibleModule(
        argument_spec,
        supports_check_mode=False,
        **openstack_module_kwargs()
    )

    try:
        plan = module.params.get('plan')
        ssh_user = module.params.get('ansible_ssh_user')
        ssh_private_key_file = module.params.get('ansible_ssh_private_key_file')
        python_interpretor = module.params.get('ansible_python_interpretor')
        ssh_network = module.params.get('ssh_network')
        work_dir = module.params.get('work_dir')

        _, conn = openstack_cloud_from_module(module)

        tripleo = tc.TripleOCommon(session=conn.session)
        heat = tripleo.get_orchestration_client()

        inventory_path = inventory.generate_tripleo_ansible_inventory(
            heat,
            conn.session.auth.auth_url,
            conn.session.auth._username,
            conn.session.auth._project_name,
            conn.session.verify,
            plan,
            work_dir,
            python_interpretor,
            ssh_user,
            ssh_private_key_file,
            ssh_network)
        result['inventory_path'] = inventory_path
        result['success'] = True
        result['changed'] = True
    except Exception as err:
        result['error'] = str(err)
        result['msg'] = ("Error generating inventory for %s: %s" % (
            plan, err))
        module.fail_json(**result)

    # in the event of a successful module execution, you will want to
    # simple AnsibleModule.exit_json(), passing the key/value results
    module.exit_json(**result)
def run_module():
    result = dict(success=False, error="", nodes=[])

    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options'])

    module = AnsibleModule(argument_spec,
                           supports_check_mode=True,
                           **openstack_module_kwargs())

    _, conn = openstack_cloud_from_module(module)
    tripleo = tc.TripleOCommon(session=conn.session)

    # if the user is working with this module in only check mode we do not
    # want to make any changes to the environment, just return the current
    # state with no modifications
    if module.check_mode:
        module.exit_json(**result)

    nodes_json = nodes.convert_nodes_json_mac_to_ports(
        module.params['nodes_json'])

    for node in nodes_json:
        caps = node.get('capabilities', {})
        caps = nodes.capabilities_to_dict(caps)
        if module.params['instance_boot_option'] is not None:
            caps.setdefault('boot_option',
                            module.params['instance_boot_option'])
        node['capabilities'] = nodes.dict_to_capabilities(caps)

    baremetal_client = tripleo.get_baremetal_client()
    image_client = tripleo.get_image_client()

    try:
        registered_nodes = nodes.register_all_nodes(
            nodes_json,
            client=baremetal_client,
            remove=module.params['remove'],
            glance_client=image_client,
            kernel_name=module.params['kernel_name'],
            ramdisk_name=module.params['ramdisk_name'])
        result['success'] = True
        result['nodes'] = [
            dict(uuid=node.uuid, provision_state=node.provision_state)
            for node in registered_nodes
        ]
    except Exception as exc:
        # LOG.exception("Error registering nodes with ironic.")
        result['error'] = str(exc)
        module.fail_json(msg='Validation Failed', **result)

    # in the event of a successful module execution, you will want to
    # simple AnsibleModule.exit_json(), passing the key/value results
    module.exit_json(**result)
def main():
    result = dict(
        dpdk_nics_numa_info=[],
        success=False,
        error=None,
    )

    module = AnsibleModule(
        openstack_full_argument_spec(
            **yaml.safe_load(DOCUMENTATION)['options']
        ),
        **openstack_module_kwargs()
    )
    _, conn = openstack_cloud_from_module(module)
    tripleo = tc.TripleOCommon(session=conn.session)
    network_configs = {}
    try:
        # Get the network configs data for the required role name
        network_configs = stack_param_utils.get_network_configs(
            tripleo.get_object_client(),
            tripleo.get_orchestration_client(),
            container=module.params["container"],
            role_name=module.params["role_name"]
        )
    except Exception as exp:
        result['error'] = str(exp)
        result['msg'] = 'Error getting network configs for role name {}: {}'.format(
            module.params["role_name"],
            exp
        )
        module.fail_json(**result)

    try:
        result['dpdk_nics_numa_info'] = _get_dpdk_nics_numa_info(
            module.params["network_configs"],
            module.params["inspect_data"],
            module.params["mtu_default"]
        )
    except tc.DeriveParamsError as dexp:
        result['error'] = str(dexp)
        result['msg'] = 'Error pulling DPDK NICs NUMA information : {}'.format(
            dexp
        )
        module.fail_json(**result)
    except Exception as exp:
        result['error'] = str(exp)
        result['msg'] = 'Error pulling DPDK NICs NUMA information : {}'.format(
            exp
        )
        module.fail_json(**result)
    else:
        result['success'] = True
        module.exit_json(**result)
예제 #14
0
def main():
    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options'])
    module = AnsibleModule(argument_spec, **openstack_module_kwargs())

    _, conn = openstack_cloud_from_module(module)
    tripleo = tc.TripleOCommon(session=conn.session)

    if hasattr(tripleo, module.params["action"]):
        action = getattr(tripleo, module.params["action"])
        result = action(kwargs=module.params["args"])
        module.exit_json(result=result)
    else:
        module.fail_json(
            msg="Unknown action name {}".format(module.params["action"]))
def run_module():
    result = dict(
        success=False,
        changed=False,
        error="",
        passwords={}
    )

    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options']
    )

    module = AnsibleModule(
        argument_spec,
        supports_check_mode=False,
        **openstack_module_kwargs()
    )

    try:
        container = module.params.get('container')
        rotate_passwords = module.params.get('rotate_passwords')
        password_list = module.params.get('password_list')
        _, conn = openstack_cloud_from_module(module)
        tripleo = tc.TripleOCommon(session=conn.session)
        swift = tripleo.get_object_client()
        heat = tripleo.get_orchestration_client()
        rotated_passwords = plan_utils.generate_passwords(
            swift, heat, container=container,
            rotate_passwords=rotate_passwords,
            rotate_pw_list=password_list)
        result['success'] = True
        result['passwords'] = rotated_passwords
        result['changed'] = True
    except Exception as err:
        result['error'] = str(err)
        result['msg'] = ("Error rotating passwords for plan %s: %s" % (
            container, err))
        module.fail_json(**result)

    # in the event of a successful module execution, you will want to
    # simple AnsibleModule.exit_json(), passing the key/value results
    module.exit_json(**result)
예제 #16
0
def run_module():
    result = dict(
        success=False,
        changed=False,
        error="",
    )

    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options']
    )

    module = AnsibleModule(
        argument_spec,
        supports_check_mode=False,
        **openstack_module_kwargs()
    )

    try:
        container = module.params.get('container')
        skip_deploy_identifier = module.params.get('skip_deploy_identifier')
        timeout_mins = module.params.get('timeout_mins')
        _, conn = openstack_cloud_from_module(module)
        tripleo = tc.TripleOCommon(session=conn.session)
        swift = tripleo.get_object_client()
        heat = tripleo.get_orchestration_client()
        stack_utils.deploy_stack(
            swift, heat,
            container=container,
            skip_deploy_identifier=skip_deploy_identifier,
            timeout_mins=timeout_mins)
        result['success'] = True
        result['changed'] = True
    except Exception as err:
        result['error'] = str(err)
        result['msg'] = ("Error updating parameters for plan %s: %s" % (
            container, err))
        module.fail_json(**result)

    # in the event of a successful module execution, you will want to
    # simple AnsibleModule.exit_json(), passing the key/value results
    module.exit_json(**result)
def run_module():
    result = dict(
        success=False,
        changed=False,
        error="",
    )

    argument_spec = openstack_full_argument_spec(
        **yaml.safe_load(DOCUMENTATION)['options'])

    module = AnsibleModule(argument_spec,
                           supports_check_mode=False,
                           **openstack_module_kwargs())

    try:
        plan = module.params.get('plan')
        config_container = module.params.get('config_container')
        work_dir = module.params.get('work_dir')
        config_type = module.params.get('config_type')
        download = module.params.get('download')

        _, conn = openstack_cloud_from_module(module)
        tripleo = tc.TripleOCommon(session=conn.session)

        swift = tripleo.get_object_client()
        heat = tripleo.get_orchestration_client()
        ooo_config.get_overcloud_config(swift, heat, plan, config_container,
                                        config_type)
        if download:
            ooo_config.download_overcloud_config(swift, config_container,
                                                 work_dir)
        result['success'] = True
        result['changed'] = True
    except Exception as err:
        result['error'] = str(err)
        result['msg'] = ("Error downloading config for %s: %s" % (plan, err))
        module.fail_json(**result)

    # in the event of a successful module execution, you will want to
    # simple AnsibleModule.exit_json(), passing the key/value results
    module.exit_json(**result)
def main():
    result = dict(
        success=False,
        changed=False,
        error=None,
    )
    module = AnsibleModule(
        openstack_full_argument_spec(
            **yaml.safe_load(DOCUMENTATION)['options']),
        **openstack_module_kwargs())
    _, conn = openstack_cloud_from_module(module)
    tripleo = tc.TripleOCommon(session=conn.session)
    try:
        result['data'] = tripleo.return_introspected_node_data(
            node_id=module.params["node_id"])
    except Exception as exp:
        result['error'] = str(exp)
        result['msg'] = 'Error pulling introspection data for {}: {}'.format(
            module.params["node_id"], exp)
        module.fail_json(**result)
    else:
        result['success'] = True
        module.exit_json(**result)