Adding requirements, deleting travis, updating pylint

This commit is contained in:
Devin Matte 2020-12-21 15:24:29 -05:00
parent 8b9567d21a
commit 7a312f1f79
5 changed files with 34 additions and 39 deletions

View file

@ -11,18 +11,16 @@ from proxstar.util import gen_password
def stop_websockify():
result = subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE)
result = subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE, check=False)
if result.stdout:
pid = result.stdout.strip()
subprocess.run(['kill', pid], stdout=subprocess.PIPE)
subprocess.run(['kill', pid], stdout=subprocess.PIPE, check=False)
time.sleep(3)
if subprocess.run(['pgrep', 'websockify'],
stdout=subprocess.PIPE).stdout:
if subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE, check=False).stdout:
time.sleep(10)
if subprocess.run(['pgrep', 'websockify'],
stdout=subprocess.PIPE).stdout:
if subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE, check=False).stdout:
logging.info("websockify didn't stop, killing forcefully")
subprocess.run(['kill', '-9', pid], stdout=subprocess.PIPE)
subprocess.run(['kill', '-9', pid], stdout=subprocess.PIPE, check=False)
def get_vnc_targets():
@ -41,8 +39,7 @@ def get_vnc_targets():
def add_vnc_target(port):
targets = get_vnc_targets()
target = next((target for target in targets if target['port'] == port),
None)
target = next((target for target in targets if target['port'] == port), None)
if target:
return target['token']
else:
@ -55,14 +52,12 @@ def add_vnc_target(port):
def delete_vnc_target(port):
targets = get_vnc_targets()
target = next(
(target for target in targets if target['port'] == str(port)), None)
target = next((target for target in targets if target['port'] == str(port)), None)
if target:
targets.remove(target)
target_file = open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w')
for target in targets:
target_file.write('{}: 127.0.0.1:{}\n'.format(
target['token'], target['port']))
target_file.write('{}: 127.0.0.1:{}\n'.format(target['token'], target['port']))
target_file.close()
@ -74,7 +69,8 @@ def start_ssh_tunnel(node, port):
ssh_pkey='proxmox_ssh_key',
ssh_private_key_password=app.config['PROXMOX_SSH_KEY_PASS'],
remote_bind_address=('127.0.0.1', port),
local_bind_address=('127.0.0.1', port))
local_bind_address=('127.0.0.1', port),
)
server.start()
return server
@ -82,9 +78,7 @@ def start_ssh_tunnel(node, port):
def stop_ssh_tunnel(vmid, ssh_tunnels):
# Tear down the SSH tunnel and VNC target entry for a given VM
port = 5900 + int(vmid)
tunnel = next(
(tunnel for tunnel in ssh_tunnels if tunnel.local_bind_port == port),
None)
tunnel = next((tunnel for tunnel in ssh_tunnels if tunnel.local_bind_port == port), None)
if tunnel:
logging.info('tearing down SSH tunnel for VM %s', vmid)
try:
@ -97,7 +91,7 @@ def stop_ssh_tunnel(vmid, ssh_tunnels):
def send_stop_ssh_tunnel(vmid):
requests.post(
'https://{}/console/vm/{}/stop'.format(app.config['SERVER_NAME'],
vmid),
'https://{}/console/vm/{}/stop'.format(app.config['SERVER_NAME'], vmid),
data={'token': app.config['VNC_CLEANUP_TOKEN']},
verify=False)
verify=False,
)