def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            name=dict(required=True, type='str'),
            state=dict(default='present', choices=['present', 'absent']),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    state = module.params['state']
    blade = get_blade(module)
    versions = blade.api_version.list_versions().versions

    if MIN_REQUIRED_API_VERSION not in versions:
        module.fail_json(msg='Minimum FlashBlade REST version required: {0}'.
                         format(MIN_REQUIRED_API_VERSION))

    s3acc = get_s3acc(module, blade)

    if state == 'absent' and s3acc:
        delete_s3acc(module, blade)
    elif state == 'present' and s3acc:
        update_s3acc(module, blade)
    elif not s3acc and state == 'present':
        create_s3acc(module, blade)
    else:
        module.exit_json(changed=False)
Esempio n. 2
0
def main():

    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            nameservers=dict(type="list", elements="str"),
            search=dict(type="list", elements="str"),
            domain=dict(type="str"),
            state=dict(type="str", default="present", choices=["absent", "present"]),
        )
    )

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    if not HAS_PURITY_FB:
        module.fail_json(msg="purity_fb sdk is required for this module")

    blade = get_blade(module)

    if module.params["state"] == "absent":
        delete_dns(module, blade)
    elif module.params["state"] == "present":
        if module.params["nameservers"]:
            module.params["nameservers"] = remove(module.params["nameservers"])
        if module.params["search"]:
            module.warn(
                "'search' parameter is deprecated and will be removed in Collection v1.6.0"
            )
        update_dns(module, blade)
    else:
        module.exit_json(changed=False)
Esempio n. 3
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            name=dict(type='str'),
            contents=dict(type='str', no_log=True),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    state = module.params['state']
    blade = get_blade(module)
    versions = blade.api_version.list_versions().versions

    if MIN_REQUIRED_API_VERSION not in versions:
        module.fail_json(msg='Minimum FlashBlade REST version required: {0}'.
                         format(MIN_REQUIRED_API_VERSION))

    try:
        cert = blade.certificates.list_certificates(
            names=[module.params['name']])
    except Exception:
        cert = None

    if not cert and state == 'present':
        create_cert(module, blade)
    elif state == 'absent' and cert:
        delete_cert(module, blade)

    module.exit_json(changed=False)
Esempio n. 4
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            banner=dict(type="str", default="Welcome to the machine..."),
            state=dict(type="str", default="present", choices=["present", "absent"]),
        )
    )

    required_if = [("state", "present", ["banner"])]

    module = AnsibleModule(
        argument_spec, required_if=required_if, supports_check_mode=True
    )
    if not HAS_PURITY_FB:
        module.fail_json(msg="purity_fb sdk is required for this module")

    state = module.params["state"]
    blade = get_blade(module)
    api_version = blade.api_version.list_versions().versions
    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(msg="Purity//FB must be upgraded to support this module.")
    current_banner = blade.login_banner.list_login_banner().login_banner

    # set banner if empty value or value differs
    if state == "present" and (
        not current_banner or current_banner != module.params["banner"]
    ):
        set_banner(module, blade)
    # clear banner if it has a value
    elif state == "absent" and current_banner:
        delete_banner(module, blade)

    module.exit_json(changed=False)
Esempio n. 5
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            address=dict(type="str"),
            protocol=dict(type="str", choices=["tcp", "tls", "udp"]),
            port=dict(type="str"),
            name=dict(type="str", required=True),
            state=dict(type="str",
                       default="present",
                       choices=["absent", "present"]),
        ))

    required_if = [["state", "present", ["address", "protocol"]]]

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

    if not HAS_PURITY_FB:
        module.fail_json(msg="purity_fb sdk is required for this module")

    blade = get_blade(module)
    api_version = blade.api_version.list_versions().versions
    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(
            msg="Purity//FB must be upgraded to support this module.")

    if module.params["state"] == "absent":
        delete_syslog(module, blade)
    else:
        add_syslog(module, blade)

    module.exit_json(changed=False)
