capsul.org webapp
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

try to fix acpid detection on nixos

forest a901a94b 919881dd

+20 -11
+3 -3
capsulflask/console.py
··· 60 60 letters_n_nummers = generate(alphabet="1234567890qwertyuiopasdfghjklzxcvbnm", size=10) 61 61 return f"capsul-{letters_n_nummers}" 62 62 63 - def double_check_capsul_address(id, existing_ipv4, get_ssh_host_keys, get_agent_details) -> VirtualMachine: 63 + def double_check_capsul_address(id, existing_ipv4, get_ssh_host_keys, get_agent_details, vm_os_id) -> VirtualMachine: 64 64 try: 65 - result = current_app.config["HUB_MODEL"].get(id, get_ssh_host_keys, get_agent_details) 65 + result = current_app.config["HUB_MODEL"].get(id, get_ssh_host_keys, get_agent_details, vm_os_id) 66 66 67 67 if result != None and result.ipv4 != "" and (existing_ipv4 == None or existing_ipv4 == ""): 68 68 get_model().update_vm_ip(email=session["account"], id=id, ipv4=result.ipv4) ··· 310 310 get_ssh_host_keys = "ssh_host_keys" not in vm or len(vm["ssh_host_keys"]) == 0 311 311 get_agent_details = True 312 312 313 - vm_from_virt_model = double_check_capsul_address(vm["id"], vm["ipv4"], get_ssh_host_keys, get_agent_details) 313 + vm_from_virt_model = double_check_capsul_address(vm["id"], vm["ipv4"], get_ssh_host_keys, get_agent_details, vm['os']) 314 314 315 315 if vm_from_virt_model is not None: 316 316 vm["ipv4"] = vm_from_virt_model.ipv4
+2 -2
capsulflask/db_model.py
··· 200 200 self.cursor.execute(""" 201 201 SELECT vms.id, vms.public_ipv4, vms.public_ipv6, os_images.description, vms.created, vms.deleted, 202 202 vm_sizes.id, vms.shortterm, vm_sizes.dollars_per_month, vm_sizes.vcpus, vm_sizes.memory_mb, vm_sizes.bandwidth_gb_per_month, 203 - vms.has_agent_socket, vms.has_guest_agent, vms.has_acpid, vms.last_backup_finished, vms.host 203 + vms.has_agent_socket, vms.has_guest_agent, vms.has_acpid, vms.last_backup_finished, vms.host, vms.os 204 204 FROM vms 205 205 JOIN os_images on vms.os = os_images.id 206 206 JOIN vm_sizes on vms.size = vm_sizes.id ··· 218 218 id=row[0], ipv4=row[1], ipv6=row[2], os_description=row[3], created=row[4], deleted=row[5], 219 219 size=row[6], shortterm=row[7], dollars_per_month=row[8], vcpus=row[9], memory_mb=row[10], 220 220 bandwidth_gb_per_month=row[11], agent_socket=row[12], guest_agent=row[13], acpid=row[14], 221 - last_backup_finished=last_backup_finished, host=row[16] 221 + last_backup_finished=last_backup_finished, host=row[16], os=row[17] 222 222 ) 223 223 224 224 self.cursor.execute("""
+7 -1
capsulflask/shell_scripts/get-guest-agent.sh
··· 1 1 #!/bin/sh -e 2 2 3 3 vmname="$1" 4 + os_image_id="$2" 4 5 5 6 if echo "$vmname" | grep -vqE '^(cvm|capsul)-[a-z0-9]{10}$'; then 6 7 echo "vmname $vmname must match "'"^capsul-[a-z0-9]{10}$"' 7 8 exit 1 8 9 fi 9 10 11 + pidof_command_json='{"path":"/usr/bin/env", "arg":["pidof","acpid"], "capture-output":true}' 12 + if echo "$os_image_id" | grep -q 'nixos'; then 13 + pidof_command_json='{"path":"/run/current-system/sw/bin/pidof", "arg":["acpid"], "capture-output":true}' 14 + fi 15 + 10 16 qemuAgentCommandOutput="no-guest-agent-socket" 11 17 if virsh dumpxml "$vmname" | grep -q guest_agent ; then 12 - isAcpidRunning='{"execute": "guest-exec", "arguments":{"path":"/usr/bin/env", "arg":["pidof","acpid"], "capture-output":true}}' 18 + isAcpidRunning='{"execute": "guest-exec", "arguments":'"$pidof_command_json}" 13 19 qemuAgentCommandOutput="$( { virsh qemu-agent-command "$vmname" --cmd "$isAcpidRunning" || printf '%s' 'no-qemu-guest-agent'; } | tr -d '\n' )" 14 20 15 21 if [ "$qemuAgentCommandOutput" != "no-qemu-guest-agent" ] ; then
+1 -1
capsulflask/spoke_api.py
··· 93 93 current_app.logger.error(f"/hosts/operation returned 400: id is required for get") 94 94 return abort(400, f"bad request; id is required for get") 95 95 96 - vm = current_app.config['SPOKE_MODEL'].get(request_body['id'], request_body['get_ssh_host_keys'], request_body['get_agent_details']) 96 + vm = current_app.config['SPOKE_MODEL'].get(request_body['id'], request_body['get_ssh_host_keys'], request_body['get_agent_details'], request_body['vm_os_id']) 97 97 if vm is None: 98 98 return jsonify(dict(assignment_status="assigned")) 99 99 return jsonify(dict(assignment_status="assigned", id=vm.id, host=vm.host, state=vm.state, ipv4=vm.ipv4, ipv6=vm.ipv6, ssh_host_keys=vm.ssh_host_keys, agent_socket=vm.agent_socket, guest_agent=vm.guest_agent, acpid=vm.acpid))
+7 -4
capsulflask/spoke_model.py
··· 28 28 def capacity_avaliable(self, additional_ram_bytes): 29 29 return True 30 30 31 - def get(self, id, get_ssh_host_keys: bool, get_agent_details: bool): 31 + def get(self, id, get_ssh_host_keys: bool, get_agent_details: bool, vm_os_id: str): 32 32 validate_capsul_id(id) 33 33 34 34 ipv4 = "1.1.1.1" ··· 118 118 119 119 return True 120 120 121 - def get(self, id, get_ssh_host_keys: bool, get_agent_details: bool): 121 + def get(self, id, get_ssh_host_keys: bool, get_agent_details: bool, os_image_id: str): 122 122 validate_capsul_id(id) 123 123 completed_process = run([join(current_app.root_path, 'shell_scripts/get.sh'), id], capture_output=True) 124 124 self.validate_completed_process(completed_process) ··· 147 147 if not re.match(r"^([0-9]{1,3}\.){3}[0-9]{1,3}$", ipaddr): 148 148 return VirtualMachine(id, current_app.config["SPOKE_HOST_ID"], state=state) 149 149 150 + if not re.match(r"^[a-z0-9]+$", os_image_id): 151 + raise ValueError(f"os_image_id '{os_image_id}' is not a valid value") 152 + 150 153 guest_agent=False 151 154 agent_socket=False 152 155 acpid=False ··· 164 167 165 168 if get_agent_details: 166 169 try: 167 - completed_process3 = run([join(current_app.root_path, 'shell_scripts/get-guest-agent.sh'), id], capture_output=True) 170 + completed_process3 = run([join(current_app.root_path, 'shell_scripts/get-guest-agent.sh'), id, os_image_id], capture_output=True) 168 171 self.validate_completed_process(completed_process3) 169 172 result = completed_process3.stdout.decode("utf-8").strip(" \t\n\r") 170 - current_app.logger.info(f"get_agent_details result: {result}") 173 + #current_app.logger.info(f"get_agent_details result: {result}") 171 174 if result != 'no-guest-agent-socket': 172 175 agent_socket = True 173 176 if result == "ok" or result == 'no-acpid':