FMC
This guide shows how to use the
CiscoFMC
client to interact with Cisco Firepower Management Center APIs.
from wingpy import FMCClient
fmc = FMCClient(
base_url="https://fmc.example.com", # (1)!
username="admin", # (2)!
password="password", # (3)!
verify=False,
)
- Environment variable:
- Environment variable:
- Environment variable:
The
fmc.get_all()
method fetches all the pages and items for you. It also uses concurrency under the hood to fetch the data in parallel, which can significantly speed up the process for large datasets.
devices = fmc.get_all("/api/fmc_config/v1/domain/{domainUUID}/devices/devicerecords")
for device in devices:
print(device["name"])
What you might also notice is that we just copied the URL from the FMC API documentation. The
CiscoFMC
client automatically handles the domain UUID for you, this means you can conveniently use the API endpoints as they are documented and paste them directly into your code.
host_data = {
"name": "TestHost",
"value": "192.0.2.10",
"type": "Host",
}
response = fmc.post(
"/api/fmc_config/v1/domain/{domainUUID}/object/hosts",
data=host_data,
)
path_params = {"objectId": response.json()["id"]}
We have created a host object and stored the objectId
in the path_params
variable, which we will use in subsequent requests.
Again, we want to preserve the ability to use the API endpoints as they are documented, so we can use the path_params
variable to pass the objectId
in the URL.
Imagine if you have a large number of objects, you can easily loop through them and perform operations on each one. For this example, we will update and delete the host object we just created.
update_data = {"name": "TestHostUpdated"}
response = fmc.patch(
"/api/fmc_config/v1/domain/{domainUUID}/object/hosts/{objectId}",
path_params=path_params,
data=update_data,
)
print(response.status_code)