Created
July 3, 2020 11:13
-
-
Save ashmonger/dd4acfcbc064da673ab1fb157b6604d9 to your computer and use it in GitHub Desktop.
update OVH Dynhost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- encoding: utf-8 -*- | |
''' | |
First, install the latest release of Python wrapper: $ pip install ovh | |
''' | |
import json | |
import ovh | |
import requests | |
import logging | |
logging.basicConfig(filename='/var/log/dynhost.log', level=logging.INFO, format='[%(asctime)s][%(levelname)s] %(message)s') | |
# Instanciate an OVH Client. | |
# You can generate new credentials with full access to your account on | |
# the token creation page | |
client = ovh.Client( | |
endpoint='ovh-eu', # Endpoint of API OVH Europe (List of available endpoints) | |
application_key='<my app key>', # Application Key | |
application_secret='<my app secret>', # Application Secret | |
consumer_key='<my consumer key>', # Consumer Key | |
) | |
ip = requests.get('https://api.ipify.org') | |
logging.info('New IP address: {}'.format(ip.text)) | |
result = client.put('/domain/zone/<my domain name>/dynHost/record/<my record>',subDomain='<my subdomain>',ip=ip.text) | |
if result is None: | |
check = client.get('/domain/zone/<my domain name>/dynHost/record/<my record>') | |
logging.info('Last Update: {}'.format(json.dumps(check))) | |
else: | |
logging.info('Error: {}'.format(json.dumps(checks))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment