Skip to content

Commit

Permalink
added support for arrays/support_contracts endpoint for Pure1 client
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Hua committed Apr 6, 2020
1 parent b5a23f5 commit 5e4970b
Show file tree
Hide file tree
Showing 13 changed files with 753 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A log of changes by version and date.
======= ========== =====
Version Date Notes
======= ========== =====
1.4.0 03/23/2020 Added support for Pure1 arrays/support-contracts endpoint
1.3.0 03/11/2020 Added support for Pure1 replication endpoints
1.2.0 12/23/2019 Added FlashArray 2.1 client
1.1.2 11/20/2019 Bug fix for FlashArray 2.0 client
Expand Down
32 changes: 32 additions & 0 deletions docs/source/pypureclient.pure1.models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ pypureclient.pure1.models.nfs module
:undoc-members:
:show-inheritance:

pypureclient.pure1.models.oauth\_token\_response module
-------------------------------------------------------

.. automodule:: pypureclient.pure1.models.oauth_token_response
:members:
:undoc-members:
:show-inheritance:

pypureclient.pure1.models.object\_store\_account module
-------------------------------------------------------

Expand Down Expand Up @@ -540,6 +548,30 @@ pypureclient.pure1.models.smb module
:undoc-members:
:show-inheritance:

pypureclient.pure1.models.support\_contract module
--------------------------------------------------

.. automodule:: pypureclient.pure1.models.support_contract
:members:
:undoc-members:
:show-inheritance:

pypureclient.pure1.models.support\_contract\_get\_response module
-----------------------------------------------------------------

.. automodule:: pypureclient.pure1.models.support_contract_get_response
:members:
:undoc-members:
:show-inheritance:

pypureclient.pure1.models.support\_contract\_response module
------------------------------------------------------------

.. automodule:: pypureclient.pure1.models.support_contract_response
:members:
:undoc-members:
:show-inheritance:

pypureclient.pure1.models.tag module
------------------------------------

Expand Down
8 changes: 8 additions & 0 deletions docs/source/pypureclient.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ Subpackages
Submodules
----------

pypureclient.api\_token\_manager module
---------------------------------------

.. automodule:: pypureclient.api_token_manager
:members:
:undoc-members:
:show-inheritance:

pypureclient.exceptions module
------------------------------

Expand Down
64 changes: 64 additions & 0 deletions pypureclient/api_token_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import requests

from .exceptions import PureError
from .keywords import Headers

class APITokenManager(object):
"""
A APITokenManager is to handle api token-based authentication for REST 2.X API
calls internally.
A valid session token is stored in memory.
"""

def __init__(self, token_endpoint, api_token, verify_ssl=True):
"""
Initialize a APITokenManager. Should be treated as a static object.
Args:
token_endpoint (str): URL to POST to for exchanging an API token for
a session token.
api_token (str): API token for the user.
Raises:
PureError: If there was any issue retrieving an session token.
"""
self._token_endpoint = token_endpoint
self._api_token = api_token
self._verify_ssl = verify_ssl
self._session_token = None
self.get_session_token(refresh=True)

def get_session_token(self, refresh=False):
"""
Get the last used session token.
Args:
refresh (bool, optional): Whether to retrieve a new session token.
Defaults to False.
Returns:
str
Raises:
PureError: If there was an error retrieving an session token.
"""
if refresh or self._session_token is None:
return self._request_session_token()
return self._session_token

