Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions fmcapi/api_objects/deployment_services/deployabledevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class DeployableDevices(
:return: List of devices needing updates.
"""

URL_SUFFIX = "/deployment/deployabledevices?expanded=true"
URL_SUFFIX = "/deployment/deployabledevices"
PENDING_CHANGES_SUFFIX = "/deployment/deployabledevices/{containerUUID}/pendingchanges"

def __init__(self, fmc):
"""
Expand All @@ -29,27 +30,36 @@ def __init__(self, fmc):
f"Waiting {self.fmc.wait_time} seconds to allow the FMC to update the list of deployable devices."
)
time.sleep(self.fmc.wait_time)
self.URL = f"{self.fmc.configuration_url}{self.URL_SUFFIX}"
self.URL = f"{self.fmc.configuration_url}{self.URL_SUFFIX}?expanded=true"

def get(self):
def get(self, containerUUID=None):
"""
Use GET API call to query FMC for a list of devices that need configuration updates pushed to them.
Use GET API call to query FMC for a list of devices that need configuration updates pushed to them,
or for pending changes for a specific device/container.

:return: (list) uuids
:param containerUUID (str, optional): UUID of the device/container for pending changes endpoint.
:return: (list or dict) uuids or pending changes
"""
logging.debug("GET method for API for DeployableDevices.")
logging.info("Getting a list of deployable devices.")
response = self.fmc.send_to_api(method="get", url=self.URL)
# Now to parse the response list to get the UUIDs of each device.
if "items" not in response:
return
uuids = []
for item in response["items"]:
if not item["canBeDeployed"]:
pass
else:
uuids.append(item)
return uuids
if containerUUID:
url = f"{self.fmc.configuration_url}{self.PENDING_CHANGES_SUFFIX.format(containerUUID=containerUUID)}?expanded=true"
logging.debug(f"GET method for API for DeployableDevices pending changes: {url}")
logging.info(f"Getting pending changes for deployable device {containerUUID}.")
response = self.fmc.send_to_api(method="get", url=url)
return response
else:
logging.debug("GET method for API for DeployableDevices.")
logging.info("Getting a list of deployable devices.")
response = self.fmc.send_to_api(method="get", url=self.URL)
# Now to parse the response list to get the UUIDs of each device.
if "items" not in response:
return
uuids = []
for item in response["items"]:
if not item["canBeDeployed"]:
pass
else:
uuids.append(item)
return uuids

def post(self):
"""POST method for API for DeployableDevices not supported."""
Expand Down
36 changes: 35 additions & 1 deletion unit_tests/deployable_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,41 @@


def test__deployable_devices(fmc):
"""
Test DeployableDevices() class with actual FMC connection.

Tests:
- Getting list of deployable devices
- Getting pending changes for a specific device (if any deployable devices exist)
- Verifying unsupported methods
"""
logging.info("Testing DeployableDevices() class.")

# Initialize and get list of deployable devices
tmp = fmcapi.DeployableDevices(fmc=fmc)
logging.info(tmp.get())
deployable_devices = tmp.get()

if deployable_devices:
logging.info(f"Found {len(deployable_devices)} deployable device(s):")
for device in deployable_devices:
logging.info(f" - {device.get('name', 'Unknown')} (ID: {device.get('id', 'Unknown')})")

# Test getting pending changes for the first deployable device
first_device_id = deployable_devices[0].get('id')
if first_device_id:
logging.info(f"Getting pending changes for device: {first_device_id}")
pending_changes = tmp.get(containerUUID=first_device_id)
if pending_changes:
logging.info("Pending changes retrieved successfully.")
else:
logging.info("No pending changes found for this device.")
else:
logging.info("No deployable devices found.")

# Test unsupported methods
logging.info("Testing unsupported methods (post, put, delete):")
tmp.post()
tmp.put()
tmp.delete()

logging.info("Testing DeployableDevices() method done.\n")