insalata.helper package¶
Submodules¶
insalata.helper.SSHWrapper module¶
-
class
insalata.helper.SSHWrapper.
SSHClient_noAuth
¶ Bases:
paramiko.client.SSHClient
-
class
insalata.helper.SSHWrapper.
SSHWrapper
¶ Bases:
object
-
close
()¶
-
connect
(name)¶
-
executeNmapServiceScan
(serviceOptions, range)¶ Run a Nmap service detection over the given SSH connection. We scan all addresses in the given range. Range must be a string that is nmap can parse.
We raise an OSError if nmap is not available on the target.
Parameters: - serviceOptions (str) – Additional command line options we want to use in the nmap service detection.
- range (str) – The range we want to scan with nmap. This must be a string nmap can parse.
-
executeTcpdump
(args)¶
-
getConnection
()¶
-
getDHCPInfo
()¶
-
getDNSInfo
()¶
-
getInterfaceInfo
()¶
-
getRoutingInfo
()¶
-
insalata.helper.SnmpWrapper module¶
-
insalata.helper.SnmpWrapper.
OidToRouteIdentifier
(oid)¶ Generate the subidentifier for one route. The oid has the schema: <oid>.<4 dot seperated values dest-network>.<4 dot seperated values netmask>.<4 dot seperated values hop>
Parameters: oid (str) – OID to split Returns: sub-oid representing the route (Without leading dot) Return type: str
-
class
insalata.helper.SnmpWrapper.
SnmpWrapper
(host, user, passwordMD5, passwordDES, port=161)¶ Bases:
object
-
getValue
(oid, number=None)¶ Execute a GET command on the host defined in the constructor.
Parameters: - oid (str) – Value/OID to receive from the host
- number (int) – Subelement of given OID if needed. For example interface if you want to read ips
Returns: Value returned by the SNMP-Agent or error code. 0 : Unknown error 1 : Connection-Timeout: Host has no installed SNMP-Agent or encryption password is wrong. 2 : Authentification failed due to wrong authentification password. 3 : Unknown username 4 : Host not reachable
Return type: tuple on success, int on error
-
walkOid
(oid)¶ Execute a GETNEXT command on the host defined in the constructor. Method will return all values which are subidentifiers of the fiven one.
Parameters: - oid (str) – Value/OID to receive from the host
- number (int) – Subelement of given OID if needed. For example interface if you want to read ips
Returns: List of values returned by the SNMP-Agent or error code. 0 : Unknown error 1 : Connection-Timeout: Host has no installed SNMP-Agent or encryption password is wrong. 2 : Authentification failed due to wrong authentification password. 3 : Unknown username 4 : Host not reachable
Return type: list on success, int on error
-
-
insalata.helper.SnmpWrapper.
checkReturnSnmp
(answer, host, name, user, logger)¶ Check the return type of SnmpWrapper functions and log if an error occured.
Parameters: - answer (list, tuple or int) – Answer received from SnmapWrapper method
- host (seealso: insalata.model.Host.Host) – Host currently processed
- name (str) – Name of this collector
- user (str) – User used for SNMP connection
- logger (seealso: insalata.Logging.Logger) – Logger used by this collector module
Returns: answer if no error occured else None
Return type: list, tuple or None
-
insalata.helper.SnmpWrapper.
toPythonType
(value)¶
insalata.helper.ansibleWrapper module¶
-
insalata.helper.ansibleWrapper.
addToKnownHosts
(hostname)¶ Sets all hosts given in hostlist as hosts known to Ansible by editing the /etc/ansible/hosts
Parameters: hostname (str) – A hostname to add to the list of known hosts for ansible
-
insalata.helper.ansibleWrapper.
copyFile
(user, filename)¶
-
insalata.helper.ansibleWrapper.
parseAnsibleCommand
(out)¶
-
insalata.helper.ansibleWrapper.
runAnsibleCommand
(host, module)¶
insalata.helper.diff module¶
-
insalata.helper.diff.
diff
(newConfig, currentConfig)¶ Diffs two testbed configurations regarding changed elements. Returns a dictionary containing all mismatching attributes.
- Keyword arguments:
- newConfig – Configuration-object representing the new configuration to deploy. currentConfig – Configuration-object representing the current state of the testbed.
-
insalata.helper.diff.
getMismatchingAttr
(obj1, obj2)¶ Returns a list of missmatching attributes between two objects. Only look at public attributes.
It works for all primitive. Complex types or lists/sets of those can be compared if their respective __eq__() method is overriden properly. Note: lists are ordered and will only match if the included objects are ordered identically, sets are unsorted as their name indicates
- Keyword arguments:
- obj1 – the object to compare obj2 to obj2 – the object that will be compared with obj1
-
insalata.helper.diff.
getMismatchingAttrSet
(set1, set2)¶ Returns a dictionary of missmatching objects between two sets, stating the respective attributes.
The objects are compared by their ID if they are not primitive. Therefore all lists of elements that will be compared with this method, have to provide a getGlobalID()-method. (Not the best solution, but it solves the case at hand)
- Keyword arguments:
- set1 – the set to compare set2’s elements to set2 – the set whose elements will be compared with set1
-
insalata.helper.diff.
objectAllNew
(obj)¶ A completely new object/attribute has nothing to be compared to and is therefore quickly built with all new attributes
- Keyword arguments:
- obj1 – the new object
-
insalata.helper.diff.
objectAllRemoved
(obj)¶ A removed object/attribute has nothing to be compared to and is therefore quickly built with all removed attributes
- Keyword arguments:
- obj1 – the removed object
-
insalata.helper.diff.
resolveEdges
(obj)¶ Resolves all “part of” edges in the graph based data structure and creates sets for the hierarchically structured diff
- Keyword arguments:
- obj – The object to resolve edges of
-
insalata.helper.diff.
resolveGraph
(config)¶ Resolves all “part of” edges in the graph based data structure inside the config and creates sets for the hierarchically structured diff
- Keyword arguments:
- config – The config to resolve edges of for all subelements
insalata.helper.ipAddressHelper module¶
-
insalata.helper.ipAddressHelper.
getBroadcastAddress
(netaddress, netmask)¶ Get the broadcast address of the given network as string.
Parameters: - netaddress (str) – The network’s address
- netmask (str) – The netmask of the given network.
Returns: The broadcast address.
Return type: str
-
insalata.helper.ipAddressHelper.
getIpAddress
(ip, offset)¶ Get the IP adddress that is [offset] units before or after the given one.
Parameters: - ip (str) – IP address to start from.
- offset (int) – Offset to add or remove from the IP address.
Returns: New IP address.
Return type: str
-
insalata.helper.ipAddressHelper.
getIpAddressDifference
(ip1, ip2)¶ Get the number of IP addresses between two given IP addresses.
Parameters: - ip1 (str) – The IP address acting as minuend.
- ip1 – The IP address acting as subtrahend.
Returns: The number of IP addresses between.
Return type: int
-
insalata.helper.ipAddressHelper.
getNetAddress
(ip, netmask)¶ Get the netaddress from an host ip and the netmask.
Parameters: - ip (str) – Hosts IP address
- netmask – Netmask of the network
Returns: Address of the network calculated using hostIP and netmask
Return type: str
-
insalata.helper.ipAddressHelper.
getPrefix
(netmask)¶ Get the CIDR prefix representing the netmask.
Parameters: netmask – Netmask to convert to CIDR Returns: CIDR prefix representing the netmask Return type: int
-
insalata.helper.ipAddressHelper.
isHostInNetwork
(hostIp, netAddr, netmask)¶ Determines whether or not the given IP address of the host is part oyf the network specified by a network address and a subnetmask
Parameters: - hostIp (str) – The IP of the host in decimal dotted notation
- netAddr (str) – The network addresss in decimal dotted notation
- netmask (str) – The netmask of the network in decimal dotted notation