Skip to content

Commit d2bc338

Browse files
authored
Merge pull request #251 from hpe-container-platform-community/snowch/implement-datatap-module-250
add datatap functionality
2 parents 13c2971 + 28c1d28 commit d2bc338

File tree

4 files changed

+189
-0
lines changed

4 files changed

+189
-0
lines changed

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.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/cli/datatap.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
"get",
41+
"list",
42+
"delete",
43+
# "examples",
44+
"wait_for_state",
45+
]
46+
47+
def examples(self):
48+
"""Show examples for working with roles."""
49+
print(
50+
dedent(
51+
"""\
52+
Coming soon ...
53+
""" # noqa: E501
54+
)
55+
)

hpecp/client.py

Lines changed: 21 additions & 0 deletions
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

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
"label_name",
34+
"label_description",
35+
"self_href",
36+
# "state",
37+
# "state_info",
38+
)
39+
40+
default_display_fields = [
41+
"label_name",
42+
"label_description",
43+
"self_href",
44+
]
45+
46+
# These fields are displayed by default, e.g. in tabulate()
47+
# TODO: Verify this with the specification
48+
# TODO: Pick a smaller subset, again based on the API response
49+
default_display_fields = all_fields
50+
51+
@property
52+
def label_name(self):
53+
"""@Field: from json['label']['name']."""
54+
try:
55+
return self.json["label"]["name"]
56+
except KeyError:
57+
return ""
58+
59+
@property
60+
def label_description(self):
61+
"""@Field: from json['label']['description']."""
62+
try:
63+
return self.json["label"]["description"]
64+
except KeyError:
65+
return ""
66+
67+
@property
68+
def self_href(self):
69+
"""@Field: from json['_links']['self']['href']."""
70+
try:
71+
return self.json["_links"]["self"]["href"]
72+
except KeyError:
73+
return ""
74+
75+
# @property
76+
# def state(self):
77+
# """@Field: from json['state']"""
78+
# try:
79+
# return self.json["state"]
80+
# except KeyError:
81+
# return ""
82+
83+
# @property
84+
# def state_info(self):
85+
# """@Field: from json['state_info']"""
86+
# try:
87+
# return self.json["state_info"]
88+
# except KeyError:
89+
# return ""
90+
91+
92+
class DatatapController(AbstractResourceController):
93+
"""Class that users will interact with to work with datataps.
94+
95+
An instance of this class is available in the
96+
`client.ContainerPlatformClient` with the attribute name
97+
:py:attr:`datatap <.client.ContainerPlatformClient.catalog>`. The methods
98+
of this class can be invoked using `client.datatap.method()`. See the
99+
example below:
100+
101+
Examples
102+
--------
103+
>>> client = ContainerPlatformClient(...).create_session()
104+
>>> client.datatap.list()
105+
"""
106+
107+
base_resource_path = "/api/v1/dataconn"
108+
109+
resource_list_path = "data_connectors"
110+
111+
resource_class = Datatap

0 commit comments

Comments
 (0)