def _request_session_token(self):
"""
Retrieve an session token from the API token exchange endpoint.
Returns:
str
Raises:
PureError: If there was an error retrieving an session token.
"""
post_headers = {Headers.api_token: self._api_token}
response = requests.post(self._token_endpoint, headers=post_headers, verify=self._verify_ssl)
if response.status_code == requests.codes.ok:
return str(response.headers[Headers.x_auth_token])
else:
raise PureError("Failed to retrieve session token with error: " + response.text)
2 changes: 2 additions & 0 deletions pypureclient/pure1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from .models.policy_rule import PolicyRule
from .models.replica_link import ReplicaLink
from .models.smb import Smb
from .models.support_contract import SupportContract
from .models.tag import Tag
from .models.tag_put import TagPut
from .models.target import Target
Expand Down Expand Up @@ -71,6 +72,7 @@ def add_properties(model):
PolicyRule,
ReplicaLink,
Smb,
SupportContract,
Tag,
TagPut,
Target,
Expand Down
132 changes: 132 additions & 0 deletions pypureclient/pure1/api/arrays_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,138 @@ def api10_arrays_get_with_http_info(self, **kwargs):
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)

def api10_arrays_support_contracts_get(self, **kwargs):
"""Get array support contracts
Retrieves the support contracts associated with arrays.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.api10_arrays_support_contracts_get(async_req=True)
>>> result = thread.get()
:param async_req bool
:param str authorization: Access token (in JWT format) required to use any API endpoint (except `/oauth2`)
:param str x_request_id: Supplied by client during request or generated by server.
: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.
:param str filter: Exclude resources that don't match the specified criteria. Single quotes are required around all strings inside the filters.
: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.
:param int offset: The offset of the first resource to return from a collection.
: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.
: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.
: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.
:return: SupportContractGetResponse
If the method is called asynchronously,
returns the request thread.
"""
kwargs['_return_http_data_only'] = True
if kwargs.get('async_req'):
return self.api10_arrays_support_contracts_get_with_http_info(**kwargs)
else:
(data) = self.api10_arrays_support_contracts_get_with_http_info(**kwargs)
return data

def api10_arrays_support_contracts_get_with_http_info(self, **kwargs):
"""Get array support contracts
Retrieves the support contracts associated with arrays.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.api10_arrays_support_contracts_get_with_http_info(async_req=True)
>>> result = thread.get()
:param async_req bool
:param str authorization: Access token (in JWT format) required to use any API endpoint (except `/oauth2`)
:param str x_request_id: Supplied by client during request or generated by server.
: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.
:param str filter: Exclude resources that don't match the specified criteria. Single quotes are required around all strings inside the filters.
: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.
:param int offset: The offset of the first resource to return from a collection.
: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.
: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.
: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.
:return: SupportContractGetResponse
If the method is called asynchronously,
returns the request thread.
"""

all_params = ['authorization', 'x_request_id', 'continuation_token', 'filter', 'limit', 'offset', 'resource_ids', 'resource_names', 'sort']
all_params.append('async_req')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')

params = locals()
for key, val in six.iteritems(params['kwargs']):
if key not in all_params:
raise TypeError(
"Got an unexpected keyword argument '%s'"
" to method api10_arrays_support_contracts_get" % key
)
params[key] = val
del params['kwargs']

if 'offset' in params and params['offset'] < 0:
raise ValueError("Invalid value for parameter `offset` when calling `api10_arrays_support_contracts_get`, must be a value greater than or equal to `0`")
collection_formats = {}

path_params = {}

query_params = []
if 'continuation_token' in params:
query_params.append(('continuation_token', params['continuation_token']))
if 'filter' in params:
query_params.append(('filter', params['filter']))
if 'limit' in params:
query_params.append(('limit', params['limit']))
if 'offset' in params:
query_params.append(('offset', params['offset']))
if 'resource_ids' in params:
query_params.append(('resource_ids', params['resource_ids']))
collection_formats['resource_ids'] = 'csv'
if 'resource_names' in params:
query_params.append(('resource_names', params['resource_names']))
collection_formats['resource_names'] = 'csv'
if 'sort' in params:
query_params.append(('sort', params['sort']))
collection_formats['sort'] = 'csv'

header_params = {}
if 'authorization' in params:
header_params['Authorization'] = params['authorization']
if 'x_request_id' in params:
header_params['X-Request-ID'] = params['x_request_id']

form_params = []
local_var_files = {}

body_params = None
# HTTP header `Accept`
header_params['Accept'] = self.api_client.select_header_accept(
['application/json'])

