예제 #1
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type="str",
                       default="present",
                       choices=["absent", "present"]),
            domain=dict(type="str"),
            nameservers=dict(type="list", elements="str"),
        ))

    required_if = [("state", "present", ["domain", "nameservers"])]

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

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

    if state == "absent":
        delete_dns(module, array)
    elif state == "present":
        module.params["nameservers"] = remove(module.params["nameservers"])
        create_dns(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=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)
예제 #3
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            ntp_servers=dict(type="list", elements="str"),
            state=dict(type="str",
                       default="present",
                       choices=["absent", "present"]),
        ))

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

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

    array = get_system(module)
    if _is_cbs(array):
        module.warn(
            "NTP settings are not necessary for a CBS array - ignoring...")
        module.exit_json(changed=False)

    if module.params["state"] == "absent":
        delete_ntp(module, array)
    else:
        module.params["ntp_servers"] = remove(module.params["ntp_servers"])
        if sorted(array.get(ntpserver=True)["ntpserver"]) != sorted(
                module.params["ntp_servers"][0:4]):
            create_ntp(module, array)

    module.exit_json(changed=False)
예제 #4
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)
예제 #5
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            name=dict(type='str', required=True),
            prefix=dict(type='str'),
            state=dict(type='str',
                       default='present',
                       choices=['present', 'absent']),
            gateway=dict(type='str'),
            enabled=dict(type='bool', default=True),
            mtu=dict(type='int', default=1500),
            vlan=dict(type='int'),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

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

    state = module.params['state']
    array = get_system(module)
    subnet = _get_subnet(module, array)
    if state == 'present' and not subnet:
        create_subnet(module, array)
    if state == 'present' and subnet:
        update_subnet(module, array, subnet)
    elif state == 'absent' and subnet:
        delete_subnet(module, array)

    module.exit_json(changed=False)
예제 #6
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=["present", "absent"]),
            address=dict(type="str"),
            gateway=dict(type="str"),
            mtu=dict(type="int", default=1500),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

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

    array = get_system(module)
    interface = _get_interface(module, array)
    if not interface:
        module.fail_json(msg="Invalid network interface specified.")

    update_interface(module, array, interface)

    module.exit_json(changed=False)
    module.exit_json(changed=False)
예제 #7
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            sender_domain=dict(type='str'),
            password=dict(type='str', no_log=True),
            user=dict(type='str'),
            relay_host=dict(type='str'),
        ))

    required_together = [['user', 'password']]

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

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

    if state == 'absent':
        delete_smtp(module, array)
    elif state == 'present':
        create_smtp(module, array)
    else:
        module.exit_json(changed=False)
예제 #8
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            ntp_servers=dict(type='list'),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
        ))

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

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

    array = get_system(module)

    if module.params['state'] == 'absent':
        delete_ntp(module, array)
    else:
        module.params['ntp_servers'] = remove(module.params['ntp_servers'])
        if sorted(array.get(ntpserver=True)['ntpserver']) != sorted(
                module.params['ntp_servers'][0:4]):
            create_ntp(module, array)

    module.exit_json(changed=False)
예제 #9
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            name=dict(type="str", required=True),
            prefix=dict(type="str"),
            state=dict(type="str",
                       default="present",
                       choices=["present", "absent"]),
            gateway=dict(type="str"),
            enabled=dict(type="bool", default=True),
            mtu=dict(type="int", default=1500),
            vlan=dict(type="int"),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

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

    state = module.params["state"]
    array = get_system(module)
    subnet = _get_subnet(module, array)
    if state == "present" and not subnet:
        create_subnet(module, array)
    if state == "present" and subnet:
        update_subnet(module, array, subnet)
    elif state == "absent" and subnet:
        delete_subnet(module, array)

    module.exit_json(changed=False)
def main():
    argument_spec = purefa_argument_spec()

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

    module.exit_json(changed=False, purefa_info=generate_hardware_dict(array))
예제 #11
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            connection=dict(type='str',
                            default='async',
                            choices=['async', 'sync']),
            target_url=dict(type='str', required=True),
            target_api=dict(type='str'),
        ))

    required_if = [('state', 'present', ['target_api'])]

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

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

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

    if state == 'present' and target_array is None:
        create_connection(module, array)
    elif state == 'absent' and target_array is not None:
        break_connection(module, array, target_array)

    module.exit_json(changed=False)