Esempio n. 6
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(state=dict(type='str',
                        default='present',
                        choices=['present', 'absent']), ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    blade = get_blade(module)
    api_version = blade.api_version.list_versions().versions
    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(
            msg="Purity//FB must be upgraded to support this module.")

    if not HAS_PURITY_FB:
        module.fail_json(msg='purity_fb SDK is required for this module')

    if module.params['state'] == 'present' and not blade.support.list_support(
    ).items[0].remote_assist_active:
        enable_ra(module, blade)
    elif module.params['state'] == 'absent' and blade.support.list_support(
    ).items[0].remote_assist_active:
        disable_ra(module, blade)
    module.exit_json(changed=False)
Esempio n. 7
0
def main():
    argument_spec = purefb_argument_spec()

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

    module.exit_json(changed=False, purefb_info=generate_hardware_dict(blade))
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(dict(
        gather_subset=dict(default='minimum', type='list', elements='str')
    ))

    module = AnsibleModule(argument_spec, supports_check_mode=False)

    blade = get_blade(module)
    versions = blade.api_version.list_versions().versions

    if MIN_REQUIRED_API_VERSION not in versions:
        module.fail_json(msg='Minimum FlashBlade REST version required: {0}'.format(MIN_REQUIRED_API_VERSION))

    subset = [test.lower() for test in module.params['gather_subset']]
    valid_subsets = ('all', 'minimum', 'config', 'performance', 'capacity',
                     'network', 'subnets', 'lags', 'filesystems', 'snapshots',
                     'buckets', 'arrays', 'replication', 'policies')
    subset_test = (test in valid_subsets for test in subset)
    if not all(subset_test):
        module.fail_json(msg="value must gather_subset must be one or more of: %s, got: %s"
                         % (",".join(valid_subsets), ",".join(subset)))

    info = {}

    if 'minimum' in subset or 'all' in subset:
        info['default'] = generate_default_dict(blade)
    if 'performance' in subset or 'all' in subset:
        info['performance'] = generate_perf_dict(blade)
    if 'config' in subset or 'all' in subset:
        info['config'] = generate_config_dict(blade)
    if 'capacity' in subset or 'all' in subset:
        info['capacity'] = generate_capacity_dict(blade)
    if 'lags' in subset or 'all' in subset:
        info['lag'] = generate_lag_dict(blade)
    if 'network' in subset or 'all' in subset:
        info['network'] = generate_network_dict(blade)
    if 'subnets' in subset or 'all' in subset:
        info['subnet'] = generate_subnet_dict(blade)
    if 'filesystems' in subset or 'all' in subset:
        info['filesystems'] = generate_fs_dict(blade)
    if 'snapshots' in subset or 'all' in subset:
        info['snapshots'] = generate_snap_dict(blade)
    if 'buckets' in subset or 'all' in subset:
        info['buckets'] = generate_bucket_dict(blade)
    api_version = blade.api_version.list_versions().versions
    if POLICIES_API_VERSION in api_version:
        if 'policies' in subset or 'all' in subset:
            info['policies'] = generate_policies_dict(blade)
    if REPLICATION_API_VERSION in api_version:
        if 'arrays' in subset or 'all' in subset:
            info['arrays'] = generate_array_conn_dict(blade)
        if 'replication' in subset or 'all' in subset:
            info['file_replication'] = generate_file_repl_dict(blade)
            info['bucket_replication'] = generate_bucket_repl_dict(blade)
            info['snap_transfers'] = generate_snap_transfer_dict(blade)
            info['remote_credentials'] = generate_remote_creds_dict(blade)
            info['targets'] = generate_targets_dict(blade)

    module.exit_json(changed=False, purefb_info=info)
Esempio n. 9
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            name=dict(type='str', required=True),
            address=dict(type='str'),
        ))

    required_if = [['state', 'present', ['address']]]

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

    if not HAS_PURITYFB:
        module.fail_json(msg='purity_fb sdk is required for this module')

    state = module.params['state']
    blade = get_blade(module)
    _check_replication_configured(module, blade)
    target = _check_connected(module, blade)
    if state == 'present' and not target:
        create_connection(module, blade)
    elif state == 'present' and target:
        update_connection(module, blade, target)
    elif state == 'absent' and target:
        break_connection(module, blade)

    module.exit_json(changed=False)
