Exemplo n.º 1
0
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=False)

    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=
            'FlashBlade REST version not supported. Minimum 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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(gather_subset=dict(
            default='minimum',
            type='list',
        )))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

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

    if MIN_REQUIRED_API_VERSION not in versions:
        module.fail_json(
            msg=
            'FlashBlade REST version not supported. Minimum 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')
    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)))

    facts = {}

    if 'minimum' in subset or 'all' in subset:
        facts['default'] = generate_default_dict(blade)
    if 'performance' in subset or 'all' in subset:
        facts['performance'] = generate_perf_dict(blade)
    if 'config' in subset or 'all' in subset:
        facts['config'] = generate_config_dict(blade)
    if 'capacity' in subset or 'all' in subset:
        facts['capacity'] = generate_capacity_dict(blade)
    if 'lags' in subset or 'all' in subset:
        facts['lag'] = generate_lag_dict(blade)
    if 'network' in subset or 'all' in subset:
        facts['network'] = generate_network_dict(blade)
    if 'subnets' in subset or 'all' in subset:
        facts['subnet'] = generate_subnet_dict(blade)
    if 'filesystems' in subset or 'all' in subset:
        facts['filesystems'] = generate_fs_dict(blade)
    if 'snapshots' in subset or 'all' in subset:
        facts['snapshots'] = generate_snap_dict(blade)

    module.exit_json(ansible_facts={'ansible_purefb_facts': facts})
Exemplo n.º 4
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            name=dict(required=True),
            eradicate=dict(default='false', type='bool'),
            nfs=dict(removed_in_version='2.10', default='true', type='bool'),
            nfsv3=dict(default='true', type='bool'),
            nfsv4=dict(default='true', type='bool'),
            nfs_rules=dict(default='*(rw,no_root_squash)'),
            smb=dict(default='false', type='bool'),
            http=dict(default='false', type='bool'),
            snapshot=dict(default='false', type='bool'),
            fastremove=dict(default='false', type='bool'),
            hard_limit=dict(default='false', type='bool'),
            user_quota=dict(type='str'),
            group_quota=dict(type='str'),
            state=dict(default='present', choices=['present', 'absent']),
            size=dict()
        )
    )

    mutually_exclusive = [['nfs', 'nfsv3']]

    module = AnsibleModule(argument_spec,
                           mutually_exclusive=mutually_exclusive,
                           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 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)
Exemplo n.º 5
0
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=False)

    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)
Exemplo n.º 6
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'])
        )
    )

    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)
    fs = get_fs(module, blade)
    snap = get_fssnapshot(module, blade)

    if state == 'present' and fs and not fs.destroyed and not snap:
        create_snapshot(module, blade)
    elif state == 'present' and fs and not fs.destroyed and snap and not snap.destroyed:
        update_snapshot(module, blade)
    elif state == 'present' and fs and not fs.destroyed and snap and snap.destroyed:
        recover_snapshot(module, blade)
    elif state == 'present' and fs and fs.destroyed:
        update_snapshot(module, blade)
    elif state == 'present' and not fs:
        update_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)
Exemplo n.º 7
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            host=dict(type='str'),
            domain=dict(type='str', required=True),
        ))

    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')

    set_smtp(module, blade)
    module.exit_json(changed=False)
Exemplo n.º 8
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='true', type='bool'),
            state=dict(default='present', choices=['present', 'absent']),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=False)

    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=
            'FlashBlade REST version not supported. Minimum 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)
    else:
        module.exit_json(changed=False)
Exemplo n.º 9
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'),
            state=dict(default='present', choices=['present', 'absent']),
        ))

    module = AnsibleModule(argument_spec)

    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 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 == '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)
Exemplo n.º 10
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']),
            itype=dict(default='vip', choices=['vip']),
        )
    )

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

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

    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)
