Guest User

Untitled

a guest
Mar 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. # class RCASSHProxy:
  2. # def __init__(self, hosts, request):
  3. # auth_str = request.headers['Authorization'].split(' ')[1]
  4. # user, passw = base64.urlsafe_b64decode(
  5. # '{}==='.format(auth_str)).decode('utf8').split(':')
  6. # usernames = it.repeat(user)
  7. # passwords = it.repeat(passw)
  8. # self.jwt = request.headers['X-AUTH-TOKEN']
  9. # self.prefix = '/opt/maglev/bin'
  10. # self.clients = [(host, paramiko.SSHClient()) for host in hosts]
  11. # for (h, c), h, u, p in zip(self.clients, hosts, usernames, passwords):
  12. # c.set_missing_host_key_policy(paramiko.WarningPolicy)
  13. # c.connect(h, username=u, password=p)
  14. #
  15. # def _exec_cmd(self, cmd, opts=None):
  16. # opts = opts or {}
  17. # abscmd='{} {}'.format(os.path.join(self.prefix, 'exec_proxy.py'), cmd)
  18. # res = [(h, c.exec_command(abscmd, environment=dict(CLUSTER=h, **opts)))
  19. # for (h, c) in self.clients]
  20. #
  21. # def try_json(ress):
  22. # utf8reader = codecs.getreader('utf8')
  23. # for h, (_, res, err) in ress:
  24. # errstr = utf8reader(err).read(-1)
  25. # r = utf8reader(res).read(-1)
  26. # try:
  27. # yield h, json.loads(r), errstr
  28. # except ValueError:
  29. # yield h, r, errstr
  30. #
  31. # return [
  32. # {
  33. # 'host': h,
  34. # 'err': e,
  35. # 'out': o
  36. # } for h, o, e in try_json(res)
  37. # ]
  38. #
  39. # def _with_err(self, x):
  40. # if any(bool(i['err']) for i in x):
  41. # return x, RCAStatus.ERROR
  42. #
  43. # status_set = {i['out']['status'] for i in x}
  44. # status = RCAStatus(status_set.pop()) if len(status_set) == 1 \
  45. # else RCAStatus.RUNNING
  46. # return x, status
  47. #
  48. # def delete(self, _id):
  49. # return self._with_err(self._exec_cmd('delete {}'.format(_id)))
  50. #
  51. # def status(self, _id):
  52. # return self._with_err(self._exec_cmd('status {}'.format(_id)))
  53. #
  54. # def exec(self, cmd, _id, name, description):
  55. # opts = dict(RCA_DIR='/var/run/maglev/{}.tmp'.format(_id),
  56. # STDOUT='/var/run/maglev/{}.stdout'.format(_id),
  57. # OUTFILE='/var/run/maglev/{}.output.tar.gz'.format(_id),
  58. # TOKEN=self.jwt)
  59. # return self._with_err(self._exec_cmd('exec {} /opt/maglev/bin/{}'
  60. # .format(_id, cmd), opts))
  61. #
  62. # def download(self, _id):
  63. # out = namedtuple('download_struct', ['tempfiles', 'outbytes_err_t'])
  64. # sftps = [c.open_sftp() for h, c in self.clients]
  65. # temptuple = [tempfile.TemporaryFile() for _ in sftps]
  66. # outbytes = []
  67. # for source, fobj in zip(sftps, temptuple):
  68. # source.getfo('/var/run/maglev/{}.compiled.tar.gz'.format(_id), fobj)
  69. # outbytes.append((fobj.tell(), None))
  70. # fobj.seek(0)
  71. # return out(tempfiles=temptuple, outbytes_err_t=outbytes)
Add Comment
Please, Sign In to add comment