Skip to content

Commit f4a2174

Browse files
committed
only use proxmox ssh backend for cloud-init
1 parent 04d588d commit f4a2174

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
for host in environ.get('PROXSTAR_PROXMOX_HOSTS', '').split(',')
3131
]
3232
PROXMOX_USER = environ.get('PROXSTAR_PROXMOX_USER', '')
33+
PROXMOX_PASS = environ.get('PROXSTAR_PROXMOX_PASS', '')
3334
PROXMOX_ISO_STORAGE = environ.get('PROXSTAR_PROXMOX_ISO_STORAGE', 'nfs-iso')
35+
PROXMOX_SSH_USER = environ.get('PROXSTAR_PROXMOX_SSH_USER', '')
3436
PROXMOX_SSH_KEY = environ.get('PROXSTAR_PROXMOX_SSH_KEY', '')
3537
PROXMOX_SSH_KEY_PASS = environ.get('PROXSTAR_PROXMOX_SSH_KEY_PASS', '')
3638

proxstar/proxmox.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ def connect_proxmox():
1010
proxmox = ProxmoxAPI(
1111
host,
1212
user=app.config['PROXMOX_USER'],
13+
password=app.config['PROXMOX_PASS'],
14+
verify_ssl=False)
15+
version = proxmox.version.get()
16+
return proxmox
17+
except:
18+
if app.config['PROXMOX_HOSTS'].index(host) == (
19+
len(app.config['PROXMOX_HOSTS']) - 1):
20+
print('Unable to connect to any of the given Proxmox servers!')
21+
raise
22+
23+
24+
def connect_proxmox_ssh():
25+
for host in app.config['PROXMOX_HOSTS']:
26+
try:
27+
proxmox = ProxmoxAPI(
28+
host,
29+
user=app.config['PROXMOX_SSH_USER'],
1330
private_key_file='proxmox_ssh_key',
1431
password=app.config['PROXMOX_SSH_KEY_PASS'],
1532
backend='ssh_paramiko')

proxstar/vm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from proxstar.db import get_vm_expire
66
from proxstar.util import lazy_property
77
from proxstar.starrs import get_ip_for_mac
8-
from proxstar.proxmox import connect_proxmox, get_node_least_mem, get_free_vmid, get_vm_node
8+
from proxstar.proxmox import connect_proxmox, connect_proxmox_ssh, get_node_least_mem, get_free_vmid, get_vm_node
99
from flask import current_app as app
1010

1111

@@ -204,16 +204,16 @@ def expire(self):
204204
return get_vm_expire(db, self.id, app.config['VM_EXPIRE_MONTHS'])
205205

206206
def set_ci_user(self, user):
207-
proxmox = connect_proxmox()
207+
proxmox = connect_proxmox_ssh()
208208
proxmox.nodes(self.node).qemu(self.id).config.put(ciuser=user)
209209

210210
def set_ci_ssh_key(self, ssh_key):
211-
proxmox = connect_proxmox()
211+
proxmox = connect_proxmox_ssh()
212212
escaped_key = urllib.parse.quote(ssh_key, safe='')
213213
proxmox.nodes(self.node).qemu(self.id).config.put(sshkey=escaped_key)
214214

215215
def set_ci_network(self):
216-
proxmox = connect_proxmox()
216+
proxmox = connect_proxmox_ssh()
217217
proxmox.nodes(self.node).qemu(self.id).config.put(ipconfig0='ip=dhcp')
218218

219219

proxstar/vnc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def start_ssh_tunnel(node, port):
7878
port = int(port)
7979
server = SSHTunnelForwarder(
8080
node,
81-
ssh_username='root',
81+
ssh_username=app.config['PROXMOX_SSH_USER'],
8282
ssh_pkey='proxmox_ssh_key',
8383
ssh_private_key_password=app.config['PROXMOX_SSH_KEY_PASS'],
8484
remote_bind_address=('127.0.0.1', port),

0 commit comments

Comments
 (0)