paradrop.lib.utils package¶
Submodules¶
paradrop.lib.utils.addresses module¶
-
areWanPortsAvailable
(portRange, takenPorts, chuteStor, name)[source]¶ Make sure that if we are forwarding a wan port, we have not already forwarded it.
-
checkPhyExists
(radioid)[source]¶ Check if this chute exists at all, a directory /sys/class/ieee80211/phyX must exist.
-
getChuteIntf
(name, netIntfs)[source]¶ This function takes a network interface name, and parses through the netIntfs object provided looking for a match, it returns name if none is found.
- Example:
- if ‘lan’ is the name, ‘lan’ will be returned. if ‘wifilxc’ is the name, ‘c####wifilxc’ will be returned.
- This function also deals with the usage of macro expansions:
- Example:
If the developer defines a ‘lan’ interface for their chute, but they also have a rule that needs to point to the HOST lan interface, a conflict will occur.
To solve this, the developer would specify the HOST lan with '@net.host.lan‘ and the chute lan with ‘lan’.
-
getGatewayIntf
(ch)[source]¶ Looks at the key:networkInterfaces for the chute and determines what the gateway should be including the IP address and the internal interface name.
- Returns:
- A tuple (gatewayIP, gatewayInterface) None if networkInterfaces doesn’t exist or there is an error
-
getInternalIntfList
(ch)[source]¶ Takes a chute object and uses the key:networkInterfaces to return a list of the internal network interfaces that will exist in the chute (e.g., eth0, eth1, ...)
- Returns:
- A list of interface names None if networkInterfaces doesn’t exist or there is an error
-
getWANIntf
(ch)[source]¶ Looks at the key:networkInterfaces for the chute and finds the WAN interface.
- Returns:
- The dict from networkInterfaces None
-
incIpaddr
(ipaddr, inc=1)[source]¶ Takes a quad dot format IP address string and adds the @inc value to it by converting it to a number.
- Returns:
- Incremented quad dot IP string or None if error
-
isIpAvailable
(ipaddr, chuteStor, name)[source]¶ Make sure this IP address is available. Checks the IP addresses of all zones on all other chutes,
makes sure subnets are not the same.
-
isRadioPassedthrough
(radioid, chuteStor, name)[source]¶ Check if any chute has already passed through to a chute.
-
isStaMeshAvailable
(chuteStor, name)[source]¶ Make sure this sta/mesh is available. Only one per device because we attach to wan directly.
-
isStaMeshOnRadio
(radioid, chuteStor, name)[source]¶ If we are a wifi chute, we cannot have an sta on this channel.
-
isStaticIpAvailable
(ipaddr, chuteStor, name)[source]¶ Make sure this static IP address is available. Checks the IP addresses of all zones on all other chutes,
makes sure not equal.
-
isWifiIntAvailable
(radioid, numWifi, chuteStor, name)[source]¶ Make sure that fewer than 7 wifi interfaces have been configured. Otherwise, the wireless card will fail.
paradrop.lib.utils.dockerapi module¶
Functions associated with deploying and cleaning up docker containers.
-
build_host_config
(update)[source]¶ Build the host_config dict for a docker container based on the passed in update.
Parameters: update (obj) – The update object containing information about the chute. Returns: (dict) The host_config dict which docker needs in order to create the container.
-
failAndCleanUpDocker
(validImages, validContainers)[source]¶ Clean up any intermediate containers that may have resulted from a failure and throw an Exception so that the abort process is called.
Parameters: Returns: None
-
removeChute
(update)[source]¶ Remove a docker container and the image it was built on based on the passed in update.
Parameters: update (obj) – The update object containing information about the chute. Returns: None
-
restartChute
(update)[source]¶ Start a docker container based on the passed in update.
Parameters: update (obj) – The update object containing information about the chute. Returns: None
-
setup_net_interfaces
(update)[source]¶ Link interfaces in the host to the internal interface in the docker container using pipework.
Parameters: update (obj) – The update object containing information about the chute. Returns: None
-
startChute
(update)[source]¶ Build and deploy a docker container based on the passed in update.
Parameters: update (obj) – The update object containing information about the chute. Returns: None
paradrop.lib.utils.pdos module¶
-
basename
(x)¶
-
fixpath
(p)[source]¶ This function is required because if we need to pass a path to something like tarfile, we cannot overwrite the function to fix the path, so we need to expose it somehow.
-
makeExecutable
(*args)[source]¶ The function that takes the list of files provided and sets the X bit on them.
-
oscall
(cmd, get=False)[source]¶ This function performs a OS subprocess call. All output is thrown away unless an error has occured or if @get is True Arguments:
@cmd: the string command to run [get] : True means return (stdout, stderr)- Returns:
- None if not @get and no error (stdout, retcode, stderr) if @get or yes error
-
readFile
(filename, array=True, delimiter='\n')[source]¶ Reads in a file, the contents is NOT expected to be binary. Arguments:
@filename: absolute path to file @array : optional: return as array if true, return as string if False @delimiter: optional: if returning as a string, this str specifies what to use to join the lines- Returns:
- A list of strings, separated by newlines None: if the file doesn’t exist
paradrop.lib.utils.pdosq module¶
Quiet pdos module. Implements utility OS operations without relying on the output module. Therefore, this module can be used by output without circular dependency.
paradrop.lib.utils.restart module¶
lib.utils.restart Contains the functions required to restart chutes properly on power cycle of device. Checks with pdconfd to make sure it was able to properly bring up all interfaces before starting chutes.
-
reloadChutes
()[source]¶ This function is called to restart any chutes that were running prior to the system being restarted. It waits for pdconfd to come up and report whether or not it failed to bring up any of the interfaces that existed before the power cycle. If pdconfd indicates something failed we then force a stop update in order to bring down all interfaces associated with that chute and mark it with a warning. If the stop fails we mark the chute with a warning manually and change its state to stopped and save to storage this isn’t great as it could mean our system still has interfaces up associated with that chute. If pdconfd doesn’t report failure we attempt to start the chute and if this fails we trust the abort process to restore the system to a consistent state and we manually mark the chute as stopped and add a warning to it. :param None :returns: (list) A list of update dicts to be used to create updateObjects that should be run before accepting new updates.
-
updateStatus
(update)[source]¶ This function is a callback for the updates we do upon restarting the system. It checks whether or not the update completed successfully and if not it changes the state of the chute to stopped and adds a warning. :param update: The update object containing information about the chute that was created and whether it was successful or not. :type update: obj :returns: None
paradrop.lib.utils.storage module¶
-
class
PDStorage
(filename, reactor, saveTimer)[source]¶ ParaDropStorage class.
This class is designed to be implemented by other classes. Its purpose is to make whatever data is considered important persistant to disk.
This is done by providing a reactor so a “LoopingCall” can be utilized to save to disk.
- The implementer can override functions in order to implement this class:
- getAttr() : Get the attr we need to save to disk setAttr() : Set the attr we got from disk importAttr(): Takes a payload and returns the properly formatted data exportAttr(): Takes the data and returns a payload attrSaveable(): Returns True if we should save this attr
paradrop.lib.utils.uci module¶
-
class
UCIConfig
(filepath)[source]¶ - Wrapper around the UCI configuration files.
These files are found under /etc/config/, and are used by OpenWrt to keep track of configuration for modules typically found in /etc/init.d/
- The modules of interest and with current support are:
- firewall
- network
- wireless
- qos
- This class should work with any UCI module but ALL others are UNTESTED!
New configuration settings can be added to the UCI file via addConfig().
Each UCI config file is expected to contain the following syntax:
- config keyA [valueA]
- option key1 value1 ... list key2 value1 list key2 value2 ... list key3 value1 list key3 value2
- Based on the UCI file above, the config syntax would look like the following:
config is a list of tuples, containing 2 dict objects in each tuple:
- tuple[0] describes the first line (config keyA [valueA])
{‘type’: keyA, ‘name’: valueA} The value parameter is optional and if missing, then the ‘name’ key is also missing (rather than set to None).
- tuple[1] describes the options associated with the settings (both ‘option’ and ‘list’ lines)
{‘key1’: ‘value1’, ...}
- If a list is present, it looks like the following:
- {
..., ‘list’: {
‘key2’: [value1, value2, ...], ‘key3’: [value1, value2, ...] }
}
- So for the example above, the full config definition would look like:
- C = {‘type’: ‘keyA’, ‘name’: ‘valueA’} O = {‘key1’: ‘value1’, ‘list’: {‘key2’: [‘value1’, ‘value2’], ‘key3’: [‘value1’, ‘value2’]}} config = [(C, O)]
-
delConfig
(config, options)[source]¶ Finds a match to the config input and removes it from the internal config data structure.
-
existsConfig
(config, options)[source]¶ Tests if the (config, options) is in the current config file.
-
getConfigIgnoreComments
(config)[source]¶ Returns a list of call configs with the given title. Comments are ignored.
-
restore
(backupToken, saveBackup=True)[source]¶ Replaces real file (at /etc/config/) with backup copy from /tmp/-@backupToken location.
- Arguments:
- backupToken: The backup token appended at the end of the backup path saveBackup : A flag to keep a backup copy or delete it (default is keep backup)
-
chuteConfigsMatch
(chutePre, chutePost)[source]¶ Takes two lists of objects, and returns whether or not they are identical.