Esempio n. 10
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            address=dict(type='str'),
            protocol=dict(type='str', choices=['tcp', 'tls', 'udp']),
            port=dict(type='str'),
            name=dict(type='str', required=True),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
        ))

    required_if = [['state', 'present', ['address', 'protocol']]]

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

    if not HAS_PURITY_FB:
        module.fail_json(msg='purity_fb sdk is required for this module')

    blade = get_blade(module)
    api_version = blade.api_version.list_versions().versions
    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(
            msg="Purity//FB must be upgraded to support this module.")

    if module.params['state'] == 'absent':
        delete_syslog(module, blade)
    else:
        add_syslog(module, blade)

    module.exit_json(changed=False)
def main():
    argument_spec = purefb_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)

    if not HAS_PURITY_FB:
        module.fail_json(msg='purity_fb sdk is required for this module')

    state = module.params['state']
    blade = get_blade(module)
    role_configured = False
    role = blade.directory_services.list_directory_services_roles(names=[module.params['role']])
    if role.items[0].group is not None:
        role_configured = True

    if state == 'absent' and role_configured:
        delete_role(module, blade)
    elif role_configured and state == 'present':
        update_role(module, blade)
    elif not role_configured and state == 'present':
        create_role(module, blade)
    else:
        module.exit_json(changed=False)
Esempio n. 12
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            name=dict(required=True),
            state=dict(default="present", choices=["present", "absent"]),
            address=dict(),
            services=dict(default="data", choices=["data", "replication"]),
            itype=dict(default="vip", choices=["vip"]),
        ))

    required_if = [["state", "present", ["address"]]]

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

    if not HAS_PURITY_FB:
        module.fail_json(msg="purity_fb sdk is required for this module")

    state = module.params["state"]
    blade = get_blade(module)
    api_version = blade.api_version.list_versions().versions
    if MINIMUM_API_VERSION not in api_version:
        module.fail_json(msg="Upgrade Purity//FB to enable this module")
    iface = get_iface(module, blade)

    if state == "present" and not iface:
        create_iface(module, blade)
    elif state == "present" and iface:
        modify_iface(module, blade)
    elif state == "absent" and iface:
        delete_iface(module, blade)
    elif state == "absent" and not iface:
        module.exit_json(changed=False)
Esempio n. 13
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type="str", default="present", choices=["absent", "present"]),
            name=dict(type="str", required=True),
            address=dict(type="str"),
        )
    )

    required_if = [["state", "present", ["address"]]]

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

    if not HAS_PURITYFB:
        module.fail_json(msg="purity_fb sdk is required for this module")

    state = module.params["state"]
    blade = get_blade(module)
    _check_replication_configured(module, blade)
    target = _check_connected(module, blade)
    if state == "present" and not target:
        create_connection(module, blade)
    elif state == "present" and target:
        update_connection(module, blade, target)
    elif state == "absent" and target:
        break_connection(module, blade)

    module.exit_json(changed=False)
Esempio n. 14
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type="str", default="present", choices=["present", "absent"]),
        )
    )

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    blade = get_blade(module)
    api_version = blade.api_version.list_versions().versions
    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(msg="Purity//FB must be upgraded to support this module.")

    if not HAS_PURITY_FB:
        module.fail_json(msg="purity_fb SDK is required for this module")

    if (
        module.params["state"] == "present"
        and not blade.support.list_support().items[0].phonehome_enabled
    ):
        enable_ph(module, blade)
    elif (
        module.params["state"] == "absent"
        and blade.support.list_support().items[0].phonehome_enabled
    ):
        disable_ph(module, blade)
    module.exit_json(changed=False)
Esempio n. 15
0
def main():

    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            nameservers=dict(type='list', elements='str'),
            search=dict(type='list', elements='str'),
            domain=dict(type='str'),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    if not HAS_PURITY_FB:
        module.fail_json(msg='purity_fb sdk is required for this module')

    blade = get_blade(module)

    if module.params['state'] == 'absent':
        delete_dns(module, blade)
    elif module.params['state'] == 'present':
        if module.params['nameservers']:
            module.params['nameservers'] = remove(module.params['nameservers'])
        if module.params['search']:
            module.params['search'] = remove(module.params['search'])
        update_dns(module, blade)
    else:
        module.exit_json(changed=False)
