Skip to content

Commit d37f786

Browse files
committed
feat(install): add install api functionality
Signed-off-by: Chris Snow <[email protected]>
1 parent 83c951b commit d37f786

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed

bin/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from hpecp.cli.datatap import DatatapProxy
4444
from hpecp.cli.gateway import GatewayProxy
4545
from hpecp.cli.httpclient import HttpClientProxy
46+
from hpecp.cli.install import InstallProxy
4647
from hpecp.cli.k8scluster import K8sClusterProxy
4748
from hpecp.cli.k8sworker import K8sWorkerProxy
4849
from hpecp.cli.license import LicenseProxy
@@ -416,6 +417,7 @@ def __init__(self):
416417
self.configure_cli = configure_cli
417418
self.catalog = CatalogProxy()
418419
self.config = ConfigProxy()
420+
self.install = InstallProxy()
419421
self.k8sworker = K8sWorkerProxy()
420422
self.k8scluster = K8sClusterProxy()
421423
self.tenant = TenantProxy()

hpecp/cli/install.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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 jmespath
27+
import sys
28+
import yaml
29+
from textwrap import dedent
30+
31+
from hpecp.cli import base
32+
from hpecp.cli_utils import TextOutput
33+
34+
35+
class InstallProxy(object):
36+
"""Proxy object to :py:attr:`<hpecp.client.install>`."""
37+
38+
def __dir__(self):
39+
"""Return the CLI method names."""
40+
return [
41+
# "examples",
42+
"get"
43+
]
44+
45+
@base.intercept_exception
46+
def get(self, output="yaml", query=None):
47+
"""Get the system config.
48+
49+
:param output: how to display the output '[yaml|json|json-pp]'
50+
"""
51+
if output not in ["yaml", "json", "json-pp", "text"]:
52+
print(
53+
(
54+
"'output' parameter must be 'yaml', 'json', "
55+
"'json-pp' or 'text'."
56+
),
57+
file=sys.stderr,
58+
)
59+
sys.exit(1)
60+
61+
if output == "yaml" and query is not None:
62+
print(
63+
"output=yaml is not supported with the query parameter.",
64+
file=sys.stderr,
65+
)
66+
sys.exit(1)
67+
68+
response = base.get_client().config.get()
69+
70+
if output == "yaml":
71+
print(
72+
yaml.dump(
73+
yaml.load(
74+
json.dumps(response),
75+
Loader=yaml.FullLoader,
76+
)
77+
)
78+
)
79+
else:
80+
if query is None:
81+
data = response
82+
else:
83+
data = jmespath.search(str(query), response)
84+
85+
if output == "json-pp":
86+
print(json.dumps(data, indent=4, sort_keys=True))
87+
elif output == "text":
88+
print(TextOutput.dump(data))
89+
else:
90+
print(json.dumps(data))
91+
92+
def examples(self):
93+
"""Show examples for working with roles."""
94+
print(
95+
dedent(
96+
"""\
97+
98+
""" # noqa: E501
99+
)
100+
)

hpecp/client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ def __init__(
446446
# for each module
447447
self._tenant = TenantController(self)
448448
self._config = ConfigController(self)
449+
self._install = InstallController(self)
449450
self._gateway = GatewayController(self)
450451
self._k8s_worker = K8sWorkerController(self)
451452
self._k8s_cluster = K8sClusterController(self)
@@ -791,6 +792,25 @@ def config(self):
791792
""" # noqa: E501
792793
return self._config
793794

795+
@property
796+
def install(self):
797+
"""Retrieve a reference to `.install.InstallController` object.
798+
799+
See the class :py:class:`.install.InstallController` for the
800+
methods available.
801+
802+
Example
803+
-------
804+
This example calls the method
805+
:py:meth:`get() <.install.InstallController.get>` in
806+
:py:class:`.install.InstallController`.
807+
808+
>>> client = ContainerPlatformClient(...)
809+
>>> client.create_session()
810+
>>> client.install.get()
811+
"""
812+
return self._install
813+
794814
@property
795815
def k8s_cluster(self):
796816
"""Retrieve a reference to `.k8s_cluster.K8sClusterController` object.

hpecp/install.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
from __future__ import absolute_import
22+
23+
24+
class InstallController:
25+
def __init__(self, client):
26+
self.client = client
27+
28+
def get(self):
29+
response = self.client._request(
30+
url="/api/v1/install",
31+
http_method="get",
32+
description="install/get",
33+
)
34+
return response.json()

0 commit comments

Comments
 (0)