mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
remove reset limits, disable debug, improve get next starrs ip, add start of template code
This commit is contained in:
parent
8fbe4de70f
commit
7b4e7fb6e8
7 changed files with 70 additions and 22 deletions
|
@ -26,10 +26,19 @@ else:
|
||||||
app.config.from_pyfile(config)
|
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()
|
['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').rstrip()
|
||||||
auth = OIDCAuthentication(
|
|
||||||
app,
|
retry = 0
|
||||||
issuer=app.config['OIDC_ISSUER'],
|
while retry < 5:
|
||||||
client_registration_info=app.config['OIDC_CLIENT_CONFIG'])
|
try:
|
||||||
|
auth = OIDCAuthentication(
|
||||||
|
app,
|
||||||
|
issuer=app.config['OIDC_ISSUER'],
|
||||||
|
client_registration_info=app.config['OIDC_CLIENT_CONFIG'])
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
retry += 1
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
cache = SimpleCache()
|
cache = SimpleCache()
|
||||||
|
|
||||||
redis_conn = Redis(app.config['REDIS_HOST'], app.config['REDIS_PORT'])
|
redis_conn = Redis(app.config['REDIS_HOST'], app.config['REDIS_PORT'])
|
||||||
|
@ -334,16 +343,6 @@ def set_limits(user):
|
||||||
return '', 403
|
return '', 403
|
||||||
|
|
||||||
|
|
||||||
@app.route('/limits/<string:user>/reset', methods=['POST'])
|
|
||||||
@auth.oidc_auth
|
|
||||||
def reset_limits(user):
|
|
||||||
if 'rtp' in session['userinfo']['groups']:
|
|
||||||
delete_user_usage_limits(user)
|
|
||||||
return '', 200
|
|
||||||
else:
|
|
||||||
return '', 403
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/user/<string:user>/delete', methods=['POST'])
|
@app.route('/user/<string:user>/delete', methods=['POST'])
|
||||||
@auth.oidc_auth
|
@auth.oidc_auth
|
||||||
def delete_user(user):
|
def delete_user(user):
|
||||||
|
@ -375,4 +374,4 @@ def logout():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run()
|
||||||
|
|
|
@ -24,7 +24,8 @@ def send_vm_expire_email(user, vms):
|
||||||
body = "The following VMs in Proxstar are expiring soon:\n\n"
|
body = "The following VMs in Proxstar are expiring soon:\n\n"
|
||||||
for vm in vms:
|
for vm in vms:
|
||||||
if vm[1] == 0:
|
if vm[1] == 0:
|
||||||
body += " - {} today (VM has been stopped)\n".format(vm[0], vm[1])
|
body += " - {} today (VM has been stopped)\n".format(
|
||||||
|
vm[0], vm[1])
|
||||||
if vm[1] == 1:
|
if vm[1] == 1:
|
||||||
body += " - {} in 1 day\n".format(vm[0])
|
body += " - {} in 1 day\n".format(vm[0])
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -28,3 +28,10 @@ class Pool_Cache(Base):
|
||||||
usage = Column(JSON, nullable=False)
|
usage = Column(JSON, nullable=False)
|
||||||
limits = Column(JSON, nullable=False)
|
limits = Column(JSON, nullable=False)
|
||||||
percents = Column(JSON, nullable=False)
|
percents = Column(JSON, nullable=False)
|
||||||
|
|
||||||
|
|
||||||
|
class Template(Base):
|
||||||
|
__tablename__ = 'template'
|
||||||
|
id = Column(Integer, primary_key=True)
|
||||||
|
name = Column(String(32), nullable=False)
|
||||||
|
desc = Column(Text)
|
||||||
|
|
|
@ -296,3 +296,25 @@ def delete_user_pool(proxmox, pool):
|
||||||
if 'rtp' not in proxmox.access.users(
|
if 'rtp' not in proxmox.access.users(
|
||||||
"{}@csh.rit.edu".format(pool)).get()['groups']:
|
"{}@csh.rit.edu".format(pool)).get()['groups']:
|
||||||
proxmox.access.users("{}@csh.rit.edu".format(pool)).delete()
|
proxmox.access.users("{}@csh.rit.edu".format(pool)).delete()
|
||||||
|
|
||||||
|
|
||||||
|
def clone_vm(proxmox, template_id, name, pool):
|
||||||
|
node = proxmox.nodes(get_vm_node(proxmox, template_id))
|
||||||
|
newid = get_free_vmid(proxmox)
|
||||||
|
target = get_node_least_mem(proxmox)
|
||||||
|
node.qemu(template_id).clone.post(
|
||||||
|
newid=newid,
|
||||||
|
name=name,
|
||||||
|
pool=pool,
|
||||||
|
full=1,
|
||||||
|
description='Managed by Proxstar',
|
||||||
|
target=target)
|
||||||
|
retry = 0
|
||||||
|
while retry < 60:
|
||||||
|
try:
|
||||||
|
mac = get_vm_mac(proxmox, newid)
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
retry += 1
|
||||||
|
time.sleep(3)
|
||||||
|
return newid, mac
|
||||||
|
|
|
@ -12,7 +12,7 @@ def get_next_ip(starrs, range_name):
|
||||||
c.execute("COMMIT")
|
c.execute("COMMIT")
|
||||||
finally:
|
finally:
|
||||||
c.close()
|
c.close()
|
||||||
return results
|
return results[0][0]
|
||||||
|
|
||||||
|
|
||||||
def get_ip_for_mac(starrs, mac):
|
def get_ip_for_mac(starrs, mac):
|
||||||
|
|
|
@ -42,8 +42,7 @@ def create_vm_task(user, name, cores, memory, disk, iso):
|
||||||
starrs = connect_starrs()
|
starrs = connect_starrs()
|
||||||
vmid, mac = create_vm(proxmox, user, name, cores, memory, disk, iso)
|
vmid, mac = create_vm(proxmox, user, name, cores, memory, disk, iso)
|
||||||
register_starrs(starrs, name, app.config['STARRS_USER'], mac,
|
register_starrs(starrs, name, app.config['STARRS_USER'], mac,
|
||||||
get_next_ip(starrs,
|
get_next_ip(starrs, app.config['STARRS_IP_RANGE']))
|
||||||
app.config['STARRS_IP_RANGE'])[0][0])
|
|
||||||
get_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS'])
|
get_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS'])
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,9 +103,30 @@ def generate_pool_cache_task():
|
||||||
store_pool_cache(db, pools)
|
store_pool_cache(db, pools)
|
||||||
|
|
||||||
|
|
||||||
def setup_template(hostname):
|
def setup_template(template_id, name, user, cores, memory):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
|
proxmox = connect_proxmox()
|
||||||
|
starrs = connect_starrs()
|
||||||
db = connect_db()
|
db = connect_db()
|
||||||
|
vmid, mac = clone_vm(proxmox, template_id, name, user)
|
||||||
|
ip = get_next_ip(starrs, app.config['STARRS_IP_RANGE'])
|
||||||
|
register_starrs(starrs, name, app.config['STARRS_USER'], mac, ip)
|
||||||
|
get_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS'])
|
||||||
|
change_vm_cpu(proxmox, vmid, cores)
|
||||||
|
change_vm_mem(proxmox, vmid, memory)
|
||||||
|
time.sleep(60)
|
||||||
|
change_vm_power(proxmox, vmid, 'start')
|
||||||
client = paramiko.SSHClient()
|
client = paramiko.SSHClient()
|
||||||
client.connect('ssh.example.com', username='root', password='todo')
|
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
|
retry = 0
|
||||||
|
while retry < 30:
|
||||||
|
try:
|
||||||
|
client.connect(ip, username='root', password='')
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
retry += 1
|
||||||
|
time.sleep(3)
|
||||||
stdin, stdout, stderr = client.exec_command('ls')
|
stdin, stdout, stderr = client.exec_command('ls')
|
||||||
|
for line in stdout:
|
||||||
|
print('... ' + line.strip('\n'))
|
||||||
|
client.close()
|
||||||
|
|
|
@ -92,7 +92,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-info proxstar-poolbtn edit-limit" data-user="{{ pool['user'] }}" data-cpu="{{ pool['limits']['cpu'] }}" data-mem="{{ pool['limits']['mem'] }}" data-disk="{{ pool['limits']['disk'] }}">EDIT</button>
|
<button class="btn btn-info proxstar-poolbtn edit-limit" data-user="{{ pool['user'] }}" data-cpu="{{ pool['limits']['cpu'] }}" data-mem="{{ pool['limits']['mem'] }}" data-disk="{{ pool['limits']['disk'] }}">EDIT</button>
|
||||||
<button class="btn btn-warning proxstar-poolbtn reset-limit" data-user="{{ pool['user'] }}">RESET</button>
|
|
||||||
{% if not pool['vms'] %}
|
{% if not pool['vms'] %}
|
||||||
<button class="btn btn-danger proxstar-poolbtn delete-user" data-user="{{ pool['user'] }}">DELETE</button>
|
<button class="btn btn-danger proxstar-poolbtn delete-user" data-user="{{ pool['user'] }}">DELETE</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue