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

@ -1,8 +0,0 @@
language: python
python:
- "3.6"
install:
- "pip install -r requirements.txt"
script:
- "pylint proxstar"

View file

@ -11,7 +11,6 @@ def send_email(toaddr, subject, body):
msg['To'] = toaddr
msg['Subject'] = subject
msg['Date'] = formatdate(localtime=True)
body = body
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('mail.csh.rit.edu', 25)
server.starttls()
@ -27,18 +26,20 @@ def send_vm_expire_email(user, vms):
for vm in vms:
if vm[2] == -6:
body += ' - {} ({}) has expired (VM has been stopped and will be deleted in 1 day)\n'.format(
vm[1], vm[0])
vm[1], vm[0]
)
elif vm[2] < 0:
body += ' - {} ({}) has expired (VM has been stopped and will be deleted in {} days)\n'.format(
vm[1], vm[0], (7 + int(vm[2])))
vm[1], vm[0], (7 + int(vm[2]))
)
elif vm[2] == 0:
body += ' - {} ({}) expires today (VM has been stopped and will be deleted in 7 days)\n'.format(
vm[1], vm[0])
vm[1], vm[0]
)
elif vm[2] == 1:
body += ' - {} ({}) expires in 1 day\n'.format(vm[1], vm[0])
else:
body += ' - {} ({}) expires in {} days\n'.format(
vm[1], vm[0], vm[2])
body += ' - {} ({}) expires in {} days\n'.format(vm[1], vm[0], vm[2])
body += '\nPlease login to Proxstar (https://proxstar.csh.rit.edu/) and renew any VMs you would like to keep.'
send_email(toaddr, subject, body)
@ -49,10 +50,10 @@ def send_rtp_vm_delete_email(vms):
body = 'The following VMs in Proxstar have expired and will be deleted soon:\n\n'
for vm in vms:
if vm[2] == -6:
body += ' - {} ({}) will be deleted in 1 day\n'.format(
vm[1], vm[0])
body += ' - {} ({}) will be deleted in 1 day\n'.format(vm[1], vm[0])
else:
body += ' - {} ({}) will be deleted in {} days\n'.format(
vm[1], vm[0], (7 + int(vm[2])))
vm[1], vm[0], (7 + int(vm[2]))
)
body += "\nPlease verify this list to ensure there aren't any pools included in Proxstar that shouldn't be."
send_email(toaddr, subject, body)

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,
)

7
pyproject.toml Normal file
View file

@ -0,0 +1,7 @@
[tool.black]
# default is 88
line-length = 100
skip-string-normalization = true
# default is per-file auto-detection
target-version = ['py38']
include = '\.py$'

View file

@ -1,3 +1,4 @@
black~=20.8b1
csh-ldap~=2.2.0
flask==1.0.2
flask-pyoidc==1.3.0
@ -16,7 +17,7 @@ sqlalchemy==1.3.20
sshtunnel==0.2.2
tenacity==5.0.2
websockify==0.8.0
pylint==2.3.1
pylint==2.6.0
pylint-quotes==0.2.1
sentry-sdk[flask]
sentry-sdk~=0.18.0
sentry-sdk~=0.19.5