# HTTP header `Content-Type`
header_params['Content-Type'] = self.api_client.select_header_content_type(
['application/json'])

# Authentication setting
auth_settings = ['AuthorizationHeader']

return self.api_client.call_api(
'/api/1.0/arrays/support-contracts', 'GET',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='SupportContractGetResponse',
auth_settings=auth_settings,
async_req=params.get('async_req'),
_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)

def api10_arrays_tags_batch_put(self, tag, **kwargs):
"""Create or update array tags
Expand Down
48 changes: 47 additions & 1 deletion pypureclient/pure1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Client(object):
TIMEOUT_KEY = 'timeout'
TIMEOUT_DEFAULT = 15.0
# Format: client/client_version/endpoint/endpoint_version/system/release
USER_AGENT = ('pypureclient/1.3.0/Pure1/1.0/{sys}/{rel}'
USER_AGENT = ('pypureclient/1.4.0/Pure1/1.0/{sys}/{rel}'
.format(sys=platform.system(), rel=platform.release()))

def __init__(self, **kwargs):
Expand Down Expand Up @@ -215,6 +215,52 @@ def get_arrays(self, references=None, **kwargs):
_process_kwargs(kwargs, list_params, quoted_params)
return self._call_api(endpoint, kwargs)

def get_arrays_support_contracts(self, resources=None, **kwargs):
"""
Retrieves the support contracts associated with arrays.
Args:
resources (list[FixedReference], optional):
A list of resources to query for. Overrides resource_ids and resource_names keyword arguments.
Keyword args:
x_request_id (str, optional):
A header to provide to track the API call. Generated by the server if not
provided.
continuation_token (str, optional):
An opaque token to iterate over a collection of resources.
filter (Filter, optional):
A filter to include only resources that match the specified criteria.
limit (int, optional):
Limit the number of resources in the response. If not specified, defaults to
1000.
offset (int, optional):
The offset of the first resource to return from a collection.
resource_ids (list[str], optional):
A list of resource IDs. If there is not at least one resource that matches each
of the elements of names, an error is returned.
resource_names (list[str], optional):
A list of resource names. If there is not at least one resource that matches
each of the elements of names, an error is returned.
sort (list[Property], optional):
Sort the response by the specified Properties. Can also be a single element.
Returns:
ValidResponse: If the call was successful.
ErrorResponse: If the call was not successful.
Raises:
PureError: If calling the API fails.
ValueError: If a parameter is of an invalid type.
TypeError: If invalid or missing parameters are used.
"""
endpoint = self._arrays_api.api10_arrays_support_contracts_get_with_http_info
_process_references(resources, ['resource_ids', 'resource_names'], kwargs)
list_params = ['resource_ids', 'resource_names', 'sort']
quoted_params = ['continuation_token', 'resource_ids', 'resource_names']
_process_kwargs(kwargs, list_params, quoted_params)
return self._call_api(endpoint, kwargs)

def put_arrays_tags(self, resources=None, **kwargs):
"""
Creates or updates array tags contextual to Pure1 only.
Expand Down
4 changes: 4 additions & 0 deletions pypureclient/pure1/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from .network_interface_get_response import NetworkInterfaceGetResponse
from .network_interface_response import NetworkInterfaceResponse
from .nfs import Nfs
from .oauth_token_response import OauthTokenResponse
from .object_store_account import ObjectStoreAccount
from .object_store_account_get_response import ObjectStoreAccountGetResponse
from .object_store_account_response import ObjectStoreAccountResponse
Expand All @@ -70,6 +71,9 @@
from .resource_no_name import ResourceNoName
from .resource_with_location import ResourceWithLocation
from .smb import Smb
from .support_contract import SupportContract
from .support_contract_get_response import SupportContractGetResponse
from .support_contract_response import SupportContractResponse
from .tag import Tag
from .tag_get_response import TagGetResponse
from .tag_put import TagPut
Expand Down
Loading

0 comments on commit 5e4970b

Please sign in to comment.