diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index 09dab173..5ec70ea2 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -1880,7 +1880,10 @@ def check_server_status(self, openstack_id: str) -> VM: serv = server.to_dict() try: - if serv["status"] == self.ACTIVE: + if serv["status"] == self.ACTIVE and serv["task_state"] not in [ + "powering-off", + "powering-on", + ]: host = self.get_server(openstack_id).floating_ip port = self.SSH_PORT @@ -1898,7 +1901,6 @@ def check_server_status(self, openstack_id: str) -> VM: ) if self.netcat(host, port): server = self.get_server(openstack_id) - if self.redis.exists(openstack_id) == 1: global active_playbooks if openstack_id in active_playbooks: @@ -1919,7 +1921,8 @@ def check_server_status(self, openstack_id: str) -> VM: return self.get_server(openstack_id) else: server = self.get_server(openstack_id) - server.status = "PORT_CLOSED" + if server.status != "SHUTDOWN": + server.status = "PORT_CLOSED" return server elif serv["status"] == self.ERROR: server = self.get_server(openstack_id) @@ -2534,12 +2537,18 @@ def netcat(self, host, port): :return: True if successfully connected, False if not """ self.LOG.info(f"Checking SSH Connection {host}:{port}") + with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: - r = sock.connect_ex((host, port)) - self.LOG.info(f"Checking SSH Connection {host}:{port} Result = {r}") - if r == 0: - return True - else: + sock.settimeout(5) + try: + r = sock.connect_ex((host, port)) + self.LOG.info(f"Checking SSH Connection {host}:{port} Result = {r}") + if r == 0: + return True + else: + return False + except socket.timeout: + self.LOG.info(f"Connection to {host}:{port} timed out") return False def is_security_group_in_use(self, security_group_id): diff --git a/VirtualMachineService/VirtualMachineService-remote b/VirtualMachineService/VirtualMachineService-remote index 4caef159..95c0b8c2 100755 --- a/VirtualMachineService/VirtualMachineService-remote +++ b/VirtualMachineService/VirtualMachineService-remote @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Autogenerated by Thrift Compiler (0.16.0) +# Autogenerated by Thrift Compiler (0.17.0) # # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING # diff --git a/VirtualMachineService/constants.py b/VirtualMachineService/constants.py index a334d1fc..8f9c3f5d 100644 --- a/VirtualMachineService/constants.py +++ b/VirtualMachineService/constants.py @@ -1,5 +1,5 @@ # -# Autogenerated by Thrift Compiler (0.16.0) +# Autogenerated by Thrift Compiler (0.17.0) # # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING # diff --git a/VirtualMachineService/ttypes.py b/VirtualMachineService/ttypes.py index 6ab72f3a..a6b1b9c0 100644 --- a/VirtualMachineService/ttypes.py +++ b/VirtualMachineService/ttypes.py @@ -1,5 +1,5 @@ # -# Autogenerated by Thrift Compiler (0.16.0) +# Autogenerated by Thrift Compiler (0.17.0) # # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING # diff --git a/requirements.txt b/requirements.txt index da6326c8..573e1f37 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ Click==8.1.7 ansible==8.5.0 flake8==6.1.0 paramiko==3.3.1 -ruamel.yaml==0.17.40 +ruamel.yaml==0.18.2 pyvim==3.0.3 redis==5.0.1 requests==2.31.0