def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            hostgroup=dict(type='str', required=True),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            host=dict(type='list'),
            lun=dict(type='int'),
            volume=dict(type='list'),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=False)

    state = module.params['state']
    array = get_system(module)
    hostgroup = get_hostgroup(module, array)

    if module.params['host']:
        try:
            for hst in module.params['host']:
                array.get_host(hst)
        except Exception:
            module.fail_json(msg='Host {0} not found'.format(hst))
    if module.params['lun'] and len(module.params['volume']) > 1:
        module.fail_json(
            msg='LUN ID cannot be specified with multiple volumes.')

    if module.params['lun'] and not 1 <= module.params['lun'] <= 4095:
        module.fail_json(msg='LUN ID of {0} is out of range (1 to 4095)'.
                         format(module.params['lun']))

    if module.params['volume']:
        try:
            for vol in module.params['volume']:
                array.get_volume(vol)
        except Exception:
            module.fail_json(msg='Volume {0} not found'.format(vol))

    if hostgroup and state == 'present':
        update_hostgroup(module, array)
    elif hostgroup and module.params['volume'] and state == 'absent':
        update_hostgroup(module, array)
    elif hostgroup and module.params['host'] and state == 'absent':
        update_hostgroup(module, array)
    elif hostgroup and state == 'absent':
        delete_hostgroup(module, array)
    elif hostgroup is None and state == 'absent':
        module.exit_json(changed=False)
    else:
        make_hostgroup(module, array)
Exemple #2
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(dict(
        name=dict(type='str', required=True),
        stretch=dict(type='str'),
        target=dict(type='str'),
        failover=dict(type='list'),
        eradicate=dict(type='bool', default=False),
        state=dict(type='str', default='present', choices=['absent', 'present']),
    ))

    mutually_exclusive = [['stretch'], ['failover', 'eradicate'],
                          ['target'], ['stretch', 'failover', 'eradicate']]

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

    state = module.params['state']
    array = get_system(module)

    api_version = array._list_available_rest_versions()
    if POD_API_VERSION not in api_version:
        module.fail_json(msg='FlashArray REST version not supported. '
                             'Minimum version required: {0}'.format(POD_API_VERSION))

    pod = get_pod(module, array)
    destroyed = ''
    if not pod:
        destroyed = get_destroyed_pod(module, array)
    if module.params['failover'] or module.params['failover'] != 'auto':
        check_arrays(module, array)

    if state == 'present' and not pod:
        create_pod(module, array)
    elif pod and module.params['stretch']:
        stretch_pod(module, array)
    elif state == 'present' and pod and module.params['target']:
        clone_pod(module, array)
    elif state == 'present' and pod and module.params['target']:
        clone_pod(module, array)
    elif state == 'present' and pod:
        update_pod(module, array)
    elif state == 'absent' and pod and not module.params['stretch']:
        delete_pod(module, array)
    elif state == 'present' and destroyed:
        recover_pod(module, array)
    elif state == 'absent' and destroyed:
        eradicate_pod(module, array)
    elif state == 'absent' and not pod:
        module.exit_json(changed=False)
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(dict(
        name=dict(type='str', required=True),
        suffix=dict(type='str'),
        target=dict(type='str'),
        overwrite=dict(type='bool', default=False),
        eradicate=dict(type='bool', default=False),
        state=dict(type='str', default='present', choices=['absent', 'copy', 'present']),
    ))

    required_if = [('state', 'copy', ['target', 'suffix'])]

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

    if module.params['suffix'] is None:
        suffix = "snap-" + str((datetime.utcnow() - datetime(1970, 1, 1, 0, 0, 0, 0)).total_seconds())
        module.params['suffix'] = suffix.replace(".", "")
    else:
        pattern = re.compile("^[a-zA-Z0-9]([a-zA-Z0-9-]{0,63}[a-zA-Z0-9])?$")
        if not pattern.match(module.params['suffix']):
            module.fail_json(msg='Suffix name {0} does not conform to suffix name rules'.format(module.params['suffix']))

    state = module.params['state']
    array = get_system(module)
    destroyed = False
    volume = get_volume(module, array)
    snap = get_snapshot(module, array)
    if not snap:
        destroyed = get_deleted_snapshot(module, array)

    if state == 'present' and volume and not destroyed:
        create_snapshot(module, array)
    elif state == 'present' and volume and destroyed:
        recover_snapshot(module, array)
    elif state == 'present' and volume and snap:
        update_snapshot(module, array)
    elif state == 'present' and not volume:
        update_snapshot(module, array)
    elif state == 'copy' and snap:
        create_from_snapshot(module, array)
    elif state == 'copy' and not snap:
        update_snapshot(module, array)
    elif state == 'absent' and snap:
        delete_snapshot(module, array)
    elif state == 'absent' and not snap:
        module.exit_json(changed=False)

    module.exit_json(changed=False)
Exemple #4
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type="str",
                       default="present",
                       choices=["absent", "present"]),
            enabled=dict(type="bool", default=True),
            name=dict(type="str", required=True),
            role=dict(
                type="str",
                choices=[
                    "readonly", "ops_admin", "storage_admin", "array_admin"
                ],
            ),
            public_key=dict(type="str", no_log=True),
            token_ttl=dict(type="int", default=86400, no_log=False),
            issuer=dict(type="str"),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    if not HAS_PURESTORAGE:
        module.fail_json(msg="py-pure-client sdk is required for this module")

    array = get_system(module)
    api_version = array._list_available_rest_versions()

    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(
            msg="FlashArray REST version not supported. "
            "Minimum version required: {0}".format(MIN_REQUIRED_API_VERSION))
    array = get_array(module)
    state = module.params["state"]

    try:
        client = list(
            array.get_api_clients(names=[module.params["name"]]).items)[0]
        exists = True
    except Exception:
        exists = False

    if not exists and state == "present":
        create_client(module, array)
    elif exists and state == "present":
        update_client(module, array, client)
    elif exists and state == "absent":
        delete_client(module, array)

    module.exit_json(changed=False)
Exemple #5
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            name=dict(type="str", required=True),
            state=dict(type="str", default="present", choices=["absent", "present"]),
            schedule=dict(
                type="str", required=True, choices=["replication", "snapshot"]
            ),
            blackout_start=dict(type="str"),
            blackout_end=dict(type="str"),
            snap_at=dict(type="int"),
            replicate_at=dict(type="int"),
            replicate_frequency=dict(type="int"),
            snap_frequency=dict(type="int"),
            all_for=dict(type="int"),
            days=dict(type="int"),
            per_day=dict(type="int"),
            target_all_for=dict(type="int"),
            target_per_day=dict(type="int"),
            target_days=dict(type="int"),
            enabled=dict(type="bool", default=True),
        )
    )

    required_together = [["blackout_start", "blackout_end"]]

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

    state = module.params["state"]
    array = get_system(module)

    pgroup = get_pgroup(module, array)
    if module.params["snap_at"] and module.params["snap_frequency"]:
        if not module.params["snap_frequency"] % 86400 == 0:
            module.fail_json(
                msg="snap_at not valid unless snapshot frequency is measured in days, ie. a multiple of 86400"
            )
    if pgroup and state == "present":
        update_schedule(module, array)
    elif pgroup and state == "absent":
        delete_schedule(module, array)
    elif pgroup is None:
        module.fail_json(
            msg="Specified protection group {0} does not exist.".format(
                module.params["pgroup"]
            )
        )
