Fileserv

class activelogic.Fileserv

This is the resource that gives access to the “Fileserv” on an ActiveLogic system. It provides a way to download/upload files of different types from/to an ActiveLogic system.

async Fileserv.list(cls, **kwargs)

Generic list function for all kinds of data that belongs to this resource.

Parameters:

cls – Object type that determines what kind of data to get.

Returns:

A list of given dataclass type.

Raises:

TypeError – Unknown file type

The following data can be listed from this resource:

  • FileservFileType: Lists all file types (directories) available on the system.

  • FileservFile: Lists all files of specified type available. The below is the mandatory key value argument:

    • ftype (FileservFileType or int or str): The FileservFileType or ID or name of the Fileserv type.

>>> fs.list(FileservFileType)
[FileservFileType(id=0, name='Host trigger files'), FileservFileType(id=1, name='Firewall trigger files'), ...]
>>> fs.list(FileservFile, ftype=FileservArea.SNMP_MIB)
[FileservFile(name=b'PACKETLOGIC-HW-MIB', size=607), ...]
>>> fs.list(FileservFile, ftype=6)
[FileservFile(name=b'PACKETLOGIC-HW-MIB', size=607), ...]
>>> fs.list(FileservFile, ftype='SNMP')
[FileservFile(name=b'PACKETLOGIC-HW-MIB', size=607), ...]
class activelogic.FileservArea

Defines set of constants for different areas in the file system.

Variables:
  • HOSTTRIGGER – File in the “Host trigger files” area.

  • FWTRIGGER – File in the “Firewall trigger files” area.

  • DHCP_SNOOPER – File in the “DHCP snooper files” area.

  • RADIUS_SNOOPER – File in the “RADIUS snooper files” area.

  • SIP_SNOOPER – File in the “SIP snooper files” area.

  • CUSTOM_SNOOPER – File in the “Custom snooper files” area.

  • SNMP_MIB – File in the “SNMP” files area.

  • DOCUMENTATION – File in the “Documentation” area.

  • PCAP_1 – File in the “PCAP writer files” area.

  • PCAP_2 – File in the “PCAP-2 writer files” area.

  • FIRMWARE_UPLOAD – File in the “Firmware upgrade files” area.

  • LICENSE_UPLOAD – File in the “Generic update files” area.

  • GENERIC_UPLOAD – File in the “Generic update files” area.

  • ATTRIBUTES – File in the “Attribute descriptions” file area.

  • BOOKMARKS – File in the “Bookmarks” file area.

  • VSDEFINITIONS – File in the “Virtual services definition files” file area.

  • SYSDIAGTRIGGER – File in the “System diagnostics triggers” file area.

  • SUPPORTBUNDLE – File in the “CLI provided backups” file area.

  • URLDATA – File in the “URL data files” file area.

  • CONNPROT_TRIGGER – File in the “Connection protection trigger files” file area.

  • DEBUG – File in the “System debugging data” file area.

  • FIRMWARE_CLI – File in the “CLI files” area.

  • PCAP_3 – File in the “PCAP-3 writer files” file area.

  • PCAP_4 – File in the “PCAP-4 writer files” file area.

  • PCAP_5 – File in the “PCAP-5 writer files” file area.

  • PCAP_6 – File in the “PCAP-6 writer files” file area.

  • PCAP_7 – File in the “PCAP-7 writer files” file area.

  • PCAP_8 – File in the “PCAP-8 writer files” file area.

  • TCPDUMP – File in the “CLI tcpdump files” file area.

class activelogic.FileservFileType

Object representing information about a Fileserv file type.

Parameters:
  • id (int) – The ID of the Fileserv file type.

  • name (str) – The name associated with the Fileserv file type.

class activelogic.FileservFile

Object representing information about a Fileserv file.

Parameters:
  • name (str) – The name of the Fileserv file of a given type.

  • size (int) – The size of the file bytes.

Downloading, uploading and removing files

async Fileserv.download(ftype, fname, *, ofile_obj=None, dest_path=None)

Download a specific file. The file to which the downloaded data is to be written to can be either a file object opened in binary mode or the path of the file to write to.

Parameters:
  • ftype (FileservFileType or int or str) – The FileservFileType or ID or name of the Fileserv type.

  • fname (str) – The name of the file to be downloaded.

  • ofile_obj (python file object) – The python file object of the file to which the downloaded data is written to.

  • dest_path (str or pathlib.Path) – The path of the file to which the downloaded data is written to.

Raises:
  • TypeError – fname must be of str type

  • TypeError – ofile_obj must be a file object

  • TypeError – ofile_obj must be writable

  • TypeError – dest_path must be an instance of str or pathlib.Path

  • TypeError – One of ofile_obj, dest_path must be provided

  • TypeError – Either one of ofile_obj, dest_path must be provided but not both

  • PLDBError – Failed to download the file

  • TypeError – ofile_obj must be opened in binary mode to download text/binary files.

The file object ofile_obj must be opened in binary writable mode to download text/binary files.

>>> fs = conn.fileserv()
>>> with open('testfile', 'wb+') as testfile:
...    fs.download(FileservArea.SNMP_MIB, 'PACKETLOGIC-HW-MIB', ofile_obj=testfile)
>>> fs.download(FileservArea.SNMP_MIB, 'PACKETLOGIC-HW-MIB', dest_path='temp_file')

BytesIO objects could also be used to download files.

>>> f = io.BytesIO()
>>> fs.download(FileservArea.PCAP_1, 'capture.pcap', ofile_obj=f)
>>> f.close()
async Fileserv.upload(ftype, fname, *, ifile_obj=None, in_path=None)

Upload a specific file. The file from which data to be uploaded is read from can be specified with either a file object opened in binary mode or path of the input file.

Parameters:
  • ftype (FileservFileType or int or str) – The FileservFileType or ID or name of the Fileserv type.

  • fname (str) – The name of the the file to be uploaded.

  • ifile_obj (python file object) – The file object of the input file to be to be uploaded.

  • in_path (str or pathlib.Path) – The path of the file from which data is to be read for upload.

Raises:
  • TypeError – fname must be of str type

  • TypeError – in_path must an instance of type str or pathlib.Path

  • TypeError – One of ifile_obj, in_path must be provided

  • TypeError – Either one of ifile_obj, in_path must be provided but not both

  • TypeError – ifile_obj must be a non-None python file object

  • TypeError – ifile_obj must be a readable file

  • TypeError – ifile_obj must be opened in binary mode

  • TypeError – Input file must be a non-empty file

  • FileNotFoundError – The file pointed by in_path is not found

The input file object must be opened in binary mode before calling this method so as to be to upload both text and binary files.

>>> fs = conn.fileserv()
>>> with open('testfile', 'rb') as testfile:
...     fs.upload(FileservArea.FIRMWARE_CLI, 'Testfile', ifile_obj=testfile)
>>> fs.upload(FileservArea.FIRMWARE_CLI, 'Testfile_', in_path='test_path')
async Fileserv.remove(ftype, fname)

Remove a specified file from Fileserv.

Parameters:
  • ftype (FileservFileType or int or str) – The FileservFileType or ID or name of the Fileserv type.

  • fname (str) – The name of the the file to be removed.

Raises:
  • TypeError – fname must be of str type

  • PLDBError – Could not remove file (file does not exist)

  • PLDBError – The fileserv type does not allow files to be removed

>>> fs = conn.fileserv()
>>> fs.remove(FileservArea.FIRMWARE_CLI, 'Testfile')