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 Feb 20, 2024
2 parents c7cb1da + f45cfae commit b8d9a77
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repos:
- id: isort

- repo: https://github.com/myint/autoflake
rev: v2.2.1
rev: v2.3.0
hooks:
- id: autoflake
args:
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pyvim==3.0.3
redis==5.0.1
requests==2.31.0
pyyaml==6.0.1
pre-commit==3.6.1
pre-commit==3.6.2
types-PyYAML==6.0.12.12
sympy==1.12
types-redis==4.6.0.20240106
types-redis==4.6.0.20240218
37 changes: 25 additions & 12 deletions simple_vm_client/openstack_connector/openstack_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1384,10 +1384,14 @@ def add_research_environment_security_group(
self, server_id: str, security_group_name: str
):
logger.info(f"Setting up {security_group_name} security group for {server_id}")
server = self.get_server(openstack_id=server_id)
security_group = self.get_research_environment_security_group(
server: Server = self.get_server(openstack_id=server_id)
security_group: SecurityGroup = self.get_research_environment_security_group(
security_group_name=security_group_name
)
if self._is_security_group_already_added_to_server(
server=server, security_group_name=security_group.name
):
return
self.openstack_connection.compute.add_security_group_to_server(
server=server, security_group=security_group
)
Expand All @@ -1397,23 +1401,32 @@ def add_metadata_to_server(self, server_id, metadata):

self.openstack_connection.compute.set_server_metadata(server, **metadata)

def _is_security_group_already_added_to_server(
self, server: Server, security_group_name: str
):
server_security_groups = self.openstack_connection.list_server_security_groups(
server
)

for sg in server_security_groups:
if sg["name"] == security_group_name:
logger.info(
f" Security group with name {security_group_name} already added to server."
)
return True
return False

def add_udp_security_group(self, server_id):
logger.info(f"Setting up UDP security group for {server_id}")
server = self.get_server(openstack_id=server_id)
sec_name = server.name + "_udp"
existing_sec = self.openstack_connection.get_security_group(name_or_id=sec_name)
if existing_sec:
logger.info(f"UDP Security group with name {sec_name} already exists.")
server_security_groups = (
self.openstack_connection.list_server_security_groups(server)
)

for sg in server_security_groups:
if sg["name"] == sec_name:
logger.info(
f"UDP Security group with name {sec_name} already added to server."
)
return
if self._is_security_group_already_added_to_server(
server=server, security_group_name=sec_name
):
return

self.openstack_connection.compute.add_security_group_to_server(
server=server_id, security_group=existing_sec
Expand Down

0 comments on commit b8d9a77

Please sign in to comment.