-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathremote.py
More file actions
67 lines (54 loc) · 1.77 KB
/
Copy pathremote.py
File metadata and controls
67 lines (54 loc) · 1.77 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
import remctl
from remctl import RemctlError
from os import environ
import logging
class Remctl( object ):
"""
generic interface to remctl; run() is a generator object spitting out the message responses
"""
command_preamble = []
args = []
def __init__(self, server, port, service, krb5ccname=None ):
if krb5ccname == None and not 'KRB5CCAME' in environ:
raise RemctlError, 'no token'
self.server = server
self.port = port
self.service = service
self.remctl = remctl.Remctl()
def connect(self):
try:
res = self.remctl.open( host=self.server, port=self.port, principal=self.service )
except RemctlError, e:
logging.error( str(e) )
raise e
def run( self, args=[] ):
"""
generator function to return the output live
"""
if len(args) == 0:
args = self.args
c = self.command_preamble + args
logging.error("Commands: " + str(c))
self.remctl.command( c )
t, o, s, st, e = self.remctl.output()
m = ''
while t != 'done':
if t == 'output':
m = o.rstrip()
# elif t == 'status':
# x = str(t) + ": " + str(st)
elif t == 'error':
m = str(t) + ": " + str(e)
yield m
t, o, s, st, e = self.remctl.output()
return
def close(self):
self.remctl.close()
def __del__(self):
self.close()
class NetShow( Remctl ):
# requires in remctl/conf.d
# net show /opt/net-config/bin/net-config ANYUSER
command_preamble = [ 'net', 'show', 'port' ]
class NetEdit( Remctl ):
command_preamble = [ 'net', 'edit', 'port' ]