Retrieve IPv6 addresses from VMs
This commit allows the model to fetch IPv6 addresses from running VMs and populate VirtualMachine objects with the value if it was retrieved successfully
This commit is contained in:
parent
ff4e63339f
commit
8a6d558402
@ -29,7 +29,8 @@ if virsh domuuid "$vmname" | grep -vqE '^[\t\s\n]*$'; then
|
|||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# this gets the ipv4
|
# this gets the vm ip addresses
|
||||||
ipv4="$(virsh domifaddr "$vmname" | awk '/ipv4/ {print $4}' | cut -d'/' -f1)"
|
ipv4="$(virsh domifaddr "$vmname" | awk '/ipv4/ {print $4}' | cut -d'/' -f1)"
|
||||||
|
ipv6="$(virsh domifaddr "$vmname" | awk '/ipv6/ {print $4}' | cut -d'/' -f1)"
|
||||||
|
|
||||||
echo "$exists $state $ipv4"
|
echo "$exists $state $ipv4 $ipv6"
|
||||||
|
@ -114,24 +114,30 @@ class ShellScriptSpoke(VirtualizationInterface):
|
|||||||
if len(fields) < 3:
|
if len(fields) < 3:
|
||||||
return VirtualMachine(id, current_app.config["SPOKE_HOST_ID"], state=state)
|
return VirtualMachine(id, current_app.config["SPOKE_HOST_ID"], state=state)
|
||||||
|
|
||||||
ipaddr = fields[2]
|
ip4addr = fields[2]
|
||||||
|
|
||||||
if not re.match(r"^([0-9]{1,3}\.){3}[0-9]{1,3}$", ipaddr):
|
if not re.match(r"^([0-9]{1,3}\.){3}[0-9]{1,3}$", ip4addr):
|
||||||
return VirtualMachine(id, current_app.config["SPOKE_HOST_ID"], state=state)
|
return VirtualMachine(id, current_app.config["SPOKE_HOST_ID"], state=state)
|
||||||
|
|
||||||
if get_ssh_host_keys:
|
if get_ssh_host_keys:
|
||||||
try:
|
try:
|
||||||
completedProcess2 = run([join(current_app.root_path, 'shell_scripts/ssh-keyscan.sh'), ipaddr], capture_output=True)
|
completedProcess2 = run([join(current_app.root_path, 'shell_scripts/ssh-keyscan.sh'), ip4addr], capture_output=True)
|
||||||
self.validate_completed_process(completedProcess2)
|
self.validate_completed_process(completedProcess2)
|
||||||
ssh_host_keys = json.loads(completedProcess2.stdout.decode("utf-8"))
|
ssh_host_keys = json.loads(completedProcess2.stdout.decode("utf-8"))
|
||||||
return VirtualMachine(id, current_app.config["SPOKE_HOST_ID"], state=state, ipv4=ipaddr, ssh_host_keys=ssh_host_keys)
|
return VirtualMachine(id, current_app.config["SPOKE_HOST_ID"], state=state, ipv4=ip4addr, ssh_host_keys=ssh_host_keys)
|
||||||
except:
|
except:
|
||||||
current_app.logger.warning(f"""
|
current_app.logger.warning(f"""
|
||||||
failed to ssh-keyscan {id} at {ipaddr}:
|
failed to ssh-keyscan {id} at {ip4addr}:
|
||||||
{my_exec_info_message(sys.exc_info())}"""
|
{my_exec_info_message(sys.exc_info())}"""
|
||||||
)
|
)
|
||||||
|
|
||||||
return VirtualMachine(id, current_app.config["SPOKE_HOST_ID"], state=state, ipv4=ipaddr)
|
if len(fields) < 4:
|
||||||
|
return VirtualMachine(id, current_app.config["SPOKE_HOST_ID"], state=state, ipv4=ip4addr)
|
||||||
|
|
||||||
|
ip6addr = fields[3]
|
||||||
|
|
||||||
|
return VirtualMachine(id, current_app.config["SPOKE_HOST_ID"], state=state, ipv4=ip4addr, ipv6=ip6addr)
|
||||||
|
|
||||||
|
|
||||||
def list_ids(self) -> list:
|
def list_ids(self) -> list:
|
||||||
completedProcess = run([join(current_app.root_path, 'shell_scripts/list-ids.sh')], capture_output=True)
|
completedProcess = run([join(current_app.root_path, 'shell_scripts/list-ids.sh')], capture_output=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user