Split into sub parts so working individually works

This commit is contained in:
Nico Schottelius 2019-05-12 10:27:07 +02:00
parent c23e25df82
commit 60edbc5f05
3 changed files with 44 additions and 27 deletions

21
ungleich_dns.py Normal file
View file

@ -0,0 +1,21 @@
import requests
import argparse
class ungleichDNS(object):
def __init__(self, parser, parents):
self.parser = parser
self.parser['dns'] = self.parser['sub'].add_parser(
'dns', parents=[parents])
self.parser['dns'].add_argument('--set-reverse', help='REQUIRED: IPv6 Address of your VM', metavar='', required=True)
self.parser['dns'].add_argument('--user', help='Your ungleich username', metavar='', required=True)
self.parser['dns'].add_argument('--token', help='Your ungleich 6 digit OTP generated token', metavar='', type=int, required=True)
self.parser['dns'].add_argument('--name', help='Hostname', metavar='', required=True)
def _handle_dns(self):
"""A dummy endpoint, to check what endpoint will be reverse-dns service."""
r = requests.post(
'https://en53kfc0hydpg.x.pipedream.net',
json={'username': args.user, 'token': args.token, 'ipaddress': args.set_reverse, 'name': args.name})
return r.text

16
ungleich_ripe.py Normal file
View file

@ -0,0 +1,16 @@
import argparse
class ungleichRIPE(object):
def __init__(self, parser, parents):
self.parser = parser
self.parser['ripe-route6'] = self.parser['sub'].add_parser(
'ripe-route6',
parents=[parents],
help="Create route6 object in the ripe database")
self.parser['ripe-route6'].add_argument('--network', required=True)
self.parser['ripe-route6'].set_defaults(func=self.route6)
def route6(self, args):
print("Adding a v6 route object at RIPE for {}".format(args.network))

View file

@ -1,19 +1,19 @@
import requests
import argparse import argparse
from ungleich_dns import ungleichDNS
from ungleich_ripe import ungleichRIPE
VERSION = "0.0.2" VERSION = "0.0.2"
def msg(name=None):
return '''ungleich-cli --set-reverse <ipv6adrress> --user <username> --token <token> --name <hostname>'''
class ungleichCLI(object): class ungleichCLI(object):
def __init__(self): def __init__(self):
self._init_parser() self._init_parser()
def _init_parser(self): # FIXME: make it generic
dns = ungleichDNS(self.parser, self.parser_parents)
ripe = ungleichRIPE(self.parser, self.parser_parents)
def _init_parser(self):
self.parser = {} self.parser = {}
# Options _all_ parsers have in common # Options _all_ parsers have in common
@ -36,29 +36,9 @@ class ungleichCLI(object):
# Parents used for all parsers # Parents used for all parsers
self.parser_parents = self.parser['loglevel'] self.parser_parents = self.parser['loglevel']
def _init_ripe(self):
self.parser['ripe'] = self.parser['sub'].add_parser(
'ripe', parents=[self.parser_parents])
def _init_dns(self):
self.parser['dns'] = self.parser['sub'].add_parser(
'dns', parents=[self.parser_parents])
self.parser['dns'].add_argument('--set-reverse', help='REQUIRED: IPv6 Address of your VM', metavar='', required=True)
self.parser['dns'].add_argument('--user', help='Your ungleich username', metavar='', required=True)
self.parser['dns'].add_argument('--token', help='Your ungleich 6 digit OTP generated token', metavar='', type=int, required=True)
self.parser['dns'].add_argument('--name', help='Hostname', metavar='', required=True)
def _handle_dns(self):
"""A dummy endpoint, to check what endpoint will be reverse-dns service."""
r = requests.post(
'https://en53kfc0hydpg.x.pipedream.net',
json={'username': args.user, 'token': args.token, 'ipaddress': args.set_reverse, 'name': args.name})
return r.text
def commandline(self): def commandline(self):
args = self.parser['main'].parse_args() args = self.parser['main'].parse_args()
args.func(args)
if __name__ == '__main__': if __name__ == '__main__':