Skip to content

Commit 4623971

Browse files
authored
feat(cli): add veadk clean to support clean app in commandline (#290)
* feat: veadk clean cli * add cli change
1 parent 49ba1be commit 4623971

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

veadk/cli/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from veadk.cli.cli_prompt import prompt
2525
from veadk.cli.cli_web import web
2626
from veadk.cli.cli_uploadevalset import uploadevalset
27+
from veadk.cli.cli_clean import clean
2728
from veadk.version import VERSION
2829

2930

@@ -49,6 +50,7 @@ def veadk():
4950
veadk.add_command(eval)
5051
veadk.add_command(kb)
5152
veadk.add_command(uploadevalset)
53+
veadk.add_command(clean)
5254

5355
if __name__ == "__main__":
5456
veadk()

veadk/cli/cli_clean.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import time
16+
import click
17+
18+
from veadk.config import getenv
19+
from veadk.integrations.ve_faas.ve_faas import VeFaaS
20+
from veadk.utils.logger import get_logger
21+
22+
logger = get_logger(__name__)
23+
24+
25+
@click.command()
26+
@click.option(
27+
"--vefaas-application-name",
28+
required=True,
29+
help="VeFaaS application name to clean",
30+
)
31+
@click.option(
32+
"--volcengine-access-key",
33+
default=None,
34+
help="Volcengine access key, if not set, will use the value of environment variable VOLCENGINE_ACCESS_KEY",
35+
)
36+
@click.option(
37+
"--volcengine-secret-key",
38+
default=None,
39+
help="Volcengine secret key, if not set, will use the value of environment variable VOLCENGINE_SECRET_KEY",
40+
)
41+
def clean(
42+
vefaas_application_name: str, volcengine_access_key: str, volcengine_secret_key: str
43+
) -> None:
44+
"""
45+
Clean and delete a VeFaaS application from the cloud.
46+
47+
This command deletes a specified VeFaaS application after user confirmation.
48+
It will prompt the user for confirmation before proceeding with the deletion
49+
and monitor the deletion process until completion.
50+
51+
Args:
52+
vefaas_application_name (str): The name of the VeFaaS application to delete
53+
volcengine_access_key (str): Volcengine access key for authentication.
54+
If None, will use VOLCENGINE_ACCESS_KEY environment variable
55+
volcengine_secret_key (str): Volcengine secret key for authentication.
56+
If None, will use VOLCENGINE_SECRET_KEY environment variable
57+
58+
Returns:
59+
None
60+
"""
61+
if not volcengine_access_key:
62+
volcengine_access_key = getenv("VOLCENGINE_ACCESS_KEY")
63+
if not volcengine_secret_key:
64+
volcengine_secret_key = getenv("VOLCENGINE_SECRET_KEY")
65+
66+
confirm = input(f"Confirm delete cloud app {vefaas_application_name}? (y/N): ")
67+
if confirm.lower() != "y":
68+
click.echo("Delete cancelled.")
69+
return
70+
else:
71+
vefaas_client = VeFaaS(
72+
access_key=volcengine_access_key, secret_key=volcengine_secret_key
73+
)
74+
vefaas_application_id = vefaas_client.find_app_id_by_name(
75+
vefaas_application_name
76+
)
77+
vefaas_client.delete(vefaas_application_id)
78+
click.echo(
79+
f"Cloud app {vefaas_application_name} delete request has been sent to VeFaaS"
80+
)
81+
while True:
82+
try:
83+
id = vefaas_client.find_app_id_by_name(vefaas_application_name)
84+
if not id:
85+
break
86+
time.sleep(3)
87+
except Exception as _:
88+
break
89+
click.echo("Delete application done.")

0 commit comments

Comments
 (0)