File tree Expand file tree Collapse file tree 2 files changed +26
-12
lines changed Expand file tree Collapse file tree 2 files changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -335,6 +335,7 @@ def vm_console(vmid):
335335 if user .rtp or int (vmid ) in user .allowed_vms :
336336 # import pdb; pdb.set_trace()
337337 vm = VM (vmid )
338+ proxmox = connect_proxmox (f'{ vm .node } .csh.rit.edu' )
338339 vnc_ticket , vnc_port = open_vnc_session (vmid , vm .node , proxmox )
339340 node = f'{ vm .node } .csh.rit.edu'
340341 token = add_vnc_target (node , vnc_port )
Original file line number Diff line number Diff line change 66from proxstar .ldapdb import is_user
77
88
9- def connect_proxmox ():
10- for host in app . config [ 'PROXMOX_HOSTS' ] :
9+ def connect_proxmox (host = None ):
10+ if host :
1111 try :
12- proxmox = ProxmoxAPI (
13- host ,
14- user = app .config ['PROXMOX_USER' ],
15- token_name = app .config ['PROXMOX_TOKEN_NAME' ],
16- token_value = app .config ['PROXMOX_TOKEN_VALUE' ],
17- verify_ssl = False ,
18- )
19- proxmox .version .get ()
20- return proxmox
12+ return attempt_proxmox_connection (host )
2113 except :
22- if app .config ['PROXMOX_HOSTS' ].index (host ) == (len (app .config ['PROXMOX_HOSTS' ]) - 1 ):
14+ logging .error (f'unable to connect to { host } ' )
15+ raise
16+
17+ for host_candidate in app .config ['PROXMOX_HOSTS' ]:
18+ try :
19+ return attempt_proxmox_connection (host_candidate )
20+ except :
21+ if app .config ['PROXMOX_HOSTS' ].index (host_candidate ) == (
22+ len (app .config ['PROXMOX_HOSTS' ]) - 1
23+ ):
2324 logging .error ('unable to connect to any of the given Proxmox servers' )
2425 raise
2526
2627
28+ def attempt_proxmox_connection (host ):
29+ proxmox = ProxmoxAPI (
30+ host ,
31+ user = app .config ['PROXMOX_USER' ],
32+ token_name = app .config ['PROXMOX_TOKEN_NAME' ],
33+ token_value = app .config ['PROXMOX_TOKEN_VALUE' ],
34+ verify_ssl = False ,
35+ )
36+ proxmox .version .get ()
37+ return proxmox
38+
39+
2740def get_node_least_mem (proxmox ):
2841 nodes = proxmox .nodes .get ()
2942 sorted_nodes = sorted (nodes , key = lambda x : ('mem' not in x , x .get ('mem' , None )))
You can’t perform that action at this time.
0 commit comments