Exemple #6
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            address=dict(type="str", required=True),
            enabled=dict(type="bool", default=True),
            state=dict(type="str", default="present", choices=["absent", "present"]),
        )
    )

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    pattern = re.compile(r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$")
    if not pattern.match(module.params["address"]):
        module.fail_json(msg="Valid email address not provided.")

    array = get_system(module)

    exists = False
    try:
        emails = array.list_alert_recipients()
    except Exception:
        module.fail_json(msg="Failed to get exisitng email list")
    for email in range(0, len(emails)):
        if emails[email]["name"] == module.params["address"]:
            exists = True
            enabled = emails[email]["enabled"]
            break
    if module.params["state"] == "present" and not exists:
        create_alert(module, array)
    elif (
        module.params["state"] == "present"
        and exists
        and not enabled
        and module.params["enabled"]
    ):
        enable_alert(module, array)
    elif (
        module.params["state"] == "present"
        and exists
        and enabled
        and not module.params["enabled"]
    ):
        disable_alert(module, array)
    elif module.params["state"] == "absent" and exists:
        delete_alert(module, array)

    module.exit_json(changed=False)
Exemple #7
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(state=dict(type="str",
                        default="disable",
                        choices=["enable", "disable"]), ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    array = get_system(module)

    if module.params["state"] == "enable":
        enable_console(module, array)
    else:
        disable_console(module, array)
    module.exit_json(changed=False)
Exemple #8
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(state=dict(type='str',
                        default='disable',
                        choices=['enable', 'disable']), ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    array = get_system(module)

    if module.params['state'] == 'enable':
        enable_console(module, array)
    else:
        disable_console(module, array)
    module.exit_json(changed=False)
Exemple #9
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            company=dict(type='str', required=True),
            name=dict(type='str', required=True),
            title=dict(type='str', required=True),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    array = get_system(module)
    api_version = array._list_available_rest_versions()
    if EULA_API_VERSION in api_version:
        set_eula(module, array)
    module.exit_json(changed=False)
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(dict(
        state=dict(type='str', default='present', choices=['absent', 'present']),
        nfs_access=dict(type='str', default='root-squash', choices=['root-squash', 'no-root-squash']),
        nfs_permission=dict(type='str', default='rw', choices=['rw', 'ro']),
        policy=dict(type='str', required=True, choices=['nfs', 'smb', 'snapshot']),
        name=dict(type='str', required=True),
        rename=dict(type='str'),
        client=dict(type='str'),
        enabled=dict(type='bool', default=True),
        snap_at=dict(type='str'),
        snap_every=dict(type='int'),
        snap_keep_for=dict(type='int'),
        snap_client_name=dict(type='str'),
        smb_anon_allowed=dict(type='bool', default=False),
        smb_encrypt=dict(type='bool', default=False),
    ))

    required_together = [['snap_keep_for', 'snap_every']]
    module = AnsibleModule(argument_spec,
                           required_together=required_together,
                           supports_check_mode=True)

    if not HAS_PURESTORAGE:
        module.fail_json(msg='py-pure-client sdk is required for this module')

    array = get_system(module)
    api_version = array._list_available_rest_versions()
    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(msg='FlashArray REST version not supported. '
                             'Minimum version required: {0}'.format(MIN_REQUIRED_API_VERSION))
    array = get_array(module)
    state = module.params['state']

    exists = bool(array.get_policies(names=[module.params['name']]).status_code == 200)

    if state == 'present' and not exists:
        create_policy(module, array)
    elif state == 'present' and exists and module.params['rename']:
        rename_policy(module, array)
    elif state == 'present' and exists:
        update_policy(module, array)
    elif state == 'absent' and exists:
        delete_policy(module, array)

    module.exit_json(changed=False)
Exemple #11
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(state=dict(type='str',
                        default='present',
                        choices=['absent', 'present']),
             enabled=dict(type='bool', default=True),
             name=dict(type='str', required=True),
             role=dict(type='str',
                       choices=[
                           'readonly', 'ops_admin', 'storage_admin',
                           'array_admin'
                       ]),
             public_key=dict(type='str', no_log=True),
             token_ttl=dict(type='int', default=86400),
             issuer=dict(type='str')))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    if not HAS_PURESTORAGE:
        module.fail_json(msg='py-pure-client sdk is required for this module')

    array = get_system(module)
    api_version = array._list_available_rest_versions()

    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(
            msg='FlashArray REST version not supported. '
            'Minimum version required: {0}'.format(MIN_REQUIRED_API_VERSION))
    array = get_array(module)
    state = module.params['state']

    try:
        client = list(
            array.get_api_clients(names=[module.params['name']]).items)[0]
        exists = True
    except Exception:
        exists = False

    if not exists and state == 'present':
        create_client(module, array)
    elif exists and state == 'present':
        update_client(module, array, client)
    elif exists and state == 'absent':
        delete_client(module, array)

    module.exit_json(changed=False)
Exemple #12
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(name=dict(type='str', required=True),
             state=dict(type='str',
                        default='present',
                        choices=['absent', 'present']),
             schedule=dict(type='str',
                           required=True,
                           choices=['replication', 'snapshot']),
             blackout_start=dict(type='str'),
             blackout_end=dict(type='str'),
             snap_at=dict(type='int'),
             replicate_at=dict(type='int'),
             replicate_frequency=dict(type='int'),
             snap_frequency=dict(type='int'),
             all_for=dict(type='int'),
             days=dict(type='int'),
             per_day=dict(type='int'),
             target_all_for=dict(type='int'),
             target_per_day=dict(type='int'),
             target_days=dict(type='int'),
             enabled=dict(type='bool', default=True)))

    required_together = [['blackout_start', 'blackout_end']]

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

    state = module.params['state']
    array = get_system(module)

    pgroup = get_pgroup(module, array)
    if module.params['snap_at'] and module.params['snap_frequency']:
        if not module.params['snap_frequency'] % 86400 == 0:
            module.fail_json(
                msg=
                "snap_at not valid unless snapshot frequency is measured in days, ie. a multiple of 86400"
            )
    if pgroup and state == 'present':
        update_schedule(module, array)
    elif pgroup and state == 'absent':
        delete_schedule(module, array)
    elif pgroup is None:
        module.fail_json(msg="Specified protection group {0} does not exist.".
                         format(module.params['pgroup']))
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            filesystem=dict(type='str', required=True),
            name=dict(type='str', required=True),
            rename=dict(type='str'),
            path=dict(type='str'),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    if not HAS_PURESTORAGE:
        module.fail_json(msg='py-pure-client sdk is required for this module')

    array = get_system(module)
    api_version = array._list_available_rest_versions()
    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(
            msg='FlashArray REST version not supported. '
            'Minimum version required: {0}'.format(MIN_REQUIRED_API_VERSION))
    array = get_array(module)
    state = module.params['state']

    try:
        filesystem = list(
            array.get_file_systems(
                names=[module.params['filesystem']]).items)[0]
    except Exception:
        module.fail_json(msg="Selected file system {0} does not exist".format(
            module.params['filesystem']))
    res = array.get_directories(
        names=[module.params['filesystem'] + ":" + module.params['name']])
    exists = bool(res.status_code == 200)

    if state == 'present' and not exists:
        create_dir(module, array)
    elif state == "present" and exists and module.params[
            'rename'] and not filesystem.destroyed:
        rename_dir(module, array)
    elif state == 'absent' and exists:
        delete_dir(module, array)

    module.exit_json(changed=False)
Exemple #14
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            uri=dict(type='list'),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            enable=dict(type='bool', default=False),
            bind_password=dict(type='str', no_log=True),
            bind_user=dict(type='str'),
            base_dn=dict(type='str'),
            group_base=dict(type='str'),
            ro_group=dict(type='str'),
            sa_group=dict(type='str'),
            aa_group=dict(type='str'),
        ))

    required_together = [[
        'uri', 'bind_password', 'bind_user', 'base_dn', 'group_base'
    ]]

    module = AnsibleModule(argument_spec,
                           required_together=required_together,
                           supports_check_mode=False)

    state = module.params['state']
    array = get_system(module)
    ds_exists = False
    dirserv = array.get_directory_service()
    ds_enabled = dirserv['enabled']
    if dirserv['base_dn']:
        ds_exists = True

    if state == 'absent' and ds_exists:
        delete_ds(module, array)
    elif ds_exists and module.params['enable'] and ds_enabled:
        update_ds(module, array)
    elif ds_exists and not module.params['enable'] and ds_enabled:
        disable_ds(module, array)
    elif ds_exists and module.params['enable'] and not ds_enabled:
        enable_ds(module, array)
    elif not ds_exists and state == 'present':
        create_ds(module, array)
    else:
        module.exit_json(changed=False)