def main():
    argument_spec = purefb_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)

    if not HAS_PURITY_FB:
        module.fail_json(msg='purity_fb SDK is required for this module')

    state = module.params['state']
    blade = get_blade(module)

    if state == 'absent':
        delete_proxy(module, blade)
    elif state == 'present':
        create_proxy(module, blade)
    else:
        module.exit_json(changed=False)
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(name=dict(type='str', required=True),
             target=dict(type='str'),
             target_bucket=dict(type='str'),
             paused=dict(type='bool', default=False),
             credential=dict(type='str'),
             state=dict(default='present', choices=['present', 'absent'])))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    if not HAS_PURITY_FB:
        module.fail_json(msg='purity_fb sdk is required for this module')

    state = module.params['state']
    module.params['name'] = module.params['name'].lower()
    blade = get_blade(module)
    versions = blade.api_version.list_versions().versions

    if MIN_REQUIRED_API_VERSION not in versions:
        module.fail_json(msg='Minimum FlashBlade REST version required: {0}'.
                         format(MIN_REQUIRED_API_VERSION))

    local_bucket = get_local_bucket(module, blade)
    local_replica_link = get_local_rl(module, blade)
    target = get_connected(module, blade)

    if not target:
        module.fail_json(msg='Selected target {0} is not connected.'.format(
            module.params['target']))

    if local_replica_link and not module.params['credential']:
        module.params[
            'credential'] = local_replica_link.remote_credentials.name.split(
                '/')[1]
    remote_cred = get_remote_cred(module, blade, target)
    if not remote_cred:
        module.fail_json(
            msg='Selected remote credential {0} does not exist for target {1}.'
            .format(module.params['credential'], module.params['target']))

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

    if local_replica_link:
        if local_replica_link.status == 'unhealthy':
            module.fail_json(
                msg='Replica Link unhealthy - please check target')

    if state == 'present' and not local_replica_link:
        create_rl(module, blade, remote_cred)
    elif state == 'present' and local_replica_link:
        update_rl_policy(module, blade, local_replica_link)
    elif state == 'absent' and local_replica_link:
        delete_rl_policy(module, blade, local_replica_link)

    module.exit_json(changed=False)
Esempio n. 18
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            name=dict(required=True),
            suffix=dict(type="str"),
            eradicate=dict(default="false", type="bool"),
            state=dict(default="present", choices=["present", "absent", "restore"]),
        )
    )

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    if not HAS_PURITY_FB:
        module.fail_json(msg="purity_fb sdk is required for this module")

    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"]
    blade = get_blade(module)
    filesystem = get_fs(module, blade)
    snap = get_fssnapshot(module, blade)

    if state == "present" and filesystem and not filesystem.destroyed and not snap:
        create_snapshot(module, blade)
    elif (
        state == "present"
        and filesystem
        and not filesystem.destroyed
        and snap
        and not snap.destroyed
    ):
        update_snapshot(module, blade)
    elif (
        state == "present"
        and filesystem
        and not filesystem.destroyed
        and snap
        and snap.destroyed
    ):
        recover_snapshot(module, blade)
    elif state == "present" and filesystem and filesystem.destroyed:
        update_snapshot(module, blade)
    elif state == "present" and not filesystem:
        update_snapshot(module, blade)
    elif state == "restore" and filesystem:
        restore_snapshot(module, blade)
    elif state == "absent" and snap and not snap.destroyed:
        delete_snapshot(module, blade)
    elif state == "absent" and snap and snap.destroyed:
        eradicate_snapshot(module, blade)
    elif state == "absent" and not snap:
        module.exit_json(changed=False)
    else:
        module.exit_json(changed=False)
