Batfish Commands

Here we describe the non-question related Batfish functions

Networks

pybatfish.client.session.Session.set_network(self, name: Optional[str] = None, prefix: str = 'pcp') → str

Configure the network used for analysis.

Parameters
  • name (str) – name of the network to set. If None, a name will be generated

  • prefix – prefix to prepend to auto-generated network names if name is empty

Returns

name of the configured network

Return type

str

Raises

BatfishException – if configuration fails

pybatfish.client.session.Session.list_networks(self)

List networks the session’s API key can access.

Returns

network names

Return type

list

pybatfish.client.session.Session.delete_network(self, name)

Delete network by name.

Parameters

name (str) – name of the network to delete

Snapshots

pybatfish.client.session.Session.init_snapshot(self, upload, name=None, overwrite=False, extra_args=None)

Initialize a new snapshot.

Parameters
  • upload (str) – path to the snapshot zip or directory

  • name (str) – name of the snapshot to initialize

  • overwrite (bool) – whether or not to overwrite an existing snapshot with the same name

  • extra_args (dict) – extra arguments to control snapshot processing: 1) “ignoremanagementinterfaces” (bool) – whether to shut management interfaces (default is True); 2) “parsereuse” (bool) – whether to reuse parsing work from prior snapshots when file content is identical (default is True)

Returns

name of initialized snapshot

Return type

str

pybatfish.client.session.Session.set_snapshot(self, name=None, index=None)

Set the current snapshot by name or index.

Parameters
  • name (str) – name of the snapshot to set as the current snapshot

  • index (int) – set the current snapshot to the index-th most recent snapshot

Returns

the name of the successfully set snapshot

Return type

str

pybatfish.client.session.Session.list_snapshots(self, verbose=False)

List snapshots for the current network.

Parameters

verbose (bool) – If true, return the full output of Batfish, including snapshot metadata.

Returns

snapshot names or the full JSON response containing snapshots and metadata (if verbose=True)

Return type

list

pybatfish.client.session.Session.delete_snapshot(self, name)

Delete specified snapshot from current network.

Parameters

name (str) – name of the snapshot to delete

pybatfish.client.session.Session.fork_snapshot(self, base_name, name=None, overwrite=False, deactivate_interfaces=None, deactivate_nodes=None, restore_interfaces=None, restore_nodes=None, add_files=None, extra_args=None)

Copy an existing snapshot and deactivate or reactivate specified interfaces, nodes, and links on the copy.

Parameters
  • base_name (str) – name of the snapshot to copy

  • name (str) – name of the snapshot to initialize

  • overwrite (bool) – whether or not to overwrite an existing snapshot with the same name

  • deactivate_interfaces (list[Interface]) – list of interfaces to deactivate in new snapshot

  • deactivate_nodes (list[str]) – list of names of nodes to deactivate in new snapshot

  • restore_interfaces (list[Interface]) – list of interfaces to reactivate

  • restore_nodes (list[str]) – list of names of nodes to reactivate

  • add_files (str) – path to zip file or directory containing files to add

  • extra_args (dict) – extra arguments to control snapshot processing: 1) “ignoremanagementinterfaces” (bool) – whether to shut management interfaces (default is True); 2) “parsereuse” (bool) – whether to reuse parsing work from prior snapshots when file content is identical (default is True)

Returns

name of initialized snapshot or None if the call fails

Return type

Optional[str]

Reference Library

pybatfish.client.session.Session.get_reference_library(self)

Returns the reference library for the active network.

pybatfish.client.session.Session.get_reference_book(self, name)

Returns the specified reference book for the active network.

Parameters

name (str) – name of the reference book to fetch

pybatfish.client.session.Session.put_reference_book(self, book)

Put a reference book in the active network.

If a book with the same name exists, it is overwritten.

Parameters

book (ReferenceBook) – The ReferenceBook object to add

pybatfish.client.session.Session.delete_reference_book(self, name)

Deletes the reference book with the specified name for the active network.

Parameters

name (str) – name of the reference book to delete

Diagnostics

pybatfish.client.session.Session.upload_diagnostics(self, dry_run: bool = True, netconan_config: Optional[str] = None, contact_info: Optional[str] = None, proxy: Optional[str] = None) → str

Fetch, anonymize, and optionally upload snapshot diagnostics information.

This runs a series of diagnostic questions on the current snapshot (including collecting parsing and conversion information).

The information collected is anonymized with Netconan which either anonymizes passwords and IP addresses (default) or uses the settings in the provided netconan_config.

The anonymous information is then either saved locally (if dry_run is True) or uploaded to Batfish developers (if dry_run is False). The uploaded information will be accessible only to Batfish developers and will be used to help diagnose any issues you encounter.

If contact_info is supplied (e.g. email address), Batfish developers may contact you if they have follow-up questions or to update you when the issues you encountered are resolved.

Parameters
  • dry_run (bool) – if True, upload is skipped and the anonymized files will be stored locally for review. If False, anonymized files will be uploaded to the Batfish developers

  • netconan_config (str) – path to Netconan configuration file

  • contact_info (str) – optional contact info associated with this upload

  • proxy – a proxy URL to use when uploading data.

Returns

location of anonymized files (local directory if doing dry run, otherwise upload ID)

Return type

str