
Previous discovery API didn't allowed agents to get dependent resources synchronously, e.g. when discovering some service, get service's configuration file via FileDiscovery agent and have it cached so that subsequent discovery of that file would not produce a new resource. New API changes how discovery is done: agents now represent a caching resource factories, so when you ask for particular resource for the second time, it will return a cached instance. Resources no more accumulated in the main loop but instead collected from agents afterwards. This overcomes the fact that some agent could produce multiple resources while current API allows only one resource to be returned from agent's discover() method. Extended file discovery methods: now you can use wildcards to collect multiple files at once and use search paths (e.g. when you want to search for config file in several directories and collect whichever found first). Cleaned up PEP8 issues regarding unused imports and 'import *'. Added CLI options for discovery_test to output JSON and choose log level. IssueReporter subclasses now won't contain duplicate entries. Change-Id: I7371ccce1e2f3c0a649fe9d6a41b146f04c0f4c1
112 lines
2.7 KiB
Python
112 lines
2.7 KiB
Python
from os import environ
|
|
#import shlex
|
|
#import subprocess
|
|
|
|
|
|
class JokerSecureShell():
|
|
|
|
def __init__(self, hostName):
|
|
self.tempDir = "/tmp"
|
|
|
|
# TODO(metacoma): implement password authentication scheme
|
|
self.credentials = {
|
|
"user": None,
|
|
"host": None,
|
|
"port": 22,
|
|
"key": None,
|
|
}
|
|
|
|
self.options = {
|
|
"proxyCommand": None,
|
|
"StrictHostKeyChecking": "no"
|
|
}
|
|
|
|
self.haveMasterSocket = False
|
|
self.masterSocketPid = None
|
|
|
|
# FIXME use inspect.stack()[0][3] ?
|
|
@property
|
|
def host(self):
|
|
print "called host getter"
|
|
return self.credentials['host']
|
|
|
|
@host.setter
|
|
def host(self, value):
|
|
print "called host setter"
|
|
self.credentials['host'] = value
|
|
|
|
@property
|
|
def user(self):
|
|
if self.credentials['user']:
|
|
return self.credentials['user']
|
|
else:
|
|
return environ['USER']
|
|
|
|
@user.setter
|
|
def user(self, value):
|
|
self.credentials.user = value
|
|
|
|
@property
|
|
def key(self):
|
|
assert self.credentials['key'] is not None, \
|
|
"Keyfile for %s@%s:%d not present" \
|
|
% (self.user, self.host, self.port)
|
|
return self.credentials['key']
|
|
|
|
@key.setter
|
|
def key(self, value):
|
|
self.credentials['key'] = value
|
|
|
|
@property
|
|
def port(self):
|
|
return self.credentials['port']
|
|
|
|
@port.setter
|
|
def port(self, value):
|
|
self.credentials.port = value
|
|
|
|
@property
|
|
def proxyCommand(self):
|
|
return self.credentials.proxyCommand
|
|
|
|
@proxyCommand.setter
|
|
def proxyCommand(self, value):
|
|
self.credentials.proxyCommand = value
|
|
|
|
@property
|
|
def masterSocketPath(self):
|
|
return "%s/%s:%d" % (self.tempDir, self.host, self.port)
|
|
|
|
@property
|
|
def sshOptions(self):
|
|
r = ""
|
|
|
|
# compile ssh options in one string
|
|
|
|
for i in self.options:
|
|
if self.options[i] is not None:
|
|
r = r + ('-o %s=%s' % (i, self.options[i]))
|
|
|
|
return r
|
|
|
|
def createMasterSocket(self):
|
|
self.haveMasterSocket = True
|
|
|
|
# XXX we support only keys without password encryption
|
|
#cmd = "ssh -i %s -p %d %s -M -S %s %s@%s" \
|
|
# % (self.key, self.port, self.sshOptions,
|
|
# self.masterSocketPath, self.user, self.host)
|
|
|
|
# subprocess.Popen(shlex.split(cmd))
|
|
|
|
def call(self, destinationCmd):
|
|
if (not self.haveMasterSocket):
|
|
self.createMasterSocket()
|
|
|
|
#cmd = "ssh %s %s" % (self.host, destinationCmd)
|
|
|
|
#stdout = stderr = None
|
|
|
|
# exitCode = subprocess.call(shlex.split(destinationCmd), \
|
|
# stdout = stdout, stderr = stderr)
|