|
|
|
@ -39,9 +39,15 @@ class MockSpoke(VirtualizationInterface):
|
|
|
|
|
|
|
|
|
|
return VirtualMachine(id, current_app.config["SPOKE_HOST_ID"], ipv4=ipv4, state="running") |
|
|
|
|
|
|
|
|
|
def get_all_by_host_and_network(self) -> dict: |
|
|
|
|
to_return = get_model().non_deleted_vms_by_host_and_network(None) |
|
|
|
|
current_app.logger.info(f"MOCK get_all_by_host_and_network: {json.dumps(to_return)}") |
|
|
|
|
def get_all_by_id(self) -> dict: |
|
|
|
|
by_host_and_network = get_model().non_deleted_vms_by_host_and_network() |
|
|
|
|
to_return = dict() |
|
|
|
|
for host in by_host_and_network.values(): |
|
|
|
|
for network in host.values(): |
|
|
|
|
for vm in network: |
|
|
|
|
to_return[vm['id']] = vm |
|
|
|
|
|
|
|
|
|
current_app.logger.info(f"MOCK get_all_by_id: {json.dumps(to_return)}") |
|
|
|
|
return to_return |
|
|
|
|
|
|
|
|
|
def create(self, email: str, id: str, template_image_file_name: str, vcpus: int, memory_mb: int, ssh_authorized_keys: list, network_name: str, public_ipv4: str): |
|
|
|
@ -140,7 +146,7 @@ class ShellScriptSpoke(VirtualizationInterface):
|
|
|
|
|
|
|
|
|
|
return VirtualMachine(id, current_app.config["SPOKE_HOST_ID"], state=state, ipv4=ipaddr) |
|
|
|
|
|
|
|
|
|
def get_all_by_host_and_network(self) -> dict: |
|
|
|
|
def get_all_by_id(self) -> dict: |
|
|
|
|
|
|
|
|
|
vm_list_process = run([join(current_app.root_path, 'shell_scripts/virsh-list.sh')], capture_output=True) |
|
|
|
|
self.validate_completed_process(vm_list_process) |
|
|
|
@ -150,9 +156,9 @@ class ShellScriptSpoke(VirtualizationInterface):
|
|
|
|
|
|
|
|
|
|
#current_app.logger.info(f"list_of_vms: {json.dumps(list_of_vms)}") |
|
|
|
|
|
|
|
|
|
vm_state_by_id = dict() |
|
|
|
|
vms_by_id = dict() |
|
|
|
|
for vm in list_of_vms: |
|
|
|
|
vm_state_by_id[vm['id']] = vm['state'] |
|
|
|
|
vms_by_id[vm['id']] = dict(id=vm['id'], macs=dict(), state=vm['state']) |
|
|
|
|
|
|
|
|
|
net_list_process = run([join(current_app.root_path, 'shell_scripts/virsh-net-list.sh')], capture_output=True) |
|
|
|
|
self.validate_completed_process(net_list_process) |
|
|
|
@ -162,7 +168,6 @@ class ShellScriptSpoke(VirtualizationInterface):
|
|
|
|
|
|
|
|
|
|
#current_app.logger.info(f"list_of_networks: {json.dumps(list_of_networks)}") |
|
|
|
|
|
|
|
|
|
vms_by_id = dict() |
|
|
|
|
vm_id_by_mac = dict() |
|
|
|
|
for network in list_of_networks: |
|
|
|
|
|
|
|
|
@ -182,14 +187,11 @@ class ShellScriptSpoke(VirtualizationInterface):
|
|
|
|
|
raise Exception(f"the mac address '{mac}' is used by both '{vm_id_by_mac[mac]}' and '{vm['domain']}'") |
|
|
|
|
|
|
|
|
|
if vm['domain'] not in vms_by_id: |
|
|
|
|
vm_state = 'shut off' |
|
|
|
|
if vm['domain'] in vm_state_by_id: |
|
|
|
|
vm_state = vm_state_by_id[vm['domain']] |
|
|
|
|
else: |
|
|
|
|
current_app.logger.warn(f"get_all_by_host_and_network: '{vm['domain']}' not in vm_state_by_id, defaulting to 'shut off'") |
|
|
|
|
|
|
|
|
|
vms_by_id[vm['domain']] = dict(id=vm['domain'], macs=dict(), state=vm_state, network_name=network['network_name']) |
|
|
|
|
|
|
|
|
|
current_app.logger.warn(f"'{vm['domain']}' was in dnsmask but not in libvirt, defaulting to 'shut off' state") |
|
|
|
|
|
|
|
|
|
vms_by_id[vm['domain']] = dict(id=vm['domain'], macs=dict(), state="shut off") |
|
|
|
|
|
|
|
|
|
vms_by_id[vm['domain']]['network_name'] = network['network_name'] |
|
|
|
|
vms_by_id[vm['domain']]['macs'][mac] = True |
|
|
|
|
|
|
|
|
|
status_json_filename = f"{current_app.config['LIBVIRT_DNSMASQ_PATH']}/{network['virtual_bridge_name']}.status" |
|
|
|
@ -205,19 +207,9 @@ class ShellScriptSpoke(VirtualizationInterface):
|
|
|
|
|
vm_id = vm_id_by_mac[status['mac-address']] |
|
|
|
|
vms_by_id[vm_id]['public_ipv4'] = status['ip-address'] |
|
|
|
|
else: |
|
|
|
|
current_app.logger.warn(f"get_all_by_host_and_network: {status['mac-address']} not in vm_id_by_mac") |
|
|
|
|
current_app.logger.warn(f"get_all_by_id: {status['mac-address']} not in vm_id_by_mac") |
|
|
|
|
|
|
|
|
|
networks = dict() |
|
|
|
|
for vm in vms_by_id.values(): |
|
|
|
|
if vm['network_name'] not in networks: |
|
|
|
|
networks[vm['network_name']] = [] |
|
|
|
|
|
|
|
|
|
networks[vm['network_name']].append(vm) |
|
|
|
|
|
|
|
|
|
to_return = dict() |
|
|
|
|
to_return[current_app.config['SPOKE_HOST_ID']] = networks |
|
|
|
|
|
|
|
|
|
return to_return |
|
|
|
|
return vms_by_id |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|