Esempio n. 19
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            name=dict(required=True, type="str"),
            account=dict(required=True, type="str"),
            access_key=dict(default="false", type="bool"),
            imported_key=dict(type="str", no_log=False),
            remove_key=dict(type="str", no_log=False),
            imported_secret=dict(type="str", no_log=True),
            state=dict(default="present", choices=["present", "absent", "remove_key"]),
        )
    )

    required_together = [["imported_key", "imported_secret"]]
    required_if = [["state", "remove_key", ["remove_key"]]]

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

    if not HAS_PURITY_FB:
        module.fail_json(msg="purity_fb sdk is required for this module")

    state = module.params["state"]
    blade = get_blade(module)
    versions = blade.api_version.list_versions().versions

    if MIN_REQUIRED_API_VERSION not in versions:
        module.fail_json(
            msg="Minimum FlashBlade REST version required: {0}".format(
                MIN_REQUIRED_API_VERSION
            )
        )

    s3acc = get_s3acc(module, blade)
    if not s3acc:
        module.fail_json(
            msg="Object Store Account {0} does not exist".format(
                module.params["account"]
            )
        )

    s3user = get_s3user(module, blade)

    if state == "absent" and s3user:
        delete_s3user(module, blade)
    elif state == "present" and s3user:
        update_s3user(module, blade)
    elif not s3user and state == "present":
        create_s3user(module, blade)
    elif state == "remove_key" and s3user:
        remove_key(module, blade)
    else:
        module.exit_json(changed=False)
Esempio n. 20
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(dict(
        name=dict(type='str', required=True),
        host=dict(type='str'),
        state=dict(type='str', default='present', choices=['absent', 'present']),
        user=dict(type='str'),
        notification=dict(type='str', choices=['inform', 'trap'], default='trap'),
        auth_passphrase=dict(type='str', no_log=True),
        auth_protocol=dict(type='str', choices=['MD5', 'SHA']),
        privacy_passphrase=dict(type='str', no_log=True),
        privacy_protocol=dict(type='str', choices=['AES', 'DES']),
        version=dict(type='str', choices=['v2c', 'v3']),
        community=dict(type='str'),
    ))

    required_together = [['auth_passphrase', 'auth_protocol'],
                         ['privacy_passphrase', 'privacy_protocol']]
    required_if = [['version', 'v2c', ['community', 'host']],
                   ['version', 'v3', ['host', 'user']]]

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

    state = module.params['state']
    blade = get_blade(module)
    api_version = blade.api_version.list_versions().versions

    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(msg="Purity//FB must be upgraded to support this module.")

    if not HAS_PURITY_FB:
        module.fail_json(msg='purity_fb SDK is required for this module')

    mgr_configured = False
    mgrs = blade.snmp_managers.list_snmp_managers()
    for mgr in range(0, len(mgrs.items)):
        if mgrs.items[mgr].name == module.params['name']:
            mgr_configured = True
            break
    if module.params['version'] == "v3":
        if module.params['auth_passphrase'] and (8 > len(module.params['auth_passphrase']) > 32):
            module.fail_json(msg="auth_password must be between 8 and 32 characters")
        if module.params['privacy_passphrase'] and 8 > len(module.params['privacy_passphrase']) > 63:
            module.fail_json(msg="privacy_password must be between 8 and 63 characters")
    if state == 'absent' and mgr_configured:
        delete_manager(module, blade)
    elif mgr_configured and state == 'present':
        update_manager(module, blade)
    elif not mgr_configured and state == 'present':
        create_manager(module, blade)
    else:
        module.exit_json(changed=False)
