Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # class RCASSHProxy:
- # def __init__(self, hosts, request):
- # auth_str = request.headers['Authorization'].split(' ')[1]
- # user, passw = base64.urlsafe_b64decode(
- # '{}==='.format(auth_str)).decode('utf8').split(':')
- # usernames = it.repeat(user)
- # passwords = it.repeat(passw)
- # self.jwt = request.headers['X-AUTH-TOKEN']
- # self.prefix = '/opt/maglev/bin'
- # self.clients = [(host, paramiko.SSHClient()) for host in hosts]
- # for (h, c), h, u, p in zip(self.clients, hosts, usernames, passwords):
- # c.set_missing_host_key_policy(paramiko.WarningPolicy)
- # c.connect(h, username=u, password=p)
- #
- # def _exec_cmd(self, cmd, opts=None):
- # opts = opts or {}
- # abscmd='{} {}'.format(os.path.join(self.prefix, 'exec_proxy.py'), cmd)
- # res = [(h, c.exec_command(abscmd, environment=dict(CLUSTER=h, **opts)))
- # for (h, c) in self.clients]
- #
- # def try_json(ress):
- # utf8reader = codecs.getreader('utf8')
- # for h, (_, res, err) in ress:
- # errstr = utf8reader(err).read(-1)
- # r = utf8reader(res).read(-1)
- # try:
- # yield h, json.loads(r), errstr
- # except ValueError:
- # yield h, r, errstr
- #
- # return [
- # {
- # 'host': h,
- # 'err': e,
- # 'out': o
- # } for h, o, e in try_json(res)
- # ]
- #
- # def _with_err(self, x):
- # if any(bool(i['err']) for i in x):
- # return x, RCAStatus.ERROR
- #
- # status_set = {i['out']['status'] for i in x}
- # status = RCAStatus(status_set.pop()) if len(status_set) == 1 \
- # else RCAStatus.RUNNING
- # return x, status
- #
- # def delete(self, _id):
- # return self._with_err(self._exec_cmd('delete {}'.format(_id)))
- #
- # def status(self, _id):
- # return self._with_err(self._exec_cmd('status {}'.format(_id)))
- #
- # def exec(self, cmd, _id, name, description):
- # opts = dict(RCA_DIR='/var/run/maglev/{}.tmp'.format(_id),
- # STDOUT='/var/run/maglev/{}.stdout'.format(_id),
- # OUTFILE='/var/run/maglev/{}.output.tar.gz'.format(_id),
- # TOKEN=self.jwt)
- # return self._with_err(self._exec_cmd('exec {} /opt/maglev/bin/{}'
- # .format(_id, cmd), opts))
- #
- # def download(self, _id):
- # out = namedtuple('download_struct', ['tempfiles', 'outbytes_err_t'])
- # sftps = [c.open_sftp() for h, c in self.clients]
- # temptuple = [tempfile.TemporaryFile() for _ in sftps]
- # outbytes = []
- # for source, fobj in zip(sftps, temptuple):
- # source.getfo('/var/run/maglev/{}.compiled.tar.gz'.format(_id), fobj)
- # outbytes.append((fobj.tell(), None))
- # fobj.seek(0)
- # return out(tempfiles=temptuple, outbytes_err_t=outbytes)
Add Comment
Please, Sign In to add comment