diff --git a/.travis.yml b/.travis.yml index e74c499..dedf392 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,4 @@ python: install: - "pip install -r requirements.txt" script: - - "pylint proxstar" + - "pylint --load-plugins pylint_quotes proxstar" diff --git a/proxstar/__init__.py b/proxstar/__init__.py index 1c4afec..a08da08 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -31,13 +31,13 @@ app = Flask(__name__) app.config.from_object(rq_dashboard.default_settings) if os.path.exists( os.path.join( - app.config.get('ROOT_DIR', os.getcwd()), "config.local.py")): + app.config.get('ROOT_DIR', os.getcwd()), 'config.local.py')): config = os.path.join( - app.config.get('ROOT_DIR', os.getcwd()), "config.local.py") + app.config.get('ROOT_DIR', os.getcwd()), 'config.local.py') else: - config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), "config.py") + config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), 'config.py') app.config.from_pyfile(config) -app.config["GIT_REVISION"] = subprocess.check_output( +app.config['GIT_REVISION'] = subprocess.check_output( ['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').rstrip() with open('proxmox_ssh_key', 'w') as ssh_key_file: @@ -98,7 +98,7 @@ def add_rq_dashboard_auth(blueprint): rq_dashboard_blueprint = rq_dashboard.blueprint add_rq_dashboard_auth(rq_dashboard_blueprint) -app.register_blueprint(rq_dashboard_blueprint, url_prefix="/rq") +app.register_blueprint(rq_dashboard_blueprint, url_prefix='/rq') @app.errorhandler(404) @@ -113,8 +113,8 @@ def forbidden(e): return render_template('403.html', user=user, e=e), 403 -@app.route("/") -@app.route("/user/") +@app.route('/') +@app.route('/user/') @auth.oidc_auth def list_vms(user_view=None): user = User(session['userinfo']['preferred_username']) @@ -155,15 +155,15 @@ def list_vms(user_view=None): 'list_vms.html', user=user, rtp_view=rtp_view, vms=vms) -@app.route("/isos") +@app.route('/isos') @auth.oidc_auth def isos(): proxmox = connect_proxmox() stored_isos = get_isos(proxmox, app.config['PROXMOX_ISO_STORAGE']) - return json.dumps({"isos": stored_isos}) + return json.dumps({'isos': stored_isos}) -@app.route("/hostname/") +@app.route('/hostname/') @auth.oidc_auth def hostname(name): valid, available = check_hostname(starrs, name) @@ -175,7 +175,7 @@ def hostname(name): return 'ok' -@app.route("/vm/") +@app.route('/vm/') @auth.oidc_auth def vm_details(vmid): user = User(session['userinfo']['preferred_username']) @@ -194,7 +194,7 @@ def vm_details(vmid): return abort(403) -@app.route("/vm//power/", methods=['POST']) +@app.route('/vm//power/', methods=['POST']) @auth.oidc_auth def vm_power(vmid, action): user = User(session['userinfo']['preferred_username']) @@ -226,7 +226,7 @@ def vm_power(vmid, action): return '', 403 -@app.route("/console/vm//stop", methods=['POST']) +@app.route('/console/vm//stop', methods=['POST']) def vm_console_stop(vmid): if request.form['token'] == app.config['VNC_CLEANUP_TOKEN']: stop_ssh_tunnel(vmid, ssh_tunnels) @@ -235,7 +235,7 @@ def vm_console_stop(vmid): return '', 403 -@app.route("/console/vm/", methods=['POST']) +@app.route('/console/vm/', methods=['POST']) @auth.oidc_auth def vm_console(vmid): user = User(session['userinfo']['preferred_username']) @@ -245,8 +245,8 @@ def vm_console(vmid): stop_ssh_tunnel(vm.id, ssh_tunnels) port = str(5900 + int(vmid)) token = add_vnc_target(port) - node = "{}.csh.rit.edu".format(vm.node) - logging.info("creating SSH tunnel to %s for VM %s", node, vm.id) + node = '{}.csh.rit.edu'.format(vm.node) + logging.info('creating SSH tunnel to %s for VM %s', node, vm.id) tunnel = start_ssh_tunnel(node, port) ssh_tunnels.append(tunnel) vm.start_vnc(port) @@ -255,7 +255,7 @@ def vm_console(vmid): return '', 403 -@app.route("/vm//cpu/", methods=['POST']) +@app.route('/vm//cpu/', methods=['POST']) @auth.oidc_auth def vm_cpu(vmid, cores): user = User(session['userinfo']['preferred_username']) @@ -276,7 +276,7 @@ def vm_cpu(vmid, cores): return '', 403 -@app.route("/vm//mem/", methods=['POST']) +@app.route('/vm//mem/', methods=['POST']) @auth.oidc_auth def vm_mem(vmid, mem): user = User(session['userinfo']['preferred_username']) @@ -297,7 +297,7 @@ def vm_mem(vmid, mem): return '', 403 -@app.route("/vm//disk//", methods=['POST']) +@app.route('/vm//disk//', methods=['POST']) @auth.oidc_auth def vm_disk(vmid, disk, size): user = User(session['userinfo']['preferred_username']) @@ -313,7 +313,7 @@ def vm_disk(vmid, disk, size): return '', 403 -@app.route("/vm//renew", methods=['POST']) +@app.route('/vm//renew', methods=['POST']) @auth.oidc_auth def vm_renew(vmid): user = User(session['userinfo']['preferred_username']) @@ -329,7 +329,7 @@ def vm_renew(vmid): return '', 403 -@app.route("/vm//eject", methods=['POST']) +@app.route('/vm//eject', methods=['POST']) @auth.oidc_auth def iso_eject(vmid): user = User(session['userinfo']['preferred_username']) @@ -342,13 +342,13 @@ def iso_eject(vmid): return '', 403 -@app.route("/vm//mount/", methods=['POST']) +@app.route('/vm//mount/', methods=['POST']) @auth.oidc_auth def iso_mount(vmid, iso): user = User(session['userinfo']['preferred_username']) connect_proxmox() if user.rtp or int(vmid) in user.allowed_vms: - iso = "{}:iso/{}".format(app.config['PROXMOX_ISO_STORAGE'], iso) + iso = '{}:iso/{}'.format(app.config['PROXMOX_ISO_STORAGE'], iso) vm = VM(vmid) vm.mount_iso(iso) return '', 200 @@ -356,7 +356,7 @@ def iso_mount(vmid, iso): return '', 403 -@app.route("/vm//delete", methods=['POST']) +@app.route('/vm//delete', methods=['POST']) @auth.oidc_auth def delete(vmid): user = User(session['userinfo']['preferred_username']) @@ -370,7 +370,7 @@ def delete(vmid): return '', 403 -@app.route("/vm//boot_order", methods=['POST']) +@app.route('/vm//boot_order', methods=['POST']) @auth.oidc_auth def get_boot_order(vmid): user = User(session['userinfo']['preferred_username']) @@ -386,7 +386,7 @@ def get_boot_order(vmid): return '', 403 -@app.route("/vm/create", methods=['GET', 'POST']) +@app.route('/vm/create', methods=['GET', 'POST']) @auth.oidc_auth def create(): user = User(session['userinfo']['preferred_username']) @@ -414,7 +414,7 @@ def create(): iso = request.form['iso'] ssh_key = request.form['ssh_key'] if iso != 'none': - iso = "{}:iso/{}".format(app.config['PROXMOX_ISO_STORAGE'], + iso = '{}:iso/{}'.format(app.config['PROXMOX_ISO_STORAGE'], iso) if not user.rtp: if template == 'none': @@ -481,7 +481,7 @@ def delete_user(user): return '', 403 -@app.route("/settings") +@app.route('/settings') @auth.oidc_auth def settings(): user = User(session['userinfo']['preferred_username']) @@ -499,33 +499,33 @@ def settings(): return abort(403) -@app.route("/pool//ignore", methods=['POST', 'DELETE']) +@app.route('/pool//ignore', methods=['POST', 'DELETE']) @auth.oidc_auth def ignored_pools(pool): if 'rtp' in session['userinfo']['groups']: if request.method == 'POST': add_ignored_pool(db, pool) - elif request.method == "DELETE": + elif request.method == 'DELETE': delete_ignored_pool(db, pool) return '', 200 else: return '', 403 -@app.route("/user//allow", methods=['POST', 'DELETE']) +@app.route('/user//allow', methods=['POST', 'DELETE']) @auth.oidc_auth def allowed_users(user): if 'rtp' in session['userinfo']['groups']: if request.method == 'POST': add_allowed_user(db, user) - elif request.method == "DELETE": + elif request.method == 'DELETE': delete_allowed_user(db, user) return '', 200 else: return '', 403 -@app.route("/console/cleanup", methods=['POST']) +@app.route('/console/cleanup', methods=['POST']) def cleanup_vnc(): if request.form['token'] == app.config['VNC_CLEANUP_TOKEN']: for target in get_vnc_targets(): @@ -567,7 +567,7 @@ def template_edit(template_id): return '', 403 -@app.route("/logout") +@app.route('/logout') @auth.oidc_logout def logout(): return redirect(url_for('list_vms'), 302) @@ -584,5 +584,5 @@ def exit_handler(): atexit.register(exit_handler) -if __name__ == "__main__": +if __name__ == '__main__': app.run(threaded=False) diff --git a/proxstar/ldapdb.py b/proxstar/ldapdb.py index 2ddc31a..c737310 100644 --- a/proxstar/ldapdb.py +++ b/proxstar/ldapdb.py @@ -8,7 +8,7 @@ def connect_ldap(): try: ldap = CSHLDAP(app.config['LDAP_BIND_DN'], app.config['LDAP_BIND_PW']) except Exception as e: - logging.error("unable to connect to LDAP: %s", e) + logging.error('unable to connect to LDAP: %s', e) raise return ldap diff --git a/proxstar/mail.py b/proxstar/mail.py index 10721b6..4e3c741 100644 --- a/proxstar/mail.py +++ b/proxstar/mail.py @@ -21,38 +21,38 @@ def send_email(toaddr, subject, body): def send_vm_expire_email(user, vms): - toaddr = "{}@csh.rit.edu".format(user) + toaddr = '{}@csh.rit.edu'.format(user) subject = 'Proxstar VM Expiration Notice' - body = "The following VMs in Proxstar are expiring soon or have already expired:\n\n" + body = 'The following VMs in Proxstar are expiring soon or have already expired:\n\n' for vm in vms: if vm[2] == -6: - body += " - {} ({}) has expired (VM has been stopped and will be deleted in 1 day)\n".format( + body += ' - {} ({}) has expired (VM has been stopped and will be deleted in 1 day)\n'.format( vm[1], vm[0]) elif vm[2] < 0: - body += " - {} ({}) has expired (VM has been stopped and will be deleted in {} days)\n".format( + body += ' - {} ({}) has expired (VM has been stopped and will be deleted in {} days)\n'.format( 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( + body += ' - {} ({}) expires today (VM has been stopped and will be deleted in 7 days)\n'.format( vm[1], vm[0]) elif vm[2] == 1: - body += " - {} ({}) expires in 1 day\n".format(vm[1], vm[0]) + body += ' - {} ({}) expires in 1 day\n'.format(vm[1], vm[0]) else: - body += " - {} ({}) expires in {} days\n".format( + 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." + body += '\nPlease login to Proxstar (https://proxstar.csh.rit.edu/) and renew any VMs you would like to keep.' send_email(toaddr, subject, body) def send_rtp_vm_delete_email(vms): toaddr = 'rtp@csh.rit.edu' subject = 'Proxstar VM Deletion Report' - body = "The following VMs in Proxstar have expired and will be deleted soon:\n\n" + 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( + body += ' - {} ({}) will be deleted in 1 day\n'.format( vm[1], vm[0]) else: - body += " - {} ({}) will be deleted in {} days\n".format( + body += ' - {} ({}) will be deleted in {} days\n'.format( 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) diff --git a/proxstar/starrs.py b/proxstar/starrs.py index faa1664..74b8a75 100644 --- a/proxstar/starrs.py +++ b/proxstar/starrs.py @@ -4,11 +4,11 @@ import psycopg2 def get_next_ip(starrs, range_name): c = starrs.cursor() try: - c.execute("BEGIN") - c.callproc("api.initialize", ('root', )) - c.callproc("api.get_address_from_range", (range_name, )) + c.execute('BEGIN') + c.callproc('api.initialize', ('root', )) + c.callproc('api.get_address_from_range', (range_name, )) results = c.fetchall() - c.execute("COMMIT") + c.execute('COMMIT') finally: c.close() return results[0][0] @@ -17,11 +17,11 @@ def get_next_ip(starrs, range_name): def get_ip_for_mac(starrs, mac): c = starrs.cursor() try: - c.execute("BEGIN") - c.callproc("api.initialize", ('root', )) - c.callproc("api.get_system_interface_addresses", (mac.lower(), )) + c.execute('BEGIN') + c.callproc('api.initialize', ('root', )) + c.callproc('api.get_system_interface_addresses', (mac.lower(), )) results = c.fetchall() - c.execute("COMMIT") + c.execute('COMMIT') finally: c.close() if not results: @@ -32,11 +32,11 @@ def get_ip_for_mac(starrs, mac): def renew_ip(starrs, addr): c = starrs.cursor() try: - c.execute("BEGIN") - c.callproc("api.initialize", ('root', )) - c.callproc("api.renew_interface_address", (addr, )) + c.execute('BEGIN') + c.callproc('api.initialize', ('root', )) + c.callproc('api.renew_interface_address', (addr, )) results = c.fetchall() - c.execute("COMMIT") + c.execute('COMMIT') finally: c.close() return results @@ -47,31 +47,31 @@ def check_hostname(starrs, hostname): c = starrs.cursor() try: # Check for invalid characters in hostname - c.execute("BEGIN") - c.callproc("api.initialize", ('root', )) - c.callproc("api.validate_name", (hostname, )) - c.execute("COMMIT") + c.execute('BEGIN') + c.callproc('api.initialize', ('root', )) + c.callproc('api.validate_name', (hostname, )) + c.execute('COMMIT') # Validate the entire domain name using Data::Validate::Domain - c.execute("BEGIN") - c.callproc("api.initialize", ('root', )) - c.callproc("api.validate_domain", (hostname, 'csh.rit.edu')) + c.execute('BEGIN') + c.callproc('api.initialize', ('root', )) + c.callproc('api.validate_domain', (hostname, 'csh.rit.edu')) valid = c.fetchall()[0][0] - c.execute("COMMIT") + c.execute('COMMIT') # Check if the hostname is available (checks A/SRV/CNAME records) - c.execute("BEGIN") - c.callproc("api.initialize", ('root', )) - c.callproc("api.check_dns_hostname", (hostname, 'csh.rit.edu')) + c.execute('BEGIN') + c.callproc('api.initialize', ('root', )) + c.callproc('api.check_dns_hostname', (hostname, 'csh.rit.edu')) available = False if not c.fetchall()[0][0]: available = True - c.execute("COMMIT") + c.execute('COMMIT') # Check if the system name is taken - c.execute("BEGIN") - c.callproc("api.initialize", ('root', )) - c.callproc("api.get_system", (hostname, )) + c.execute('BEGIN') + c.callproc('api.initialize', ('root', )) + c.callproc('api.get_system', (hostname, )) if c.fetchall(): available = False - c.execute("COMMIT") + c.execute('COMMIT') except psycopg2.InternalError: valid = False available = False @@ -83,13 +83,13 @@ def check_hostname(starrs, hostname): def register_starrs(starrs, name, owner, mac, addr): c = starrs.cursor() try: - c.execute("BEGIN") - c.callproc("api.initialize", ('root', )) + c.execute('BEGIN') + c.callproc('api.initialize', ('root', )) c.callproc( - "api.create_system_quick", + 'api.create_system_quick', (name, owner, 'members', mac, addr, 'csh.rit.edu', 'dhcp', True)) results = c.fetchall() - c.execute("COMMIT") + c.execute('COMMIT') finally: c.close() return results @@ -98,11 +98,11 @@ def register_starrs(starrs, name, owner, mac, addr): def delete_starrs(starrs, name): c = starrs.cursor() try: - c.execute("BEGIN") - c.callproc("api.initialize", ('root', )) - c.callproc("api.remove_system", (name, )) + c.execute('BEGIN') + c.callproc('api.initialize', ('root', )) + c.callproc('api.remove_system', (name, )) results = c.fetchall() - c.execute("COMMIT") + c.execute('COMMIT') finally: c.close() return results diff --git a/proxstar/tasks.py b/proxstar/tasks.py index 8615bde..92e5ef5 100644 --- a/proxstar/tasks.py +++ b/proxstar/tasks.py @@ -23,11 +23,11 @@ logging.basicConfig( app = Flask(__name__) if os.path.exists( os.path.join( - app.config.get('ROOT_DIR', os.getcwd()), "config.local.py")): + app.config.get('ROOT_DIR', os.getcwd()), 'config.local.py')): config = os.path.join( - app.config.get('ROOT_DIR', os.getcwd()), "config.local.py") + app.config.get('ROOT_DIR', os.getcwd()), 'config.local.py') else: - config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), "config.py") + config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), 'config.py') app.config.from_pyfile(config) @@ -58,11 +58,11 @@ def create_vm_task(user, name, cores, memory, disk, iso): proxmox = connect_proxmox() db = connect_db() starrs = connect_starrs() - logging.info("[{}] Creating VM.".format(name)) + logging.info('[{}] Creating VM.'.format(name)) set_job_status(job, 'creating VM') vmid = create_vm(proxmox, user, name, cores, memory, disk, iso) logging.info( - "[{}] Waiting until Proxmox is done provisioning.".format(name)) + '[{}] Waiting until Proxmox is done provisioning.'.format(name)) set_job_status(job, 'waiting for Proxmox') timeout = 20 retry = 0 @@ -73,11 +73,11 @@ def create_vm_task(user, name, cores, memory, disk, iso): continue break if retry == timeout: - logging.info("[{}] Failed to provision, deleting.".format(name)) + logging.info('[{}] Failed to provision, deleting.'.format(name)) set_job_status(job, 'failed to provision') delete_vm_task(vmid) return - logging.info("[{}] Registering in STARRS.".format(name)) + logging.info('[{}] Registering in STARRS.'.format(name)) set_job_status(job, 'registering in STARRS') vm = VM(vmid) ip = get_next_ip(starrs, app.config['STARRS_IP_RANGE']) @@ -85,7 +85,7 @@ def create_vm_task(user, name, cores, memory, disk, iso): ip) set_job_status(job, 'setting VM expiration') get_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS']) - logging.info("[{}] VM successfully provisioned.".format(name)) + logging.info('[{}] VM successfully provisioned.'.format(name)) set_job_status(job, 'complete') @@ -129,7 +129,7 @@ def process_expiring_vms_task(): vm.stop() elif days <= -7: logging.info( - "Deleting {} ({}) as it has been at least a week since expiration." + 'Deleting {} ({}) as it has been at least a week since expiration.' .format(vm.name, vm.id)) send_stop_ssh_tunnel(vm.id) delete_vm_task(vm.id) @@ -153,14 +153,14 @@ def setup_template_task(template_id, name, user, ssh_key, cores, memory): proxmox = connect_proxmox() starrs = connect_starrs() db = connect_db() - logging.info("[{}] Retrieving template info for template {}.".format( + logging.info('[{}] Retrieving template info for template {}.'.format( name, template_id)) get_template(db, template_id) - logging.info("[{}] Cloning template {}.".format(name, template_id)) + logging.info('[{}] Cloning template {}.'.format(name, template_id)) set_job_status(job, 'cloning template') vmid = clone_vm(proxmox, template_id, name, user) logging.info( - "[{}] Waiting until Proxmox is done provisioning.".format(name)) + '[{}] Waiting until Proxmox is done provisioning.'.format(name)) set_job_status(job, 'waiting for Proxmox') timeout = 20 retry = 0 @@ -171,43 +171,43 @@ def setup_template_task(template_id, name, user, ssh_key, cores, memory): continue break if retry == timeout: - logging.info("[{}] Failed to provision, deleting.".format(name)) + logging.info('[{}] Failed to provision, deleting.'.format(name)) set_job_status(job, 'failed to provision') delete_vm_task(vmid) return - logging.info("[{}] Registering in STARRS.".format(name)) + logging.info('[{}] Registering in STARRS.'.format(name)) set_job_status(job, 'registering in STARRS') vm = VM(vmid) ip = get_next_ip(starrs, app.config['STARRS_IP_RANGE']) register_starrs(starrs, name, app.config['STARRS_USER'], vm.get_mac(), ip) get_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS']) - logging.info("[{}] Setting CPU and memory.".format(name)) + logging.info('[{}] Setting CPU and memory.'.format(name)) set_job_status(job, 'setting CPU and memory') vm.set_cpu(cores) vm.set_mem(memory) - logging.info("[{}] Applying cloud-init config.".format(name)) + logging.info('[{}] Applying cloud-init config.'.format(name)) set_job_status(job, 'applying cloud-init') vm.set_ci_user(user) vm.set_ci_ssh_key(ssh_key) vm.set_ci_network() logging.info( - "[{}] Waiting for STARRS to propogate before starting VM.".format( + '[{}] Waiting for STARRS to propogate before starting VM.'.format( name)) set_job_status(job, 'waiting for STARRS') job.save_meta() time.sleep(90) - logging.info("[{}] Starting VM.".format(name)) + logging.info('[{}] Starting VM.'.format(name)) set_job_status(job, 'starting VM') job.save_meta() vm.start() - logging.info("[{}] Template successfully provisioned.".format(name)) + logging.info('[{}] Template successfully provisioned.'.format(name)) set_job_status(job, 'completed') job.save_meta() def cleanup_vnc_task(): requests.post( - "https://{}/console/cleanup".format(app.config['SERVER_NAME']), + 'https://{}/console/cleanup'.format(app.config['SERVER_NAME']), data={'token': app.config['VNC_CLEANUP_TOKEN']}, verify=False) diff --git a/proxstar/user.py b/proxstar/user.py index 1febf5d..17b70ff 100644 --- a/proxstar/user.py +++ b/proxstar/user.py @@ -108,11 +108,11 @@ class User(): proxmox = connect_proxmox() proxmox.pools(self.name).delete() users = proxmox.access.users.get() - if any(user['userid'] == "{}@csh.rit.edu".format(self.name) + if any(user['userid'] == '{}@csh.rit.edu'.format(self.name) for user in users): - if 'rtp' not in proxmox.access.users("{}@csh.rit.edu".format( + if 'rtp' not in proxmox.access.users('{}@csh.rit.edu'.format( self.name)).get()['groups']: - proxmox.access.users("{}@csh.rit.edu".format( + proxmox.access.users('{}@csh.rit.edu'.format( self.name)).delete() diff --git a/proxstar/util.py b/proxstar/util.py index 2ef474b..d218160 100644 --- a/proxstar/util.py +++ b/proxstar/util.py @@ -3,7 +3,7 @@ import random def gen_password( length, - charset="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*" + charset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*' ): # use secrets module once this works in python 3.6 return ''.join(random.choice(charset) for x in range(length)) diff --git a/proxstar/vm.py b/proxstar/vm.py index 7b76a0c..26eca11 100644 --- a/proxstar/vm.py +++ b/proxstar/vm.py @@ -210,7 +210,7 @@ class VM(): proxmox = connect_proxmox() port = str(int(port) - 5900) proxmox.nodes(self.node).qemu(self.id).monitor.post( - command="change vnc 127.0.0.1:{}".format(port)) + command='change vnc 127.0.0.1:{}'.format(port)) @retry(wait=wait_fixed(2), stop=stop_after_attempt(5)) def eject_iso(self): @@ -222,12 +222,12 @@ class VM(): def mount_iso(self, iso): proxmox = connect_proxmox() proxmox.nodes(self.node).qemu( - self.id).config.post(ide2="{},media=cdrom".format(iso)) + self.id).config.post(ide2='{},media=cdrom'.format(iso)) def resize_disk(self, disk, size): proxmox = connect_proxmox() proxmox.nodes(self.node).qemu(self.id).resize.put( - disk=disk, size="+{}G".format(size)) + disk=disk, size='+{}G'.format(size)) @lazy_property def expire(self): @@ -263,8 +263,8 @@ def create_vm(proxmox, user, name, cores, memory, disk, iso): cores=cores, memory=memory, storage='ceph', - virtio0="ceph:{}".format(disk), - ide2="{},media=cdrom".format(iso), + virtio0='ceph:{}'.format(disk), + ide2='{},media=cdrom'.format(iso), net0='virtio,bridge=vmbr0', pool=user, description='Managed by Proxstar') diff --git a/proxstar/vnc.py b/proxstar/vnc.py index d133f16..3dd196e 100644 --- a/proxstar/vnc.py +++ b/proxstar/vnc.py @@ -21,7 +21,7 @@ def stop_websockify(): time.sleep(10) if subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE).stdout: - logging.info('websockify didn\'t stop, killing forcefully') + logging.info("websockify didn't stop, killing forcefully") subprocess.run(['kill', '-9', pid], stdout=subprocess.PIPE) @@ -48,7 +48,7 @@ def add_vnc_target(port): else: target_file = open(app.config['WEBSOCKIFY_TARGET_FILE'], 'a') token = gen_password(32, 'abcdefghijklmnopqrstuvwxyz0123456789') - target_file.write("{}: 127.0.0.1:{}\n".format(token, str(port))) + target_file.write('{}: 127.0.0.1:{}\n'.format(token, str(port))) target_file.close() return token @@ -61,7 +61,7 @@ def delete_vnc_target(port): 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_file.write('{}: 127.0.0.1:{}\n'.format( target['token'], target['port'])) target_file.close() @@ -97,7 +97,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'], + 'https://{}/console/vm/{}/stop'.format(app.config['SERVER_NAME'], vmid), data={'token': app.config['VNC_CLEANUP_TOKEN']}, verify=False)