Exemple #15
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(dict(
        name=dict(type='str', required=True),
        rename=dict(type='str'),
        host=dict(type='str'),
        hgroup=dict(type='str'),
        eradicate=dict(type='bool', default=False),
        state=dict(type='str', default='present', choices=['absent', 'present']),
    ))

    mutually_exclusive = [['rename', 'eradicate'],
                          ['host', 'hgroup']]

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

    state = module.params['state']
    destroyed = False
    array = get_system(module)
    api_version = array._list_available_rest_versions()
    if VGROUPS_API_VERSION not in api_version:
        module.fail_json(msg='Purity version does not support endpoints. Please contact support')
    volume = get_volume(module.params['name'], array)
    if volume:
        module.fail_json(msg='Volume {0} is an true volume. Please use the purefa_volume module'.format(module.params['name']))
    endpoint = get_endpoint(module.params['name'], array)
    if not endpoint:
        destroyed = get_destroyed_endpoint(module.params['name'], array)

    if state == 'present' and not endpoint and not destroyed:
        create_endpoint(module, array)
    elif state == 'present' and endpoint and module.params['rename']:
        rename_endpoint(module, array)
    elif state == 'present' and destroyed:
        recover_endpoint(module, array)
    elif state == 'absent' and endpoint:
        delete_endpoint(module, array)
    elif state == 'absent' and destroyed:
        eradicate_endpoint(module, array)
    elif state == 'absent' and not endpoint and not volume:
        module.exit_json(changed=False)

    module.exit_json(changed=False)
