Utilities¶
A few general utilites for working with the API and it’s objects, such as importing data from CSV files.
-
firepyer.utils.
read_objects_csv
(filename)¶ Takes a CSV with headings and converts each row to a dict. Useful for populating create_network()
- Parameters
filename (str) – Full filename of the CSV
- Returns
A list of dicts, each dict is a row from the CSV, with the heading as key and column as value
- Return type
list
>>> utils.read_objects_csv('network_objects.csv') [{'description': 'HOST1-NIC1', 'name': 'Host1-NIC1', 'type': 'host', 'value': '10.0.1.1'}, {'description': 'HOST1-NIC2', 'name': 'Host1-NIC2', 'type': 'host', 'value': '10.0.1.2'}]
1 2 3 | name,value,type,description
Host1-NIC1,10.0.1.1,host,HOST1-NIC1
Host1-NIC2,10.0.1.2,host,HOST1-NIC2
|
-
firepyer.utils.
read_groups_csv
(filename)¶ Takes a CSV with headings in format: name,objects,description and converts each group to a dict. CSV file must be in hierarchical order if nested groups are to be created. Useful for populating create_group()
- Parameters
filename (str) – Full filename of the CSV
- Returns
A list of dicts, each dict representing a group, with objects in the same group stored as list under the ‘objects’ key
- Return type
list
>>> utils.read_groups_csv('network_groups.csv') [{'description': 'Host1', 'name': 'GROUP-HOST1', 'objects': ['Host1-NIC1', 'Host1-NIC2']}, {'description': 'Host2', 'name': 'GROUP-HOST2', 'objects': ['Host2-NIC1', 'Host2-NIC2']}, {'description': 'All hosts', 'name': 'GROUP-ALL-HOSTS', 'objects': ['GROUP-HOST1', 'GROUP-HOST2']}]
1 2 3 4 5 6 7 | name,objects,description
GROUP-HOST1,Host1-NIC1,Host1
GROUP-HOST1,Host1-NIC2,Host1
GROUP-HOST2,Host2-NIC1,Host2
GROUP-HOST2,Host2-NIC2,Host2
GROUP-ALL-HOSTS,GROUP-HOST1,All hosts
GROUP-ALL-HOSTS,GROUP-HOST2,All hosts
|
-
firepyer.utils.
expand_merged_csv
(filename)¶ Takes a CSV that’s had merged cells (to show a group in Excel) and fills the blanks with the previous row
- Parameters
filename (str) – Full filename of the CSV
- Returns
A list of dicts, each dict is a row from the CSV, with the heading as key and column as value
- Return type
list
>>> utils.expand_merged_csv('raw_network_groups.csv') [{'description': 'Host1', 'name': 'GROUP-HOST1', 'objects': 'Host1-NIC1'}, {'description': 'Host1', 'name': 'GROUP-HOST1', 'objects': 'Host1-NIC2'}, {'description': 'Host2', 'name': 'GROUP-HOST2', 'objects': 'Host2-NIC1'}, {'description': 'Host2', 'name': 'GROUP-HOST2', 'objects': 'Host2-NIC2'}, {'description': 'All hosts', 'name': 'GROUP-ALL-HOSTS', 'objects': 'GROUP-HOST1'}, {'description': 'All hosts', 'name': 'GROUP-ALL-HOSTS', 'objects': 'GROUP-HOST2'}]
1 2 3 4 5 6 7 | name,objects,description
GROUP-HOST1,Host1-NIC1,Host1
,Host1-NIC2,
GROUP-HOST2,Host2-NIC1,Host2
,Host2-NIC2,
GROUP-ALL-HOSTS,GROUP-HOST1,All hosts
,GROUP-HOST2,
|