forked from SUNET/cnaas-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
86 lines (62 loc) · 1.79 KB
/
cli.py
File metadata and controls
86 lines (62 loc) · 1.79 KB
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
85
86
import sys
import getopt
from urllib.parse import urlparse
from cli.command import CliHandler
def usage():
"""
Print usage string
"""
print('cli.py -u <url> -t <token>')
sys.exit(0)
def get_domain(url):
"""
Get domain name from URL
"""
uri = urlparse(url)
if uri.scheme == '' or uri.netloc == '':
print('Could not parse URL.')
sys.exit(0)
return uri.netloc
def main(argv):
url = ''
token = ''
banner = """
_______ ,---. .--. ____ ____ .-'''-.
/ __ \\ | \\ | | .' __ `. .' __ `. / _ \\
| ,_/ \\__) | , \\ | |/ ' \\ \\/ ' \\ \\ (`' )/`--'
,-./ ) | |\\_ \\| ||___| / ||___| / |(_ o _).
\\ '_ '`) | _( )_\\ | _.-` | _.-` | (_,_). '.
> (_) ) __ | (_ o _) |.' _ |.' _ |.---. \\ :
( . .-'_/ )| (_,_)\\ || _( )_ || _( )_ |\\ `-' |
`-'`-' / | | | |\\ (_ o _) /\\ (_ o _) / \\ /
`._____.' '--' '--' '.(_,_).' '.(_,_).' `-...-'
CNaaS - Command Line Interface\n
(C) SUNET (http://www.sunet.se), 2020
'Type "help" for help.
"""
try:
opts, args = getopt.getopt(argv, 'u:t:')
except getopt.GetoptError:
usage(argv)
for opt, arg in opts:
if opt == '-u':
url = arg
if opt == '-t':
token = arg
if token == '':
usage()
if url == '':
usage()
domain = get_domain(url)
prompt = 'CNaaS NMS (%s)# ' % domain
try:
cli = CliHandler(url, token=token, banner=banner, prompt=prompt)
while True:
cli.loop()
except KeyboardInterrupt as e:
print('\n' + (str(str(e))))
except EOFError:
print('\nGoodbye!')
sys.exit(0)
if __name__ == '__main__':
main(sys.argv[1:])