Skip to content

Commit e588721

Browse files
committed
Using jmespath to allow query/filtering
1 parent 334edff commit e588721

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
"python.formatting.provider": "black",
2525
"python.pythonPath": "/bin/python3",
2626
"python.envFile": "${workspaceFolder}/gitpod.env",
27-
"editor.formatOnSave": true
27+
"editor.formatOnSave": true,
28+
"files.insertFinalNewline": true
2829
}

bin/cli.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,17 @@
1010
from collections import OrderedDict
1111

1212
import fire
13+
import jmespath
1314
import yaml
1415

15-
from hpecp.gateway import (
16-
Gateway,
17-
GatewayStatus,
18-
)
19-
from hpecp.k8s_cluster import (
20-
K8sClusterHostConfig,
21-
K8sClusterStatus,
22-
)
2316
from hpecp import (
24-
ContainerPlatformClient,
25-
ContainerPlatformClientException,
2617
APIException,
2718
APIItemConflictException,
19+
ContainerPlatformClient,
20+
ContainerPlatformClientException,
2821
)
22+
from hpecp.gateway import Gateway, GatewayStatus
23+
from hpecp.k8s_cluster import K8sClusterHostConfig, K8sClusterStatus
2924
from hpecp.k8s_worker import WorkerK8sStatus
3025

3126
if sys.version_info[0] >= 3:
@@ -118,7 +113,7 @@ def get(
118113
print(response.json)
119114

120115
def list(
121-
self, output="table", columns=Gateway.default_display_fields,
116+
self, output="table", columns=Gateway.default_display_fields, query={}
122117
):
123118
"""Retrieve the list of Gateways
124119
@@ -135,7 +130,10 @@ def list(
135130
)
136131
)
137132
else:
138-
print(get_client().gateway.list().json)
133+
data = get_client().gateway.list().json
134+
if query:
135+
print(jmespath.search(query, data))
136+
print(data)
139137

140138
def delete(
141139
self, gateway_id, wait_for_delete_secs=0,
@@ -189,7 +187,7 @@ def wait_for_state(
189187
success = get_client().gateway.wait_for_state(
190188
gateway_id=gateway_id, state=gateway_states,
191189
)
192-
except:
190+
except Exception:
193191
success = False
194192

195193
if not success:
@@ -257,7 +255,7 @@ def list(
257255
get_client()
258256
.k8s_worker.list()
259257
.tabulate(
260-
columns=columns, style="plain", display_headers=False,
258+
columns=columns, style="plain", display_headers=False
261259
)
262260
)
263261
else:

hpecp/k8s_worker.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from __future__ import absolute_import
2-
from .logger import Logger
3-
4-
from .exceptions import APIItemNotFoundException
52

3+
import re
4+
from enum import Enum
65
from operator import attrgetter
7-
from tabulate import tabulate
6+
87
import polling
9-
from enum import Enum
10-
import re
8+
from tabulate import tabulate
9+
10+
from .exceptions import APIItemNotFoundException
1111

1212
try:
1313
basestring
@@ -129,7 +129,7 @@ def create_with_ssh_key(self, ip, ssh_key_data, tags=[]):
129129
ip: str
130130
The IP address of the proxy host. Used for internal communication.
131131
ssh_key_data: str
132-
The ssh key data as a string.
132+
The ssh key data as a string.
133133
tags: list
134134
Tags to use, e.g. "{ 'tag1': 'foo', 'tag2', 'bar' }".
135135
@@ -206,7 +206,7 @@ def wait_for_status(self, worker_id, status=[], timeout_secs=1200):
206206
207207
Returns:
208208
bool: True if status was found before timeout, otherwise False
209-
209+
210210
Raises:
211211
APIItemNotFoundException: if the item is not found and status is not empty
212212
APIException: if a generic API exception occurred

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ configparser; python_version == "2.7"
66
polling
77
pyyaml
88
fire
9+
jmespath

0 commit comments

Comments
 (0)