diff --git a/addons/cetmix_tower_ovh/demo/demo_data.xml b/addons/cetmix_tower_ovh/demo/demo_data.xml new file mode 100644 index 0000000..efc892f --- /dev/null +++ b/addons/cetmix_tower_ovh/demo/demo_data.xml @@ -0,0 +1,180 @@ + + + + + OVH Application Key + ovh_application_key + s + + + + + OVH Application Secret + ovh_application_secret + s + + + + + OVH Consumer Key + ovh_consumer_key + s + + + + + + + + OVH Endpoint + ovh_endpoint + o + + + + OVH Zone Name + ovh_zone_name + + + + + + + your_zone.name + + + + + ovh-eu + ovh-eu + ovh-eu + 10 + + + + ovh-us + ovh-us + ovh-us + 20 + + + + ovh-ca + ovh-ca + ovh-ca + 30 + + + + soyoustart-eu + soyoustart-eu + soyoustart-eu + 40 + + + + soyoustart-ca + soyoustart-ca + soyoustart-ca + 50 + + + + kimsufi-eu + kimsufi-eu + kimsufi-eu + 60 + + + + kimsufi-ca + kimsufi-ca + kimsufi-ca + 70 + + + + + + Register OVH DNS Record + python_code + +# ---------------- +# Tower properties +# ---------------- +cetmix_tower = env["cetmix.tower"] + +# Ensure the domain in your server URL matches your OVH DNS Zone name! +# Example: If your DNS Zone is "example.com", your URL should be "*.example.com" + +instance_url = {{ tower.server.url }} +ovh_endpoint = env["cx.tower.variable.option"].get_by_reference("option_ovh_endpoint_eu").value_char +ovh_application_key = #!cxtower.secret.ovh_application_key!# +ovh_application_secret = #!cxtower.secret.ovh_application_secret!# +ovh_consumer_key = #!cxtower.secret.ovh_consumer_key!# +ovh_zone_name = {{ ovh_zone_name }} +# ---------------- +# Request settings +# ---------------- + +path = "/domain/zone/"+ovh_zone_name+"/record" + +# Subdomain extraction with tldextract: +sub_domain = tldextract.extract(instance_url).subdomain + +# Send request to Ovh +exit_code = 0 +message = "" + +try: + client = ovh.Client( + endpoint=ovh_endpoint, + application_key=ovh_application_key, + application_secret=ovh_application_secret, + consumer_key=ovh_consumer_key + ) + records = client.get(path, subDomain=sub_domain, fieldType="A") + if not records: + records = client.post( + path, + fieldType="A", + subDomain=sub_domain, + target={{ tower.server.ipv4 }}, + ttl=3600 + ) + client.post("/domain/zone/" + ovh_zone_name + "/refresh") + if records: + exit_code = 0 + message = "subDomain " + sub_domain + " registered" + else: + exit_code = 0 + message = "subDomain " + sub_domain + " already exists" +except Exception as e: + exit_code = 500 + message = str(e) + +result = { + "exit_code": exit_code, + "message": message, +} + + + + + + Register or check DNS A record for current server in OVH DNS zone + +