Skip to content

Commit 5e4970b

Browse files
author
Victor Hua
committed
added support for arrays/support_contracts endpoint for Pure1 client
1 parent b5a23f5 commit 5e4970b

13 files changed

+753
-3
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ A log of changes by version and date.
66
======= ========== =====
77
Version Date Notes
88
======= ========== =====
9+
1.4.0 03/23/2020 Added support for Pure1 arrays/support-contracts endpoint
910
1.3.0 03/11/2020 Added support for Pure1 replication endpoints
1011
1.2.0 12/23/2019 Added FlashArray 2.1 client
1112
1.1.2 11/20/2019 Bug fix for FlashArray 2.0 client

docs/source/pypureclient.pure1.models.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,14 @@ pypureclient.pure1.models.nfs module
380380
:undoc-members:
381381
:show-inheritance:
382382

383+
pypureclient.pure1.models.oauth\_token\_response module
384+
-------------------------------------------------------
385+
386+
.. automodule:: pypureclient.pure1.models.oauth_token_response
387+
:members:
388+
:undoc-members:
389+
:show-inheritance:
390+
383391
pypureclient.pure1.models.object\_store\_account module
384392
-------------------------------------------------------
385393

@@ -540,6 +548,30 @@ pypureclient.pure1.models.smb module
540548
:undoc-members:
541549
:show-inheritance:
542550

551+
pypureclient.pure1.models.support\_contract module
552+
--------------------------------------------------
553+
554+
.. automodule:: pypureclient.pure1.models.support_contract
555+
:members:
556+
:undoc-members:
557+
:show-inheritance:
558+
559+
pypureclient.pure1.models.support\_contract\_get\_response module
560+
-----------------------------------------------------------------
561+
562+
.. automodule:: pypureclient.pure1.models.support_contract_get_response
563+
:members:
564+
:undoc-members:
565+
:show-inheritance:
566+
567+
pypureclient.pure1.models.support\_contract\_response module
568+
------------------------------------------------------------
569+
570+
.. automodule:: pypureclient.pure1.models.support_contract_response
571+
:members:
572+
:undoc-members:
573+
:show-inheritance:
574+
543575
pypureclient.pure1.models.tag module
544576
------------------------------------
545577

docs/source/pypureclient.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ Subpackages
1212
Submodules
1313
----------
1414

15+
pypureclient.api\_token\_manager module
16+
---------------------------------------
17+
18+
.. automodule:: pypureclient.api_token_manager
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
1523
pypureclient.exceptions module
1624
------------------------------
1725

pypureclient/api_token_manager.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import requests
2+
3+
from .exceptions import PureError
4+
from .keywords import Headers
5+
6+
class APITokenManager(object):
7+
"""
8+
A APITokenManager is to handle api token-based authentication for REST 2.X API
9+
calls internally.
10+
A valid session token is stored in memory.
11+
"""
12+
13+
def __init__(self, token_endpoint, api_token, verify_ssl=True):
14+
"""
15+
Initialize a APITokenManager. Should be treated as a static object.
16+
17+
Args:
18+
token_endpoint (str): URL to POST to for exchanging an API token for
19+
a session token.
20+
api_token (str): API token for the user.
21+
22+
Raises:
23+
PureError: If there was any issue retrieving an session token.
24+
"""
25+
self._token_endpoint = token_endpoint
26+
self._api_token = api_token
27+
self._verify_ssl = verify_ssl
28+
self._session_token = None
29+
self.get_session_token(refresh=True)
30+
31+
def get_session_token(self, refresh=False):
32+
"""
33+
Get the last used session token.
34+
35+
Args:
36+
refresh (bool, optional): Whether to retrieve a new session token.
37+
Defaults to False.
38+
39+
Returns:
40+
str
41+
42+
Raises:
43+
PureError: If there was an error retrieving an session token.
44+
"""
45+
if refresh or self._session_token is None:
46+
return self._request_session_token()
47+
return self._session_token
48+
49+
def _request_session_token(self):
50+
"""
51+
Retrieve an session token from the API token exchange endpoint.
52+
53+
Returns:
54+
str
55+
56+
Raises:
57+
PureError: If there was an error retrieving an session token.
58+
"""
59+
post_headers = {Headers.api_token: self._api_token}
60+
response = requests.post(self._token_endpoint, headers=post_headers, verify=self._verify_ssl)
61+
if response.status_code == requests.codes.ok:
62+
return str(response.headers[Headers.x_auth_token])
63+
else:
64+
raise PureError("Failed to retrieve session token with error: " + response.text)