Esempio n. 21
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(name=dict(type='str', required=True),
             target_fs=dict(type='str'),
             target_array=dict(type='str'),
             policy=dict(type='str'),
             state=dict(default='present', choices=['present', 'absent'])))

    required_if = [['state', 'absent', ['policy']]]

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

    if not HAS_PURITY_FB:
        module.fail_json(msg='purity_fb sdk is required for this module')

    state = module.params['state']
    blade = get_blade(module)
    versions = blade.api_version.list_versions().versions

    if MIN_REQUIRED_API_VERSION not in versions:
        module.fail_json(msg='Minimum FlashBlade REST version required: {0}'.
                         format(MIN_REQUIRED_API_VERSION))

    local_fs = get_local_fs(module, blade)
    local_replica_link = get_local_rl(module, blade)

    if not local_fs:
        module.fail_json(msg='Selected local filesystem {0} does not exist.'.
                         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 module.params['policy']:
        try:
            policy = blade.policies.list_policies(
                names=[module.params['policy']])
        except Exception:
            module.fail_json(msg='Selected policy {0} does not exist.'.format(
                module.params['policy']))
    else:
        policy = None
    if state == 'present' and not local_replica_link:
        create_rl(module, blade)
    elif state == 'present' and local_replica_link and policy:
        add_rl_policy(module, blade)
    elif state == 'absent' and policy:
        delete_rl_policy(module, blade)

    module.exit_json(changed=False)
Esempio n. 22
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            name=dict(type="str", required=True),
            target_fs=dict(type="str"),
            target_array=dict(type="str"),
            policy=dict(type="str"),
            state=dict(default="present", choices=["present", "absent"]),
        ))

    required_if = [["state", "absent", ["policy"]]]

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

    if not HAS_PURITY_FB:
        module.fail_json(msg="purity_fb sdk is required for this module")

    state = module.params["state"]
    blade = get_blade(module)
    versions = blade.api_version.list_versions().versions

    if MIN_REQUIRED_API_VERSION not in versions:
        module.fail_json(msg="Minimum FlashBlade REST version required: {0}".
                         format(MIN_REQUIRED_API_VERSION))

    local_fs = get_local_fs(module, blade)
    local_replica_link = get_local_rl(module, blade)

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

    if module.params["policy"]:
        try:
            policy = blade.policies.list_policies(
                names=[module.params["policy"]])
        except Exception:
            module.fail_json(msg="Selected policy {0} does not exist.".format(
                module.params["policy"]))
    else:
        policy = None
    if state == "present" and not local_replica_link:
        create_rl(module, blade)
    elif state == "present" and local_replica_link and policy:
        add_rl_policy(module, blade)
    elif state == "absent" and policy:
        delete_rl_policy(module, blade)

    module.exit_json(changed=False)
Esempio n. 23
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(name=dict(type='str', required=True),
             eradicate=dict(default='false', type='bool'),
             nfsv3=dict(default='true', type='bool'),
             nfsv4=dict(default='true', type='bool'),
             nfs_rules=dict(type='str'),
             smb=dict(default='false', type='bool'),
             http=dict(default='false', type='bool'),
             snapshot=dict(default='false', type='bool'),
             writable=dict(type='bool'),
             promote=dict(type='bool'),
             fastremove=dict(default='false', type='bool'),
             hard_limit=dict(default='false', type='bool'),
             user_quota=dict(type='str'),
             policy=dict(type='str'),
             group_quota=dict(type='str'),
             smb_aclmode=dict(type='str',
                              default='shared',
                              choices=['shared', 'native']),
             policy_state=dict(default='present',
                               choices=['present', 'absent']),
             state=dict(default='present', choices=['present', 'absent']),
             delete_link=dict(default=False, type='bool'),
             discard_snaps=dict(default=False, type='bool'),
             size=dict(type='str')))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    if not HAS_PURITY_FB:
        module.fail_json(msg='purity_fb sdk is required for this module')

    state = module.params['state']
    blade = get_blade(module)
    fsys = get_fs(module, blade)

    if module.params['eradicate'] and state == 'present':
        module.warn('Eradicate flag ignored without state=absent')

    if state == 'present' and not fsys:
        create_fs(module, blade)
    elif state == 'present' and fsys:
        modify_fs(module, blade)
    elif state == 'absent' and fsys and not fsys.destroyed:
        delete_fs(module, blade)
    elif state == 'absent' and fsys and fsys.destroyed and module.params[
            'eradicate']:
        eradicate_fs(module, blade)
    elif state == 'absent' and not fsys:
        module.exit_json(changed=False)
    module.exit_json(changed=False)