예제 #12
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            name=dict(required=True, type='str'),
            role=dict(type='str',
                      choices=['readonly', 'storage_admin', 'array_admin']),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            password=dict(type='str', no_log=True),
            old_password=dict(type='str', no_log=True),
            api=dict(type='bool', default=False),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=False)

    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='FlashArray REST version not supported. '
            'Minimum version required: {0}'.format(MIN_REQUIRED_API_VERSION))

    if state == 'absent':
        delete_user(module, array)
    elif state == 'present':
        create_user(module, array)
    else:
        module.exit_json(changed=False)
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            name=dict(type='str', required=True),
            copyable=dict(type='bool', default=True),
            namespace=dict(type='str', default='default'),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            kvp=dict(type='list', elements='str', required=True),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    state = module.params['state']
    if module.params['kvp'] is not None:
        module.params['kvp'] = sorted(module.params['kvp'][0:5])
    else:
        module.fail_json(msg='No KVPs specified. Minimum of 1 is required.')
    array = get_system(module)
    api_version = array._list_available_rest_versions()

    if TAGS_API_VERSION not in api_version:
        module.fail_json(
            msg=
            'Volume tags are not supported. Purity 6.0.0, or higher, is required.'
        )

    volume = get_volume(module, array)
    endpoint = get_endpoint(module.params['name'], array)

    if not volume:
        module.fail_json(
            msg='Volume {0} does not exist.'.format(module.params['name']))
    if endpoint:
        module.fail_json(msg='Volume {0} is an endpoint. Tags not allowed.'.
                         format(module.params['name']))
    if "." in module.params['name']:
        current_tags = array.get_volume(module.params['name'],
                                        snap=True,
                                        pending=True,
                                        tags=True,
                                        namespace=module.params['namespace'])
    else:
        current_tags = array.get_volume(module.params['name'],
                                        pending=True,
                                        tags=True,
                                        namespace=module.params['namespace'])

    if state == 'present' and not current_tags:
        create_tag(module, array)
    elif state == 'absent' and not current_tags:
        module.exit_json(changed=False)
    elif state == 'present' and current_tags:
        update_tag(module, array, current_tags)
    elif state == 'absent' and current_tags:
        delete_tag(module, array, current_tags)

    module.exit_json(changed=False)
예제 #14
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            address=dict(type="str", required=True),
            protocol=dict(type="str",
                          choices=["tcp", "tls", "udp"],
                          required=True),
            port=dict(type="str"),
            name=dict(type="str"),
            state=dict(type="str",
                       default="present",
                       choices=["absent", "present"]),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    array = get_system(module)

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

    api_version = array._list_available_rest_versions()

    if SYSLOG_NAME_API in api_version and module.params["name"]:
        arrayv6 = get_array(module)
    else:
        arrayv6 = None

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

    module.exit_json(changed=False)
예제 #15
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            domain=dict(type='str'),
            nameservers=dict(type='list', elements='str'),
        ))

    required_if = [('state', 'present', ['domain', 'nameservers'])]

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

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

    if state == 'absent':
        delete_dns(module, array)
    elif state == 'present':
        module.params['nameservers'] = remove(module.params['nameservers'])
        create_dns(module, array)
    else:
        module.exit_json(changed=False)
예제 #16
0
def main():
    argument_spec = purefa_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)

    state = module.params['state']
    array = get_system(module)
    current_banner = array.get(banner=True)['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, array)
    # clear banner if it has a value
    elif state == 'absent' and current_banner:
        delete_banner(module, array)

    module.exit_json(changed=False)
예제 #17
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)
예제 #18
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type="str",
                       default="present",
                       choices=["present", "absent"]),
            name=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 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))
    try:
        app = array.get_app(module.params["name"])
    except Exception:
        module.fail_json(msg="Selected application {0} does not exist".format(
            module.params["name"]))
    if not app["enabled"]:
        module.fail_json(
            msg="Application {0} is not enabled".format(module.params["name"]))
    if module.params["state"] == "present":
        enable_vnc(module, array, app)
    else:
        disable_vnc(module, array, app)
    module.exit_json(changed=False)
예제 #19
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type='str',
                       default='present',
                       choices=['present', 'absent']),
            name=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 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))
    try:
        app = array.get_app(module.params['name'])
    except Exception:
        module.fail_json(msg='Selected application {0} does not exist'.format(
            module.params['name']))
    if not app['enabled']:
        module.fail_json(
            msg='Application {0} is not enabled'.format(module.params['name']))
    if module.params['state'] == 'present':
        enable_vnc(module, array, app)
    else:
        disable_vnc(module, array, app)
    module.exit_json(changed=False)
예제 #20
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            state=dict(type="str",
                       default="present",
                       choices=["absent", "present"]),
            sender_domain=dict(type="str"),
            password=dict(type="str", no_log=True),
            user=dict(type="str"),
            relay_host=dict(type="str"),
        ))

    required_together = [["user", "password"]]

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

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

    if state == "absent":
        delete_smtp(module, array)
    elif state == "present":
        create_smtp(module, array)
    else:
        module.exit_json(changed=False)
예제 #21
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            name=dict(required=True, type="str"),
            role=dict(type="str",
                      choices=["readonly", "storage_admin", "array_admin"]),
            state=dict(type="str",
                       default="present",
                       choices=["absent", "present"]),
            password=dict(type="str", no_log=True),
            old_password=dict(type="str", no_log=True),
            api=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 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))

    if state == "absent":
        delete_user(module, array)
    elif state == "present":
        create_user(module, array)
    else:
        module.exit_json(changed=False)
