Skip to content

Commit 38a9fde

Browse files
authored
Merge pull request #55 from hpe-container-platform-community/fix_client_docstrings
add docstrings to catalog
2 parents db1df0b + bff7859 commit 38a9fde

File tree

5 files changed

+156
-126
lines changed

5 files changed

+156
-126
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
install:
3737
- pip3 install flake8 flake8-docstrings flake8-per-file-ignores
3838
script:
39-
- flake8 --exclude hpecp/catalog.py,hpecp/config.py,hpecp/gateway.py,hpecp/logger.py,hpecp/lock.py,hpecp/k8s_cluster.py,hpecp/k8s_worker.py,hpecp/license.py,hpecp/exceptions.py,hpecp/user.py,hpecp/tenant.py,hpecp/role.py --docstring-convention numpy bin/ hpecp/
39+
- flake8 --exclude hpecp/gateway.py,hpecp/logger.py,hpecp/k8s_cluster.py,hpecp/user.py,hpecp/tenant.py,hpecp/role.py --docstring-convention numpy bin/ hpecp/
4040
- stage: coverage_library
4141
name: "Code coverage LIBRARY (./hpecp)"
4242
python: 3.8

hpecp/catalog.py

+73-51
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
class CatalogController:
28-
"""This is the main class that users will interact with to talk to catalogs.
28+
"""Class that users will interact with to work with catalogs.
2929
3030
An instance of this class is available in the
3131
`client.ContainerPlatformClient` with the attribute name
@@ -43,13 +43,16 @@ def __init__(self, client):
4343
self.client = client
4444