Exemple #16
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            name=dict(type='str', required=True),
            suffix=dict(type='str'),
            target=dict(type='str'),
            overwrite=dict(type='bool', default=False),
            eradicate=dict(type='bool', default=False),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'copy', 'present']),
        ))

    required_if = [('state', 'copy', ['target', 'suffix'])]

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

    if module.params['suffix'] is None:
        suffix = "snap-" + str(
            (datetime.utcnow() -
             datetime(1970, 1, 1, 0, 0, 0, 0)).total_seconds())
        module.params['suffix'] = suffix.replace(".", "")

    state = module.params['state']
    array = get_system(module)
    volume = get_volume(module, array)
    snap = get_snapshot(module, array)

    if state == 'present' and volume and not snap:
        create_snapshot(module, array)
    elif state == 'present' and volume and snap:
        update_snapshot(module, array)
    elif state == 'present' and not volume:
        update_snapshot(module, array)
    elif state == 'copy' and snap:
        create_from_snapshot(module, array)
    elif state == 'copy' and not snap:
        update_snapshot(module, array)
    elif state == 'absent' and snap:
        delete_snapshot(module, array)
    elif state == 'absent' and not snap:
        module.exit_json(changed=False)
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(dict(
        name=dict(type='str', required=True),
        state=dict(type='str', default='present', choices=['present']),
    ))

    module = AnsibleModule(argument_spec,
                           supports_check_mode=False)

    array = get_system(module)
    pattern = re.compile("^[a-zA-Z0-9]([a-zA-Z0-9-]{0,54}[a-zA-Z0-9])?$")
    if not pattern.match(module.params['name']):
        module.fail_json(msg='Array name {0} does not conform to array name rules'.format(module.params['name']))
    if module.params['name'] != array.get()['array_name']:
        update_name(module, array)

    module.exit_json(changed=False)
