This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mast_utils.py
77 lines (53 loc) · 1.86 KB
/
mast_utils.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
import logging
import output_parser
import shell
logger = logging.getLogger(__name__)
makefile = '/usr/sbin/mast-utils'
def add_printer(site, hostname, description=None):
command = [makefile, 'add-channel',
'NAME=' + site,
'PRINTER=' + hostname,
'DESC=' + description]
response = shell.execute(command)
response['results'] = output_parser.add_printer(response['results'])
return response
def list_site_and_printers():
command = [makefile, 'list-channels']
response = shell.execute(command)
response['results'] = output_parser.list_all_printers(response['results'])
return response
def list_printers(site):
command = [makefile, 'list-channels']
if site:
command.append(' NAME=' + site)
response = shell.execute(command)
response['results'] = output_parser.list_printers(response['results'], site)
return response
def remove_printer(site, printer_id):
command = [makefile, 'remove-channel',
'NAME=' + site,
'ID=' + str(printer_id)
]
return shell.execute(command)
def list_sites(site=None):
command = [makefile, 'list-hosts']
if site:
command.append(' NAME=' + site)
response = shell.execute(command)
response['results'] = output_parser.list_sites(response['results'])
return response
def add_site(name, hostname):
command = [makefile, 'add-host',
'NAME=' + name,
'REMOTE_HOST=' + hostname,
'INTERACTIVE=false'
]
logger.debug(name, hostname, " ".join(command))
return shell.execute(command)
def remove_site(name):
command = [makefile, 'remove-host', 'NAME=' + name]
return shell.execute(command)
def get_printer(printers, id):
for printer in printers:
if printer['id'] == id:
return printer