From 4affa7393f902ee2e233e02d5124c2773217f745 Mon Sep 17 00:00:00 2001 From: pierre Date: Wed, 19 Jun 2024 13:30:21 +0100 Subject: [PATCH] :boom: add all the files --- Dockerfile | 10 ++++++++ Dyndns_python_Cron_jobs.yaml | 34 ++++++++++++++++++++++++++++ Update_dynhost.py | 44 ++++++++++++++++++++++++++++++++++++ credentials.py | 6 +++++ requirements.txt | 4 ++++ 5 files changed, 98 insertions(+) create mode 100644 Dockerfile create mode 100644 Dyndns_python_Cron_jobs.yaml create mode 100644 Update_dynhost.py create mode 100644 credentials.py create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f3f17b0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3 + +WORKDIR /usr/src/app + +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD [ "python", "./Update_dynhost.py" ] diff --git a/Dyndns_python_Cron_jobs.yaml b/Dyndns_python_Cron_jobs.yaml new file mode 100644 index 0000000..775c728 --- /dev/null +++ b/Dyndns_python_Cron_jobs.yaml @@ -0,0 +1,34 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: dyndns-python +--- +apiVersion: batch/v1 +kind: CronJob +spec: + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchFields: + - key: metadata.name + operator: In + values: + - kube-master +metadata: + name: dyndns-pythonrenew + namespace: dyndns-python +spec: + schedule: "0 * * * *" + jobTemplate: + spec: + ttlSecondsAfterFinished: 100 + template: + spec: +# nodeName: kube-master + containers: + - name: dyndns-python +# image: dyndns_python:latest + image: localhost:31795/dyndns_python + restartPolicy: Never + diff --git a/Update_dynhost.py b/Update_dynhost.py new file mode 100644 index 0000000..df271db --- /dev/null +++ b/Update_dynhost.py @@ -0,0 +1,44 @@ +# -*- encoding: utf-8 -*- +''' +First, install the latest release of Python wrapper: $ pip install ovh +''' +import json +import ovh +import requests +import credentials as credential_perso + + +# Instanciate an OVH Client. +# You can generate new credentials with full access to your account on +# the token creation page +client = ovh.Client( + + endpoint=credential_perso.endpoint, + application_key=credential_perso.application_key, + application_secret=credential_perso.application_secret, + consumer_key=credential_perso.consumer_key, +) + +new_subdomain = credential_perso.my_subdomain +new_domain = credential_perso.my_zone + +def Domain_id(): + domain_id = client.get('/domain/zone/'+new_domain+'/dynHost/record', subDomain=new_subdomain) + return domain_id + +def update_zone(subdomain,new_ip,domain_id): + result = client.put('/domain/zone/'+new_domain+'/dynHost/record/'+domain_id, + ip=new_ip, + subDomain=subdomain) + refresh_dns() + return result + +def refresh_dns(): + result_refresh = client.post('/domain/zone/'+new_domain+'/refresh') + return result_refresh + +def MyIP(): + response = requests.get('https://ifconfig.me/ip') + return response.text + +result_update = update_zone(new_subdomain,MyIP(),str(Domain_id()[0])) diff --git a/credentials.py b/credentials.py new file mode 100644 index 0000000..86fcd10 --- /dev/null +++ b/credentials.py @@ -0,0 +1,6 @@ +endpoint = 'ovh-eu' +application_key = 'HmqcHin8SVEgAyQU' +application_secret = 'jxCrdTVgftimcf4T4GnJWXvehjqQwfdz' +consumer_key = 'VH0vWJx5oDqg8FnXNHSNKUDlsie0pQ9c' +my_zone = 'geeraert.eu' +my_subdomain = 'tryton' diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8c7c2a0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +ovh +requests + +