4545
def list(self):
46-
"""Retrieve a list of Catalogs
46+
"""Retrieve a list of Catalogs.
4747
48-
Returns:
49-
CatalogList: list of Catalogs
48+
Returns
49+
-------
50+
CatalogList
51+
list of Catalogs
5052
51-
Raises:
52-
APIException
53+
Raises
54+
------
55+
APIException
5356
"""
5457
response = self.client._request(
5558
url="/api/v1/catalog/",
@@ -61,17 +64,21 @@ def list(self):
6164
)
6265

6366
def get(self, catalog_id):
64-
"""Retrieve a catalog identified by {catalog_id}
67+
"""Retrieve a catalog identified by {catalog_id}.
6568
66-
Args:
67-
catalog_id: str
68-
The Catalog ID - format: '/api/v1/catalog/[0-9]+'
69+
Parameters
70+
----------
71+
catalog_id: str
72+
The Catalog ID - format: '/api/v1/catalog/[0-9]+'
6973
70-
Raises:
71-
APIException
74+
Returns
75+
-------
76+
Catalog
77+
object representing the requested Catalog
7278
73-
Returns:
74-
Catalog -- object representing the requested Catalog
79+
Raises
80+
------
81+
APIException
7582
"""
7683
assert isinstance(
7784
catalog_id, str
@@ -88,19 +95,7 @@ def get(self, catalog_id):
8895

8996

9097
class Catalog:
91-
"""Create an instance of Catalog from json data returned from the HPE
92-
93-
Container Platform API. Users of this library are not expected to create an
94-
instance of this class.
95-
96-
Parameters:
97-
json : str
98-
The json returned by the API representing a Catalog.
99-
100-
Returns:
101-
Catalog:
102-
An instance of Catalog
103-
"""
98+
"""Catalog Image item."""
10499

105100
# All of the fields of Catalog objects as returned by the HPE Container
106101
# Platform API.
@@ -133,6 +128,23 @@ class Catalog:
133128
default_display_fields = all_fields
134129

135130
def __init__(self, json):
131+
"""Create a Catalog Image.
132+
133+
Parameters
134+
----------
135+
json : str
136+
The json returned by the API representing a Catalog.
137+
138+
Returns
139+
-------
140+
Catalog:
141+
An instance of Catalog
142+
143+
Note
144+
----
145+
Users of the library aren't expected to create instances of this class
146+
directly.
147+
"""
136148
self.json = json
137149
self.display_columns = Catalog.default_display_fields
138150

@@ -155,13 +167,15 @@ def __len__(self):
155167

156168
def set_display_columns(self, columns):
157169
"""Set the columns this instance should have when the instance is used
158-
159170
with :py:meth:`.CatalogList.tabulate`.
160171
161-
Parameters:
162-
columns : list[str]
163-
Set the list of colums to return
172+
Parameters
173+
----------
174+
columns : list[str]
175+
Set the list of colums to return
164176
177+
See Also
178+
--------
165179
See :py:attr:`all_fields` for the complete list of field names.
166180
"""
167181
self.display_columns = columns
@@ -185,14 +199,17 @@ def state(self):
185199

186200

187201
class CatalogList:
188-
"""List of :py:obj:`.Catalog` objects
202+
"""List of :py:obj:`.Catalog` objects.
189203
190-
This class is not expected to be instantiated by users.
204+
Parameters
205+
----------
206+
json : str
207+
json data returned from the HPE Container Platform API get request
208+
to /api/v1/catalog
191209
192-
Parameters:
193-
json : str
194-
json data returned from the HPE Container Platform API get request
195-
to /api/v1/catalog
210+
Note
211+
----
212+
This class is not expected to be instantiated by users.
196213
"""
197214

198215
def __init__(self, json):
@@ -234,25 +251,30 @@ def tabulate(
234251
style="pretty",
235252
display_headers=True,
236253
):
237-
"""Provide a tabular represenation of the list of Catalogs
254+
"""Provide a tabular represenation of the list of Catalog images.
255+
256+
Parameters
257+
----------
258+
columns : list[str]
259+
list of columns to return in the table - default
260+
:py:attr:`.Catalog.default_display_fields`
261+
style: str
262+
See: https://github.com/astanin/python-tabulate#table-format
238263
239-
Parameters:
240-
columns : list[str]
241-
list of columns to return in the table - default
242-
:py:attr:`.Catalog.default_display_fields`
243-
style: str
244-
See: https://github.com/astanin/python-tabulate#table-format
264+
Returns
265+
-------
266+
str
267+
table output
245268
246-
Returns:
247-
str : table output
269+
Example
270+
-------
271+
Print the catalog list with all of the avaialble fields:
248272
249-
Example::
273+
>>> print(hpeclient.catalog.list().tabulate())
250274
251-
# Print the catalog list with all of the avaialble fields
252-
print(hpeclient.catalog.list().tabulate())
275+
Print the cluster list with a subset of the fields:
253276
254-
# Print the cluster list with a subset of the fields
255-
print(hpeclient.catalog.list().tabulate(columns=['id', 'state']))
277+
>>> print(hpeclient.catalog.list().tabulate(columns=['id', 'state']))
256278
"""
257279
if columns != Catalog.default_display_fields:
258280
assert isinstance(

hpecp/k8s_worker.py

+36-28
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,22 @@ def create_with_ssh_password(self, username, password):
144144
raise NotImplementedError()
145145

146146
def create_with_ssh_key(self, ip, ssh_key_data, tags=[]):
147-
"""Create a gateway instance using SSH key credentials to access the host
148-
149-
Args:
150-
ip: str
151-
The IP address of the proxy host. Used for internal
152-
communication.
153-
ssh_key_data: str
154-
The ssh key data as a string.
155-
tags: list
156-
Tags to use, e.g. "{ 'tag1': 'foo', 'tag2', 'bar' }".
157-
158-
Returns: Worker ID
147+
"""Create a gateway instance using SSH key credentials to access the host.
148+
149+
Parameters
150+
----------
151+
ip: str
152+
The IP address of the proxy host. Used for internal
153+
communication.
154+
ssh_key_data: str
155+
The ssh key data as a string.
156+
tags: list
157+
Tags to use, e.g. "{ 'tag1': 'foo', 'tag2', 'bar' }".
158+
159+
Returns
160+
-------
161+
string
162+
Worker ID
159163
"""
160164

161165
assert isinstance(
@@ -221,22 +225,26 @@ def delete(self, worker_id):
221225
def wait_for_status(self, worker_id, status=[], timeout_secs=1200):
222226
"""Wait for K8S worker status.
223227
224-
Args:
225-
worker_id: str
226-
The worker ID - format: '/api/v1/workers/[0-9]+'
227-
status: list[:py:class:`WorkerK8sStatus`]
228-
Status(es) to wait for. Use an empty array if you want to
229-
wait for a cluster's existence to cease.
230-
timeout_secs: int
231-
How long to wait for the status(es) before raising an
232-
exception.
233-
234-
Returns:
235-
bool: True if status was found before timeout, otherwise False
236-
237-
Raises:
238-
APIItemNotFoundException: if the item is not found and status is
239-
not empty
228+
Parameters
229+
----------
230+
worker_id: str
231+
The worker ID - format: '/api/v1/workers/[0-9]+'
232+
status: list[:py:class:`WorkerK8sStatus`]
233+
Status(es) to wait for. Use an empty array if you want to
234+
wait for a cluster's existence to cease.
235+
timeout_secs: int
236+
How long to wait for the status(es) before raising an
237+
exception.
238+
239+
Returns
240+
-------
241+
bool
242+
True if status was found before timeout, otherwise False
243+
244+
Raises
245+
------
246+
APIItemNotFoundException
247+
If the item is not found and status is not empty
240248
APIException: if a generic API exception occurred
241249
"""
242250
assert isinstance(

hpecp/license.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ def upload_with_ssh_pass(
8080
)
8181

8282
def register(self, server_filename):
83-
"""Register a license that has been uploaded to
84-
'/srv/bluedata/license/' on the controller.
85-
86-
Arguments:
87-
88-
server_filename: str
89-
Filepath to the license on the server, e.g.
90-
'/srv/bluedata/license/LICENSE-1.txt'
91-
92-
Raises:
93-
94-
APIException
83+
"""Register a license. The license must have previously been uploaded
84+
to '/srv/bluedata/license/' on the controller.
85+
86+
Parameters
87+
----------
88+
server_filename: str
89+
Filepath to the license on the server, e.g.
90+
'/srv/bluedata/license/LICENSE-1.txt'
91+
92+
Raises
93+
------
94+
APIException
9595
"""
9696
data = {"hpelicense_file": server_filename}
9797
return self.client._request(
@@ -102,16 +102,16 @@ def register(self, server_filename):
102102
)
103103

104104
def delete(self, license_key):
105-
"""Delete a license by LicenseKey
106-
107-
Arguments:
108-
109-
license_key: str
110-
The license key, e.g. '1234 1234 ... 1234 "SOMETEXT"'
105+
"""Delete a license by LicenseKey.
111106
112-
Raises:
107+
Parameters
108+
----------
109+
license_key: str
110+
The license key, e.g. '1234 1234 ... 1234 "SOMETEXT"'
113111
114-
APIException
112+
Raises
113+
------
114+
APIException
115115
"""
116116

117117
try:

0 commit comments

Comments
 (0)