Exemple #18
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            address=dict(type='str', required=True),
            enabled=dict(type='bool', default=True),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    pattern = re.compile(r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$")
    if not pattern.match(module.params['address']):
        module.fail_json(msg='Valid email address not provided.')

    array = get_system(module)

    exists = False
    try:
        emails = array.list_alert_recipients()
    except Exception:
        module.fail_json(msg='Failed to get exisitng email list')
    for email in range(0, len(emails)):
        if emails[email]['name'] == module.params['address']:
            exists = True
            enabled = emails[email]['enabled']
            break
    if module.params['state'] == 'present' and not exists:
        create_alert(module, array)
    elif module.params[
            'state'] == 'present' and exists and not enabled and module.params[
                'enabled']:
        enable_alert(module, array)
    elif module.params[
            'state'] == 'present' and exists and enabled and not module.params[
                'enabled']:
        disable_alert(module, array)
    elif module.params['state'] == 'absent' and exists:
        delete_alert(module, array)

    module.exit_json(changed=False)
Exemple #19
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            name=dict(type="str", required=True),
            target_pod=dict(type="str"),
            target_array=dict(type="str"),
            pause=dict(type="bool"),
            state=dict(default="present", choices=["present", "absent"]),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    state = module.params["state"]
    array = get_system(module)
    api_version = array._list_available_rest_versions()

    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(msg="Purity v6.0.0 or higher required.")

    local_pod = get_local_pod(module, array)
    local_replica_link = get_local_rl(module, array)

    if not local_pod:
        module.fail_json(msg="Selected local pod {0} does not exist.".format(
            module.params["name"]))

    if len(local_pod["arrays"]) > 1:
        module.fail_json(msg="Local Pod {0} is already stretched.".format(
            module.params["name"]))

    if local_replica_link:
        if local_replica_link["status"] == "unhealthy":
            module.fail_json(
                msg="Replca Link unhealthy - please check remote array")
    if state == "present" and not local_replica_link:
        create_rl(module, array)
    elif state == "present" and local_replica_link:
        update_rl(module, array, local_replica_link)
    elif state == "absent" and local_replica_link:
        delete_rl(module, array, local_replica_link)

    module.exit_json(changed=False)
Exemple #20
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type="str",
                       default="present",
                       choices=["absent", "present"]),
            filesystem=dict(type="str", required=True),
            directory=dict(type="str", required=True),
            name=dict(type="str", required=True),
            nfs_policy=dict(type="str"),
            smb_policy=dict(type="str"),
        ))

    required_if = [["state", "present", ["filesystem", "directory"]]]
    module = AnsibleModule(argument_spec,
                           required_if=required_if,
                           supports_check_mode=True)

    if not HAS_PURESTORAGE:
        module.fail_json(msg="py-pure-client sdk is required for this module")

    array = get_system(module)
    api_version = array._list_available_rest_versions()
    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(
            msg="FlashArray REST version not supported. "
            "Minimum version required: {0}".format(MIN_REQUIRED_API_VERSION))
    array = get_array(module)
    state = module.params["state"]

    exists = bool(
        array.get_directory_exports(
            export_names=[module.params["name"]]).status_code == 200)

    if state == "present":
        create_export(module, array)
    elif state == "absent" and exists:
        delete_export(module, array)

    module.exit_json(changed=False)
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            filesystem=dict(type='str', required=True),
            directory=dict(type='str', required=True),
            name=dict(type='str', required=True),
            nfs_policy=dict(type='str'),
            smb_policy=dict(type='str'),
        ))

    required_if = [['state', 'present', ['filesystem', 'directory']]]
    module = AnsibleModule(argument_spec,
                           required_if=required_if,
                           supports_check_mode=True)

    if not HAS_PURESTORAGE:
        module.fail_json(msg='py-pure-client sdk is required for this module')

    array = get_system(module)
    api_version = array._list_available_rest_versions()
    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(
            msg='FlashArray REST version not supported. '
            'Minimum version required: {0}'.format(MIN_REQUIRED_API_VERSION))
    array = get_array(module)
    state = module.params['state']

    exists = bool(
        array.get_directory_exports(
            export_names=[module.params['name']]).status_code == 200)

    if state == 'present':
        create_export(module, array)
    elif state == 'absent' and exists:
        delete_export(module, array)

    module.exit_json(changed=False)
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(name=dict(type='str', required=True),
             target_pod=dict(type='str'),
             target_array=dict(type='str'),
             pause=dict(type='bool'),
             state=dict(default='present', choices=['present', 'absent'])))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    state = module.params['state']
    array = get_system(module)
    api_version = array._list_available_rest_versions()

    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(msg='Purity v6.0.0 or higher required.')

    local_pod = get_local_pod(module, array)
    local_replica_link = get_local_rl(module, array)

    if not local_pod:
        module.fail_json(msg='Selected local pod {0} does not exist.'.format(
            module.params['name']))

    if len(local_pod['arrays']) > 1:
        module.fail_json(msg='Local Pod {0} is already stretched.'.format(
            module.params['name']))

    if local_replica_link:
        if local_replica_link['status'] == 'unhealthy':
            module.fail_json(
                msg='Replca Link unhealthy - please check remote array')
    if state == 'present' and not local_replica_link:
        create_rl(module, array)
    elif state == 'present' and local_replica_link:
        update_rl(module, array, local_replica_link)
    elif state == 'absent' and local_replica_link:
        delete_rl(module, array, local_replica_link)

    module.exit_json(changed=False)
