Skip to content

Commit 1dde72e

Browse files
committed
2 parents 881850e + 5be2771 commit 1dde72e

File tree

6 files changed

+343
-2
lines changed

6 files changed

+343
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/hpe-container-platform-community/hpecp-python-library)
1111
[![Good first issues open](https://img.shields.io/github/issues/hpe-container-platform-community/hpecp-python-library/good%20first%20issue.svg?label=good%20first%20issue)](https://github.com/hpe-container-platform-community/hpecp-python-library/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
1212

13-
13+
1414
----
1515

1616
## Documentation

bin/cli.py

+2
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.datatap import DatatapProxy
4243
from hpecp.cli.gateway import GatewayProxy
4344
from hpecp.cli.httpclient import HttpClientProxy
4445
from hpecp.cli.k8scluster import K8sClusterProxy
@@ -415,6 +416,7 @@ def __init__(self,):
415416
self.user = UserProxy()
416417
self.role = RoleProxy()
417418
self.version = version
419+
self.datatap = DatatapProxy()
418420

419421

420422
if __name__ == "__main__":

hpecp/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
)
3636
from .logger import Logger
3737

38-
__version__ = "0.8.11"
38+
__version__ = "0.9.3"

hpecp/cli/datatap.py

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
from textwrap import dedent
26+
from hpecp.datatap import Datatap
27+
from hpecp.cli import base
28+
29+
30+
class DatatapProxy(base.BaseProxy):
31+
"""Proxy object to :py:attr:`<hpecp.client.datatap>`."""
32+
33+
def __init__(self):
34+
"""Create instance of proxy class with the client module name."""
35+
super(DatatapProxy, self).new_instance("datatap", Datatap)
36+
37+
def __dir__(self):
38+
"""Return the CLI method names."""
39+
return [
40+
"create_hdfs_with_kerberos",
41+
"get",
42+
"list",
43+
"delete",
44+
# "examples",
45+
"wait_for_state",
46+
]
47+
48+
def examples(self):
49+
"""Show examples for working with roles."""
50+
print(
51+
dedent(
52+
"""\
53+
Coming soon ...
54+
""" # noqa: E501
55+
)
56+
)
57+
58+
def create_hdfs_with_kerberos(
59+
self,
60+
name,
61+
description,
62+
path_from_endpoint,
63+
kdc_data_host,
64+
kdc_data_port,
65+
realm,
66+
client_principal,
67+
browse_only,
68+
host,
69+
service_id,
70+
backup_host,
71+
endpoint_type,
72+
endpoint_port,
73+
read_only,
74+
keytab="",
75+
):
76+
"""TODO.
77+
78+
Parameters
79+
----------
80+
name : [type]
81+
[description]
82+
description : [type]
83+
[description]
84+
path_from_endpoint : [type]
85+
[description]
86+
kdc_data_host : [type]
87+
[description]
88+
kdc_data_port : [type]
89+
[description]
90+
realm : [type]
91+
[description]
92+
client_principal : [type]
93+
[description]
94+
browse_only : [type]
95+
[description]
96+
host : [type]
97+
[description]
98+
keytab : [type]
99+
[description]
100+
service_id : [type]
101+
[description]
102+
backup_host : [type]
103+
[description]
104+
endpoint_type : [type]
105+
[description]
106+
endpoint_port : [type]
107+
[description]
108+
read_only : [type]
109+
[description]
110+
"""
111+
base.get_client().datatap.create(
112+
name,
113+
description,
114+
path_from_endpoint,
115+
kdc_data_host,
116+
kdc_data_port,
117+
realm,
118+
client_principal,
119+
browse_only,
120+
host,
121+
keytab,
122+
service_id,
123+
backup_host,
124+
endpoint_type,
125+
endpoint_port,
126+
read_only,
127+
)

hpecp/client.py

+21
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
from .catalog import CatalogController
4545
from .config import ConfigController
46+
from .datatap import DatatapController
4647
from .exceptions import (
4748
APIException,
4849
APIItemConflictException,
@@ -453,6 +454,7 @@ def __init__(
453454
self._user = UserController(self)
454455
self._catalog = CatalogController(self)
455456
self._role = RoleController(self)
457+
self._datatap = DatatapController(self)
456458

457459
def create_session(self):
458460
"""Create a session with the HPE CP controller.
@@ -960,3 +962,22 @@ def role(self):
960962
>>> client.role.get()
961963
"""
962964
return self._role
965+
966+
@property
967+
def datatap(self):
968+
"""Retrieve a reference to a `.datatap.DatatapController` object.
969+
970+
See the class :py:class:`.role.DatatapController` for the methods
971+
available.
972+
973+
Example
974+
-------
975+
This example calls the method :py:meth:`get()
976+
<.datatap.DatatapController.get>`
977+
in :py:class:`.datatap.DatatapController`.
978+
979+
>>> client = ContainerPlatformClient(...)
980+
>>> client.create_session()
981+
>>> client.datatap.get()
982+
"""
983+
return self._datatap

hpecp/datatap.py

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
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+
"""Module for working with datatap."""
22+
23+
from .base_resource import AbstractResource, AbstractResourceController
24+
25+
26+
class Datatap(AbstractResource):
27+
"""Datatap Image item."""
28+
29+
# All of the fields of Catalog objects as returned by the HPE Container
30+
# Platform API.
31+
# TODO: Verify this with the specification
32+
all_fields = (
33+
"id",
34+
"name",
35+
"description",
36+
"type",
37+
"status",
38+
)
39+
40+
default_display_fields = [
41+
"id",
42+
"name",
43+
"description",
44+
"type",
45+
"status",
46+
]
47+
48+
# These fields are displayed by default, e.g. in tabulate()
49+
# TODO: Verify this with the specification
50+
# TODO: Pick a smaller subset, again based on the API response
51+
default_display_fields = all_fields
52+
53+
@property
54+
def name(self):
55+
"""@Field: from json['_embedded']['label']['name']."""
56+
try:
57+
return self.json["_embedded"]["label"]["name"]
58+
except KeyError:
59+
return ""
60+
61+
@property
62+
def description(self):
63+
"""@Field: from json['_embedded']['label']['description']."""
64+
try:
65+
return self.json["_embedded"]["label"]["description"]
66+
except KeyError:
67+
return ""
68+
69+
@property
70+
def type(self):
71+
"""@Field: from json['_embedded']['endpoint']['type']."""
72+
try:
73+
return self.json["_embedded"]["endpoint"]["type"]
74+
except KeyError:
75+
return ""
76+
77+
@property
78+
def self_href(self):
79+
"""@Field: from json['_links']['self']['href']."""
80+
try:
81+
return self.json["_links"]["self"]["href"]
82+
except KeyError:
83+
return ""
84+
85+
@property
86+
def status(self):
87+
"""@Field: from json['_embedded']['status']."""
88+
try:
89+
return self.json["_embedded"]["status"]
90+
except KeyError:
91+
return ""
92+
93+
94+
class DatatapController(AbstractResourceController):
95+
"""Class that users will interact with to work with datataps.
96+
97+
An instance of this class is available in the
98+
`client.ContainerPlatformClient` with the attribute name
99+
:py:attr:`datatap <.client.ContainerPlatformClient.catalog>`. The methods
100+
of this class can be invoked using `client.datatap.method()`. See the
101+
example below:
102+
103+
Examples
104+
--------
105+
>>> client = ContainerPlatformClient(...).create_session()
106+
>>> client.datatap.list()
107+
"""
108+
109+
base_resource_path = "/api/v1/dataconn"
110+
111+
resource_list_path = "data_connectors"
112+
113+
resource_class = Datatap
114+
115+
def create_hdfs_with_kerberos(
116+
self,
117+
name,
118+
description,
119+
path_from_endpoint,
120+
kdc_data_host,
121+
kdc_data_port,
122+
realm,
123+
client_principal,
124+
browse_only,
125+
host,
126+
keytab,
127+
service_id,
128+
backup_host,
129+
endpoint_type,
130+
endpoint_port,
131+
read_only,
132+
):
133+
"""TODO.
134+
135+
Parameters
136+
----------
137+
name : [type]
138+
[description]
139+
description : [type]
140+
[description]
141+
path_from_endpoint : [type]
142+
[description]
143+
kdc_data_host : [type]
144+
[description]
145+
kdc_data_port : [type]
146+
[description]
147+
realm : [type]
148+
[description]
149+
client_principal : [type]
150+
[description]
151+
browse_only : [type]
152+
[description]
153+
host : [type]
154+
[description]
155+
keytab : [type]
156+
[description]
157+
service_id : [type]
158+
[description]
159+
backup_host : [type]
160+
[description]
161+
endpoint_type : [type]
162+
[description]
163+
endpoint_port : [type]
164+
[description]
165+
read_only : [type]
166+
[description]
167+
"""
168+
_data = {
169+
"bdfs_root": {"path_from_endpoint": path_from_endpoint},
170+
"endpoint": {
171+
"kdc_data": [{"host": kdc_data_host, "port": kdc_data_port}],
172+
"realm": realm,
173+
"client_principal": client_principal,
174+
"browse_only": browse_only,
175+
"host": host,
176+
"keytab": keytab,
177+
"service_id": service_id,
178+
"backup_host": backup_host,
179+
"type": endpoint_type,
180+
"port": endpoint_port,
181+
},
182+
"flags": {"read_only": read_only},
183+
"label": {"name": name, "description": description},
184+
}
185+
186+
self.client._request(
187+
url=DatatapController.base_resource_path,
188+
http_method="post",
189+
description="datatap/create",
190+
data=_data,
191+
)

0 commit comments

Comments
 (0)