-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns.py
84 lines (63 loc) · 1.98 KB
/
dns.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
# coding=utf-8
"""
@version:0.1
@author: ysicing
@file: alidns/alidns.py
@time: 05/02/186 12:02
"""
import os
import sys
import click
from core import DNS
if os.path.exists(os.path.join(os.path.abspath('.'), 'config.py')):
from config import AccessKeyId as aliid, AccessKeySecret as alikey
print(alikey)
elif os.path.exists(os.path.join(os.path.abspath('.'), 'config_same.py')):
from config_same import AccessKeyId as aliid, AccessKeySecret as alikey
print(alikey)
else:
print('just run dns init ')
sys.exit('0')
dns = DNS(aliid=aliid, alikey=alikey)
@click.group()
def cli():
pass
@click.command(help='add new domain record')
@click.argument('domain')
@click.option('--types', '-t', default='A')
@click.option('-ip', default='127.0.0.1')
def add(domain, types, ip):
add_cmd = dns.add_record(domain=domain, types=types, ip=ip)
click.echo("add record. {}".format(add_cmd))
@click.command(help='update domain record')
@click.argument('domain')
@click.option('--types', '-t', default='A')
@click.option('-ip', default='127.0.0.1')
def update(domain, types, ip):
up_cmd = dns.update_record(domain, types, ip)
click.echo('update domain record {}'.format(up_cmd))
@click.command(help='delete domain record')
@click.argument('domain')
def delete(domain):
del_cmd = dns.del_record(domain=domain)
click.echo('delete recird: {}'.format(del_cmd))
@click.command(help='show domain record')
@click.argument('domain')
def show(domain):
ckd_two = dns.check_rr(domain=domain)
click.echo('show domain info{}'.format(ckd_two))
@click.command(help='init domain')
@click.option('--aliid')
@click.option('--alikey')
def init(aliid, alikey):
with open('config_same.py', 'w') as f:
f.write('AccessKeyId = "{}"\n'.format(aliid))
f.write('AccessKeySecret = "{}"\n'.format(alikey))
cli.add_command(init)
cli.add_command(add)
cli.add_command(update)
cli.add_command(delete)
cli.add_command(show)
if __name__ == '__main__':
cli()