Skip to main content

FMC REST API Client

Project description

## FMC REST CLIENT
Easy to use REST Client for Firepower Management Center REST API

### Features
* Create object for FMC REST resources and perform CRUD operations
* Maintains REST connection with FMC
* Listing for a particular resource type supports fetching all results in single go
* Easy to add support for new resources or url endpoints

### Enhancements in future
* Support for bulk operations, leveraging FMC REST API where available or support in client
* Iterator for list operation
* Get by name

## How to use

### Using REST Client
Create FMCRestClient instance
```
fmc = FMCRestClient(fmc_server_url, username, password)
# create a resource instance
host1 = Host('host1', '1.1.1.1')
# create in FMC
host1 = fmc.create(host1)
# get all Host objects
hosts = fmc.list(Host())
for host in hosts:
print(host.name)
print(host.json())
# update value for host1
host1.value = '2.2.2.2'
fmc.update(host1)
# get host1 from FMC
host1 = fmc.load(host1)
print(host1.json())
# delete host1 from FMC
fmc.remove(host1)
```
### Adding a new FMC resource class
To add a new class representing FMC REST API resource, follow the below guideline
* Class name should be singular name of the FMC REST resource or url endpoint.
* The class should extend the appropriate base classes defined in 'fmc_rest_client.core.base_resources' module.
* The member variables name should match the attribute names in json
* Complex structure or nested attributes in json can be models as dictionary or another object of a class extending BaseContainedResource class.

#### Examples <br>
##### Resource having list attribute
For Network Group object we have following json -
```
{
"id": "005056A9-0AC2-0ed3-0000-025769807771",
"name": "nog1",
"type": "NetworkGroup"
"objects": {
"type": "Range",
"id": "005056A9-0AC2-0ed3-0000-025769808881",
"name": "range1",
}
],
"literals": [
{
"type": "Network",
"value": "1.2.3.0/24"
}
]
}

```
A simple resource class for this can be like below -
```
class NetworkGroup(ObjectResource):
def __init__(self, name=None, objects=None, literals=None):
super().__init__(name)
self.objects = objects
self.literals = literals
```
Or a complex resource class can look like following -
```
class NetworkGroup(ObjectResource):
def __init__(self, name=None, objects=None, literals=None):
super().__init__(name)
if objects == None:
objects = []
super().__setattr__('objects',objects)
if literals == None:
literals = []
super().__setattr__('literals', literals)

def __setattr__(self, name, value):
if name in ['objects', 'literals']:
raise Exception("You cannot set value for attribute {}. Its a list, operate on that, "
"e.g net_grp_obj.{}.append(host1)".format(name, name))
else:
super().__setattr__(name, value)
```
##### Resource with complex structure
Refer AccessPolicy and AccessRule class examples in fmc_rest_client.resources module.
AccessPolicy uses a AccessPolicyDefaultAction for a nested structure for defaultAction field, while AccessRule
uses a dict for field sourceNetworks.



Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fmc_rest_client-0.2.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fmc_rest_client-0.2-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file fmc_rest_client-0.2.tar.gz.

File metadata

  • Download URL: fmc_rest_client-0.2.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fmc_rest_client-0.2.tar.gz
Algorithm Hash digest
SHA256 70ef7c1ba62bd9ce0c46534960931cfdea753ee5f19a3cbc03fe17e33060cdf8
MD5 f4892308898124405a5da99d55c45975
BLAKE2b-256 9a5443ddf6aed098c8e2e1c556fda6120d00cc1873dffd5d71c95282ab207af9

See more details on using hashes here.

File details

Details for the file fmc_rest_client-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fmc_rest_client-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e41f00d0776a2eace6622a0452b3b68dd232c1fe7a32a7bfa435482b8c8f3f6d
MD5 cec3f3150adc08b37e54ba0a676558b5
BLAKE2b-256 995ed4cac31e7042ff4da94a6943006cbcf2747316cf0cefc8ec13694460717e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page