Skip to content

Commit

Permalink
Merge pull request #38 from KarthikSKumar98/v1.3-release-fixes
Browse files Browse the repository at this point in the history
V1.3 release fixes
  • Loading branch information
KarthikSKumar98 authored Oct 23, 2023
2 parents 1e8c927 + b27ac6b commit 6a2c2b7
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 17 deletions.
28 changes: 24 additions & 4 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
requests
PyYAML
urllib3
certifi
alabaster==0.7.13
Babel==2.13.0
certifi==2023.7.22
charset-normalizer==3.3.1
docutils==0.18.1
idna==3.4
imagesize==1.4.1
Jinja2==3.1.2
MarkupSafe==2.1.3
packaging==23.2
Pygments==2.16.1
PyYAML==6.0.1
requests==2.31.0
snowballstemmer==2.2.0
Sphinx==7.2.6
sphinx-rtd-theme==1.3.0
sphinxcontrib-applehelp==1.0.7
sphinxcontrib-devhelp==1.0.5
sphinxcontrib-htmlhelp==2.0.4
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.6
sphinxcontrib-serializinghtml==1.1.9
urllib3==2.0.7
26 changes: 17 additions & 9 deletions docs/source/pycentral.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ Indices and tables
pycentral package
=================

Subpackages
-----------

.. toctree::
:maxdepth: 4

pycentral.workflows

pycentral.audit\_logs module
----------------------------

Expand Down Expand Up @@ -80,6 +72,14 @@ pycentral.monitoring module
:undoc-members:
:show-inheritance:

pycentral.msp module
---------------------------

.. automodule:: pycentral.msp
:members:
:undoc-members:
:show-inheritance:

pycentral.rapids module
-----------------------

Expand Down Expand Up @@ -118,4 +118,12 @@ pycentral.visualrf module
.. automodule:: pycentral.visualrf
:members:
:undoc-members:
:show-inheritance:
:show-inheritance:

Subpackages
-----------

.. toctree::
:maxdepth: 4

pycentral.workflows
31 changes: 28 additions & 3 deletions pycentral/msp.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def __create_customer_body__(self, conn, customer_details):
"countries/country codes"
logger.error(log_message)
return

