Skip to content

Commit bfe08a4

Browse files
authored
Merge pull request #57 from hpe-container-platform-community/fix_client_docstrings
add hpecp/tenant doc check
2 parents 3215199 + e88cfb3 commit bfe08a4

File tree

5 files changed

+463
-382
lines changed

5 files changed

+463
-382
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
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/gateway.py,hpecp/logger.py,hpecp/k8s_cluster.py,hpecp/user.py,hpecp/tenant.py,hpecp/role.py --docstring-convention numpy bin/ hpecp/
39+
- flake8 --exclude hpecp/role.py --docstring-convention numpy bin/ hpecp/
4040
- stage: coverage_library
4141
name: "Code coverage LIBRARY (./hpecp)"
4242
python: 3.8

hpecp/gateway.py

Lines changed: 126 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,17 @@
3636

3737

3838
class GatewayController:
39-
"""This is the main class that users will interact with to work with
40-
41-
Gateways. An instance of this class is available in the
39+
"""Class that users will interact with to work with Gateways. An instance
40+
of this class is available in the
4241
client.ContainerPlatformClient with the attribute name
4342
:py:attr:`gateway <.client.ContainerPlatformClient.gateway>`. The methods
4443
of this class can be invoked using `client.gateway.method()`. See the
4544
example below:
4645
47-
Example::
48-
49-
client = ContainerPlatformClient(...).create_session()
50-
client.gateway.list()
51-
46+
Example
47+
-------
48+
>>> client = ContainerPlatformClient(...).create_session()
49+
>>> client.gateway.list()
5250
"""
5351

5452
def __init__(self, client):
@@ -62,22 +60,25 @@ def create_with_ssh_key(
6260
self, ip, proxy_node_hostname, ssh_key_data, tags=[]
6361
):
6462
"""Create a gateway instance using SSH key credentials to access the
65-
6663
host.
6764
68-
Args:
69-
ip: str
70-
The IP address of the proxy host. Used for internal
71-
communication.
72-
proxy_node_hostname: str
73-
Clients will access cluster services will be accessed using
74-
this name.
75-
ssh_key_data: str
76-
The ssh key data as a string.
77-
tags: list
78-
Tags to use, e.g. "{ 'tag1': 'foo', 'tag2', 'bar' }".
79-
80-
Returns: gateway ID
65+
Parameters
66+
----------
67+
ip: str
68+
The IP address of the proxy host. Used for internal
69+
communication.
70+
proxy_node_hostname: str
71+
Clients will access cluster services will be accessed using
72+
this name.
73+
ssh_key_data: str
74+
The ssh key data as a string.
75+
tags: list
76+
Tags to use, e.g. "{ 'tag1': 'foo', 'tag2', 'bar' }".
77+
78+
Returns
79+
-------
80+
str
81+
gateway ID
8182
"""
8283

8384
assert isinstance(
@@ -110,13 +111,16 @@ def create_with_ssh_key(
110111
return response.headers["location"]
111112

112113
def list(self):
113-
"""Retrieve a list of Gateways
114+
"""Retrieve a list of Gateways.
114115
115-
Returns:
116-
GatewayList: list of Gateways
116+
Returns
117+
-------
118+
GatewayList
119+
list of Gateways
117120
118-
Raises:
119-
APIException
121+
Raises
122+
------
123+
APIException
120124
"""
121125
response = self.client._request(
122126
url="/api/v1/workers/",
@@ -128,15 +132,19 @@ def list(self):
128132
def get(self, gateway_id):
129133
"""Retrieve a Gateway by ID.
130134
131-
Args:
132-
gateway_id: str
133-
The gateway ID - format: '/api/v1/workers/[0-9]+'
135+
Parameters
136+
----------
137+
gateway_id: str
138+
The gateway ID - format: '/api/v1/workers/[0-9]+'
134139
135-
Returns:
136-
Gateway: object representing Gateway
140+
Returns
141+
-------
142+
Gateway
143+
object representing a Gateway
137144
138-
Raises:
139-
APIException
145+
Raises
146+
------
147+
APIException
140148
"""
141149
assert isinstance(
142150
gateway_id, str
@@ -163,12 +171,14 @@ def delete(self, gateway_id):
163171
You can use :py:meth:`wait_for_status` to check for the gateway
164172
state/existence.
165173
166-
Args:
167-
gateway_id: str
168-
The Gateway ID - format: '/api/v1/workers/[0-9]+'
174+
Parameters
175+
----------
176+
gateway_id: str
177+
The Gateway ID - format: '/api/v1/workers/[0-9]+'
169178
170-
Raises:
171-
APIException
179+
Raises
180+
------
181+
APIException
172182
"""
173183
assert isinstance(
174184
gateway_id, str
@@ -188,37 +198,45 @@ def delete(self, gateway_id):
188198
def wait_for_delete(self, gateway_id, timeout_secs=1200):
189199
"""Wait for gateway to be deleted.
190200
191-
Args:
192-
gateway_id: str
193-
The gateway ID - format: '/api/v1/workers/[0-9]+'
194-
timeout_secs: int
195-
How long to wait for the status(es) before raising an
196-
exception.
197-
198-
Returns:
199-
bool: True if gateway was deleted before timeout, otherwise False
201+
Parameters
202+
----------
203+
gateway_id: str
204+
The gateway ID - format: '/api/v1/workers/[0-9]+'
205+
timeout_secs: int
206+
How long to wait for the status(es) before raising an
207+
exception.
208+
209+
Returns
210+
-------
211+
bool
212+
True if gateway was deleted before timeout, otherwise False
200213
"""
201214

202215
def wait_for_state(self, gateway_id, state=[], timeout_secs=1200):
203216
"""Wait for gateway state.
204217
205-
Args:
206-
gateway_id: str
207-
The gateway ID - format: '/api/v1/workers/[0-9]+'
208-
status: list[:py:class:`GatewayStatus`]
209-
Status(es) to wait for. Use an empty array if you want to wait
210-
for a cluster's existence to cease.
211-
timeout_secs: int
212-
How long to wait for the status(es) before raising an
213-
exception.
214-
215-
Returns:
216-
bool: True if status was found before timeout, otherwise False
217-
218-
Raises:
219-
APIItemNotFoundException: if the item is not found and state is not
220-
empty
221-
APIException: if a generic API exception occurred
218+
Parameters
219+
----------
220+
gateway_id: str
221+
The gateway ID - format: '/api/v1/workers/[0-9]+'
222+
status: list[:py:class:`GatewayStatus`]
223+
Status(es) to wait for. Use an empty array if you want to wait
224+
for a cluster's existence to cease.
225+
timeout_secs: int
226+
How long to wait for the status(es) before raising an
227+
exception.
228+
229+
Returns
230+
-------
231+
bool
232+
True if status was found before timeout, otherwise False
233+
234+
Raises
235+
------
236+
APIItemNotFoundException
237+
if the item is not found and state is not empty
238+
APIException
239+
if a generic API exception occurred
222240
"""
223241
assert isinstance(
224242
gateway_id, basestring
@@ -305,13 +323,15 @@ class Gateway:
305323
Container Platform API. Users of this library are not expected to create an
306324
instance of this class.
307325
308-
Parameters:
309-
json : str
310-
The json returned by the API representing a Gateway.
326+
Parameters
327+
----------
328+
json : str
329+
The json returned by the API representing a Gateway.
311330
312-
Returns:
313-
Gateway:
314-
An instance of Gateway
331+
Returns
332+
-------
333+
Gateway
334+
An instance of Gateway
315335
"""
316336

317337
# All of the fields of Gateway objects as returned by the HPE Container
@@ -368,10 +388,13 @@ def set_display_columns(self, columns):
368388
369389
with :py:meth:`.GatewayList.tabulate`
370390
371-
Parameters:
372-
columns : list[str]
373-
Set the list of colums to return
391+
Parameters
392+
----------
393+
columns : list[str]
394+
Set the list of colums to return
374395
396+
See Also
397+
--------
375398
See :py:attr:`all_fields` for the complete list of field names.
376399
"""
377400
self.display_columns = columns
@@ -450,17 +473,18 @@ def _links(self):
450473

451474

452475
class GatewayList:
453-
"""List of :py:obj:`.Gateway` objects
476+
"""List of :py:obj:`.Gateway` objects."""
454477

455-
This class is not expected to be instantiated by users.
478+
def __init__(self, json):
479+
"""Create a GatewayList. This class is not expected to be
480+
instantiated by users.
456481
457-
Parameters:
482+
Parameters
483+
----------
458484
json : str
459485
json data returned from the HPE Container Platform API get request
460486
to /api/v1/Gateway
461-
"""
462-
463-
def __init__(self, json):
487+
"""
464488
self.json = [g for g in json if g["purpose"] == "proxy"]
465489
self.gateways = sorted(
466490
[Gateway(g) for g in json if g["purpose"] == "proxy"],
@@ -500,25 +524,28 @@ def tabulate(
500524
style="pretty",
501525
display_headers=True,
502526
):
503-
"""Provide a tabular represenation of the list of Gateways
504-
505-
Parameters:
506-
columns : list[str]
507-
list of columns to return in the table -
508-
default :py:attr:`.Gateway.default_display_fields`
509-
style: str
510-
See: https://github.com/astanin/python-tabulate#table-format
511-
512-
Returns:
513-
str : table output
514-
515-
Example::
516-
517-
# Print the gateway list with all of the avaialble fields
518-
print(hpeclient.gateway.list().tabulate())
519-
520-
# Print the cluster list with a subset of the fields
521-
print(hpeclient.gateway.list().tabulate(columns=['id', 'state']))
527+
"""Provide a tabular represenation of the list of Gateways.
528+
529+
Parameters
530+
----------
531+
columns : list[str]
532+
list of columns to return in the table -
533+
default :py:attr:`.Gateway.default_display_fields`
534+
style: str
535+
See: https://github.com/astanin/python-tabulate#table-format
536+
537+
Returns
538+
-------
539+
str
540+
table output
541+
542+
Example
543+
-------
544+
Print the gateway list with all of the avaialble fields
545+
>>> print(hpeclient.gateway.list().tabulate())
546+
547+
Print the cluster list with a subset of the fields
548+
>>> print(hpeclient.gateway.list().tabulate(columns=['id', 'state']))
522549
"""
523550
if columns != Gateway.default_display_fields:
524551
assert isinstance(

0 commit comments

Comments
 (0)