[1413] | 1 | #!/usr/bin/python |
---|
[1336] | 2 | |
---|
[1413] | 3 | from invirt.config import structs as config |
---|
[2261] | 4 | from subprocess import Popen, check_call, PIPE, CalledProcessError |
---|
[1413] | 5 | import tempfile |
---|
| 6 | import os |
---|
| 7 | import sys |
---|
| 8 | import shutil |
---|
[1336] | 9 | |
---|
[2261] | 10 | def check_wait(popen): |
---|
| 11 | retcode = popen.wait() |
---|
| 12 | if retcode != 0: |
---|
| 13 | raise CalledProcessError(retcode, popen.pid) |
---|
| 14 | return retcode |
---|
| 15 | |
---|
[1413] | 16 | def main(): |
---|
[2261] | 17 | check_call(['kinit', '-k', 'daemon/%s' % config.web.hostname]) |
---|
[1413] | 18 | |
---|
[2261] | 19 | temp_dir = tempfile.mkdtemp() |
---|
| 20 | |
---|
| 21 | jarfile = os.path.join(temp_dir, 'VncViewer.jar') |
---|
| 22 | |
---|
[1588] | 23 | shutil.copy('/usr/share/invirt-vnc-client/VncViewer.src.jar', |
---|
[2261] | 24 | jarfile) |
---|
[1588] | 25 | |
---|
[1413] | 26 | keystore = os.path.join(temp_dir, 'trust.store') |
---|
| 27 | for host in config.hosts: |
---|
[1418] | 28 | cert = Popen(['remctl', config.remote.hostname, 'web', 'vnccert', host.hostname], |
---|
| 29 | stdout=PIPE) |
---|
[2261] | 30 | check_wait(cert) |
---|
| 31 | check_call(['keytool', '-import', '-noprompt', '-alias', host.hostname, |
---|
| 32 | '-keystore', keystore, '-storepass', 'foobar'], |
---|
| 33 | stdin=cert.stdout) |
---|
[1413] | 34 | |
---|
[2261] | 35 | check_call(['jar', 'uf', jarfile, |
---|
| 36 | '-C', temp_dir, 'trust.store']) |
---|
| 37 | |
---|
| 38 | shutil.move(jarfile, '/usr/share/invirt-vnc-client/VncViewer.jar') |
---|
[1413] | 39 | |
---|
| 40 | shutil.rmtree(temp_dir) |
---|
[1336] | 41 | |
---|
[1413] | 42 | if __name__ == '__main__': |
---|
| 43 | sys.exit(main()) |
---|