Exemple #23
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(dict(
        timeout=dict(type='int', default=30),
        state=dict(type='str', default='present', choices=['present', 'absent']),
    ))

    module = AnsibleModule(argument_spec,
                           supports_check_mode=True)

    state = module.params['state']
    if 5 < module.params['timeout'] > 180 and module.params['timeout'] != 0:
        module.fail_json(msg='Timeout value must be between 5 and 180 minutes')
    array = get_system(module)
    current_timeout = array.get(idle_timeout=True)['idle_timeout']
    if state == 'present' and current_timeout != module.params['timeout']:
        set_timeout(module, array)
    elif state == 'absent' and current_timeout != 0:
        disable_timeout(module, array)

    module.exit_json(changed=False)
Exemple #24
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            name=dict(type='str', required=True),
            subnet=dict(type='str', required=True),
            enabled=dict(type='bool', default=True),
            state=dict(type='str',
                       default='present',
                       choices=['present', 'absent']),
            address=dict(type='str'),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    state = module.params['state']
    array = get_system(module)
    subnet = _get_subnet(module, array)
    interface = _get_interface(module, array)
    if not subnet:
        module.fail_json(msg="Invalid subnet specified.")
    if not interface:
        module.fail_json(msg="Invalid interface specified.")
    if 'iscsi' not in interface['services']:
        module.fail_json(
            msg=
            "Invalid interface specified - must have the iSCSI service enabled."
        )
    if subnet['vlan']:
        vif_name = module.params['name'] + "." + str(subnet['vlan'])
    vif = bool(vif_name in subnet['interfaces'])

    if state == 'present' and not vif:
        create_vif(module, array, interface, subnet)
    elif state == 'present' and vif:
        update_vif(module, array, interface, subnet)
    elif state == 'absent' and vif:
        delete_vif(module, array, subnet)

    module.exit_json(changed=False)
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            role=dict(
                required=True,
                type="str",
                choices=[
                    "array_admin", "ops_admin", "readonly", "storage_admin"
                ],
            ),
            state=dict(type="str",
                       default="present",
                       choices=["absent", "present"]),
            group_base=dict(type="str"),
            group=dict(type="str"),
        ))

    required_together = [["group", "group_base"]]

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

    state = module.params["state"]
    array = get_system(module)
    role_configured = False
    role = array.list_directory_service_roles(names=[module.params["role"]])
    if role[0]["group"] is not None:
        role_configured = True

    if state == "absent" and role_configured:
        delete_role(module, array)
    elif role_configured and state == "present":
        update_role(module, array)
    elif not role_configured and state == "present":
        create_role(module, array)
    else:
        module.exit_json(changed=False)
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            role=dict(required=True,
                      type='str',
                      choices=[
                          'array_admin', 'ops_admin', 'readonly',
                          'storage_admin'
                      ]),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            group_base=dict(type='str'),
            group=dict(type='str'),
        ))

    required_together = [['group', 'group_base']]

    module = AnsibleModule(argument_spec,
                           required_together=required_together,
                           supports_check_mode=False)

    state = module.params['state']
    array = get_system(module)
    role_configured = False
    role = array.list_directory_services_roles(names=[module.params['role']])
    if role['group'] is not None:
        role_configured = True

    if state == 'absent' and role_configured:
        delete_role(module, array)
    elif role_configured and state == 'present':
        update_role(module, array)
    elif not role_configured and state == 'present':
        create_role(module, array)
    else:
        module.exit_json(changed=False)
