コード例 #1
0
def get_nimos_client():
    global os_client
    if os_client is None:
        # Read the config which contains array credentials
        array_detail = get_config_section_detail(NIMBLE_ARRAY_CREDENTIALS)
        if (array_detail.__len__() == 3):
            os_client = client.NimOSClient(array_detail[ARRAY_HOSTNAME],
                                           array_detail[ARRAY_USERNAME],
                                           array_detail[ARRAY_PASSWORD])
        else:
            raise Exception("Array Credentials not present in config file.")
    return os_client
コード例 #2
0
def main():

    fields = {
        "gather_subset": {
            "required": False,
            "type": "list",
            "elements": 'raw',
            'default': "minimum"
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    gather_subset = module.params["gather_subset"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg=
            "Missing variables: hostname, username and password is mandatory.")
    # defaults
    return_status = changed = False
    msg = "No task to run."
    try:
        client_obj = client.NimOSClient(
            hostname, username, password,
            f"HPE Nimble Ansible Modules v{NIMBLE_ANSIBLE_VERSION}")

        return_status, changed, msg, result_dict = get_subset_info(
            client_obj, gather_subset)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(
                result_dict) is False and result_dict.__len__() > 0:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             message=msg,
                             nimble_info=result_dict)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #3
0
def get_downstream_client():
    # read the config which contains array credentials
    arraydetail = nimosclientbase.get_config_section_detail(
        REPLICATION_ARRAY_CREDENTIALS)
    if (arraydetail.__len__() == 3):
        rep_osclient = nimclient.NimOSClient(
            arraydetail[nimosclientbase.ARRAY_HOSTNAME],
            arraydetail[nimosclientbase.ARRAY_USERNAME],
            arraydetail[nimosclientbase.ARRAY_PASSWORD])
    else:
        raise Exception("replication Array credentials "
                        "not present in config file.")
    return rep_osclient
コード例 #4
0
def main():

    fields = {
        "state": {
            "required":
            True,
            "choices":
            ['present', 'absent', 'create', 'online', 'offline', 'restore'],
            "type":
            "str"
        },
        "name": {
            "required": True,
            "type": "str"
        },
        "size": {
            "type": "int",
            "default": 100
        },
        "description": {
            "required": False,
            "type": "str",
            "default": None
        },
        "perf_policy": {
            "required": False,
            "type": "str",
            "default": None
        },
        "limit": {
            "required": False,
            "type": "int",
        },
        "online": {
            "required": False,
            "type": "bool",
            "default": True
        },
        "owned_by_group": {
            "required": False,
            "type": "str",
            "default": None
        },
        "multi_initiator": {
            "required": False,
            "type": "bool"
        },
        "iscsi_target_scope": {
            "required": False,
            "choices": ['volume', 'group'],
            "type": "str",
            "default": 'volume'
        },
        "pool": {
            "required": False,
            "type": "str",
            "default": None
        },
        "read_only": {
            "required": False,
            "type": "bool",
            "default": False
        },
        "block_size": {
            "required": False,
            "type": "int",
            "default": 4096
        },
        "clone": {
            "required": False,
            "type": "bool",
            "default": False
        },
        "agent_type": {
            "required": False,
            "choices": ['none', 'smis', 'vvol', 'openstack', 'openstackv2'],
            "type": "str",
            "default": 'none'
        },
        "destination": {
            "required": False,
            "type": "str",
            "default": None
        },
        "cache_pinned": {
            "required": False,
            "type": "bool",
            "default": False
        },
        "thinly_provisioned": {
            "required": False,
            "type": "bool",
            "default": True
        },
        "encryption_cipher": {
            "required": False,
            "choices": ['none', 'aes_256_xts'],
            "type": "str",
            "default": 'none'
        },
        "app_uuid": {
            "required": False,
            "type": "str"
        },
        "folder": {
            "required": False,
            "type": "str",
        },
        "dedupe": {
            "required": False,
            "type": "bool",
            "default": False
        },
        "limit_iops": {
            "required": False,
            "type": "int"
        },
        "limit_mbps": {
            "required": False,
            "type": "int"
        },
        "parent": {
            "required": False,
            "type": "str",
            "default": None
        },
        "snapshot": {
            "required": False,
            "type": "str",
            "default": None
        },
        "volcoll": {
            "required": False,
            "type": "str",
            "default": None
        },
        "metadata": {
            "required": False,
            "type": "dict",
            "default": None
        },
        "force": {
            "required": False,
            "type": "bool"
        },
        "caching": {
            "required": False,
            "type": "bool"
        },
        "force_vvol": {
            "required": False,
            "type": "bool"
        },
        "move": {
            "required": False,
            "type": "bool"
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    required_if = [('state', 'restore', ['snapshot'])]

    module = AnsibleModule(argument_spec=fields, required_if=required_if)
    if client is None:
        module.fail_json(msg='the python nimble-sdk module is required.')

    state = module.params["state"]
    vol_name = module.params["name"]
    size = module.params["size"]
    description = module.params["description"]
    perf_policy = module.params["perf_policy"]
    limit = module.params["limit"]
    online = module.params["online"]
    owned_by_group = module.params["owned_by_group"]
    multi_initiator = module.params["multi_initiator"]
    iscsi_target_scope = module.params["iscsi_target_scope"]
    pool = module.params["pool"]
    read_only = module.params["read_only"]
    block_size = module.params["block_size"]
    clone = module.params["clone"]
    agent_type = module.params["agent_type"]
    dest_pool = module.params["destination"]
    cache_pinned = module.params["cache_pinned"]
    thinly_provisioned = module.params["thinly_provisioned"]
    encryption_cipher = module.params["encryption_cipher"]
    app_uuid = module.params["app_uuid"]
    folder = module.params["folder"]
    dedupe = module.params["dedupe"]
    limit_iops = module.params["limit_iops"]
    limit_mbps = module.params["limit_mbps"]
    parent = module.params["parent"]  # used for cloning
    snapshot = module.params["snapshot"]
    volcoll = module.params["volcoll"]
    metadata = module.params["metadata"]
    force = module.params["force"]
    caching = module.params["caching"]
    force_vvol = module.params["force_vvol"]
    move = module.params["move"]
    hostname = module.params["hostname"]
    username = module.params["username"]
    password = module.params["password"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg=
            "Volume creation failed. Storage system IP or username or password is null."
        )

    client_obj = client.NimOSClient(hostname, username, password)
    # defaults
    return_status = changed = False
    msg = "No Task to run."

    # States
    if move is True and state == "present":
        if utils.is_null_or_empty(dest_pool) is False:
            return_status, changed, msg, changed_attrs_dict = move_volume(
                client_obj, vol_name, dest_pool, force_vvol)
        else:
            module.fail_json(
                msg="Volume move failed as destination pool is null.")

    elif (move is None or move is False) and (state == "create"
                                              or state == "present"):
        if utils.is_null_or_empty(vol_name):
            return_status = changed = False
            msg = "Volume creation failed as volume name is null"

        # state create/present can be provided for creating a new volume or
        # creating a clone from source volume
        if parent is not None:
            return_status, changed, msg, changed_attrs_dict = clone_volume(
                client_obj, parent, state, vol_name, snapshot)
        else:
            vol_resp = client_obj.volumes.get(id=None, name=vol_name)
            if utils.is_null_or_empty(vol_resp) or state == "create":
                return_status, changed, msg, changed_attrs_dict = create_volume(
                    client_obj,
                    vol_name,
                    perfpolicy_id=utils.get_perfpolicy_id(
                        client_obj, perf_policy),
                    size=size,
                    description=description,
                    limit=limit,
                    online=online,
                    owned_by_group_id=utils.get_owned_by_group_id(
                        client_obj, owned_by_group),
                    multi_initiator=multi_initiator,
                    iscsi_target_scope=iscsi_target_scope,
                    pool_id=utils.get_pool_id(client_obj, pool),
                    read_only=read_only,
                    block_size=block_size,
                    clone=clone,
                    agent_type=agent_type,
                    dest_pool_id=utils.get_pool_id(client_obj, dest_pool),
                    cache_pinned=cache_pinned,
                    thinly_provisioned=thinly_provisioned,
                    encryption_cipher=encryption_cipher,
                    app_uuid=app_uuid,
                    folder_id=utils.get_folder_id(client_obj, folder),
                    metadata=metadata,
                    dedupe_enabled=dedupe,
                    limit_iops=limit_iops,
                    limit_mbps=limit_mbps)
            else:
                # if we are here it means volume is already present. hence issue update call
                return_status, changed, msg, changed_attrs_dict = update_volume(
                    client_obj,
                    vol_resp,
                    size=size,
                    description=description,
                    perfpolicy_id=utils.get_perfpolicy_id(
                        client_obj, perf_policy),
                    limit=limit,
                    online=online,
                    owned_by_group_id=utils.get_owned_by_group_id(
                        client_obj, owned_by_group),
                    multi_initiator=multi_initiator,
                    iscsi_target_scope=iscsi_target_scope,
                    read_only=read_only,
                    block_size=block_size,
                    volcoll_id=utils.get_volcoll_id(client_obj, volcoll),
                    agent_type=agent_type,
                    force=force,
                    cache_pinned=cache_pinned,
                    thinly_provisioned=thinly_provisioned,
                    app_uuid=app_uuid,
                    folder_id=utils.get_folder_id(client_obj, folder),
                    metadata=metadata,
                    caching_enabled=caching,
                    dedupe_enabled=dedupe,
                    limit_iops=limit_iops,
                    limit_mbps=limit_mbps)

    elif state == "offline":
        return_status, changed, msg, changed_attrs_dict = change_volume_state(
            client_obj, vol_name, False)

    elif state == "online":
        return_status, changed, msg, changed_attrs_dict = change_volume_state(
            client_obj, vol_name, True)

    elif state == "absent":
        return_status, changed, msg, changed_attrs_dict = delete_volume(
            client_obj, vol_name)

    elif state == "restore":
        return_status, changed, msg, changed_attrs_dict = restore_volume(
            client_obj, vol_name, snapshot)

    if return_status:
        if not utils.is_null_or_empty(
                changed_attrs_dict) and changed_attrs_dict.__len__() > 0:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             message=msg,
                             modified_attrs=changed_attrs_dict)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             message=msg)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #5
0
def main():

    fields = {
        "state": {
            "required": True,
            "choices": ['present', 'absent', 'create'],
            "type": "str"
        },
        "prot_template": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "name": {
            "required": True,
            "type": "str",
            "no_log": False
        },
        "change_name": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "description": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "replication_type": {
            "choices": ['periodic_snapshot', 'synchronous'],
            "required": False,
            "type": "str",
            "no_log": False
        },
        "app_sync": {
            "choices": ['none', 'vss', 'vmware', 'generic'],
            "required": False,
            "type": "str",
            "no_log": False
        },
        "app_server": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "app_id": {
            "required":
            False,
            "choices": [
                'inval', 'exchange', 'exchange_dag', 'hyperv', 'sql2005',
                'sql2008', 'sql2012', 'sql2014', 'sql2016', 'sql2017'
            ],
            "type":
            "str",
            "no_log":
            False
        },
        "app_cluster": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "app_service": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "vcenter_hostname": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "vcenter_username": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "vcenter_password": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "agent_hostname": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "agent_username": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "agent_password": {
            "required": False,
            "type": "str",
            "no_log": True
        },
        "is_standalone_volcoll": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "metadata": {
            "required": False,
            "type": "dict",
            "no_log": False
        },
        "promote": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "demote": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "handover": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "abort_handover": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "validate": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "replication_partner": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "invoke_on_upstream_partner": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "no_reverse": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "override_upstream_down": {
            "required": False,
            "type": "bool",
            "no_log": False
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    module = AnsibleModule(argument_spec=fields)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    prot_template = module.params["prot_template"]
    volcoll_name = module.params["name"]
    change_name = module.params["change_name"]
    description = module.params["description"]
    replication_type = module.params["replication_type"]
    app_sync = module.params["app_sync"]
    app_server = module.params["app_server"]
    app_id = module.params["app_id"]
    app_cluster = module.params["app_cluster"]
    app_service = module.params["app_service"]
    vcenter_hostname = module.params["vcenter_hostname"]
    vcenter_username = module.params["vcenter_username"]
    vcenter_password = module.params["vcenter_password"]
    agent_hostname = module.params["agent_hostname"]
    agent_username = module.params["agent_username"]
    agent_password = module.params["agent_password"]
    is_standalone_volcoll = module.params["is_standalone_volcoll"]
    metadata = module.params["metadata"]
    promote = module.params["promote"]
    demote = module.params["demote"]
    handover = module.params["handover"]
    abort_handover = module.params["abort_handover"]
    validate = module.params["validate"]
    replication_partner = module.params["replication_partner"]
    invoke_on_upstream_partner = module.params["invoke_on_upstream_partner"]
    no_reverse = module.params["no_reverse"]
    override_upstream_down = module.params["override_upstream_down"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg=
            "Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None

    try:
        client_obj = client.NimOSClient(hostname, username, password)

        # States.
        if state == 'present' and promote is True:
            return_status, changed, msg, changed_attrs_dict = promote_volcoll(
                client_obj, volcoll_name)

        elif state == 'present' and demote is True:
            return_status, changed, msg, changed_attrs_dict = demote_volcoll(
                client_obj,
                volcoll_name,
                invoke_on_upstream_partner=invoke_on_upstream_partner,
                replication_partner_id=utils.get_replication_partner_id(
                    client_obj, replication_partner))

        elif state == 'present' and handover is True:
            return_status, changed, msg, changed_attrs_dict = handover_volcoll(
                client_obj,
                volcoll_name,
                invoke_on_upstream_partner,
                no_reverse,
                override_upstream_down,
                replication_partner_id=utils.get_replication_partner_id(
                    client_obj, replication_partner))

        elif state == 'present' and abort_handover is True:
            return_status, changed, msg, changed_attrs_dict = abort_handover_volcoll(
                client_obj, volcoll_name)

        elif state == 'present' and validate is True:
            return_status, changed, msg, changed_attrs_dict, resp = validate_volcoll(
                client_obj, volcoll_name)

        elif ((promote is None or promote is False)
              and (demote is None or demote is False)
              and (abort_handover is None or abort_handover is False)
              and (handover is None or handover is False)
              and (validate is None or validate is False)
              and (state == "create" or state == "present")):

            volcoll_resp = client_obj.volume_collections.get(id=None,
                                                             name=volcoll_name)
            if utils.is_null_or_empty(volcoll_resp) or state == "create":
                return_status, changed, msg, changed_attrs_dict, resp = create_volcoll(
                    client_obj,
                    volcoll_name,
                    prottmpl_id=utils.get_prottmpl_id(client_obj,
                                                      prot_template),
                    description=description,
                    replication_type=replication_type,
                    app_sync=app_sync,
                    app_server=app_server,
                    app_id=app_id,
                    app_cluster=app_cluster,
                    app_service=app_service,
                    vcenter_hostname=vcenter_hostname,
                    vcenter_username=vcenter_username,
                    vcenter_password=vcenter_password,
                    agent_hostname=agent_hostname,
                    agent_username=agent_username,
                    agent_password=agent_password,
                    is_standalone_volcoll=is_standalone_volcoll,
                    metadata=metadata)
            else:
                # update op
                return_status, changed, msg, changed_attrs_dict, resp = update_volcoll(
                    client_obj,
                    volcoll_resp,
                    name=change_name,
                    description=description,
                    app_sync=app_sync,
                    app_server=app_server,
                    app_id=app_id,
                    app_cluster=app_cluster,
                    app_service=app_service,
                    vcenter_hostname=vcenter_hostname,
                    vcenter_username=vcenter_username,
                    vcenter_password=vcenter_password,
                    agent_hostname=agent_hostname,
                    agent_username=agent_username,
                    agent_password=agent_password,
                    metadata=metadata)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_volcoll(
                client_obj, volcoll_name)

    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
def main():

    fields = {
        "state": {
            "required": True,
            "choices": ['present',
                        'absent',
                        'create'
                        ],
            "type": "str"
        },
        "change_name": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "name": {
            "required": True,
            "type": "str",
            "no_log": False
        },
        "description": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "volcoll": {
            "required": True,
            "type": "str",
            "no_log": False
        },
        "is_external_trigger": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "vol_snap_attr_list": {
            "required": False,
            "type": "list",
            "elements": 'dict',
            "no_log": False
        },
        "replicate_to": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "start_online": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "allow_writes": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "disable_appsync": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "snap_verify": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "skip_db_consistency_check": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "invoke_on_upstream_partner": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "agent_type": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "metadata": {
            "required": False,
            "type": "dict",
            "no_log": False
        },
        "expiry_after": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "force": {
            "required": False,
            "type": "bool",
            "no_log": False
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)

    module = AnsibleModule(argument_spec=fields)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    snapcoll_name = module.params["name"]
    change_name = module.params["change_name"]
    description = module.params["description"]
    volcoll = module.params["volcoll"]
    is_external_trigger = module.params["is_external_trigger"]
    vol_snap_attr_list = module.params["vol_snap_attr_list"]
    replicate_to = module.params["replicate_to"]
    start_online = module.params["start_online"]
    allow_writes = module.params["allow_writes"]
    disable_appsync = module.params["disable_appsync"]
    snap_verify = module.params["snap_verify"]
    skip_db_consistency_check = module.params["skip_db_consistency_check"]
    invoke_on_upstream_partner = module.params["invoke_on_upstream_partner"]
    agent_type = module.params["agent_type"]
    metadata = module.params["metadata"]
    expiry_after = module.params["expiry_after"]
    force = module.params["force"]

    if (username is None or password is None or hostname is None or snapcoll_name is None):
        module.fail_json(
            msg="Missing variables: hostname, username, password and snapshot collection name is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(
            hostname,
            username,
            password
        )

        # States
        if state == "create" or state == "present":
            snapcoll_resp = client_obj.snapshot_collections.get(id=None, name=snapcoll_name, volcoll_name=volcoll)
            if utils.is_null_or_empty(snapcoll_resp) or state == "create":
                return_status, changed, msg, changed_attrs_dict, resp = create_snapcoll(
                    client_obj,
                    snapcoll_name,
                    volcoll,
                    description=description,
                    volcoll_id=utils.get_volcoll_id(client_obj, volcoll),
                    is_external_trigger=is_external_trigger,
                    vol_snap_attr_list=vol_snap_attr_list,
                    replicate_to=replicate_to,
                    start_online=start_online,
                    allow_writes=allow_writes,
                    disable_appsync=disable_appsync,
                    snap_verify=snap_verify,
                    skip_db_consistency_check=skip_db_consistency_check,
                    invoke_on_upstream_partner=invoke_on_upstream_partner,
                    agent_type=agent_type,
                    metadata=metadata)
            else:
                # update op
                return_status, changed, msg, changed_attrs_dict, resp = update_snapcoll(
                    client_obj,
                    snapcoll_resp,
                    name=change_name,
                    description=description,
                    replicate_to=replicate_to,
                    expiry_after=expiry_after,
                    metadata=metadata,
                    force=force)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_snapcoll(client_obj,
                                                                              snapcoll_name,
                                                                              volcoll)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status, changed=changed, msg=msg)
        else:
            module.exit_json(return_status=return_status, changed=changed, msg=msg, attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #7
0
def main():

    fields = {
        "array_name_or_serial": {
            "required": True,
            "type": "str",
            "no_log": False
        },
        "controller": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "hw_upgrade": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "name": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "online": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "precheck": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "regenerate": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "state": {
            "required": True,
            "choices": ['present'],
            "type": "str"
        },
        "wwnn_base_str": {
            "required": False,
            "type": "str",
            "no_log": False
        },
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    module = AnsibleModule(argument_spec=fields)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    array_name_or_serial = module.params["array_name_or_serial"]
    controller = module.params["controller"]
    hw_upgrade = module.params["hw_upgrade"]
    fc_name = module.params["name"]
    online = module.params["online"]
    precheck = module.params["precheck"]
    regenerate = module.params["regenerate"]
    state = module.params["state"]
    wwnn_base_str = module.params["wwnn_base_str"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg="Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(
            hostname,
            username,
            password
        )

        # States
        if state == "present":
            if regenerate is True:
                return_status, changed, msg, changed_attrs_dict, resp = regenerate_wwn(
                    client_obj,
                    array_name_or_serial,
                    wwnn_base_str,
                    precheck)

            elif hw_upgrade is True:
                return_status, changed, msg, changed_attrs_dict, resp = upgrade_hardware(
                    client_obj,
                    array_name_or_serial)

            else:
                return_status, changed, msg, changed_attrs_dict, resp = update_fc_interface(
                    client_obj,
                    array_name_or_serial,
                    fc_name,
                    controller,
                    online)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status, changed=changed, msg=msg)
        else:
            module.exit_json(return_status=return_status, changed=changed, msg=msg, attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #8
0
def main():

    fields = {
        "state": {
            "required": True,
            "choices": ['present', 'absent', 'create'],
            "type": "str"
        },
        "change_name": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "name": {
            "required": True,
            "type": "str",
            "no_log": False
        },
        "description": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "volume": {
            "required": True,
            "type": "str"
        },
        "online": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "writable": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "app_uuid": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "metadata": {
            "required": False,
            "type": "dict"
        },
        "agent_type": {
            "required": False,
            "choices": ['none', 'smis', 'vvol', 'openstack', 'openstackv2'],
            "type": "str"
        },
        "expiry_after": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "force": {
            "required": False,
            "type": "bool",
            "default": False,
            "no_log": False
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    required_if = [('state', 'create', ['volume'])]

    module = AnsibleModule(argument_spec=fields, required_if=required_if)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    snapshot_name = module.params["name"]
    change_name = module.params["change_name"]
    description = module.params["description"]
    vol_name = module.params["volume"]
    online = module.params["online"]
    writable = module.params["writable"]
    app_uuid = module.params["app_uuid"]
    metadata = module.params["metadata"]
    agent_type = module.params["agent_type"]
    expiry_after = module.params["expiry_after"]
    force = module.params["force"]

    if (username is None or password is None or hostname is None
            or snapshot_name is None):
        module.fail_json(
            msg=
            "Storage system IP or username or password is null or snapshot name is null."
        )

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(hostname, username, password)

        # States
        if state == "create" or state == "present":
            snap_resp = client_obj.snapshots.get(id=None,
                                                 vol_name=vol_name,
                                                 name=snapshot_name)
            if utils.is_null_or_empty(snap_resp) or state == "create":
                return_status, changed, msg, changed_attrs_dict, resp = create_snapshot(
                    client_obj,
                    vol_name,
                    snapshot_name,
                    description=description,
                    online=online,
                    writable=writable,
                    app_uuid=app_uuid,
                    metadata=metadata,
                    agent_type=agent_type)
            else:
                # update op
                return_status, changed, msg, changed_attrs_dict, resp = update_snapshot(
                    client_obj,
                    snap_resp,
                    name=change_name,
                    description=description,
                    online=online,
                    expiry_after=expiry_after,
                    app_uuid=app_uuid,
                    metadata=metadata,
                    force=force)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_snapshot(
                client_obj, vol_name, snapshot_name)

    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #9
0
def main():

    fields = {
        "state": {
            "required": True,
            "choices": ['present', 'absent', 'create'],
            "type": "str"
        },
        "apply_to": {
            "required":
            False,
            "choices": [
                'volume', 'snapshot', 'both', 'pe', 'vvol_volume',
                'vvol_snapshot'
            ],
            "type":
            "str",
            "no_log":
            False,
            "default":
            "both"
        },
        "chap_user": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "lun": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "volume": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "pe_ids": {
            "required": False,
            "type": "list",
            "no_log": False
        },
        "protocol_endpoint": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "snapshot": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "initiator_group": {
            "required": False,
            "type": "str",
            "no_log": False
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    module = AnsibleModule(argument_spec=fields)
    if client is None:
        module.fail_json(msg='the python nimble-sdk module is required.')

    hostname = module.params["hostname"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    apply_to = module.params["apply_to"]
    chap_user = module.params["chap_user"]
    lun = module.params["lun"]
    volume = module.params["volume"]
    pe_ids = module.params["pe_ids"]
    protocol_endpoint = module.params["protocol_endpoint"]
    snapshot = module.params["snapshot"]
    initiator_group = module.params["initiator_group"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg="Storage system IP or username or password is null.")

    client_obj = client.NimOSClient(hostname, username, password)

    # defaults
    return_status = changed = False
    msg = "No Task to run."

    # States
    if state == "create" or state == "present":
        return_status, changed, msg = create_acr(
            client_obj,
            initiator_group,
            volume,
            state,
            apply_to=apply_to,
            chap_user_id=utils.get_chap_user_id(client_obj, chap_user),
            lun=lun,
            pe_id=utils.get_pe_id(client_obj, protocol_endpoint),
            snap_id=utils.get_snapshot_id(client_obj, snapshot),
            pe_ids=pe_ids)

    elif state == "absent":
        return_status, changed, msg = delete_acr(client_obj, volume)

    if return_status:
        module.exit_json(return_status=return_status, changed=changed, msg=msg)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #10
0
def main():

    fields = {
        "change_name": {
            "required": False,
            "type": "str"
        },
        "description": {
            "required": False,
            "type": "str"
        },
        "initiator_iqns": {
            "required": False,
            "type": "list",
            "elements": 'dict'
        },
        "name": {
            "required": True,
            "type": "str"
        },
        "user_password": {
            "required": False,
            "type": "str",
            "no_log": True
        },
        "state": {
            "required": True,
            "choices": ['create', 'present', 'absent'],
            "type": "str"
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    required_if = [('state', 'create', ['user_password'])]

    module = AnsibleModule(argument_spec=fields, required_if=required_if)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    change_name = module.params["change_name"]
    description = module.params["description"]
    initiator_iqns = module.params["initiator_iqns"]
    user_name = module.params["name"]
    user_password = module.params["user_password"]
    state = module.params["state"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg=
            "Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(
            hostname, username, password,
            f"HPE Nimble Ansible Modules v{NIMBLE_ANSIBLE_VERSION}")

        # States
        if state == "create" or state == "present":
            if not client_obj.chap_users.get(
                    id=None, name=user_name) or state == "create":
                return_status, changed, msg, changed_attrs_dict, resp = create_chap_user(
                    client_obj,
                    user_name,
                    user_password,
                    description=description)
            else:
                # update op
                return_status, changed, msg, changed_attrs_dict, resp = update_chap_user(
                    client_obj,
                    user_name,
                    name=change_name,
                    password=user_password,
                    description=description,
                    initiator_iqns=initiator_iqns)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_chap_user(
                client_obj, user_name)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #11
0
def main():

    fields = {
        "control_port": {
            "required": False,
            "type": "int"
        },
        "data_port": {
            "required": False,
            "type": "int"
        },
        "description": {
            "required": False,
            "type": "str"
        },
        "folder": {
            "required": False,
            "type": "str"
        },
        "match_folder": {
            "required": False,
            "type": "bool"
        },
        "name": {
            "required": False,
            "type": "str"
        },
        "downstream_hostname": {
            "required": True,
            "type": "str"
        },
        "pause": {
            "required": False,
            "type": "bool"
        },
        "pool": {
            "required": False,
            "type": "str"
        },
        "repl_data_hostname": {
            "required": False,
            "type": "str"
        },
        "resume": {
            "required": False,
            "type": "bool"
        },
        "secret": {
            "required": False,
            "type": "str",
            "no_log": True
        },
        "subnet_label": {
            "required": False,
            "type": "str"
        },
        "subnet_type": {
            "required":
            False,
            "choices": [
                'invalid', 'unconfigured', 'unconfigured', 'mgmt', 'data',
                'mgmt_data'
            ],
            "type":
            "str"
        },
        "test": {
            "required": False,
            "type": "bool"
        },
        "throttles": {
            "required": False,
            "type": "list",
            "elements": 'dict'
        },
        "state": {
            "required": True,
            "choices": ['create', 'present', 'absent'],
            "type": "str"
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    required_if = [('state', 'create',
                    ['subnet_label', 'secret', 'downstream_hostname', 'name'])]

    module = AnsibleModule(argument_spec=fields, required_if=required_if)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    control_port = module.params["control_port"]
    data_port = module.params["data_port"]
    description = module.params["description"]
    folder = module.params["folder"]
    match_folder = module.params["match_folder"]
    repl_partner_name = module.params["name"]
    downstream_hostname = module.params["downstream_hostname"]
    pause = module.params["pause"]
    pool = module.params["pool"]
    repl_data_hostname = module.params["repl_data_hostname"]
    resume = module.params["resume"]
    secret = module.params["secret"]
    subnet_label = module.params["subnet_label"]
    subnet_type = module.params["subnet_type"]
    test = module.params["test"]
    throttles = module.params["throttles"]
    state = module.params["state"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg=
            "Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(
            hostname, username, password,
            f"HPE Nimble Ansible Modules v{NIMBLE_ANSIBLE_VERSION}")

        # States
        if ((test is None or test is False)
                and (resume is None or resume is False)
                and (pause is None or pause is False)
                and (state == "create" or state == "present")):
            if not client_obj.replication_partners.get(
                    id=None,
                    hostname=downstream_hostname) or state == "create":
                return_status, changed, msg, changed_attrs_dict, resp = create_partner(
                    client_obj,
                    downstream_hostname,
                    control_port=control_port,
                    data_port=data_port,
                    description=description,
                    folder_id=utils.get_folder_id(client_obj, folder),
                    match_folder=match_folder,
                    name=repl_partner_name,  # downstream partner name
                    pool_id=utils.get_pool_id(client_obj, pool),
                    repl_hostname=repl_data_hostname,
                    secret=secret,
                    subnet_label=subnet_label,
                    subnet_type=subnet_type,
                    throttles=throttles)
            else:
                # update op
                return_status, changed, msg, changed_attrs_dict, resp = update_partner(
                    client_obj,
                    downstream_hostname,
                    secret,
                    control_port=control_port,
                    data_port=data_port,
                    description=description,
                    folder_id=utils.get_folder_id(client_obj, folder),
                    match_folder=match_folder,
                    name=repl_partner_name,  # downstream partner name
                    pool_id=utils.get_pool_id(client_obj, pool),
                    repl_hostname=repl_data_hostname,
                    subnet_label=subnet_label,
                    subnet_type=subnet_type,
                    throttles=throttles)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_partner(
                client_obj, downstream_hostname)

        elif state == "present" and test is True:
            return_status, changed, msg, changed_attrs_dict = test_partner(
                client_obj, downstream_hostname)

        elif state == "present" and pause is True:
            return_status, changed, msg, changed_attrs_dict = pause_partner(
                client_obj, downstream_hostname)

        elif state == "present" and resume is True:
            return_status, changed, msg, changed_attrs_dict = resume_partner(
                client_obj, downstream_hostname)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #12
0
def main():

    fields = {
        "state": {
            "required": True,
            "choices": ['present', 'absent', 'create'],
            "type": "str"
        },
        "change_name": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "name": {
            "required": True,
            "type": "str",
            "no_log": False
        },
        "description": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "app_sync": {
            "choices": ['none', 'vss', 'vmware', 'generic'],
            "required": False,
            "type": "str",
            "no_log": False
        },
        "app_server": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "app_id": {
            "required":
            False,
            "choices": [
                'inval', 'exchange', 'exchange_dag', 'hyperv', 'sql2005',
                'sql2008', 'sql2012', 'sql2014', 'sql2016', 'sql2017'
            ],
            "type":
            "str",
            "no_log":
            False
        },
        "app_cluster": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "app_service_name": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "vcenter_hostname": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "vcenter_username": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "vcenter_password": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "agent_hostname": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "agent_username": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "agent_password": {
            "required": False,
            "type": "str",
            "no_log": False
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    module = AnsibleModule(argument_spec=fields)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    prot_template_name = module.params["name"]
    change_name = module.params["change_name"]
    description = module.params["description"]
    app_sync = module.params["app_sync"]
    app_server = module.params["app_server"]
    app_id = module.params["app_id"]
    app_cluster = module.params["app_cluster"]
    app_service_name = module.params["app_service_name"]
    vcenter_hostname = module.params["vcenter_hostname"]
    vcenter_username = module.params["vcenter_username"]
    vcenter_password = module.params["vcenter_password"]
    agent_hostname = module.params["agent_hostname"]
    agent_username = module.params["agent_username"]
    agent_password = module.params["agent_password"]

    if (username is None or password is None or hostname is None
            or prot_template_name is None):
        module.fail_json(
            msg=
            "Missing variables: hostname, username, password and protection template is mandatory."
        )

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(hostname, username, password)

        # States
        if state == "create" or state == "present":
            prot_template_resp = client_obj.protection_templates.get(
                id=None, name=prot_template_name)
            if utils.is_null_or_empty(prot_template_resp) or state == "create":
                return_status, changed, msg, changed_attrs_dict, resp = create_prot_template(
                    client_obj,
                    prot_template_name,
                    description=description,
                    app_sync=app_sync,
                    app_server=app_server,
                    app_id=app_id,
                    app_cluster_name=app_cluster,
                    app_service_name=app_service_name,
                    vcenter_hostname=vcenter_hostname,
                    vcenter_username=vcenter_username,
                    vcenter_password=vcenter_password,
                    agent_hostname=agent_hostname,
                    agent_username=agent_username,
                    agent_password=agent_password)
            else:
                # update op
                return_status, changed, msg, changed_attrs_dict, resp = update_prot_template(
                    client_obj,
                    prot_template_resp,
                    name=change_name,
                    description=description,
                    app_sync=app_sync,
                    app_server=app_server,
                    app_id=app_id,
                    app_cluster_name=app_cluster,
                    app_service_name=app_service_name,
                    vcenter_hostname=vcenter_hostname,
                    vcenter_username=vcenter_username,
                    vcenter_password=vcenter_password,
                    agent_hostname=agent_hostname,
                    agent_username=agent_username,
                    agent_password=agent_password)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_prot_template(
                client_obj, prot_template_name)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
def main():

    fields = {
        "state": {
            "required": True,
            "choices": ['present', 'absent', 'create'],
            "type": "str"
        },
        "change_name": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "name": {
            "required": True,
            "type": "str",
            "no_log": False
        },
        "description": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "volcoll_or_prottmpl_type": {
            "choices": ['protection_template', 'volume_collection'],
            "required": True,
            "type": "str",
            "no_log": False,
        },
        "volcoll_name": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "prot_template_name": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "period": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "period_unit": {
            "choices": ['minutes', 'hours', 'days', 'weeks'],
            "required": False,
            "type": "str",
            "no_log": False,
        },
        "at_time": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "until_time": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "days": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "num_retain": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "downstream_partner": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "replicate_every": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "num_retain_replica": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "repl_alert_thres": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "snap_verify": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "skip_db_consistency_check": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "disable_appsync": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "schedule_type": {
            "choices": ['regular', 'external_trigger'],
            "required": False,
            "type": "str",
            "no_log": False,
        },
        "use_downstream_for_DR": {
            "required": False,
            "type": "bool",
            "no_log": False
        }
    }

    mutually_exclusive = [['prot_template_name', 'volcoll_name']]
    required_if = [['state', 'create', ['num_retain']]]
    required_one_of = [['volcoll_name', 'prot_template_name']]
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    module = AnsibleModule(argument_spec=fields,
                           mutually_exclusive=mutually_exclusive,
                           required_if=required_if,
                           required_one_of=required_one_of)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    prot_schedule_name = module.params["name"]
    change_name = module.params["change_name"]
    description = module.params["description"]
    volcoll_or_prottmpl_type = module.params["volcoll_or_prottmpl_type"]
    volcoll_name = module.params["volcoll_name"]
    prot_template_name = module.params["prot_template_name"]
    period = module.params["period"]
    period_unit = module.params["period_unit"]
    at_time = module.params["at_time"]
    until_time = module.params["until_time"]
    days = module.params["days"]
    num_retain = module.params["num_retain"]
    downstream_partner = module.params["downstream_partner"]
    replicate_every = module.params["replicate_every"]
    num_retain_replica = module.params["num_retain_replica"]
    repl_alert_thres = module.params["repl_alert_thres"]
    snap_verify = module.params["snap_verify"]
    skip_db_consistency_check = module.params["skip_db_consistency_check"]
    disable_appsync = module.params["disable_appsync"]
    schedule_type = module.params["schedule_type"]
    use_downstream_for_DR = module.params["use_downstream_for_DR"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg=
            "Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(hostname, username, password)

        # States
        if state == "create" or state == "present":
            # we need to enforce the below params as mandatory as there can be a scenario where in a protection schedule with the same name
            # exists in a different volume collection or in different protection tempalate. Hence, if a user wants to modify/update
            # a protection schedule , they need to provide all the three params for us to query and find the exact protection schedule
            if volcoll_name is None and prot_template_name is None or volcoll_or_prottmpl_type is None:
                module.fail_json(
                    msg=
                    'Please provide the Mandatory params : volcoll_or_prottmpl_type, and volcoll_name or prot_template_name.'
                )

            prot_schedule_resp = client_obj.protection_schedules.get(
                id=None,
                name=prot_schedule_name,
                volcoll_or_prottmpl_type=volcoll_or_prottmpl_type,
                volcoll_or_prottmpl_id=utils.get_volcoll_or_prottmpl_id(
                    client_obj, volcoll_name, prot_template_name))

            if utils.is_null_or_empty(prot_schedule_resp) or state == "create":
                return_status, changed, msg, changed_attrs_dict, resp = create_prot_schedule(
                    client_obj,
                    prot_schedule_name,
                    description=description,
                    volcoll_or_prottmpl_type=volcoll_or_prottmpl_type,
                    volcoll_or_prottmpl_id=utils.get_volcoll_or_prottmpl_id(
                        client_obj, volcoll_name, prot_template_name),
                    period=period,
                    period_unit=period_unit,
                    at_time=at_time,
                    until_time=until_time,
                    days=days,
                    num_retain=num_retain,
                    downstream_partner=downstream_partner,
                    downstream_partner_id=utils.get_downstream_partner_id(
                        client_obj, downstream_partner),
                    replicate_every=replicate_every,
                    num_retain_replica=num_retain_replica,
                    repl_alert_thres=repl_alert_thres,
                    snap_verify=snap_verify,
                    skip_db_consistency_check=skip_db_consistency_check,
                    disable_appsync=disable_appsync,
                    schedule_type=schedule_type)
            else:
                # update op
                return_status, changed, msg, changed_attrs_dict, resp = update_prot_schedule(
                    client_obj,
                    prot_schedule_resp,
                    name=change_name,
                    description=description,
                    period=period,
                    period_unit=period_unit,
                    at_time=at_time,
                    until_time=until_time,
                    days=days,
                    num_retain=num_retain,
                    downstream_partner=downstream_partner,
                    downstream_partner_id=utils.get_downstream_partner_id(
                        client_obj, downstream_partner),
                    replicate_every=replicate_every,
                    num_retain_replica=num_retain_replica,
                    repl_alert_thres=repl_alert_thres,
                    snap_verify=snap_verify,
                    skip_db_consistency_check=skip_db_consistency_check,
                    disable_appsync=disable_appsync,
                    schedule_type=schedule_type,
                    use_downstream_for_DR=use_downstream_for_DR)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_prot_schedule(
                client_obj, prot_schedule_name, volcoll_or_prottmpl_type,
                utils.get_volcoll_or_prottmpl_id(client_obj, volcoll_name,
                                                 prot_template_name))
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #14
0
def main():

    fields = {
        "state": {
            "required": True,
            "choices": ['create', 'present', 'absent'],
            "type": "str"
        },
        "name": {
            "required": True,
            "type": "str",
            "no_log": False
        },
        "pool_name": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "serial": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "change_name": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "create_pool": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "pool_description": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "allow_lower_limits": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "ctrlr_a_support_ip": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "ctrlr_b_support_ip": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "nic_list": {
            "required": False,
            "type": 'list',
            "elements": 'dict',
            "no_log": False
        },
        "secondary_mgmt_ip": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "force": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "failover": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "halt": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "reboot": {
            "required": False,
            "type": "bool",
            "no_log": False
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    module = AnsibleModule(argument_spec=fields)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    array_name = module.params["name"]
    change_name = module.params["change_name"]
    pool_name = module.params["pool_name"]
    serial = module.params["serial"]
    create_pool = module.params["create_pool"]
    pool_description = module.params["pool_description"]
    allow_lower_limits = module.params["allow_lower_limits"]
    ctrlr_a_support_ip = module.params["ctrlr_a_support_ip"]
    ctrlr_b_support_ip = module.params["ctrlr_b_support_ip"]
    nic_list = module.params["nic_list"]
    secondary_mgmt_ip = module.params["secondary_mgmt_ip"]
    force = module.params["force"]
    failover = module.params["failover"]
    halt = module.params["halt"]
    reboot = module.params["reboot"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg=
            "Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(hostname, username, password)

        # States
        if state == "present" and failover is True:
            return_status, changed, msg, changed_attrs_dict = failover_array(
                client_obj, array_name, force=force)

        elif state == "present" and halt is True:
            return_status, changed, msg, changed_attrs_dict = halt_array(
                client_obj, array_name)

        elif state == "present" and reboot is True:
            return_status, changed, msg, changed_attrs_dict = reboot_array(
                client_obj, array_name)

        elif ((failover is None or failover is False)
              and (halt is None or halt is False)
              and (reboot is None or reboot is False)
              and (state == "create" or state == "present")):

            array_resp = client_obj.arrays.get(name=array_name)
            if array_resp is None or state == "create":
                return_status, changed, msg, changed_attrs_dict, resp = create_array(
                    client_obj,
                    array_name,
                    pool_name=pool_name,
                    serial=serial,
                    create_pool=create_pool,
                    pool_description=pool_description,
                    allow_lower_limits=allow_lower_limits,
                    ctrlr_a_support_ip=ctrlr_a_support_ip,
                    ctrlr_b_support_ip=ctrlr_b_support_ip,
                    nic_list=nic_list,
                    secondary_mgmt_ip=secondary_mgmt_ip,
                    force=force,
                    failover=failover,
                    halt=halt,
                    reboot=reboot)
            else:
                return_status, changed, msg, changed_attrs_dict, resp = update_array(
                    client_obj, array_resp, name=change_name, force=force)
        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_array(
                client_obj, array_name)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #15
0
def main():

    fields = {
        "array_list": {
            "required": False,
            "type": "list",
            "elements": 'dict',
            "no_log": False
        },
        "change_name": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "description": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "dedupe_all_volumes": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "force": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "is_default": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "merge": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "name": {
            "required": True,
            "type": "str",
            "no_log": False
        },
        "state": {
            "required": True,
            "choices": ['present', 'absent', 'create'],
            "type": "str"
        },
        "target": {
            "required": False,
            "type": "str",
            "no_log": False
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    required_if = [('state', 'create', ['array_list'])]

    module = AnsibleModule(argument_spec=fields, required_if=required_if)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    pool_name = module.params["name"]
    change_name = module.params["change_name"]
    description = module.params["description"]
    array_list = module.params["array_list"]
    force = module.params["force"]
    dedupe_all_volumes = module.params["dedupe_all_volumes"]
    is_default = module.params["is_default"]
    target = module.params["target"]
    merge = module.params["merge"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg=
            "Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(hostname, username, password)

        # States
        if state == 'present' and merge is True:
            return_status, changed, msg, changed_attrs_dict, resp = merge_pool(
                client_obj, pool_name, target, force=force)

        elif (merge is None or merge is False) and (state == "create"
                                                    or state == "present"):
            pool_resp = client_obj.pools.get(id=None, name=pool_name)

            if utils.is_null_or_empty(pool_resp) or state == "create":
                return_status, changed, msg, changed_attrs_dict, resp = create_pool(
                    client_obj,
                    pool_name,
                    description=description,
                    array_list=array_list,
                    dedupe_all_volumes=dedupe_all_volumes)
            else:
                # update op
                return_status, changed, msg, changed_attrs_dict, resp = update_pool(
                    client_obj,
                    pool_resp,
                    name=change_name,
                    description=description,
                    array_list=array_list,
                    force=force,
                    dedupe_all_volumes=dedupe_all_volumes,
                    is_default=is_default)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_pool(
                client_obj, pool_name)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #16
0
def main():

    fields = {
        "activate": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "array": {
            "required": False,
            "type": "list",
            "elements": 'dict',
            "no_log": False
        },
        "change_name": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "iscsi_automatic_connection_method": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "iscsi_connection_rebalancing": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "ignore_validation_mask": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "mgmt_ip": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "name": {
            "required": True,
            "choices": ['active', 'backup', 'draft'],
            "type": "str",
            "no_log": False
        },
        "secondary_mgmt_ip": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "subnet": {
            "required": False,
            "type": "list",
            "elements": 'dict',
            "no_log": False
        },
        "route": {
            "required": False,
            "type": "list",
            "elements": 'dict',
            "no_log": False
        },
        "state": {
            "required": True,
            "choices": ['create', 'present', 'absent'],
            "type": "str"
        },
        "validate": {
            "required": False,
            "type": "bool",
            "no_log": False
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    required_if = [('state', 'create', [
        'array', 'iscsi_automatic_connection_method',
        'iscsi_connection_rebalancing', 'mgmt_ip', 'subnet', 'route'
    ])]
    module = AnsibleModule(argument_spec=fields, required_if=required_if)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    activate = module.params["activate"]
    array = module.params["array"]
    iscsi_automatic_connection_method = module.params[
        "iscsi_automatic_connection_method"]
    iscsi_connection_rebalancing = module.params[
        "iscsi_connection_rebalancing"]
    ignore_validation_mask = module.params["ignore_validation_mask"]
    mgmt_ip = module.params["mgmt_ip"]
    name = module.params["name"]
    change_name = module.params["change_name"]
    secondary_mgmt_ip = module.params["secondary_mgmt_ip"]
    subnet = module.params["subnet"]
    route = module.params["route"]
    state = module.params["state"]
    validate = module.params["validate"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg=
            "Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(hostname, username, password)

        # States
        if ((validate is None or validate is False)
                and (activate is None or activate is False)
                and (state == "create" or state == "present")):
            # if not client_obj.network_configs.get(id=None, name=name) or state == "create":
            return_status, changed, msg, changed_attrs_dict, resp = create_update_network_config(
                client_obj,
                name,
                state,
                iscsi_automatic_connection_method,
                iscsi_connection_rebalancing,
                mgmt_ip,
                change_name,
                array_list=array,
                ignore_validation_mask=ignore_validation_mask,
                secondary_mgmt_ip=secondary_mgmt_ip,
                subnet_list=subnet,
                route_list=route)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_network_config(
                client_obj, name)

        elif state == "present" and validate is True:
            return_status, changed, msg, changed_attrs_dict = validate_network_config(
                client_obj, name, ignore_validation_mask)

        elif state == "present" and activate is True:
            return_status, changed, msg, changed_attrs_dict = activate_network_config(
                client_obj, name, ignore_validation_mask)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #17
0
def main():

    fields = {
        "state": {
            "required": True,
            "choices": ['present'],
            "type": 'str'
        },
        "allowed_attempts": {
            "required": False,
            "type": "int"
        },
        "min_length": {
            "required": False,
            "type": "int"
        },
        "upper": {
            "required": False,
            "type": "int"
        },
        "lower": {
            "required": False,
            "type": "int"
        },
        "digit": {
            "required": False,
            "type": "int"
        },
        "special": {
            "required": False,
            "type": "int"
        },
        "previous_diff": {
            "required": False,
            "type": "int"
        },
        "no_reuse": {
            "required": False,
            "type": "int"
        },
        "max_sessions": {
            "required": False,
            "type": "int"
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    module = AnsibleModule(argument_spec=fields)
    if client is None:
        module.fail_json(msg='the python nimble_sdk module is required')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    allowed_attempts = module.params["allowed_attempts"]
    min_length = module.params["min_length"]
    upper = module.params["upper"]
    lower = module.params["lower"]
    digit = module.params["digit"]
    special = module.params["special"]
    previous_diff = module.params["previous_diff"]
    no_reuse = module.params["no_reuse"]
    max_sessions = module.params["max_sessions"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg="Storage system IP or username or password is null")
    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None

    try:
        client_obj = client.NimOSClient(
            hostname, username, password,
            f"HPE Nimble Ansible Modules v{NIMBLE_ANSIBLE_VERSION}")

        # States
        if state == "present":
            return_status, changed, msg, changed_attrs_dict, resp = update_user_policy(
                client_obj,
                allowed_attempts=allowed_attempts,
                min_length=min_length,
                upper=upper,
                lower=lower,
                digit=digit,
                special=special,
                previous_diff=previous_diff,
                no_reuse=no_reuse,
                max_sessions=max_sessions)

    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #18
0
def main():

    fields = {
        "alarms": {
            "required": False,
            "type": "bool"
        },
        "alert_to_email_addrs": {
            "required": False,
            "type": "str"
        },
        "alert_from_email_addrs": {
            "required": False,
            "type": "str"
        },
        "alert_min_level": {
            "required": False,
            "choices": ['info', 'notice', 'warning', 'critical'],
            "type": "str"
        },
        "allow_analytics_gui": {
            "required": False,
            "type": "bool"
        },
        "allow_support_tunnel": {
            "required": False,
            "type": "bool"
        },
        "auto_switchover": {
            "required": False,
            "type": "bool"
        },
        "autoclean_unmanaged_snapshots": {
            "required": False,
            "type": "bool"
        },
        "autoclean_unmanaged_snapshots_ttl_unit": {
            "required": False,
            "type": "int"
        },
        "autosupport": {
            "required": False,
            "type": "bool"
        },
        "cc_mode": {
            "required": False,
            "type": "bool"
        },
        "change_name": {
            "required": False,
            "type": "str"
        },
        "check_migrate": {
            "required": False,
            "type": "bool"
        },
        "date": {
            "required": False,
            "type": "int"
        },
        "default_iscsi_target_scope": {
            "required": False,
            "choices": ['volume', 'group'],
            "type": "str"
        },
        "default_volume_limit": {
            "required": False,
            "type": "int"
        },
        "domain_name": {
            "required": False,
            "type": "str"
        },
        "dns_servers": {
            "required": False,
            "type": "list",
            "elements": 'dict'
        },
        "fc_enabled": {
            "required": False,
            "type": "bool"
        },
        "force": {
            "required": False,
            "type": "bool",
            "default": False
        },
        "group_snapshot_ttl": {
            "required": False,
            "type": "int"
        },
        "group_target_enabled": {
            "required": False,
            "type": "bool"
        },
        "group_target_name": {
            "required": False,
            "type": "str"
        },
        "halt": {
            "required": False,
            "type": "bool"
        },
        "iscsi_enabled": {
            "required": False,
            "type": "bool"
        },
        "isns_enabled": {
            "required": False,
            "type": "bool"
        },
        "isns_port": {
            "required": False,
            "type": "int"
        },
        "isns_server": {
            "required": False,
            "type": "str"
        },
        "level": {
            "required": False,
            "choices": ['info', 'notice', 'warning', 'critical'],
            "type": "str"
        },
        "login_banner_after_auth": {
            "required": False,
            "type": "bool"
        },
        "login_banner_message": {
            "required": False,
            "type": "str"
        },
        "login_banner_reset": {
            "required": False,
            "type": "str"
        },
        "merge": {
            "required": False,
            "type": "bool"
        },
        "migrate": {
            "required": False,
            "type": "bool"
        },
        "name": {
            "required": True,
            "type": "str"
        },
        "ntp_server": {
            "required": False,
            "type": "str"
        },
        "proxy_port": {
            "required": False,
            "type": "int"
        },
        "proxy_server": {
            "required": False,
            "type": "str"
        },
        "proxy_username": {
            "required": False,
            "type": "str"
        },
        "proxy_password": {
            "required": False,
            "type": "str",
            "no_log": True
        },
        "reboot": {
            "required": False,
            "type": "bool"
        },
        "repl_throttle_list": {
            "required": False,
            "type": "list",
            "elements": 'dict'
        },
        "send_alert_to_support": {
            "required": False,
            "type": "bool"
        },
        "skip_secondary_mgmt_ip": {
            "required": False,
            "type": "bool"
        },
        "smtp_auth_enabled": {
            "required": False,
            "type": "bool"
        },
        "smtp_auth_password": {
            "required": False,
            "type": "str",
            "no_log": True
        },
        "smtp_auth_username": {
            "required": False,
            "type": "str"
        },
        "smtp_port": {
            "required": False,
            "type": "int"
        },
        "smtp_encrypt_type": {
            "required": False,
            "choices": ['none', 'starttls', 'ssl'],
            "type": "str"
        },
        "snmp_community": {
            "required": False,
            "type": "str"
        },
        "snmp_get_enabled": {
            "required": False,
            "type": "bool"
        },
        "snmp_get_port": {
            "required": False,
            "type": "int"
        },
        "snmp_trap_enabled": {
            "required": False,
            "type": "bool"
        },
        "snmp_trap_host": {
            "required": False,
            "type": "str"
        },
        "snmp_trap_port": {
            "required": False,
            "type": "int"
        },
        "snmp_sys_contact": {
            "required": False,
            "type": "str"
        },
        "snmp_sys_location": {
            "required": False,
            "type": "str"
        },
        "src_group_ip": {
            "required": False,
            "type": "str"
        },
        "src_group_name": {
            "required": False,
            "type": "str"
        },
        "src_username": {
            "required": False,
            "type": "str"
        },
        "src_passphrase": {
            "required": False,
            "type": "str",
            "no_log": True
        },
        "src_password": {
            "required": False,
            "type": "str",
            "no_log": True
        },
        "state": {
            "required": True,
            "choices": ['present', 'absent'],
            "type": "str"
        },
        "syslogd_enabled": {
            "required": False,
            "type": "bool"
        },
        "syslogd_port": {
            "required": False,
            "type": "int"
        },
        "syslogd_server": {
            "required": False,
            "type": "str"
        },
        "tdz_enabled": {
            "required": False,
            "type": "bool"
        },
        "tdz_prefix": {
            "required": False,
            "type": "str"
        },
        "test_alert": {
            "required": False,
            "type": "bool"
        },
        "timezone": {
            "required": False,
            "type": "str"
        },
        "tlsv1_enabled": {
            "required": False,
            "type": "bool"
        },
        "user_inactivity_timeout": {
            "required": False,
            "type": "int"
        },
        "validate_merge": {
            "required": False,
            "type": "bool"
        },
        "vss_validation_timeout": {
            "required": False,
            "type": "int"
        },
        "vvol_enabled": {
            "required": False,
            "type": "bool"
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    module = AnsibleModule(argument_spec=fields)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    alarms = module.params["alarms"]
    alert_to_email_addrs = module.params["alert_to_email_addrs"]
    alert_from_email_addrs = module.params["alert_from_email_addrs"]
    alert_min_level = module.params["alert_min_level"]
    allow_analytics_gui = module.params["allow_analytics_gui"]
    allow_support_tunnel = module.params["allow_support_tunnel"]
    auto_switchover = module.params["auto_switchover"]
    autoclean_unmanaged_snapshots = module.params[
        "autoclean_unmanaged_snapshots"]
    autoclean_unmanaged_snapshots_ttl_unit = module.params[
        "autoclean_unmanaged_snapshots_ttl_unit"]
    autosupport = module.params["autosupport"]
    cc_mode = module.params["cc_mode"]
    change_name = module.params["change_name"]
    check_migrate = module.params["check_migrate"]
    date = module.params["date"]
    default_iscsi_target_scope = module.params["default_iscsi_target_scope"]
    default_volume_limit = module.params["default_volume_limit"]
    domain_name = module.params["domain_name"]
    dns_servers = module.params["dns_servers"]
    fc_enabled = module.params["fc_enabled"]
    force = module.params["force"]
    group_snapshot_ttl = module.params["group_snapshot_ttl"]
    group_target_enabled = module.params["group_target_enabled"]
    group_target_name = module.params["group_target_name"]
    halt = module.params["halt"]
    iscsi_enabled = module.params["iscsi_enabled"]
    isns_enabled = module.params["isns_enabled"]
    isns_port = module.params["isns_port"]
    isns_server = module.params["isns_server"]
    level = module.params["level"]
    login_banner_after_auth = module.params["login_banner_after_auth"]
    login_banner_message = module.params["login_banner_message"]
    login_banner_reset = module.params["login_banner_reset"]
    merge = module.params["merge"]
    migrate = module.params["migrate"]
    group_name = module.params["name"]
    ntp_server = module.params["ntp_server"]
    proxy_port = module.params["proxy_port"]
    proxy_server = module.params["proxy_server"]
    proxy_username = module.params["proxy_username"]
    proxy_password = module.params["proxy_password"]
    reboot = module.params["reboot"]
    repl_throttle_list = module.params["repl_throttle_list"]
    send_alert_to_support = module.params["send_alert_to_support"]
    skip_secondary_mgmt_ip = module.params["skip_secondary_mgmt_ip"]
    smtp_auth_enabled = module.params["smtp_auth_enabled"]
    smtp_auth_password = module.params["smtp_auth_password"]
    smtp_auth_username = module.params["smtp_auth_username"]
    smtp_port = module.params["smtp_port"]
    smtp_encrypt_type = module.params["smtp_encrypt_type"]
    snmp_community = module.params["snmp_community"]
    snmp_get_enabled = module.params["snmp_get_enabled"]
    snmp_get_port = module.params["snmp_get_port"]
    snmp_trap_enabled = module.params["snmp_trap_enabled"]
    snmp_trap_host = module.params["snmp_trap_host"]
    snmp_trap_port = module.params["snmp_trap_port"]
    snmp_sys_contact = module.params["snmp_sys_contact"]
    snmp_sys_location = module.params["snmp_sys_location"]
    src_group_ip = module.params["src_group_ip"]
    src_group_name = module.params["src_group_name"]
    src_username = module.params["src_username"]
    src_passphrase = module.params["src_passphrase"]
    src_password = module.params["src_password"]
    state = module.params["state"]
    syslogd_enabled = module.params["syslogd_enabled"]
    syslogd_port = module.params["syslogd_port"]
    syslogd_server = module.params["syslogd_server"]
    tdz_enabled = module.params["tdz_enabled"]
    tdz_prefix = module.params["tdz_prefix"]
    test_alert = module.params["test_alert"]
    timezone = module.params["timezone"]
    tlsv1_enabled = module.params["tlsv1_enabled"]
    user_inactivity_timeout = module.params["user_inactivity_timeout"]
    validate_merge = module.params["validate_merge"]
    vss_validation_timeout = module.params["vss_validation_timeout"]
    vvol_enabled = module.params["vvol_enabled"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg=
            "Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(
            hostname, username, password,
            f"HPE Nimble Ansible Modules v{NIMBLE_ANSIBLE_VERSION}")

        # States
        if state == "present":
            if reboot is True:
                return_status, changed, msg, changed_attrs_dict = reboot_group(
                    client_obj, group_name)

            elif halt is True:
                return_status, changed, msg, changed_attrs_dict = halt_group(
                    client_obj, group_name, force=force)

            elif test_alert is True:
                return_status, changed, msg, changed_attrs_dict = test_alert_group(
                    client_obj, group_name, level)

            elif validate_merge is True:
                return_status, changed, msg, changed_attrs_dict, resp = validate_merge_group(
                    client_obj,
                    group_name,
                    src_group_ip=src_group_ip,
                    src_group_name=src_group_name,
                    src_password=src_password,
                    src_username=src_username,
                    skip_secondary_mgmt_ip=skip_secondary_mgmt_ip,
                    src_passphrase=src_passphrase)

            elif merge is True:
                return_status, changed, msg, changed_attrs_dict, resp = merge_group(
                    client_obj,
                    group_name,
                    src_group_ip=src_group_ip,
                    src_group_name=src_group_name,
                    src_password=src_password,
                    src_username=src_username,
                    force=force,
                    skip_secondary_mgmt_ip=skip_secondary_mgmt_ip,
                    src_passphrase=src_passphrase)

            elif check_migrate is True:
                return_status, changed, msg, changed_attrs_dict = check_migrate_group(
                    client_obj, group_name)

            elif migrate is True:
                return_status, changed, msg, changed_attrs_dict = migrate_group(
                    client_obj, group_name)

            else:
                # update op
                return_status, changed, msg, changed_attrs_dict, resp = update_group(
                    client_obj,
                    group_name,
                    name=change_name,
                    alarms=alarms,
                    alert_to_email_addrs=alert_to_email_addrs,
                    alert_from_email_addrs=alert_from_email_addrs,
                    alert_min_level=alert_min_level,
                    allow_analytics_gui=allow_analytics_gui,
                    allow_support_tunnel=allow_support_tunnel,
                    auto_switchover=auto_switchover,
                    autoclean_unmanaged_snapshots=autoclean_unmanaged_snapshots,
                    autoclean_unmanaged_snapshots_ttl_unit=
                    autoclean_unmanaged_snapshots_ttl_unit,
                    autosupport=autosupport,
                    cc_mode=cc_mode,
                    date=date,
                    default_iscsi_target_scope=default_iscsi_target_scope,
                    default_volume_limit=default_volume_limit,
                    domain_name=domain_name,
                    dns_servers=dns_servers,
                    fc_enabled=fc_enabled,
                    group_snapshot_ttl=group_snapshot_ttl,
                    group_target_enabled=group_target_enabled,
                    group_target_name=group_target_name,
                    iscsi_enabled=iscsi_enabled,
                    isns_enabled=isns_enabled,
                    isns_port=isns_port,
                    isns_server=isns_server,
                    login_banner_after_auth=login_banner_after_auth,
                    login_banner_message=login_banner_message,
                    login_banner_reset=login_banner_reset,
                    ntp_server=ntp_server,
                    proxy_port=proxy_port,
                    proxy_password=proxy_password,
                    proxy_server=proxy_server,
                    proxy_username=proxy_username,
                    repl_throttle_list=repl_throttle_list,
                    send_alert_to_support=send_alert_to_support,
                    smtp_auth_enabled=smtp_auth_enabled,
                    smtp_auth_password=smtp_auth_password,
                    smtp_auth_username=smtp_auth_username,
                    smtp_port=smtp_port,
                    smtp_encrypt_type=smtp_encrypt_type,
                    snmp_community=snmp_community,
                    snmp_get_enabled=snmp_get_enabled,
                    snmp_get_port=snmp_get_port,
                    snmp_trap_enabled=snmp_trap_enabled,
                    snmp_trap_host=snmp_trap_host,
                    snmp_trap_port=snmp_trap_port,
                    snmp_sys_contact=snmp_sys_contact,
                    snmp_sys_location=snmp_sys_location,
                    syslogd_enabled=syslogd_enabled,
                    syslogd_port=syslogd_port,
                    syslogd_server=syslogd_server,
                    tdz_enabled=tdz_enabled,
                    tdz_prefix=tdz_prefix,
                    timezone=timezone,
                    tlsv1_enabled=tlsv1_enabled,
                    user_inactivity_timeout=user_inactivity_timeout,
                    vss_validation_timeout=vss_validation_timeout,
                    vvol_enabled=vvol_enabled)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = reboot_group(
                client_obj, group_name)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
    else:
        if utils.is_null_or_empty(resp):
            module.fail_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.fail_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
コード例 #19
0
def main():

    fields = {
        "active": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "age": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "encryption_config": {
            "required": False,
            "type": "dict",
            "no_log": False
        },
        "group_encrypt": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "name": {
            "required": True,
            "type": "str",
            "no_log": False
        },
        "passphrase": {
            "required": False,
            "type": "str",
            "no_log": True
        },
        "purge_inactive": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "new_passphrase": {
            "required": False,
            "type": "str",
            "no_log": True
        },
        "state": {
            "required": True,
            "choices": ['create',
                        'present',
                        'absent'
                        ],
            "type": "str"
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    required_if = [('state', 'create', ['passphrase'])]

    module = AnsibleModule(argument_spec=fields, required_if=required_if)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    active = module.params["active"]
    age = module.params["age"]
    encryption_config = module.params["encryption_config"]
    group_encrypt = module.params["group_encrypt"]
    master_key = module.params["name"]
    passphrase = module.params["passphrase"]
    purge_inactive = module.params["purge_inactive"]
    new_passphrase = module.params["new_passphrase"]
    state = module.params["state"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg="Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(
            hostname,
            username,
            password
        )

        # States
        if ((purge_inactive is None or purge_inactive is False)
            and (group_encrypt is None or group_encrypt is False)
                and (state == "create" or state == "present")):
            if not client_obj.master_key.get(id=None, name=master_key) or state == "create":
                return_status, changed, msg, changed_attrs_dict, resp = create_master_key(
                    client_obj,
                    master_key,
                    passphrase)
            else:
                # update op
                return_status, changed, msg, changed_attrs_dict, resp = update_master_key(
                    client_obj,
                    master_key,
                    active,
                    passphrase=passphrase,
                    new_passphrase=new_passphrase)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_master_key(client_obj, master_key)

        elif state == "present" and purge_inactive is True:
            return_status, changed, msg, changed_attrs_dict = purge_inactive_key(
                client_obj,
                master_key,
                age=age)

        elif state == "present" and group_encrypt is True:
            group_name = module.params["name"]
            return_status, changed, msg, changed_attrs_dict, resp = group_encryption(
                client_obj,
                group_name,
                encryption_config)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status, changed=changed, msg=msg)
        else:
            module.exit_json(return_status=return_status, changed=changed, msg=msg, attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #20
0
def main():

    fields = {
        "state": {
            "required": True,
            "choices": ['present', 'absent', 'create'],
            "type": "str"
        },
        "change_name": {
            "required": False,
            "type": "str"
        },
        "name": {
            "required": True,
            "type": "str"
        },
        "description": {
            "required": False,
            "type": "str"
        },
        "access_protocol": {
            "choices": ['iscsi', 'fc'],
            "required": False,
            "type": "str"
        },
        "host_type": {
            "required": False,
            "type": "str"
        },
        "fc_tdz_ports": {
            "required": False,
            "type": "list",
            "elements": 'int'
        },
        "target_subnets": {
            "required": False,
            "type": "list",
            "elements": 'dict'
        },
        "iscsi_initiators": {
            "required": False,
            "type": "list",
            "elements": 'dict'
        },
        "fc_initiators": {
            "required": False,
            "type": "list",
            "elements": 'dict'
        },
        "app_uuid": {
            "required": False,
            "type": "str"
        },
        "metadata": {
            "required": False,
            "type": "dict"
        }
    }

    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    required_if = [('state', 'create', ['access_protocol'])]
    module = AnsibleModule(argument_spec=fields, required_if=required_if)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    initiator_group_name = module.params["name"]
    change_name = module.params["change_name"]
    description = module.params["description"]
    access_protocol = module.params["access_protocol"]
    host_type = module.params["host_type"]
    fc_tdz_ports = module.params["fc_tdz_ports"]
    target_subnets = module.params["target_subnets"]
    iscsi_initiators = module.params["iscsi_initiators"]
    fc_initiators = module.params["fc_initiators"]
    app_uuid = module.params["app_uuid"]
    metadata = module.params["metadata"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg=
            "Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(
            hostname, username, password,
            f"HPE Nimble Ansible Modules v{NIMBLE_ANSIBLE_VERSION}")

        # States
        if state == "create" or state == "present":
            ig_resp = client_obj.initiator_groups.get(
                id=None, name=initiator_group_name)
            if utils.is_null_or_empty(ig_resp) or state == "create":

                return_status, changed, msg, changed_attrs_dict, resp = create_igroup(
                    client_obj,
                    initiator_group_name,
                    description=description,
                    access_protocol=access_protocol,
                    host_type=host_type,
                    fc_tdz_ports=fc_tdz_ports,
                    target_subnets=target_subnets,
                    iscsi_initiators=iscsi_initiators,
                    fc_initiators=fc_initiators,
                    app_uuid=app_uuid,
                    metadata=metadata)
            else:
                return_status, changed, msg, changed_attrs_dict, resp = update_igroup(
                    client_obj,
                    ig_resp,
                    name=change_name,
                    description=description,
                    host_type=host_type,
                    fc_tdz_ports=fc_tdz_ports,
                    target_subnets=target_subnets,
                    iscsi_initiators=iscsi_initiators,
                    fc_initiators=fc_initiators,
                    metadata=metadata)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_igroup(
                client_obj, initiator_group_name)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #21
0
def main():

    fields = {
        "state": {
            "required": True,
            "choices": ['create', 'present', 'absent'],
            "type": "str"
        },
        "change_name": {
            "required": False,
            "type": "str"
        },
        "name": {
            "required": True,
            "type": "str"
        },
        "description": {
            "required": False,
            "type": "str"
        },
        "role": {
            "required": False,
            "choices": ['administrator', 'poweruser', 'operator', 'guest'],
            "type": "str"
        },
        "user_password": {
            "required": False,
            "type": "str",
            "no_log": True
        },
        "inactivity_timeout": {
            "required": False,
            "type": "int"
        },
        "full_name": {
            "required": False,
            "type": "str"
        },
        "email_addr": {
            "required": False,
            "type": "str"
        },
        "disabled": {
            "required": False,
            "type": "bool"
        },
        "auth_password": {
            "required": False,
            "type": "str",
            "no_log": True
        },
        "unlock": {
            "required": False,
            "type": "bool"
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    required_if = [('state', 'create', ['user_password'])]

    module = AnsibleModule(argument_spec=fields, required_if=required_if)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    user_name = module.params["name"]
    change_name = module.params["change_name"]
    description = module.params["description"]
    role = module.params["role"]
    user_password = module.params["user_password"]
    inactivity_timeout = module.params["inactivity_timeout"]
    full_name = module.params["full_name"]
    email_addr = module.params["email_addr"]
    disabled = module.params["disabled"]
    auth_password = module.params["auth_password"]
    unlock = module.params["unlock"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg=
            "Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(
            hostname, username, password,
            f"HPE Nimble Ansible Modules v{NIMBLE_ANSIBLE_VERSION}")

        # States
        if ((unlock is None or unlock is False)
                and (state == "create" or state == "present")):
            if not client_obj.users.get(id=None,
                                        name=user_name) or state == "create":
                return_status, changed, msg, changed_attrs_dict, resp = create_user(
                    client_obj,
                    user_name,
                    user_password,
                    description=description,
                    role=role,
                    inactivity_timeout=inactivity_timeout,
                    full_name=full_name,
                    email_addr=email_addr,
                    disabled=disabled)
            else:
                # update op
                return_status, changed, msg, changed_attrs_dict, resp = update_user(
                    client_obj,
                    user_name,
                    name=change_name,
                    password=user_password,
                    description=description,
                    role=role,
                    inactivity_timeout=inactivity_timeout,
                    full_name=full_name,
                    email_addr=email_addr,
                    disabled=disabled,
                    auth_password=auth_password)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_user(
                client_obj, user_name)

        elif state == "present" and unlock is True:
            return_status, changed, msg, changed_attrs_dict = unlock_user(
                client_obj, user_name)

    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg)
        else:
            module.exit_json(return_status=return_status,
                             changed=changed,
                             msg=msg,
                             attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #22
0
def main():

    fields = {
        "state": {
            "required": True,
            "choices": ['present'],
            "type": "str"
        },
        "disk_op": {
            "required": True,
            "choices": ['add', 'remove'],
            "type": "str"
        },
        "slot": {
            "required": True,
            "type": "int"
        },
        "shelf_location": {
            "required": True,
            "type": "str"
        },
        "force": {
            "required": False,
            "type": "bool"
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    module = AnsibleModule(argument_spec=fields)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    disk_op = module.params["disk_op"]
    slot = module.params["slot"]
    shelf_location = module.params["shelf_location"]
    force = module.params["force"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg="Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(
            hostname,
            username,
            password,
            f"HPE Nimble Ansible Modules v{NIMBLE_ANSIBLE_VERSION}"
        )

        # States
        if state == "present":
            return_status, changed, msg, changed_attrs_dict, resp = update_disk(
                client_obj,
                slot,
                shelf_location,
                disk_op=disk_op,
                force=force)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status, changed=changed, msg=msg)
        else:
            module.exit_json(return_status=return_status, changed=changed, msg=msg, attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
def main():

    fields = {
        "state": {
            "required": True,
            "choices": ['present', 'absent', 'create'],
            "type": "str"
        },
        "apply_to": {
            "required": False,
            "choices": ['volume', 'snapshot', 'both'],
            "type": "str",
            "no_log": False
        },
        "chap_user": {
            "required": False,
            "type": "str",
            "no_log": False
        },
        "lun": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "volume": {
            "required": True,
            "type": "str",
            "no_log": False
        },
        "initiator_group": {
            "required": True,
            "type": "str",
            "no_log": False
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)

    module = AnsibleModule(argument_spec=fields)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    apply_to = module.params["apply_to"]
    chap_user = module.params["chap_user"]
    lun = module.params["lun"]
    volume = module.params["volume"]
    initiator_group = module.params["initiator_group"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg="Missing variables: hostname, username and password is mandatory.")
    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(
            hostname,
            username,
            password
        )

        # States
        if state == "create" or state == "present":
            return_status, changed, msg, resp = create_acr(
                client_obj,
                state,
                initiator_group,
                volume,
                apply_to=apply_to,
                chap_user_id=utils.get_chap_user_id(client_obj, chap_user),
                lun=lun)

        elif state == "absent":
            return_status, changed, msg = delete_acr(
                client_obj,
                initiator_group,
                volume,
                chap_user=chap_user)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status, changed=changed, msg=msg)
        else:
            module.exit_json(return_status=return_status, changed=changed, msg=msg, attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
コード例 #24
0
def main():

    fields = {
        "state": {
            "required": True,
            "choices": ['present'],
            "type": "str"
        },
        "shelf_serial": {
            "required": True,
            "type": "str",
            "no_log": False
        },
        "activated": {
            "required": True,
            "type": "bool",
            "no_log": False
        },
        "driveset": {
            "required": False,
            "type": "int",
            "no_log": False
        },
        "force": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "accept_foreign": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "accept_dedupe_impact": {
            "required": False,
            "type": "bool",
            "no_log": False
        },
        "last_request": {
            "required": False,
            "type": "bool",
            "no_log": False
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    module = AnsibleModule(argument_spec=fields)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    state = module.params["state"]
    shelf_serial = module.params["shelf_serial"]
    activated = module.params["activated"]
    driveset = module.params["driveset"]
    force = module.params["force"]
    accept_foreign = module.params["accept_foreign"]
    accept_dedupe_impact = module.params["accept_dedupe_impact"]
    last_request = module.params["last_request"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg=
            "Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(hostname, username, password)

        # States
        if state == "present":
            return_status, changed, msg, resp = update_shelve(
                client_obj,
                shelf_serial,
                activated=activated,
                driveset=driveset,
                force=force,
                accept_foreign=accept_foreign,
                accept_dedupe_impact=accept_dedupe_impact,
                last_request=last_request)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        module.exit_json(return_status=return_status,
                         changed=changed,
                         msg=msg,
                         attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)
def main():

    fields = {
        "app_category": {
            "required": False,
            "type": "str"
        },
        "block_size": {
            "required": False,
            "type": "int"
        },
        "cache": {
            "required": False,
            "type": "bool"
        },
        "cache_policy": {
            "required": False,
            "choices": ['disabled', 'normal', 'aggressive', 'no_write', 'aggressive_read_no_write'],
            "type": "str"
        },
        "change_name": {
            "required": False,
            "type": "str"
        },
        "compress": {
            "required": False,
            "type": "bool"
        },
        "description": {
            "required": False,
            "type": "str"
        },
        "dedupe": {
            "required": False,
            "type": "bool"
        },
        "name": {
            "required": True,
            "type": "str"
        },
        "space_policy": {
            "required": False,
            "choices": ['invalid', 'offline', 'non_writable', 'read_only', 'login_only'],
            "type": "str"
        },
        "state": {
            "required": True,
            "choices": ['present',
                        'absent',
                        'create'
                        ],
            "type": "str"
        }
    }
    default_fields = utils.basic_auth_arg_fields()
    fields.update(default_fields)
    module = AnsibleModule(argument_spec=fields)
    if client is None:
        module.fail_json(msg='Python nimble-sdk could not be found.')

    hostname = module.params["host"]
    username = module.params["username"]
    password = module.params["password"]
    app_category = module.params["app_category"]
    block_size = module.params["block_size"]
    cache = module.params["cache"]
    cache_policy = module.params["cache_policy"]
    compress = module.params["compress"]
    description = module.params["description"]
    dedupe = module.params["dedupe"]
    perf_policy_name = module.params["name"]
    change_name = module.params["change_name"]
    space_policy = module.params["space_policy"]
    state = module.params["state"]

    if (username is None or password is None or hostname is None):
        module.fail_json(
            msg="Missing variables: hostname, username and password is mandatory.")

    # defaults
    return_status = changed = False
    msg = "No task to run."
    resp = None
    try:
        client_obj = client.NimOSClient(
            hostname,
            username,
            password,
            f"HPE Nimble Ansible Modules v{NIMBLE_ANSIBLE_VERSION}"
        )

        # States
        if state == "create" or state == "present":
            perf_policy_resp = client_obj.performance_policies.get(id=None, name=perf_policy_name)
            if utils.is_null_or_empty(perf_policy_resp) or state == "create":
                return_status, changed, msg, changed_attrs_dict, resp = create_perf_policy(
                    client_obj,
                    perf_policy_name,
                    app_category=app_category,
                    block_size=block_size,
                    cache=cache,
                    cache_policy=cache_policy,
                    compress=compress,
                    description=description,
                    dedupe_enabled=dedupe,
                    space_policy=space_policy)
            else:
                # update op
                return_status, changed, msg, changed_attrs_dict, resp = update_perf_policy(
                    client_obj,
                    perf_policy_resp,
                    name=change_name,
                    app_category=app_category,
                    cache=cache,
                    cache_policy=cache_policy,
                    compress=compress,
                    description=description,
                    dedupe_enabled=dedupe,
                    space_policy=space_policy)

        elif state == "absent":
            return_status, changed, msg, changed_attrs_dict = delete_perf_policy(
                client_obj,
                perf_policy_name)
    except Exception as ex:
        # failed for some reason.
        msg = str(ex)

    if return_status:
        if utils.is_null_or_empty(resp):
            module.exit_json(return_status=return_status, changed=changed, msg=msg)
        else:
            module.exit_json(return_status=return_status, changed=changed, msg=msg, attrs=resp)
    else:
        module.fail_json(return_status=return_status, changed=changed, msg=msg)