Esempio n. 24
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            name=dict(required=True),
            account=dict(required=True),
            eradicate=dict(default="false", type="bool"),
            versioning=dict(
                default="absent", choices=["enabled", "suspended", "absent"]
            ),
            state=dict(default="present", choices=["present", "absent"]),
        )
    )

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    if not HAS_PURITY_FB:
        module.fail_json(msg="purity_fb sdk is required for this module")

    state = module.params["state"]
    blade = get_blade(module)
    api_version = blade.api_version.list_versions().versions
    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(msg="Purity//FB must be upgraded to support this module.")
    bucket = get_bucket(module, blade)
    if not get_s3acc(module, blade):
        module.fail_json(
            msg="Object Store Account {0} does not exist.".format(
                module.params["account"]
            )
        )

    if module.params["eradicate"] and state == "present":
        module.warn("Eradicate flag ignored without state=absent")

    if state == "present" and not bucket:
        create_bucket(module, blade)
    elif state == "present" and bucket and bucket.destroyed:
        recover_bucket(module, blade)
    elif state == "absent" and bucket and not bucket.destroyed:
        delete_bucket(module, blade)
    elif state == "present" and bucket:
        update_bucket(module, blade, bucket)
    elif (
        state == "absent" and bucket and bucket.destroyed and module.params["eradicate"]
    ):
        eradicate_bucket(module, blade)
    elif state == "absent" and not bucket:
        module.exit_json(changed=False)

    module.exit_json(changed=False)
Esempio n. 25
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            user=dict(type="str"),
            auth_passphrase=dict(type="str", no_log=True),
            auth_protocol=dict(type="str", choices=["MD5", "SHA"]),
            privacy_passphrase=dict(type="str", no_log=True),
            privacy_protocol=dict(type="str", choices=["AES", "DES"]),
            version=dict(type="str", choices=["v2c", "v3"]),
            community=dict(type="str"),
        ))

    required_together = [
        ["auth_passphrase", "auth_protocol"],
        ["privacy_passphrase", "privacy_protocol"],
    ]
    required_if = [["version", "v2c", ["community"]],
                   ["version", "v3", ["user"]]]

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

    blade = get_blade(module)
    api_version = blade.api_version.list_versions().versions

    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(
            msg="Purity//FB must be upgraded to support this module.")

    if not HAS_PURITY_FB:
        module.fail_json(msg="purity_fb SDK is required for this module")

    if module.params["version"] == "v3":
        if module.params["auth_passphrase"] and (8 > len(
                module.params["auth_passphrase"]) > 32):
            module.fail_json(
                msg="auth_password must be between 8 and 32 characters")
        if (module.params["privacy_passphrase"]
                and 8 > len(module.params["privacy_passphrase"]) > 63):
            module.fail_json(
                msg="privacy_password must be between 8 and 63 characters")

    update_agent(module, blade)

    module.exit_json(changed=False)
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            enabled=dict(type='bool', default=True),
            timezone=dict(type='str'),
            name=dict(type='str'),
            at=dict(type='str'),
            every=dict(type='int'),
            keep_for=dict(type='int'),
            filesystem=dict(type='list', elements='str'),
            replica_link=dict(type='list', elements='str'),
        ))

    required_together = [['keep_for', 'every']]

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

    if not HAS_PURITYFB:
        module.fail_json(msg='purity_fb sdk is required for this module')
    if not HAS_PYTZ:
        module.fail_json(msg='pytz is required for this module')

    state = module.params['state']
    blade = get_blade(module)
    versions = blade.api_version.list_versions().versions

    if MIN_REQUIRED_API_VERSION not in versions:
        module.fail_json(msg='Minimum FlashBlade REST version required: {0}'.
                         format(MIN_REQUIRED_API_VERSION))

    try:
        policy = blade.policies.list_policies(names=[module.params['name']])
    except Exception:
        policy = None

    if policy and state == 'present':
        update_policy(module, blade, policy.items[0])
    elif state == 'present' and not policy:
        create_policy(module, blade)
    elif state == 'absent' and policy:
        delete_policy(module, blade)

    module.exit_json(changed=False)
