Exemplo n.º 1
0
def main():
    module_args = oci_utils.get_common_arg_spec(supports_create=True,
                                                supports_wait=True)
    module_args.update(
        dict(compartment_id=dict(type='str', required=False),
             name=dict(type='str', required=False, aliases=['zone_name']),
             zone_id=dict(type='str', required=False, aliases=['id']),
             zone_type=dict(type='str',
                            required=False,
                            choices=['PRIMARY', 'SECONDARY']),
             external_masters=dict(type='list', required=False),
             state=dict(type='str',
                        required=False,
                        default='present',
                        choices=['absent', 'present'])))

    module = AnsibleModule(
        argument_spec=module_args,
        supports_check_mode=False,
        mutually_exclusive=['zone_id', 'name'],
    )

    if not HAS_OCI_PY_SDK:
        module.fail_json(msg='oci python sdk required for this module.')

    config = oci_utils.get_oci_config(module)
    dns_client = DnsClient(config)

    state = module.params['state']
    zone_id = module.params['zone_id']

    if state == 'absent':
        result = delete_zone(dns_client, module)

    else:
        if zone_id is not None:
            module.params['zone_name_or_id'] = get_zone_name_or_id(module)
            result = update_zone(dns_client, module)
            # XXX: also handle case where zone name is specified
        else:
            if module.params['zone_type'] is None:
                module.fail_json(
                    msg='Zone_type must be specified while creating a Zone')
            kwargs_list = {'compartment_id': module.params['compartment_id']}

            result = oci_utils.check_and_create_resource(
                resource_type='zone',
                create_fn=create_zone,
                kwargs_create={
                    'dns_client': dns_client,
                    'module': module
                },
                list_fn=dns_client.list_zones,
                kwargs_list=kwargs_list,
                module=module,
                model=CreateZoneDetails(),
                exclude_attributes=None)
    module.exit_json(**result)
Exemplo n.º 2
0
def create_zone(dns_client, module):
    create_zone_details = CreateZoneDetails()
    for attribute in create_zone_details.attribute_map:
        if attribute in module.params:
            setattr(create_zone_details, attribute, module.params[attribute])

    result = oci_utils.create_and_wait(
        resource_type="zone",
        create_fn=dns_client.create_zone,
        kwargs_create={"create_zone_details": create_zone_details},
        client=dns_client,
        get_fn=dns_client.get_zone,
        get_param="zone_name_or_id",
        module=module)
    return result
Exemplo n.º 3
0
def main():
    module_args = oci_utils.get_common_arg_spec(supports_create=True,
                                                supports_wait=True)
    module_args.update(
        dict(
            compartment_id=dict(type="str", required=False),
            name=dict(type="str", required=False, aliases=["zone_name"]),
            zone_id=dict(type="str", required=False, aliases=["id"]),
            zone_type=dict(type="str",
                           required=False,
                           choices=["PRIMARY", "SECONDARY"]),
            external_masters=dict(type="list", required=False),
            state=dict(
                type="str",
                required=False,
                default="present",
                choices=["absent", "present"],
            ),
        ))

    module = AnsibleModule(
        argument_spec=module_args,
        supports_check_mode=False,
        mutually_exclusive=["zone_id", "name"],
    )

    if not HAS_OCI_PY_SDK:
        module.fail_json(msg="oci python sdk required for this module.")

    dns_client = oci_utils.create_service_client(module, DnsClient)

    state = module.params["state"]
    zone_id = module.params["zone_id"]

    if state == "absent":
        result = delete_zone(dns_client, module)

    else:
        if zone_id is not None:
            module.params["zone_name_or_id"] = get_zone_name_or_id(module)
            result = update_zone(dns_client, module)
            # XXX: also handle case where zone name is specified
        else:
            if module.params["zone_type"] is None:
                module.fail_json(
                    msg="Zone_type must be specified while creating a Zone")
            kwargs_list = {"compartment_id": module.params["compartment_id"]}

            result = oci_utils.check_and_create_resource(
                resource_type="zone",
                create_fn=create_zone,
                kwargs_create={
                    "dns_client": dns_client,
                    "module": module
                },
                list_fn=dns_client.list_zones,
                kwargs_list=kwargs_list,
                module=module,
                model=CreateZoneDetails(),
                exclude_attributes=None,
            )
    module.exit_json(**result)