Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1573 from deNBI/fix/shutdown
Browse files Browse the repository at this point in the history
Fix/shutdown
  • Loading branch information
vktrrdk authored Oct 26, 2023
2 parents a2f1440 + 2d3f3c1 commit f46304e
Show file tree
Hide file tree
Showing 5 changed files with 459 additions and 1,483 deletions.
22 changes: 14 additions & 8 deletions VirtualMachineService/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ 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

Expand All @@ -1897,7 +1897,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:
Expand All @@ -1918,7 +1917,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)
Expand Down Expand Up @@ -2529,12 +2529,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):
Expand Down
2 changes: 1 addition & 1 deletion VirtualMachineService/VirtualMachineService-remote
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion VirtualMachineService/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__all__ = ["ttypes", "constants", "VirtualMachineService"]
__all__ = ['ttypes', 'constants', 'VirtualMachineService']
11 changes: 2 additions & 9 deletions VirtualMachineService/constants.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f46304e

Please sign in to comment.