Skip to content

Commit eccd3c2

Browse files
add more delete functionalities
1 parent 5540b04 commit eccd3c2

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

test/test_utils/ec2.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,8 +1829,13 @@ def get_subnet_id_by_vpc(ec2_client, vpc_id):
18291829
},
18301830
],
18311831
)
1832-
print(response)
1833-
return response
1832+
1833+
subnet_ids = []
1834+
for subnet in response["Subnets"]:
1835+
if subnet["SubnetId"] is not None:
1836+
subnet_ids.append(subnet["SubnetId"])
1837+
1838+
return subnet_ids
18341839

18351840

18361841
def get_vpc_id_by_name(ec2_client, vpc_name):

vllm/infra/ec2.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,23 @@ def setup():
222222
ec2_cli = ec2_client(DEFAULT_REGION)
223223

224224
vpc_id = get_default_vpc_id(ec2_cli)
225-
subnet_id = get_subnet_id_by_vpc(ec2_cli, vpc_id)
225+
subnet_ids = get_subnet_id_by_vpc(ec2_cli, vpc_id)
226226

227227
# create fsx
228228
sg_fsx = fsx.create_security_group(vpc_id, "vllm-ec2-fsx-sg", "SG for Fsx Mounting")
229229
ingress_rules = {"protocol": "tcp", "port": "988-1023"}
230230
fsx.add_security_group_ingress_rules(sg_fsx, ingress_rules)
231231

232232
fsx_config = fsx.create_fsx_filesystem(
233-
subnet_id, sg_fsx, 1200, "SCRATCH_2", {"Name": "vllm-fsx-storage"}
233+
subnet_ids[0], sg_fsx, 1200, "SCRATCH_2", {"Name": "vllm-fsx-storage"}
234234
)
235235

236236
print(fsx_config)
237237

238+
fsx.delete_fsx_filesystem(fsx_config["filesystem_id"])
239+
240+
fsx.delete_security_group(sg_fsx)
241+
238242

239243
if __name__ == "__main__":
240244
setup()

vllm/infra/utils/fsx_utils.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,30 @@ def create_fsx_filesystem(
5858
logger.error(f"Failed to create FSx filesystem: {e}")
5959
raise
6060

61+
def delete_fsx_filesystem(self, fsx_id: str):
62+
63+
try:
64+
fsx_id = run(
65+
f"aws fsx delete-file-system"
66+
f" --file-system-id {fsx_id}"
67+
f' --query "FileSystem.FileSystemId"'
68+
f" --output text"
69+
).stdout.strip()
70+
71+
print(f"Deleted FSx filesystem: {fsx_id}")
72+
73+
except Exception as e:
74+
logger.error(f"Failed to create FSx filesystem: {e}")
75+
raise
76+
6177
def wait_for_filesystem(self, filesystem_id: str):
6278
"""
6379
Wait for FSx filesystem to become available and return its details
6480
: param filesystem_id: FSx filesystem ID
6581
: return: dictionary containing filesystem details (filesystem_id, dns_name, mount_name)
6682
: raises: Exception if filesystem enters FAILED, DELETING, or DELETED state
6783
"""
68-
logger.info(f"Waiting for FSx filesystem {filesystem_id} to be available...")
84+
print(f"Waiting for FSx filesystem {filesystem_id} to be available...")
6985
while True:
7086
status = run(
7187
f"aws fsx describe-file-systems --file-system-id {filesystem_id} "
@@ -77,7 +93,7 @@ def wait_for_filesystem(self, filesystem_id: str):
7793
elif status in ["FAILED", "DELETING", "DELETED"]:
7894
raise Exception(f"FSx filesystem entered {status} state")
7995

80-
logger.info(f"FSx status: {status}, waiting...")
96+
print(f"FSx status: {status}, waiting...")
8197
time.sleep(30)
8298

8399
# get fs DNS and mount name
@@ -111,13 +127,30 @@ def create_security_group(self, vpc_id: str, name: str, description: str):
111127
f' --query "GroupId"'
112128
f" --output text"
113129
).stdout.strip()
114-
logger.info(f"Created security group: {sg_id}")
130+
print(f"Created security group: {sg_id}")
115131
return sg_id
116132

117133
except Exception as e:
118134
logger.error(f"Failed to create security group: {e}")
119135
raise
120136

137+
def delete_security_group(self, group_id: str):
138+
"""
139+
Create a security group in the specified VPC
140+
: param vpc_id: VPC ID where the security group will be created
141+
: param name: name of the security group
142+
: param description: description of the security group
143+
: return: created security group ID
144+
: raises: Exception if security group creation fails
145+
"""
146+
try:
147+
sg_id = run(f"aws ec2 delete-security-group" f" --group-id {group_id}").stdout.strip()
148+
print(f"Deleted security group: {sg_id}")
149+
150+
except Exception as e:
151+
logger.error(f"Failed to create security group: {e}")
152+
raise
153+
121154
def add_security_group_ingress_rules(
122155
self, security_group_id: str, ingress_rules: List[Dict[str, Any]]
123156
):

0 commit comments

Comments
 (0)