customer_JSON = {
"customer_name": customer_details['customer_name'],
"description": "",
Expand Down Expand Up @@ -243,6 +244,7 @@ def update_customer(
logger.error(
"Attribute Error. Pass either customer_id or customer_name")
return

elif customer_id is None and customer_name:
customer_id = self.get_customer_id(
conn, customer_name=customer_name)
Expand All @@ -251,6 +253,7 @@ def update_customer(
'valid customer name'
logger.error(log_message)
return

if self.__validate_customer_attributes__(customer_details):
customer_apiData = self.__create_customer_body__(conn, customer_details)
apiPath = f'{urls.MSP["V2_CUSTOMER"]}/{customer_id}'
Expand Down Expand Up @@ -316,12 +319,15 @@ def get_customer_details(self, conn, customer_id=None, customer_name=None):
logger.error(
"Attribute Error. Pass either customer_id or customer_name")
return None

elif customer_id is None and customer_name:
customer_id = self.get_customer_id(
conn, customer_name=customer_name)
if customer_id is None:
logger.error(
'Unable to get customer_id. Please provide a valid customer name')
return

apiPath = f'{urls.MSP["V1_CUSTOMER"]}/{customer_id}'
resp = conn.command(apiMethod="GET", apiPath=apiPath)
if (resp["code"] == 200):
Expand Down Expand Up @@ -349,6 +355,7 @@ def get_customer_id(self, conn, customer_name=None):
'passed. Please provide a valid customer name'
logger.error(log_message)
return None

apiPath = urls.MSP["V1_CUSTOMER"]
apiParams = {
"customer_name": customer_name
Expand Down Expand Up @@ -480,6 +487,7 @@ def get_customer_users(
log_message = f'Unable to get customer_id of {customer_name}.' \
'Please provide a valid customer name'
logger.error(log_message)
return

apiPath = urls.MSP["USERS"].split('/')
apiPath.insert(-1, customer_id)
Expand Down Expand Up @@ -569,12 +577,14 @@ def get_customer_devices_and_subscriptions(
logger.error(
"Attribute Error. Provide either customer_id or customer_name")
return

elif customer_id is None and customer_name:
customer_id = self.get_customer_id(
conn, customer_name=customer_name)
if customer_id is None:
logger.error(
'Unable to get customer_id. Please provide a valid customer name')
return

apiPath = f'{urls.MSP["V1_CUSTOMER"]}/{customer_id}/devices'
apiParams = {
Expand Down Expand Up @@ -625,18 +635,21 @@ def assign_devices_to_customers(
log_message = 'Attribute Error. Please provide list of devices that'\
'should be moved to the customer'
logger.error(log_message)
return

if customer_id is None and customer_name is None:
logger.error(
"Attribute Error. Provide either customer_id or customer_name")
return

elif customer_id is None and customer_name:
customer_id = self.get_customer_id(
conn, customer_name=customer_name)
if customer_id is None:
log_message = 'Unable to get customer_id. Please provide a'\
'valid customer name'
logger.error(log_message)
return

apiPath = f'{urls.MSP["V1_CUSTOMER"]}/{customer_id}/devices'
apiData = {
Expand Down Expand Up @@ -678,6 +691,7 @@ def unassign_devices_from_customers(self, conn, devices, msp_id=None):
log_message = 'Attribute Error. Please provide list of devices that' \
' should be moved from the customer to the MSP device inventory.'
logger.error(log_message)
return

if msp_id is None:
msp_id = self.get_msp_id(conn)
Expand Down Expand Up @@ -726,13 +740,15 @@ def unassign_all_customer_device(
logger.error(
"Attribute Error. Provide either customer_id or customer_name")
return

elif customer_id is None and customer_name:
customer_id = self.get_customer_id(
conn, customer_name=customer_name)
if customer_id is None:
log_message = 'Unable to get customer_id. Please provide a ' \
'valid customer name'
logger.error(log_message)
return

apiSubPath = "/".join(urls.MSP["V2_CUSTOMER"].split("/")[:-1])
apiPath = f'{apiSubPath}/{customer_id}/devices'
Expand Down Expand Up @@ -816,6 +832,8 @@ def get_msp_all_devices_and_subscriptions(self, conn, customer_name=None):
log_message = 'Unable to get customer_id. ' \
'Please provide a valid customer name'
logger.error(log_message)
return

offset = 0
limit = 50
device_list = []
Expand All @@ -826,11 +844,16 @@ def get_msp_all_devices_and_subscriptions(self, conn, customer_name=None):
else:
resp = self.get_msp_devices_and_subscriptions(
conn, offset=offset, limit=limit)
if 'devices' in resp:
resp_devices = resp['devices']
if resp['code'] == 200 and resp['msg']['status'] == 'success' \
and 'deviceList' in resp['msg']:
resp_message = resp['msg']['deviceList']
resp_devices = resp_message['devices']
device_list.extend(resp_devices)
if (len(device_list) == resp['total_devices']):
if (len(device_list) == resp_message['total_devices']):
break
else:
logger.error(resp)
return
offset += limit
return device_list

Expand All @@ -853,6 +876,8 @@ def get_customers_per_group(self, conn, group_name, offset=0, limit=10):

if group_name is None:
logger.error("Attribute Error. Provide a valid group name.")
return

apiPath = f'{urls.MSP["GROUPS"]}/{group_name}/customers'
apiParams = {
"offset": offset,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="pycentral",
version="1.2.1",
version="1.3",
author="aruba-automation",
author_email="[email protected]",
description="Aruba Central Python Package",
Expand Down

0 comments on commit 6a2c2b7

Please sign in to comment.