Esempio n. 27
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type="str",
                       default="present",
                       choices=["absent", "present"]),
            enabled=dict(type="bool", default=True),
            timezone=dict(type="str"),
            name=dict(type="str"),
            at=dict(type="str"),
            every=dict(type="int"),
            keep_for=dict(type="int"),
            filesystem=dict(type="list", elements="str"),
            replica_link=dict(type="list", elements="str"),
        ))

    required_together = [["keep_for", "every"]]

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

    if not HAS_PURITYFB:
        module.fail_json(msg="purity_fb sdk is required for this module")
    if not HAS_PYTZ:
        module.fail_json(msg="pytz is required for this module")

    state = module.params["state"]
    blade = get_blade(module)
    versions = blade.api_version.list_versions().versions

    if MIN_REQUIRED_API_VERSION not in versions:
        module.fail_json(msg="Minimum FlashBlade REST version required: {0}".
                         format(MIN_REQUIRED_API_VERSION))

    try:
        policy = blade.policies.list_policies(names=[module.params["name"]])
    except Exception:
        policy = None

    if policy and state == "present":
        update_policy(module, blade, policy.items[0])
    elif state == "present" and not policy:
        create_policy(module, blade)
    elif state == "absent" and policy:
        delete_policy(module, blade)

    module.exit_json(changed=False)
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type='str',
                       default='present',
                       choices=['present', 'absent']),
            name=dict(type='str', required=True),
            access_key=dict(type='str'),
            secret=dict(type='str', no_log=True),
            target=dict(type='str', required=True),
        ))

    required_if = [['state', 'present', ['access_key', 'secret']]]

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

    if not HAS_PURITY_FB:
        module.fail_json(msg='purity_fb sdk is required for this module')

    blade = get_blade(module)
    api_version = blade.api_version.list_versions().versions

    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(
            msg='FlashBlade REST version not supported. '
            'Minimum version required: {0}'.format(MIN_REQUIRED_API_VERSION))

    target = get_connected(module, blade)

    if not target:
        module.fail_json(msg='Selected target {0} is not connected.'.format(
            module.params['target']))

    remote_cred = get_remote_cred(module, blade)

    if module.params['state'] == 'present' and not remote_cred:
        create_credential(module, blade)
    elif module.params['state'] == 'present':
        update_credential(module, blade)
    elif module.params['state'] == 'absent' and remote_cred:
        delete_credential(module, blade)

    module.exit_json(changed=False)
Esempio n. 29
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            user=dict(type='str'),
            auth_passphrase=dict(type='str', no_log=True),
            auth_protocol=dict(type='str', choices=['MD5', 'SHA']),
            privacy_passphrase=dict(type='str', no_log=True),
            privacy_protocol=dict(type='str', choices=['AES', 'DES']),
            version=dict(type='str', choices=['v2c', 'v3']),
            community=dict(type='str'),
        ))

    required_together = [['auth_passphrase', 'auth_protocol'],
                         ['privacy_passphrase', 'privacy_protocol']]
    required_if = [['version', 'v2c', ['community']],
                   ['version', 'v3', ['user']]]

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

    blade = get_blade(module)
    api_version = blade.api_version.list_versions().versions

    if MIN_REQUIRED_API_VERSION not in api_version:
        module.fail_json(
            msg="Purity//FB must be upgraded to support this module.")

    if not HAS_PURITY_FB:
        module.fail_json(msg='purity_fb SDK is required for this module')

    if module.params['version'] == "v3":
        if module.params['auth_passphrase'] and (8 > len(
                module.params['auth_passphrase']) > 32):
            module.fail_json(
                msg="auth_password must be between 8 and 32 characters")
        if module.params['privacy_passphrase'] and 8 > len(
                module.params['privacy_passphrase']) > 63:
            module.fail_json(
                msg="privacy_password must be between 8 and 63 characters")

    update_agent(module, blade)

    module.exit_json(changed=False)
Esempio n. 30
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type="str",
                       default="present",
                       choices=["present", "absent"]),
            name=dict(type="str", required=True),
            access_key=dict(type="str", no_log=False),
            secret=dict(type="str", no_log=True),
            target=dict(type="str", required=True),
        ))

    required_if = [["state", "present", ["access_key", "secret"]]]

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

    if not HAS_PURITY_FB:
        module.fail_json(msg="purity_fb sdk is required for this module")

    blade = get_blade(module)
    api_version = blade.api_version.list_versions().versions

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

    target = get_connected(module, blade)

    if not target:
        module.fail_json(msg="Selected target {0} is not connected.".format(
            module.params["target"]))

    remote_cred = get_remote_cred(module, blade)

    if module.params["state"] == "present" and not remote_cred:
        create_credential(module, blade)
    elif module.params["state"] == "present":
        update_credential(module, blade)
    elif module.params["state"] == "absent" and remote_cred:
        delete_credential(module, blade)

    module.exit_json(changed=False)