pypureclient/pure1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from .models.policy_rule import PolicyRule
3333
from .models.replica_link import ReplicaLink
3434
from .models.smb import Smb
35+
from .models.support_contract import SupportContract
3536
from .models.tag import Tag
3637
from .models.tag_put import TagPut
3738
from .models.target import Target
@@ -71,6 +72,7 @@ def add_properties(model):
7172
PolicyRule,
7273
ReplicaLink,
7374
Smb,
75+
SupportContract,
7476
Tag,
7577
TagPut,
7678
Target,

pypureclient/pure1/api/arrays_api.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,138 @@ def api10_arrays_get_with_http_info(self, **kwargs):
160160
_request_timeout=params.get('_request_timeout'),
161161
collection_formats=collection_formats)
162162

163+
def api10_arrays_support_contracts_get(self, **kwargs):
164+
"""Get array support contracts
165+
166+
Retrieves the support contracts associated with arrays.
167+
This method makes a synchronous HTTP request by default. To make an
168+
asynchronous HTTP request, please pass async_req=True
169+
>>> thread = api.api10_arrays_support_contracts_get(async_req=True)
170+
>>> result = thread.get()
171+
172+
:param async_req bool
173+
:param str authorization: Access token (in JWT format) required to use any API endpoint (except `/oauth2`)
174+
:param str x_request_id: Supplied by client during request or generated by server.
175+
:param str continuation_token: An opaque token used to iterate over a collection. The token to use on the next request is returned in the continuation_token field of the result. Single quotes are required around all strings.
176+
:param str filter: Exclude resources that don't match the specified criteria. Single quotes are required around all strings inside the filters.
177+
:param int limit: Limit the size of the response to the specified number of resources. A limit of 0 can be used to get the number of resources without getting all of the resources. It will be returned in the total_item_count field. If a client asks for a page size larger than the maximum number, the request is still valid. In that case the server just returns the maximum number of items, disregarding the client's page size request. If not specified, defaults to 1000.
178+
:param int offset: The offset of the first resource to return from a collection.
179+
:param list[str] resource_ids: A comma-separated list of resource IDs. If there is not at least one resource that matches each of the elements of names, an error is returned. Single or double quotations are required around all strings.
180+
:param list[str] resource_names: A comma-separated list of resource names. If there is not at least one resource that matches each of the elements of names, an error is returned. Single quotes are required around all strings.
181+
:param list[str] sort: Sort the response by the specified fields (in descending order if '-' is appended to the field name). If you provide a sort you will not get a continuation token in the response.
182+
:return: SupportContractGetResponse
183+
If the method is called asynchronously,
184+
returns the request thread.
185+
"""
186+
kwargs['_return_http_data_only'] = True
187+
if kwargs.get('async_req'):
188+
return self.api10_arrays_support_contracts_get_with_http_info(**kwargs)
189+
else:
190+
(data) = self.api10_arrays_support_contracts_get_with_http_info(**kwargs)
191+
return data
192+
193+
def api10_arrays_support_contracts_get_with_http_info(self, **kwargs):
194+
"""Get array support contracts
195+
196+
Retrieves the support contracts associated with arrays.
197+
This method makes a synchronous HTTP request by default. To make an
198+
asynchronous HTTP request, please pass async_req=True
199+
>>> thread = api.api10_arrays_support_contracts_get_with_http_info(async_req=True)
200+
>>> result = thread.get()
201+
202+
:param async_req bool
203+
:param str authorization: Access token (in JWT format) required to use any API endpoint (except `/oauth2`)
204+
:param str x_request_id: Supplied by client during request or generated by server.
205+
:param str continuation_token: An opaque token used to iterate over a collection. The token to use on the next request is returned in the continuation_token field of the result. Single quotes are required around all strings.
206+
:param str filter: Exclude resources that don't match the specified criteria. Single quotes are required around all strings inside the filters.
207+
:param int limit: Limit the size of the response to the specified number of resources. A limit of 0 can be used to get the number of resources without getting all of the resources. It will be returned in the total_item_count field. If a client asks for a page size larger than the maximum number, the request is still valid. In that case the server just returns the maximum number of items, disregarding the client's page size request. If not specified, defaults to 1000.
208+
:param int offset: The offset of the first resource to return from a collection.
209+
:param list[str] resource_ids: A comma-separated list of resource IDs. If there is not at least one resource that matches each of the elements of names, an error is returned. Single or double quotations are required around all strings.
210+
:param list[str] resource_names: A comma-separated list of resource names. If there is not at least one resource that matches each of the elements of names, an error is returned. Single quotes are required around all strings.
211+
:param list[str] sort: Sort the response by the specified fields (in descending order if '-' is appended to the field name). If you provide a sort you will not get a continuation token in the response.
212+
:return: SupportContractGetResponse
213+
If the method is called asynchronously,
214+
returns the request thread.
215+
"""
216+
217+
all_params = ['authorization', 'x_request_id', 'continuation_token', 'filter', 'limit', 'offset', 'resource_ids', 'resource_names', 'sort']
218+
all_params.append('async_req')
219+
all_params.append('_return_http_data_only')
220+
all_params.append('_preload_content')
221+
all_params.append('_request_timeout')
222+
223+
params = locals()
224+
for key, val in six.iteritems(params['kwargs']):
225+
if key not in all_params:
226+
raise TypeError(
227+
"Got an unexpected keyword argument '%s'"
228+
" to method api10_arrays_support_contracts_get" % key
229+
)
230+
params[key] = val
231+
del params['kwargs']
232+
233+
if 'offset' in params and params['offset'] < 0:
234+
raise ValueError("Invalid value for parameter `offset` when calling `api10_arrays_support_contracts_get`, must be a value greater than or equal to `0`")
235+
collection_formats = {}
236+
237+
path_params = {}
238+
239+
query_params = []
240+
if 'continuation_token' in params:
241+
query_params.append(('continuation_token', params['continuation_token']))
242+
if 'filter' in params:
243+
query_params.append(('filter', params['filter']))
244+
if 'limit' in params:
245+
query_params.append(('limit', params['limit']))
246+
if 'offset' in params:
247+
query_params.append(('offset', params['offset']))
248+
if 'resource_ids' in params:
249+
query_params.append(('resource_ids', params['resource_ids']))
250+
collection_formats['resource_ids'] = 'csv'
251+
if 'resource_names' in params:
252+
query_params.append(('resource_names', params['resource_names']))
253+
collection_formats['resource_names'] = 'csv'
254+
if 'sort' in params:
255+
query_params.append(('sort', params['sort']))
256+
collection_formats['sort'] = 'csv'
257+
258+
header_params = {}
259+
if 'authorization' in params:
260+
header_params['Authorization'] = params['authorization']
261+
if 'x_request_id' in params:
262+
header_params['X-Request-ID'] = params['x_request_id']
263+
264+
form_params = []
265+
local_var_files = {}
266+
267+
body_params = None
268+
# HTTP header `Accept`
269+
header_params['Accept'] = self.api_client.select_header_accept(
270+
['application/json'])
271+
272+
# HTTP header `Content-Type`
273+
header_params['Content-Type'] = self.api_client.select_header_content_type(
274+
['application/json'])
275+
276+
# Authentication setting
277+
auth_settings = ['AuthorizationHeader']
278+
279+
return self.api_client.call_api(
280+
'/api/1.0/arrays/support-contracts', 'GET',
281+
path_params,
282+
query_params,
283+
header_params,
284+
body=body_params,
285+
post_params=form_params,
286+
files=local_var_files,
287+
response_type='SupportContractGetResponse',
288+
auth_settings=auth_settings,
289+
async_req=params.get('async_req'),
290+
_return_http_data_only=params.get('_return_http_data_only'),
291+
_preload_content=params.get('_preload_content', True),
292+
_request_timeout=params.get('_request_timeout'),
293+
collection_formats=collection_formats)
294+
163295
def api10_arrays_tags_batch_put(self, tag, **kwargs):
164296
"""Create or update array tags
165297

pypureclient/pure1/client.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Client(object):
3131
TIMEOUT_KEY = 'timeout'
3232
TIMEOUT_DEFAULT = 15.0
3333
# Format: client/client_version/endpoint/endpoint_version/system/release
34-
USER_AGENT = ('pypureclient/1.3.0/Pure1/1.0/{sys}/{rel}'
34+
USER_AGENT = ('pypureclient/1.4.0/Pure1/1.0/{sys}/{rel}'
3535
.format(sys=platform.system(), rel=platform.release()))
3636

3737
def __init__(self, **kwargs):
@@ -215,6 +215,52 @@ def get_arrays(self, references=None, **kwargs):
215215
_process_kwargs(kwargs, list_params, quoted_params)
216216
return self._call_api(endpoint, kwargs)
217217

218+
def get_arrays_support_contracts(self, resources=None, **kwargs):
219+
"""
220+
Retrieves the support contracts associated with arrays.
221+
222+
Args:
223+
resources (list[FixedReference], optional):
224+
A list of resources to query for. Overrides resource_ids and resource_names keyword arguments.
225+
226+
Keyword args:
227+
x_request_id (str, optional):
228+
A header to provide to track the API call. Generated by the server if not
229+
provided.
230+
continuation_token (str, optional):
231+
An opaque token to iterate over a collection of resources.
232+
filter (Filter, optional):
233+
A filter to include only resources that match the specified criteria.
234+
limit (int, optional):
235+
Limit the number of resources in the response. If not specified, defaults to
236+
1000.
237+
offset (int, optional):
238+
The offset of the first resource to return from a collection.
239+
resource_ids (list[str], optional):
240+
A list of resource IDs. If there is not at least one resource that matches each
241+
of the elements of names, an error is returned.
242+
resource_names (list[str], optional):
243+
A list of resource names. If there is not at least one resource that matches
244+
each of the elements of names, an error is returned.
245+
sort (list[Property], optional):
246+
Sort the response by the specified Properties. Can also be a single element.
247+
248+
Returns:
249+
ValidResponse: If the call was successful.
250+
ErrorResponse: If the call was not successful.
251+
252+
Raises:
253+
PureError: If calling the API fails.
254+
ValueError: If a parameter is of an invalid type.
255+
TypeError: If invalid or missing parameters are used.
256+
"""
257+
endpoint = self._arrays_api.api10_arrays_support_contracts_get_with_http_info
258+
_process_references(resources, ['resource_ids', 'resource_names'], kwargs)
259+
list_params = ['resource_ids', 'resource_names', 'sort']
260+
quoted_params = ['continuation_token', 'resource_ids', 'resource_names']
261+
_process_kwargs(kwargs, list_params, quoted_params)
262+
return self._call_api(endpoint, kwargs)
263+
218264
def put_arrays_tags(self, resources=None, **kwargs):
219265
"""
220266
Creates or updates array tags contextual to Pure1 only.

pypureclient/pure1/models/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from .network_interface_get_response import NetworkInterfaceGetResponse
5151
from .network_interface_response import NetworkInterfaceResponse
5252
from .nfs import Nfs
53+
from .oauth_token_response import OauthTokenResponse
5354
from .object_store_account import ObjectStoreAccount
5455
from .object_store_account_get_response import ObjectStoreAccountGetResponse
5556
from .object_store_account_response import ObjectStoreAccountResponse
@@ -70,6 +71,9 @@
7071
from .resource_no_name import ResourceNoName
7172
from .resource_with_location import ResourceWithLocation
7273
from .smb import Smb
74+
from .support_contract import SupportContract
75+
from .support_contract_get_response import SupportContractGetResponse
76+
from .support_contract_response import SupportContractResponse
7377
from .tag import Tag
7478
from .tag_get_response import TagGetResponse
7579
from .tag_put import TagPut

0 commit comments

Comments
 (0)