def singleton_patch(login, password, fos_ip_addr, module_name, obj_name,
                    fos_version, is_https, auth, vfid, result, new_attributes,
                    ssh_hostkeymust, timeout):
    """
        update existing user config configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type struct: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param diff_attributes: list of attributes for update
        :type ports: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: list of dict of chassis configurations
        :rtype: list
    """
    if module_name == "brocade_chassis" and obj_name == "chassis":
        return chassis_patch(login, password, fos_ip_addr, fos_version,
                             is_https, auth, vfid, result, new_attributes,
                             ssh_hostkeymust, timeout)

    if module_name == "brocade_fibrechannel_configuration" and obj_name == "fabric":
        return fabric_patch(login, password, fos_ip_addr, fos_version,
                            is_https, auth, vfid, result, new_attributes,
                            ssh_hostkeymust, timeout)

    if module_name == "brocade_fibrechannel_configuration" and obj_name == "port_configuration":
        return port_configuration_patch(login, password, fos_ip_addr,
                                        fos_version, is_https, auth, vfid,
                                        result, new_attributes,
                                        ssh_hostkeymust, timeout)

    full_url, validate_certs = full_url_get(
        is_https, fos_ip_addr, REST_PREFIX + module_name + "/" + obj_name)

    xml_str = singleton_xml_str(result, obj_name, new_attributes)

    result["patch_obj_str"] = xml_str

    if module_name == "brocade_security" and obj_name == "security_certificate_generate":
        return url_post(fos_ip_addr, is_https, auth, vfid, result, full_url,
                        xml_str, timeout)

    return url_patch(fos_ip_addr, is_https, auth, vfid, result, full_url,
                     xml_str, timeout)
Exemple #2
0
def main():
    """
    Main function
    """

    argument_spec = dict(
        credential=dict(required=True, type='dict'),
        vfid=dict(required=False, type='int'),
        throttle=dict(required=False, type='float'),
        fabric=dict(required=True, type='dict'))

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

    input_params = module.params

    # Set up state variables
    fos_ip_addr = input_params['credential']['fos_ip_addr']
    fos_user_name = input_params['credential']['fos_user_name']
    fos_password = input_params['credential']['fos_password']
    https = input_params['credential']['https']
    throttle = input_params['throttle']
    vfid = input_params['vfid']
    fabric = input_params['fabric']
    result = {"changed": False}

    if vfid is None:
        vfid = 128

    ret_code, auth, fos_version = login(fos_ip_addr,
                           fos_user_name, fos_password,
                           https, throttle, result)
    if ret_code != 0:
        module.exit_json(**result)

    ret_code, response = fabric_get(fos_user_name, fos_password,
                                    fos_ip_addr, fos_version, https,
                                    auth, vfid, result)
    if ret_code != 0:
        exit_after_login(fos_ip_addr, https, auth, result, module)

    resp_fabric = response["Response"]["fabric"]

    to_human_fabric(resp_fabric)

    diff_attributes = generate_diff(result, resp_fabric, fabric)
    result["resp_fabric"] = resp_fabric
    result["fabric"] = fabric
    result["diff_attributes"] = diff_attributes

    if len(diff_attributes) > 0:
        ret_code = to_fos_fabric(diff_attributes, result)
        if ret_code != 0:
            exit_after_login(fos_ip_addr, https, auth, result, module)

        if not module.check_mode:
            ret_code = fabric_patch(fos_user_name, fos_password,
                                    fos_ip_addr, fos_version, https,
                                    auth, vfid, result, diff_attributes)
            if ret_code != 0:
                exit_after_login(fos_ip_addr, https, auth, result, module)

        result["changed"] = True
    else:
        logout(fos_ip_addr, https, auth, result)
        module.exit_json(**result)

    logout(fos_ip_addr, https, auth, result)
    module.exit_json(**result)