skip assigning IP on creation and add back update_vm_ip for now
because IP assignment on creation isn't done yet (need to manage MAC address)
This commit is contained in:
parent
2941ec6cd5
commit
cd26fcec5d
@ -27,10 +27,13 @@ def make_capsul_id():
|
|||||||
letters_n_nummers = generate(alphabet="1234567890qwertyuiopasdfghjklzxcvbnm", size=10)
|
letters_n_nummers = generate(alphabet="1234567890qwertyuiopasdfghjklzxcvbnm", size=10)
|
||||||
return f"capsul-{letters_n_nummers}"
|
return f"capsul-{letters_n_nummers}"
|
||||||
|
|
||||||
def double_check_capsul_address(id, get_ssh_host_keys):
|
def double_check_capsul_address(id, existing_ipv4, get_ssh_host_keys):
|
||||||
try:
|
try:
|
||||||
result = current_app.config["HUB_MODEL"].get(id, get_ssh_host_keys)
|
result = current_app.config["HUB_MODEL"].get(id, get_ssh_host_keys)
|
||||||
|
|
||||||
|
if result != None and result != "" and (existing_ipv4 == None or existing_ipv4 == ""):
|
||||||
|
get_model().update_vm_ip(email=session["account"], id=id, ipv4=result.ipv4)
|
||||||
|
|
||||||
if result != None and result.ssh_host_keys != None and get_ssh_host_keys:
|
if result != None and result.ssh_host_keys != None and get_ssh_host_keys:
|
||||||
get_model().update_vm_ssh_host_keys(email=session["account"], id=id, ssh_host_keys=result.ssh_host_keys)
|
get_model().update_vm_ssh_host_keys(email=session["account"], id=id, ssh_host_keys=result.ssh_host_keys)
|
||||||
except:
|
except:
|
||||||
@ -56,7 +59,7 @@ def index():
|
|||||||
# for now we are going to check the IP according to the virt model
|
# for now we are going to check the IP according to the virt model
|
||||||
# on every request. this could be done by a background job and cached later on...
|
# on every request. this could be done by a background job and cached later on...
|
||||||
for vm in vms:
|
for vm in vms:
|
||||||
result = double_check_capsul_address(vm["id"], False)
|
result = double_check_capsul_address(vm["id"], vm["ipv4"], False)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
vm["ipv4"] = result.ipv4
|
vm["ipv4"] = result.ipv4
|
||||||
vm["state"] = result.state
|
vm["state"] = result.state
|
||||||
@ -166,7 +169,7 @@ def detail(id):
|
|||||||
else:
|
else:
|
||||||
needs_ssh_host_keys = "ssh_host_keys" not in vm or len(vm["ssh_host_keys"]) == 0
|
needs_ssh_host_keys = "ssh_host_keys" not in vm or len(vm["ssh_host_keys"]) == 0
|
||||||
|
|
||||||
vm_from_virt_model = double_check_capsul_address(vm["id"], needs_ssh_host_keys)
|
vm_from_virt_model = double_check_capsul_address(vm["id"], vm["ipv4"], needs_ssh_host_keys)
|
||||||
|
|
||||||
if vm_from_virt_model is not None:
|
if vm_from_virt_model is not None:
|
||||||
vm["ipv4"] = vm_from_virt_model.ipv4
|
vm["ipv4"] = vm_from_virt_model.ipv4
|
||||||
|
@ -150,6 +150,10 @@ class DBModel:
|
|||||||
self.cursor.fetchall()
|
self.cursor.fetchall()
|
||||||
))
|
))
|
||||||
|
|
||||||
|
def update_vm_ip(self, email, id, ipv4):
|
||||||
|
self.cursor.execute("UPDATE vms SET public_ipv4 = %s WHERE email = %s AND id = %s", (ipv4, email, id))
|
||||||
|
self.connection.commit()
|
||||||
|
|
||||||
def update_vm_ssh_host_keys(self, email, id, ssh_host_keys):
|
def update_vm_ssh_host_keys(self, email, id, ssh_host_keys):
|
||||||
for key in ssh_host_keys:
|
for key in ssh_host_keys:
|
||||||
self.cursor.execute("""
|
self.cursor.execute("""
|
||||||
|
@ -161,10 +161,12 @@ def can_claim_create(payload, host_id) -> (str, str):
|
|||||||
return "", f"host \"{host_id}\" does not have any avaliable IP addresses on any of its networks."
|
return "", f"host \"{host_id}\" does not have any avaliable IP addresses on any of its networks."
|
||||||
|
|
||||||
# payload["network_name"] = allocated_network_name
|
# payload["network_name"] = allocated_network_name
|
||||||
# hard-code the network name for now until we can fix the phantom dhcp lease issues.
|
# payload["public_ipv4"] = allocated_ipv4_address
|
||||||
|
# hard-code the network name and IP for now until we can implement https://git.cyberia.club/cyberia/capsul-flask/issues/11
|
||||||
|
# enable static IP -> capsul mapping via libvirt (manage MAC addresses)
|
||||||
|
|
||||||
payload["network_name"] = 'public3'
|
payload["network_name"] = 'public3'
|
||||||
payload["public_ipv4"] = allocated_ipv4_address
|
payload["public_ipv4"] = ""
|
||||||
|
|
||||||
return payload, ""
|
return payload, ""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user