Network¶
-
class
pybsd.network.Interface(name, ips=None)[source]¶ Bases:
objectDescribes a network interface
An interface has main
ipaddress.IPv4Interfaceand a mainipaddress.IPv6Interface. Any otheripaddress.IPvxInterfacewill be added as an alias. Main addresses as used by the defaultBaseJailHandleras the basis to calculate jail interfaces (seederive_interface). Interfaces can be checked for equality based on their name and list of ips.Parameters: - name (
str) – a name that identifies the interface. - ips (Optional[
str,list`[:py:class:`str] orset`(:py:class:`str) ]) – a single ip address or a list of ip addresses, represented as strings. Duplicates are silently ignored. The first ip added for each version will become the main ip address for this interface.
-
add_ips(ips)[source]¶ Adds a single ip address or a list of ip addresses, represented as strings, to the interface.
None and duplicates are silently ignored.
Parameters: ips ( str,list`[:py:class:`str] orset`(:py:class:`str)) – a single ip address or a list of ip addresses, represented as strings. Duplicates are silently ignored. The first ip added for each version will become the main ip address for this interface.
-
alias_ifsv4¶ sortedcontainers.SortedSet([ipaddress.IPv4Interface]): a sorted set containing this interface’s IPv4 aliases
-
alias_ifsv6¶ sortedcontainers.SortedSet([ipaddress.IPv4Interface]): a sorted set containing this interface’s IPv6 aliases
-
ifsv4= None¶ sortedcontainers.SortedSet([ipaddress.IPv4Interface]): a sorted set containing all the IPv4 interfaces on this physical interface.
-
ifsv6= None¶ sortedcontainers.SortedSet([ipaddress.IPv6Interface]): a sorted set containing all the IPv6 interfaces on this physical interface.
-
ips¶ sortedcontainers.SortedSet([str]): a sorted set containing all ips on this interface.
-
main_ifv4= None¶ ipaddress.IPv4Interface: this interface’s main IPv4 interface
-
main_ifv6= None¶ ipaddress.IPv6Interface: this interface’s main IPv6 interface
-
name= None¶ str: a name that identifies the interface.
- name (
Handlers¶
-
class
pybsd.handlers.BaseJailHandler(master=None, jail_root=None)[source]¶ Bases:
objectProvides a base jail handler
Handlers allow custom parametrization and customization of all logic pertaining to the jails. Each aspect of the handling is delegated to a method that can be called from the master or the jail.
Parameters: - master (Optional[
Master]) – The handler’s master. - jail_root (
str) – the path on the host’s filesystem to the jails directory that the handler will enforce
-
default_jail_root¶ strthe default jail_root.
-
jail_class_ids¶ dicta dictionary linking jail class types and the numerical ids that are to be linked to them by this handler.
Raises: MissingMainIPError– when a master’s interface does not define a main_ifInvalidMainIPError– when a master’s main_if violates established rulesMasterJailMismatchError– if a master and a jail called in a method are not related
-
check_mismatch(jail)[source]¶ Checks whether a given jail belongs to the handler’s master
Parameters: jail ( Jail) – the jail whose status is checkedReturns: whether the jail belongs to the handler’s master Return type: boolRaises: MasterJailMismatchError– if a master and a jail called in a method are not related
-
classmethod
derive_interface(master_if, jail)[source]¶ Derives a jail’s
Interfacebased on the handler’s master’sParameters: Returns: the jail’s
InterfaceReturn type: Raises: MissingMainIPError– when a master’s interface does not define a main_ifInvalidMainIPError– when a master’s main_if violates established rules
-
get_jail_ext_if(jail)[source]¶ Returns a given jail’s ext_if
Parameters: jail ( Jail) – the jail whose ext_if is requestedReturns: the jail’s ext_if Return type: Interface
-
get_jail_hostname(jail, strict=True)[source]¶ Returns a given jail’s hostname.
if strict is set to False, it will evaluate what the jail hostname would be if it were attached to the handler’s master.
Parameters: - jail (
Jail) – the jail whose hostname is requested - strict (Optional[
bool]) – whether the handler should only return hostnames for jails attached to its master. Default is True.
Returns: the jail’s path
Return type: unipath.Path- jail (
-
get_jail_lo_if(jail)[source]¶ Returns a given jail’s lo_if
Parameters: jail ( Jail) – the jail whose lo_if is requestedReturns: the jail’s lo_if Return type: Interface
-
get_jail_path(jail)[source]¶ Returns a given jail’s path
Parameters: jail ( Jail) – the jail whose path is requestedReturns: the jail’s path Return type: unipath.Path
-
get_jail_type(jail)[source]¶ Returns a given jail’s type.
The default implementation simply honours the master’s default jail type and provides an esaily overridable method where custom logic can be applied.
Parameters: jail ( Jail) – the jail whose jail type is requestedReturns: the jail’s type. For base values see jail_type()Return type: str
- master (Optional[
Executors¶
-
class
pybsd.executors.Executor(instance=None, prefix_args=(), splitlines=False)[source]¶ Bases:
objectExecutes a command Adapted from https://github.com/ployground/ploy
Utils¶
-
pybsd.utils.from_split_if(chunks)[source]¶ Converts a list-based description of an
ipaddress.IPVxInterface‘s ip and prefixlen such as that returned bypybsd.utils.split_if()into a string.The returned string can be used as the argument to
ipaddress.ip_interface()Parameters: chunks ( list) – a list of 6 (IPv4) or 10 (IPv6) elements describing an interfaceReturns: a string-based description of an ipaddress.IPVxInterface‘s ip and prefixlenReturn type: str
-
pybsd.utils.safe_unicode(string)[source]¶ Converts a string to unicode
Parameters: string ( basestring(python 2/3) orstr(python 2/3) orunicode(python 2) orbytes(python 3)) – the string to be convertedReturns: a unicode string Return type: unicode(python 2) orstr(python 3)
-
pybsd.utils.split_if(interface)[source]¶ Returns a list-based description of an
ipaddress.IPVxInterface‘s ip and prefixlen- Some significative indexes of the list always describe the same aspect of the interface:
- 0: version
- 1: prefixlen
- 2: first octet of the interface’s ip address
- -1: last octet of the interface’s ip address
Parameters: interface ( ipaddress.IPV4Interfaceoripaddress.IPV6Interface) – the interface to be describedReturns: a list of 6 (IPv4) or 10 (IPv6) elements describing an interface Return type: list