Skip to content

Commit

Permalink
Merge branch 'dev' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz committed Dec 12, 2024
2 parents 63a6adc + afb0432 commit e9088b7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion simple_vm_client/openstack_connector/openstack_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,23 @@ def stop_server(self, openstack_id: str) -> None:
logger.exception(f"Stop Server {openstack_id} failed!")
raise OpenStackConflictException(message=e.message)

def _delete_security_groups_if_not_used(self, security_groups: list[SecurityGroup]):
if security_groups is not None:
for sg in security_groups:
sec = self.openstack_connection.get_security_group(
name_or_id=sg["name"]
)
if sg[
"name"
] != self.DEFAULT_SECURITY_GROUP_NAME and not self.is_security_group_in_use(
security_group_id=sec.id
):
logger.info(f"Delete security group {sec}")
try:
self.openstack_connection.delete_security_group(sec)
except ResourceNotFound:
logger.info(f"Could not delete security group {sec.id}")

def _remove_security_groups_from_server(self, server: Server) -> None:
security_groups = server.security_groups

Expand Down Expand Up @@ -1363,9 +1380,13 @@ def delete_server(self, openstack_id: str) -> None:
)

self._validate_server_for_deletion(server=server)
self._remove_security_groups_from_server(server=server)

logger.info(f"Start deleting Server {openstack_id}")
self.openstack_connection.compute.delete_server(server.id, force=True)

security_groups = server.security_groups
self._delete_security_groups_if_not_used(security_groups)

except ConflictException as e:
logger.exception(f"Delete Server {openstack_id} failed!")

Expand Down

0 comments on commit e9088b7

Please sign in to comment.