Skip to content

Commit 7497460

Browse files
feat(deployments): allow filtering by project and cluster IDs in list methods (#379)
1 parent 812c25f commit 7497460

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

gradient/api_sdk/repositories/gradient_deployments.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def get_deployment(id, first=100, api_key=None):
8484
}
8585
cluster {
8686
id
87-
}
87+
}
8888
data {
8989
command
9090
env {
@@ -130,16 +130,25 @@ def get_deployment(id, first=100, api_key=None):
130130
return client.execute(query, variable_values=params)
131131

132132

133-
def list_deployments(first=100, api_key=None):
133+
def list_deployments(name=None, project_id=None, cluster_id=None, first=100, api_key=None):
134134
client = graphql_client(api_key)
135135
query = gql(
136136
"""
137-
query getDeployments($first: Int!) {
138-
deployments(first: $first) {
137+
query getDeployments(
138+
$first: Int!
139+
$projectId: String
140+
$clusterId: String
141+
$name: String
142+
) {
143+
deployments(
144+
first: $first
145+
projectId: $projectId
146+
name: $name
147+
) {
139148
nodes {
140149
id
141150
name
142-
deploymentSpecs(first: $first) {
151+
deploymentSpecs(first: $first, clusterId: $clusterId) {
143152
nodes {
144153
id
145154
data {
@@ -172,14 +181,17 @@ def list_deployments(first=100, api_key=None):
172181
}
173182
}
174183
}
175-
}
184+
}
176185
}
177186
}
178187
}
179188
"""
180189
)
181190
params = {
182191
"first": first,
192+
"projectId": project_id,
193+
"clusterId": cluster_id,
194+
"name": name
183195
}
184196
return client.execute(query, variable_values=params)['deployments']['nodes']
185197

gradient/cli/gradient_deployments.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,36 @@ def update_deployment_command(ctx, api_key, id, name, project_id, spec_path, clu
135135

136136

137137
@deployments.command("list", help="List deployments")
138+
@click.option(
139+
"--name",
140+
"name",
141+
required=False,
142+
help="Name",
143+
cls=common.GradientOption,
144+
)
145+
@click.option(
146+
"--projectId",
147+
"project_id",
148+
required=False,
149+
help="Project ID",
150+
cls=common.GradientOption,
151+
)
152+
@click.option(
153+
"--clusterId",
154+
"cluster_id",
155+
required=False,
156+
help="Cluster ID",
157+
cls=common.GradientOption,
158+
)
138159
@api_key_option
139160
@click.pass_context
140-
def list_deployments_command(ctx, api_key):
161+
def list_deployments_command(ctx, name, project_id, cluster_id, api_key):
141162
try:
142-
deployments = gradient_deployments.list_deployments(api_key=api_key)
163+
deployments = gradient_deployments.list_deployments(
164+
name,
165+
project_id,
166+
cluster_id,
167+
api_key=api_key)
143168
if len(deployments) == 0:
144169
print('No deployments found')
145170
return

0 commit comments

Comments
 (0)