예제 #22
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']]]

    mutually_exclusive = [['stretch', 'failover'], ['strecth', 'eradicate'],
                          ['target', 'stretch'], ['target', 'failover'],
                          ['target', '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)
예제 #23
0
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)
예제 #24
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(".", "")
    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)
예제 #25
0
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', elements='str'),
            lun=dict(type='int'),
            volume=dict(type='list', elements='str'),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    state = module.params['state']
    array = get_system(module)
    if module.params['host'] is not None:
        new_hosts = [host.lower() for host in module.params['host']]
        module.params['host'] = new_hosts
    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)

    module.exit_json(changed=False)
예제 #26
0
def main():
    argument_spec = purefa_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', default='v2c', 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']
    array = get_system(module)
    mgr_configured = False
    mgrs = array.list_snmp_managers()
    for mgr in range(0, len(mgrs)):
        if mgrs[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, array)
    elif mgr_configured and state == 'present':
        update_manager(module, array)
    elif not mgr_configured and state == 'present':
        create_manager(module, array)
    else:
        module.exit_json(changed=False)
예제 #27
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(
        dict(
            pgroup=dict(type='str', required=True),
            state=dict(type='str',
                       default='present',
                       choices=['absent', 'present']),
            volume=dict(type='list'),
            host=dict(type='list'),
            hostgroup=dict(type='list'),
            target=dict(type='list'),
            eradicate=dict(type='bool', default=False),
            enabled=dict(type='bool', default=True),
        ))

    mutually_exclusive = [['volume', 'host', 'hostgroup']]
    module = AnsibleModule(argument_spec,
                           mutually_exclusive=mutually_exclusive,
                           supports_check_mode=False)

    state = module.params['state']
    array = get_system(module)
    api_version = array._list_available_rest_versions()
    if ":" in module.params[
            'pgroup'] and OFFLOAD_API_VERSION not in api_version:
        module.fail_json(
            msg='API version does not support offload protection groups.')

    pgroup = get_pgroup(module, array)
    xpgroup = get_pending_pgroup(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['hostgroup']:
        try:
            for hstg in module.params['hostgroup']:
                array.get_hgroup(hstg)
        except Exception:
            module.fail_json(msg='Hostgroup {0} not found'.format(hstg))

    if pgroup and state == 'present':
        update_pgroup(module, array)
    elif pgroup and state == 'absent':
        delete_pgroup(module, array)
    elif xpgroup and state == 'absent' and module.params['eradicate']:
        eradicate_pgroup(module, array)
    elif not pgroup and not xpgroup and state == 'present':
        make_pgroup(module, array)
    elif pgroup is None and state == 'absent':
        module.exit_json(changed=False)
예제 #28
0
def main():
    argument_spec = purefa_argument_spec()
    argument_spec.update(dict(
        name=dict(type='str', required=True),
        suffix=dict(type='str'),
        restore=dict(type='str'),
        offload=dict(type='str'),
        overwrite=dict(type='bool', default=False),
        target=dict(type='str'),
        eradicate=dict(type='bool', default=False),
        now=dict(type='bool', default=False),
        apply_retention=dict(type='bool', default=False),
        remote=dict(type='bool', default=False),
        state=dict(type='str', default='present', choices=['absent', 'present', 'copy']),
    ))

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

    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(".", "")

    if not module.params['target'] and module.params['restore']:
        module.params['target'] = module.params['restore']

    state = module.params['state']
    array = get_system(module)
    api_version = array._list_available_rest_versions()
    if OFFLOAD_API not in api_version and module.params['offload']:
        module.fail_json(msg='Minimum version {0} required for offload support'.format(OFFLOAD_API))
    pgroup = get_pgroup(module, array)
    if pgroup is None:
        module.fail_json(msg="Protection Group {0} does not exist.".format(module.params['name']))
    pgsnap = get_pgsnapshot(module, array)
    if state != "absent" and module.params['offload']:
        module.fail_json(msg='offload parameter not supported for state {0}'.format(state))
    elif state == 'copy':
        restore_pgsnapvolume(module, array)
    elif state == 'present' and not pgsnap:
        create_pgsnapshot(module, array)
    elif state == 'present' and pgsnap:
        module.exit_json(changed=False)
    elif state == 'absent' and module.params['offload'] and get_offload_snapshot(module, array):
        delete_offload_snapshot(module, array)
    elif state == 'absent' and pgsnap:
        delete_pgsnapshot(module, array)
    elif state == 'absent' and not pgsnap:
        module.exit_json(changed=False)

    module.exit_json(changed=False)
예제 #29
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)
예제 #30
0
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", elements="str"),
            lun=dict(type="int"),
            volume=dict(type="list", elements="str"),
        )
    )

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    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)

    module.exit_json(changed=False)