def core(module): domain_name = module.params.get('domain_name', None) rest = DigitalOceanHelper(module) domain_results = [] if domain_name is not None: response = rest.get("domains/%s" % domain_name) status_code = response.status_code if status_code != 200: module.fail_json(msg="Failed to retrieve domain for DigitalOcean") resp_json = response.json domains = [resp_json['domain']] else: domains = rest.get_paginated_data(base_url="domains?", data_key_name='domains') for temp_domain in domains: temp_domain_dict = { "name": temp_domain['name'], "ttl": temp_domain['ttl'], "zone_file": temp_domain['zone_file'], "domain_records": list(), } base_url = "domains/%s/records?" % temp_domain['name'] temp_domain_dict["domain_records"] = rest.get_paginated_data(base_url=base_url, data_key_name='domain_records') domain_results.append(temp_domain_dict) module.exit_json(changed=False, data=domain_results)
def core(module): snapshot_type = module.params['snapshot_type'] rest = DigitalOceanHelper(module) base_url = 'snapshots?' snapshot = [] if snapshot_type == 'by_id': base_url += "/{0}".format(module.params.get('snapshot_id')) response = rest.get(base_url) status_code = response.status_code if status_code != 200: module.fail_json(msg="Failed to fetch snapshot information due to error : %s" % response.json['message']) snapshot.extend(response.json["snapshot"]) else: if snapshot_type == 'droplet': base_url += "resource_type=droplet&" elif snapshot_type == 'volume': base_url += "resource_type=volume&" snapshot = rest.get_paginated_data(base_url=base_url, data_key_name='snapshots') module.exit_json(changed=False, data=snapshot)
def core(module): region_name = module.params.get('region_name', None) rest = DigitalOceanHelper(module) base_url = 'volumes?' if region_name is not None: base_url += "region=%s&" % region_name volumes = rest.get_paginated_data(base_url=base_url, data_key_name='volumes') module.exit_json(changed=False, data=volumes)
def core(module): image_type = module.params['image_type'] rest = DigitalOceanHelper(module) base_url = 'images?' if image_type == 'distribution': base_url += "type=distribution&" elif image_type == 'application': base_url += "type=application&" elif image_type == 'private': base_url += "private=true&" images = rest.get_paginated_data(base_url=base_url, data_key_name='images') module.exit_json(changed=False, data=images)
def core(module): tag_name = module.params.get('tag_name', None) rest = DigitalOceanHelper(module) base_url = 'tags?' if tag_name is not None: response = rest.get("%s/%s" % (base_url, tag_name)) status_code = response.status_code if status_code != 200: module.fail_json(msg="Failed to retrieve tags for DigitalOcean") resp_json = response.json tag = resp_json['tag'] else: tag = rest.get_paginated_data(base_url=base_url, data_key_name='tags') module.exit_json(changed=False, data=tag)
def core(module): firewall_name = module.params.get('name', None) rest = DigitalOceanHelper(module) base_url = 'firewalls?' response = rest.get("%s" % base_url) status_code = response.status_code if status_code != 200: module.fail_json(msg="Failed to retrieve firewalls from Digital Ocean") firewalls = rest.get_paginated_data(base_url=base_url, data_key_name='firewalls') if firewall_name is not None: rule = {} for firewall in firewalls: if firewall['name'] == firewall_name: rule.update(firewall) module.exit_json(changed=False, data=rule) else: module.exit_json(changed=False, data=firewalls)
def core(module): certificate_id = module.params.get('certificate_id', None) rest = DigitalOceanHelper(module) base_url = 'certificates?' if certificate_id is not None: response = rest.get("%s/%s" % (base_url, certificate_id)) status_code = response.status_code if status_code != 200: module.fail_json( msg="Failed to retrieve certificates for DigitalOcean") resp_json = response.json certificate = resp_json['certificate'] else: certificate = rest.get_paginated_data(base_url=base_url, data_key_name='certificates') module.exit_json(changed=False, data=certificate)