Exemple #27
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            name=dict(type='str', required=True),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            bw_qos=dict(type='str'),
            iops_qos=dict(type='str'),
            eradicate=dict(type='bool', default=False),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    state = module.params['state']
    array = get_system(module)
    api_version = array._list_available_rest_versions()
    if VGROUP_API_VERSION not in api_version:
        module.fail_json(msg='API version does not support volume groups.')

    vgroup = get_vgroup(module, array)
    xvgroup = get_pending_vgroup(module, array)

    if xvgroup and state == 'present':
        recover_vgroup(module, array)
    elif vgroup and state == 'absent':
        delete_vgroup(module, array)
    elif xvgroup and state == 'absent' and module.params['eradicate']:
        eradicate_vgroup(module, array)
    elif not vgroup and not xvgroup and state == 'present':
        make_vgroup(module, array)
    elif vgroup and state == 'present':
        update_vgroup(module, array)
    elif vgroup is None and state == 'absent':
        module.exit_json(changed=False)

    module.exit_json(changed=False)
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            timeout=dict(type="int", default=30),
            state=dict(type="str",
                       default="present",
                       choices=["present", "absent"]),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    state = module.params["state"]
    if 5 < module.params["timeout"] > 180 and module.params["timeout"] != 0:
        module.fail_json(msg="Timeout value must be between 5 and 180 minutes")
    array = get_system(module)
    current_timeout = array.get(idle_timeout=True)["idle_timeout"]
    if state == "present" and current_timeout != module.params["timeout"]:
        set_timeout(module, array)
    elif state == "absent" and current_timeout != 0:
        disable_timeout(module, array)

    module.exit_json(changed=False)
Exemple #29
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(dict(
        state=dict(type='str', default='present', choices=['absent', 'present']),
        host=dict(type='str'),
        port=dict(type='int'),
    ))

    required_together = [['host', 'port']]

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

    state = module.params['state']
    array = get_system(module)

    if state == 'absent':
        delete_proxy(module, array)
    elif state == 'present':
        create_proxy(module, array)
    else:
        module.exit_json(changed=False)
Exemple #30
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            smis=dict(type="bool", default=True),
            slp=dict(type="bool", default=True),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    if not HAS_PURESTORAGE:
        module.fail_json(msg="py-pure-client sdk is required for this module")

    array = get_system(module)
    api_version = array._list_available_rest_versions()

    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(
            msg="FlashArray REST version not supported. "
            "Minimum version required: {0}".format(MIN_REQUIRED_API_VERSION))
    array = get_array(module)

    update_smis(module, array)