Skip to content

Commit 60d2eca

Browse files
authored
Merge pull request #258 from hpe-container-platform-community/snowch/implement-api-v-config-180
Snowch/implement api v config 180
2 parents 732fad8 + 6f03254 commit 60d2eca

File tree

4 files changed

+94
-1
lines changed

4 files changed

+94
-1
lines changed

.gitpod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tasks:
44
- command: /home/gitpod/.pyenv/versions/3.5.9/bin/python3 -m pip install -U pytest tox mock awscli flake8 flake8-docstrings -r ./requirements.txt --user && exit
55
- command: /home/gitpod/.pyenv/versions/3.6.9/bin/python3 -m pip install -U pytest tox mock awscli black flake8 flake8-docstrings -r ./requirements.txt --user && exit
66
- command: /home/gitpod/.pyenv/versions/3.7.7/bin/python3 -m pip install -U pytest tox mock awscli black flake8 flake8-docstrings -r ./requirements.txt --user && exit
7-
- command: /bin/python3 -m pip install -U pytest tox mock awscli black flake8 flake8-docstrings -r ./requirements.txt --user && exit
7+
- command: /bin/python3 -m pip install -U pytest tox mock awscli black flake8 flake8-docstrings isort -r ./requirements.txt --user && ln -s -f $(which black) /bin && ln -s -f $(which isort) /bin && exit
88

99
# - command: /home/gitpod/.pyenv/versions/3.9-dev/bin/python3 -m pip install -U pytest tox mock awscli black flake8 -r ./requirements.txt --user && exit
1010
- command: cd docs && make html && cd build/html && python3 -m http.server 9090

bin/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import hpecp
4040
from hpecp import ContainerPlatformClient
4141
from hpecp.cli.catalog import CatalogProxy
42+
from hpecp.cli.config import ConfigProxy
4243
from hpecp.cli.datatap import DatatapProxy
4344
from hpecp.cli.gateway import GatewayProxy
4445
from hpecp.cli.httpclient import HttpClientProxy
@@ -414,6 +415,7 @@ def __init__(self):
414415
self.autocomplete = AutoComplete(self)
415416
self.configure_cli = configure_cli
416417
self.catalog = CatalogProxy()
418+
self.config = ConfigProxy()
417419
self.k8sworker = K8sWorkerProxy()
418420
self.k8scluster = K8sClusterProxy()
419421
self.tenant = TenantProxy()

hpecp/cli/config.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# (C) Copyright [2020] Hewlett Packard Enterprise Development LP
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a
4+
# copy of this software and associated documentation files (the "Software"),
5+
# to deal in the Software without restriction, including without limitation
6+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
7+
# and/or sell copies of the Software, and to permit persons to whom the
8+
# Software is furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included
11+
# in all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
17+
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19+
# OTHER DEALINGS IN THE SOFTWARE.
20+
21+
"""HPE Container Platform CLI."""
22+
23+
from __future__ import print_function
24+
25+
import json
26+
import sys
27+
import yaml
28+
29+
from hpecp.cli import base
30+
31+
32+
class ConfigProxy(object):
33+
"""Proxy object to :py:attr:`<hpecp.client.config>`."""
34+
35+
def __dir__(self):
36+
"""Return the CLI method names."""
37+
return [
38+
"get",
39+
]
40+
41+
@base.intercept_exception
42+
def get(self, output="yaml", query=None):
43+
"""Get the system config.
44+
45+
:param output: how to display the output '[yaml|json|json-pp]'
46+
"""
47+
if output not in ["yaml", "json", "json-pp", "text"]:
48+
print(
49+
"'output' parameter must be 'yaml', 'json', 'json-pp' or 'text'.",
50+
file=sys.stderr,
51+
)
52+
sys.exit(1)
53+
54+
if output == "yaml" and query is not None:
55+
print(
56+
"output=yaml is not supported when providing the query parameter.",
57+
file=sys.stderr,
58+
)
59+
sys.exit(1)
60+
61+
response = base.get_client().config.get()
62+
63+
if output == "yaml":
64+
print(
65+
yaml.dump(
66+
yaml.load(
67+
json.dumps(response),
68+
Loader=yaml.FullLoader,
69+
)
70+
)
71+
)
72+
else:
73+
if query is None:
74+
data = response
75+
else:
76+
data = jmespath.search(str(query), response)
77+
78+
if output == "json-pp":
79+
print(json.dumps(data, indent=4, sort_keys=True))
80+
elif output == "text":
81+
print(TextOutput.dump(data))
82+
else:
83+
print(json.dumps(data))

hpecp/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ class ConfigController:
2525
def __init__(self, client):
2626
self.client = client
2727

28+
def get(self):
29+
response = self.client._request(
30+
url="/api/v2/config",
31+
http_method="get",
32+
description="config/get",
33+
)
34+
return response.json()
35+
2836
def auth(self, data):
2937
"""
3038
Example::

0 commit comments

Comments
 (0)