Exemplo n.º 11
0
def main():
    argument_spec = purefb_argument_spec()
    argument_spec.update(
        dict(
            uri=dict(type='list'),
            dstype=dict(required=True,
                        type='str',
                        choices=['management', 'nfs', 'smb']),
            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'),
            join_ou=dict(type='str'),
            nis_domain=dict(type='str'),
            nis_servers=dict(type='list'),
        ))

    required_together = [['uri', 'bind_password', 'bind_user', 'base_dn'],
                         ['nis_servers', 'nis_domain'], ['join_ou', 'uri']]
    mutually_exclusive = [['uri', 'nis_domain']]

    module = AnsibleModule(argument_spec,
                           required_together=required_together,
                           mutually_exclusive=mutually_exclusive,
                           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
    ds_configured = False
    dirserv = blade.directory_services.list_directory_services(
        names=[module.params['dstype']])
    ds_enabled = dirserv.items[0].enabled
    if dirserv.items[0].base_dn is not None:
        ds_configured = True
    if (module.params['nis_domain'] or
            module.params['join_ou']) and (NIS_API_VERSION not in api_version):
        module.fail_json(
            msg=
            "NFS or SMB directory service attributes are not supported in your FlashBlade Purity version."
        )
    ldap_uri = False
    set_ldap = False
    for uri in range(0, len(dirserv.items[0].uris)):
        if "ldap" in dirserv.items[0].uris[uri].lower():
            ldap_uri = True
    if module.params['uri']:
        for uri in range(0, len(module.params['uri'])):
            if "ldap" in module.params['uri'][uri].lower():
                set_ldap = True
    if not module.params['uri'] and ldap_uri or \
       module.params['uri'] and set_ldap:
        if module.params['nis_servers'] or module.params['nis_domain']:
            module.fail_json(
                msg="NIS configuration not supported in an LDAP environment")
    if state == 'absent':
        delete_ds(module, blade)
    elif ds_configured and module.params['enable'] and ds_enabled:
        update_ds(module, blade)
    elif ds_configured and not module.params['enable'] and ds_enabled:
        disable_ds(module, blade)
    elif ds_configured and module.params['enable'] and not ds_enabled:
        enable_ds(module, blade)
        # Now we have enabled the DS lets make sure there aren't any new updates...
        update_ds(module, blade)
    elif not ds_configured and state == 'present':
        create_ds(module, blade)
    else:
        module.exit_json(changed=False)
Exemplo 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']),
            gateway=dict(),
            mtu=dict(type='int', default=1500),
            prefix=dict(),
            vlan=dict(type='int', default=0),
        ))

    required_if = [["state", "present", ["gateway", 'prefix']]]

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

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

    if not HAS_NETADDR:
        module.fail_json(msg='netaddr module is required')

    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')
    subnet = get_subnet(module, blade)
    if state == 'present':
        if not (1280 <= module.params['mtu'] <= 9216):
            module.fail_json(msg='MTU {0} is out of range (1280 to 9216)'.
                             format(module.params['mtu']))
        if not (0 <= module.params['vlan'] <= 4094):
            module.fail_json(msg='VLAN ID {0} is out of range (0 to 4094)'.
                             format(module.params['vlan']))
        if netaddr.IPAddress(
                module.params['gateway']) not in netaddr.IPNetwork(
                    module.params['prefix']):
            module.fail_json(msg='Gateway and subnet are not compatible.')
        subnets = blade.subnets.list_subnets()
        nrange = netaddr.IPSet([module.params['prefix']])
        for sub in range(0, len(subnets.items)):
            if subnets.items[sub].vlan == module.params[
                    'vlan'] and subnets.items[sub].name != module.params[
                        'name']:
                module.fail_json(msg='VLAN ID {0} is already in use.'.format(
                    module.params['vlan']))
            if nrange & netaddr.IPSet([
                    subnets.items[sub].prefix
            ]) and subnets.items[sub].name != module.params['name']:
                module.fail_json(
                    msg='Prefix CIDR overlaps with existing subnet.')

    if state == 'present' and not subnet:
        create_subnet(module, blade)
    elif state == 'present' and subnet:
        modify_subnet(module, blade)
    elif state == 'absent' and subnet:
        delete_subnet(module, blade)
    elif state == 'absent' and not subnet:
        module.exit_json(changed=False)