Skip to content

Commit c8331b6

Browse files
committed
Use correct node in API call
1 parent 5ca4d71 commit c8331b6

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

proxstar/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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)

proxstar/proxmox.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,35 @@
66
from proxstar.ldapdb import is_user
77

88

9-
def connect_proxmox():
9+
def connect_proxmox(host=None):
10+
if host:
11+
attempted_connection = attempt_proxmox_connection(host)
12+
if attempted_connection:
13+
return attempted_connection
14+
logging.error(f'unable to connect to {host}')
15+
raise
16+
1017
for host in app.config['PROXMOX_HOSTS']:
11-
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
21-
except:
22-
if app.config['PROXMOX_HOSTS'].index(host) == (len(app.config['PROXMOX_HOSTS']) - 1):
23-
logging.error('unable to connect to any of the given Proxmox servers')
24-
raise
18+
attempted_connection = attempt_proxmox_connection(host)
19+
if attempted_connection:
20+
return attempted_connection
21+
logging.error('unable to connect to any of the given Proxmox servers')
22+
raise
23+
24+
25+
def attempt_proxmox_connection(host):
26+
try:
27+
proxmox = ProxmoxAPI(
28+
host,
29+
user=app.config['PROXMOX_USER'],
30+
token_name=app.config['PROXMOX_TOKEN_NAME'],
31+
token_value=app.config['PROXMOX_TOKEN_VALUE'],
32+
verify_ssl=False,
33+
)
34+
proxmox.version.get()
35+
return proxmox
36+
except:
37+
return None
2538

2639

2740
def get_node_least_mem(proxmox):

0 commit comments

Comments
 (0)