debinterface

Submodules

debinterface.adapter

The NetworkAdapter class represents an interface and its configuration from the /etc/network/interfaces. It tries to validate data before writting, but it is by no means fool proof. It has setter for many common options, but it is impossible to have setter for every options on earth !

class debinterface.adapter.NetworkAdapter(options, interfaces_path=None)[source]

Bases: object

A representation a network adapter.

attributes
get_attr(attr)[source]
validateAll()[source]

Not thorough validations... and quick coded.

Raises:ValueError – if there is a validation error
validateOne(opt, validations, val)[source]

Not thorough validations... and quick coded.

Parameters:
  • opt (str) – key name of the option
  • validations (dict) – contains the validations to checks
  • val (any) – the option value
Raises:

ValueError – if there is a validation error

static validateIP(ip)[source]

Validate an IP Address. Works for subnet masks too. Tries ipv4 then ipv6

Args:
ip (str): the IP as a string
Raises:
socket.error on invalid IP
setName(name)[source]

Set the name option of an interface.

Parameters:name (str) – the name of the interface
Raises:ValueError – if there is a validation error
setAddrFam(address_family)[source]

Set the address family option of an interface.

Parameters:address_family (str) – one of ‘inet’, ‘inet6’, ‘ipx’
Raises:ValueError – if there is a validation error
setAddressSource(address_source)[source]

Set the address source for an interface.

Valid values are : dhcp, static, loopback, manual, bootp, ppp, wvdial, dynamic, ipv4ll, v4tunnel

Args:
address_source (string): address source for an interface
Raises:
ValueError: if there is a validation error
setAddress(ip_address)[source]

Set the ipaddress of an interface.

Parameters:ip_address (str) – the IP as a string
Raises:ValueError – if there is a validation error
setNetmask(netmask)[source]

Set the netmask of an interface.

Parameters:netmask (str) – the netmask IP as a string
Raises:ValueError – if there is a validation error
setGateway(gateway)[source]

Set the default gateway of an interface.

Parameters:gateway (str) – the gateway IP as a string
Raises:ValueError – if there is a validation error
setBroadcast(broadcast)[source]

Set the broadcast address of an interface.

Parameters:broadcast (str) – the broadcast IP as a string
Raises:ValueError – if there is a validation error
setNetwork(network)[source]

Set the network identifier of an interface.

Parameters:network (str) – the IP as a string
Raises:ValueError – if there is a validation error
setAuto(auto)[source]

Set the option to autostart the interface.

Parameters:auto (bool) – interface will be set as auto if True
Raises:ValueError – if there is a validation error
setHotplug(hotplug)[source]

Set the option to allow hotplug on the interface. Beware, option is really called allow-hotplug, that’s a small historic cruft...

Args:
hotplug (bool): interface hotplug will be set if True
Raises:
ValueError: if there is a validation error
setHostapd(hostapd)[source]

Set the wifi conf file on the interface.

Raises:ValueError – if there is a validation error
setNameservers(nameserver)[source]

Set the ipaddress of an interface.

Raises:ValueError – if there is a validation error
setDnsNameservers(nameservers)[source]

Set the dns nameservers on the interface.

Parameters:nameservers (str, list) – the IP as a string
Raises:ValueError – if there is a validation error
setDnsSearch(searchUri)[source]

Set the dns default search URI.

Parameters:searchURI (str, list) – The default search domain
Raises:ValueError – if there is a validation error
setBropts(opts)[source]

Set the bridge options of an interface.

Parameters:opts (dict) – a dictionary mapping option names and values. In the interfaces file, options will have a bridge prefix.
Raises:ValueError – if there is a validation error
setWpaConf(conf_path)[source]

Set the wpa supplicant configuration path for supplicant config for wireless interfaces.

Parameters:conf_path (str) – Path at which the supplicant config is located.
replaceBropt(key, value)[source]

Set a discrete bridge option key with value

Parameters:
  • key (str) – the option key in the bridge option
  • value (any) – the value
appendBropts(key, value)[source]

Set a discrete bridge option key with value

Parameters:
  • key (str) – the option key in the bridge option
  • value (any) – the value
setUp(up)[source]

Set and add to the up commands for an interface.

Parameters:up (list) – list of shell commands
appendUp(cmd)[source]

Append a shell command to run when the interface is up.

Parameters:cmd (str) – a shell command
setDown(down)[source]

Set and add to the down commands for an interface.

Parameters:down (list) – list of shell commands
appendDown(cmd)[source]

Append a shell command to run when the interface is down.

Parameters:cmd (str) – a shell command
setPreUp(pre)[source]

Set and add to the pre-up commands for an interface.

Parameters:pre (list) – list of shell commands
appendPreUp(cmd)[source]

Append a shell command to run when the interface is pre-up.

Parameters:cmd (str) – a shell command
setPreDown(pre)[source]

Set and add to the pre-down commands for an interface.

Parameters:pre (list) – list of shell commands
appendPreDown(cmd)[source]

Append a shell command to run when the interface is pre-down.

Parameters:cmd (str) – a shell command
setPostUp(post)[source]

Set and add to the post-up commands for an interface.

Parameters:post (list) – list of shell commands
appendPostUp(cmd)[source]

Append a shell command to run when the interface is post-up.

Parameters:cmd (str) – a shell command
setPostDown(post)[source]

Set and add to the post-down commands for an interface.

Parameters:post (list) – list of shell commands
appendPostDown(cmd)[source]

Append a shell command to run when the interface is post-down.

Parameters:cmd (str) – a shell command
setUnknown(key, val)[source]

Stores uncommon options as there are with no special handling It’s impossible to know about all available options WARNING: duplicated directives are overwriten. TODO better

Args:
key (str): the option name val (any): the option value
export(options_list=None)[source]

Return a copy of the ifAttributes data structure as dict. You may optionally pass a list of options to return

Args:
options_list (list, optional): a list of options you want
Returns:
dict: the ifAttributes data structure, optionally filtered
display()[source]

Display a (kind of) human readable representation of the adapter.

reset()[source]

Initialize attribute storage structure.

set_options(options)[source]

Set options, either only the name if options is a str, or all given options if options is a dict

Args:
options (str/dict): historical code... only set
the name if options is a str, or all given options if options is a dict
Raises:
ValueError: if validation error socket.error: if validation error of an IP Exception: if anything weird happens

debinterface.adapterValidation

The NetworkAdapterValidation tries to validate data before writting, but it is by no means fool proof as it is impossible to have checks for everything as any package can add its keys.

class debinterface.adapterValidation.NetworkAdapterValidation[source]

Bases: object

Class to validate an adapter. It validates some options for: - presence - type - authorized values

validate_all(if_attributes)[source]

Not thorough validations... and quick coded.

Parameters:if_attributes (dict) – the dict representation of the interface
Raises:ValueError – if there is a validation error
validate_one(opt, validations, val)[source]

Not thorough validations... and quick coded.

Parameters:
  • opt (str) – key name of the option
  • validations (dict) – contains the validations to checks
  • val (any) – the option value
Raises:

ValueError – if there is a validation error

static validate_ip(ip, opt)[source]

Validate an IP Address. Works for subnet masks too.

Parameters:
  • ip (str) – the IP as a string
  • opt (str) – the opt name
Raises:

ValueError – on invalid IP

static validate_broadcast_ip(ip, opt)[source]

Validate an IP Address. Works for subnet masks too.

Parameters:
  • ip (str) – the IP as a string
  • opt (str) – the opt name
Raises:

ValueError – on invalid IP

debinterface.dnsmasqRange

class debinterface.dnsmasqRange.DnsmasqRange(path, backup_path=None, leases_path='/var/tmp/dnsmasq.leases')[source]

Bases: object

Basic dnsmasq conf of the more file which holds the ip ranges per interface. Made for handling very basic dhcp-range options

backup_path = None
config
set(key, value)[source]
validate()[source]
update_range(interface, start, end, lease_time)[source]

Update existing range based on the interface name If does not exist will be created

Parameters:
  • interface (str) – interface name
  • start (str) – start ip of range
  • end (str) – end ip of range
  • lease_time (str) – lease_time
Returns:

True if configuration was updated or created,

False otherwise

Return type:

bool

get_itf_range(if_name)[source]

If no interface, return None

rm_itf_range(if_name)[source]

Rm range info for the given interface

Parameters:if_name (str) – interface name
Returns:True if configuration was updated, False otherwise
Return type:bool
set_defaults()[source]

Defaults for my needs, you should probably override this one

read(path=None)[source]
write(path=None)[source]
static controlService(action)[source]

return True/False, command output

clear_leases()[source]

rm /var/tmp/dnsmasq.leases

backup()[source]

return True/False, command output

restore()[source]

return True/False, command output

delete()[source]

return True/False, command output

apply_changes()[source]

Write changes to fs and restart daemon

debinterface.hostapd

class debinterface.hostapd.Hostapd(path, backup_path=None)[source]

Bases: object

basic hostapd conf file handling

backup_path = None
config
set(key, value)[source]
validate()[source]

Not sure which ones are really necessary for everyone, here are the ones I require. I created 4 groups of keys : basic must always be there, wireless if you want to be an AP, auth if you want to add some security, bridge for, well, bridging Not foul proof !

Returns:

True if everything went ok

Return type:

bool

Raises:
  • KeyError – missing key
  • ValueError – invalid data
set_defaults()[source]

ssid and wpa_passphrase defaults to cashpad-FTED and cashpad-GH67

read(path=None)[source]
write(path=None)[source]
static controlService(action)[source]

return True/False, command output

backup()[source]

return True/False, command output

restore()[source]

return True/False, command output

delete()[source]

return True/False, command output

debinterface.interfaces

class debinterface.interfaces.Interfaces(update_adapters=True, interfaces_path='/etc/network/interfaces', backup_path=None, header_comment=None)[source]

Bases: object

By default read interface file on init

Parameters:
  • update_adapters (bool, optional) – load adapters from interface file. Default True
  • interfaces_path (str, optional) – default to /etc/network/interfaces
  • backup_path (str, optional) – default to /etc/network/interfaces.bak
  • header_comment (str, optional) – default to none, otherwise sets comments at the top of the interfaces file.
adapters
interfaces_path

Returns the path of the main interface file Others may come from the source directive. Adapters register the path

backup_path
header_comment
updateAdapters()[source]

(re)read interfaces file and save adapters

writeInterfaces()[source]

write adapters to interfaces file

getAdapter(name)[source]

Find adapter by interface name

Parameters:name (str) – the name of the interface
Returns:the new adapter or None if not found
Return type:NetworkAdapter
addAdapter(options, index=None, interfaces_path=None)[source]

Insert a NetworkAdapter before the given index or at the end of the list. Options should be a string (name) or a dict

Parameters:
  • options (string or dict) – options to build a network adaptator
  • index (integer, optional) – index to insert the NetworkAdapter
  • interfaces_path (str, optional) – path to the source file of the adadpter.
Returns:

the new adapter

Return type:

NetworkAdapter

removeAdapter(index)[source]

Remove the adapter at the given index. TODO: handle file deletion of sourced paths

Args:
index (int): the position of the adapter
removeAdapterByName(name)[source]

Remove the adapter with the given name.

Parameters:name (str) – the name of the interface
static upAdapter(if_name)[source]

Uses ifup

Parameters:if_name (str) – the name of the interface
Returns:True/False, command output.
Return type:bool, str
static downAdapter(if_name)[source]

Uses ifdown

Parameters:if_name (str) – the name of the interface
Returns:True/False, command output.
Return type:bool, str
_set_paths(interfaces_path, backup_path)[source]

Either use user input or defaults

Parameters:
  • interfaces_path (str) – path to interfaces file
  • backup_path (str) – default to interfaces_path + .bak

debinterface.interfacesReader

class debinterface.interfacesReader.InterfacesReader(interfaces_path)[source]

Bases: object

Short lived class to read interfaces file

adapters
header_comments
parse_interfaces(read_comments=False)[source]

Read /etc/network/interfaces (or specified file). Save adapters Return an array of networkAdapter instances.

_read_file(current_path)[source]

Open up the given interfaces file. Read only. If a source directive is found, it will call itself recursively

_read_auto(line)[source]

Identify which adapters are flagged auto.

_read_hotplug(line)[source]

Identify which adapters are flagged allow-hotplug.

_read_sourced_path(line)[source]

Identify source path/to/file. If so will return the path to open it. Relative paths will be expanded from root path

Returns:
str: absolute path to the sourced file

debinterface.interfacesWriter

class debinterface.interfacesWriter.InterfacesWriter(adapters, interfaces_path, backup_path=None, header_comment=None)[source]

Bases: object

Short lived class to write interfaces file

if backup_path is None => no backup

adapters
write_interfaces()[source]
_check_interfaces(interfaces_path)[source]

Uses ifup to check interfaces file. If it is not in the default place, each interface must be checked one by one.

Parameters:interfaces_path (string) – the path to interfaces file
Raises:ValueError – if invalid network interfaces
_write_auto(interfaces, adapter, ifAttributes)[source]

Write if applicable

_write_hotplug(interfaces, adapter, ifAttributes)[source]

Write if applicable

_write_addrFam(interfaces, adapter, ifAttributes)[source]

Construct and write the iface declaration. The addrFam clause needs a little more processing.

_write_bridge(interfaces, adapter, ifAttributes)[source]

Write the bridge information.

_write_callbacks(interfaces, adapter, ifAttributes)[source]

Write the up, down, pre-up, pre-down, post-up, and post-down clauses.

_write_plugins(interfaces, adapter, ifAttributes)[source]

Write plugins options, currently hostapd.

_write_unknown(interfaces, adapter, ifAttributes)[source]

Write unknowns options

_write_sourced_paths(interfaces, adapter, ifAttributes)[source]

Write sourced paths

_backup_interfaces(adapters_paths)[source]

Backup interfaces file is the file exists

Returns:True/False, command output
Raises:IOError – if the copy fails and the source file exists
_restore_interfaces(adapters_paths)[source]

Restore interfaces file is the file exists

Returns:True/False, command output
Raises:IOError – if the copy fails and the source file exists

debinterface.toolutils

debinterface.toolutils.safe_subprocess(command_array)[source]

Executes shell command. Do not raise

Parameters:command_array (list) – ideally an array of string elements, but may be a string. Will be converted to an array of strings
Returns:True/False (command succeeded), command output
Return type:bool, str
debinterface.toolutils.atomic_write(*args, **kwds)[source]
Writeable file object that atomically updates a file
(using a temporary file).
Parameters:filepath (str) – the file path to be opened

Module contents

Imports for easier use

class debinterface.NetworkAdapter(options, interfaces_path=None)[source]

Bases: object

A representation a network adapter.

appendBropts(key, value)[source]

Set a discrete bridge option key with value

Parameters:
  • key (str) – the option key in the bridge option
  • value (any) – the value
appendDown(cmd)[source]

Append a shell command to run when the interface is down.

Parameters:cmd (str) – a shell command
appendPostDown(cmd)[source]

Append a shell command to run when the interface is post-down.

Parameters:cmd (str) – a shell command
appendPostUp(cmd)[source]

Append a shell command to run when the interface is post-up.

Parameters:cmd (str) – a shell command
appendPreDown(cmd)[source]

Append a shell command to run when the interface is pre-down.

Parameters:cmd (str) – a shell command
appendPreUp(cmd)[source]

Append a shell command to run when the interface is pre-up.

Parameters:cmd (str) – a shell command
appendUp(cmd)[source]

Append a shell command to run when the interface is up.

Parameters:cmd (str) – a shell command
attributes
display()[source]

Display a (kind of) human readable representation of the adapter.

export(options_list=None)[source]

Return a copy of the ifAttributes data structure as dict. You may optionally pass a list of options to return

Args:
options_list (list, optional): a list of options you want
Returns:
dict: the ifAttributes data structure, optionally filtered
get_attr(attr)[source]
replaceBropt(key, value)[source]

Set a discrete bridge option key with value

Parameters:
  • key (str) – the option key in the bridge option
  • value (any) – the value
reset()[source]

Initialize attribute storage structure.

setAddrFam(address_family)[source]

Set the address family option of an interface.

Parameters:address_family (str) – one of ‘inet’, ‘inet6’, ‘ipx’
Raises:ValueError – if there is a validation error
setAddress(ip_address)[source]

Set the ipaddress of an interface.

Parameters:ip_address (str) – the IP as a string
Raises:ValueError – if there is a validation error
setAddressSource(address_source)[source]

Set the address source for an interface.

Valid values are : dhcp, static, loopback, manual, bootp, ppp, wvdial, dynamic, ipv4ll, v4tunnel

Args:
address_source (string): address source for an interface
Raises:
ValueError: if there is a validation error
setAuto(auto)[source]

Set the option to autostart the interface.

Parameters:auto (bool) – interface will be set as auto if True
Raises:ValueError – if there is a validation error
setBroadcast(broadcast)[source]

Set the broadcast address of an interface.

Parameters:broadcast (str) – the broadcast IP as a string
Raises:ValueError – if there is a validation error
setBropts(opts)[source]

Set the bridge options of an interface.

Parameters:opts (dict) – a dictionary mapping option names and values. In the interfaces file, options will have a bridge prefix.
Raises:ValueError – if there is a validation error
setDnsNameservers(nameservers)[source]

Set the dns nameservers on the interface.

Parameters:nameservers (str, list) – the IP as a string
Raises:ValueError – if there is a validation error
setDnsSearch(searchUri)[source]

Set the dns default search URI.

Parameters:searchURI (str, list) – The default search domain
Raises:ValueError – if there is a validation error
setDown(down)[source]

Set and add to the down commands for an interface.

Parameters:down (list) – list of shell commands
setGateway(gateway)[source]

Set the default gateway of an interface.

Parameters:gateway (str) – the gateway IP as a string
Raises:ValueError – if there is a validation error
setHostapd(hostapd)[source]

Set the wifi conf file on the interface.

Raises:ValueError – if there is a validation error
setHotplug(hotplug)[source]

Set the option to allow hotplug on the interface. Beware, option is really called allow-hotplug, that’s a small historic cruft...

Args:
hotplug (bool): interface hotplug will be set if True
Raises:
ValueError: if there is a validation error
setName(name)[source]

Set the name option of an interface.

Parameters:name (str) – the name of the interface
Raises:ValueError – if there is a validation error
setNameservers(nameserver)[source]

Set the ipaddress of an interface.

Raises:ValueError – if there is a validation error
setNetmask(netmask)[source]

Set the netmask of an interface.

Parameters:netmask (str) – the netmask IP as a string
Raises:ValueError – if there is a validation error
setNetwork(network)[source]

Set the network identifier of an interface.

Parameters:network (str) – the IP as a string
Raises:ValueError – if there is a validation error
setPostDown(post)[source]

Set and add to the post-down commands for an interface.

Parameters:post (list) – list of shell commands
setPostUp(post)[source]

Set and add to the post-up commands for an interface.

Parameters:post (list) – list of shell commands
setPreDown(pre)[source]

Set and add to the pre-down commands for an interface.

Parameters:pre (list) – list of shell commands
setPreUp(pre)[source]

Set and add to the pre-up commands for an interface.

Parameters:pre (list) – list of shell commands
setUnknown(key, val)[source]

Stores uncommon options as there are with no special handling It’s impossible to know about all available options WARNING: duplicated directives are overwriten. TODO better

Args:
key (str): the option name val (any): the option value
setUp(up)[source]

Set and add to the up commands for an interface.

Parameters:up (list) – list of shell commands
setWpaConf(conf_path)[source]

Set the wpa supplicant configuration path for supplicant config for wireless interfaces.

Parameters:conf_path (str) – Path at which the supplicant config is located.
set_options(options)[source]

Set options, either only the name if options is a str, or all given options if options is a dict

Args:
options (str/dict): historical code... only set
the name if options is a str, or all given options if options is a dict
Raises:
ValueError: if validation error socket.error: if validation error of an IP Exception: if anything weird happens
validateAll()[source]

Not thorough validations... and quick coded.

Raises:ValueError – if there is a validation error
static validateIP(ip)[source]

Validate an IP Address. Works for subnet masks too. Tries ipv4 then ipv6

Args:
ip (str): the IP as a string
Raises:
socket.error on invalid IP
validateOne(opt, validations, val)[source]

Not thorough validations... and quick coded.

Parameters:
  • opt (str) – key name of the option
  • validations (dict) – contains the validations to checks
  • val (any) – the option value
Raises:

ValueError – if there is a validation error

class debinterface.NetworkAdapterValidation[source]

Bases: object

Class to validate an adapter. It validates some options for: - presence - type - authorized values

validate_all(if_attributes)[source]

Not thorough validations... and quick coded.

Parameters:if_attributes (dict) – the dict representation of the interface
Raises:ValueError – if there is a validation error
static validate_broadcast_ip(ip, opt)[source]

Validate an IP Address. Works for subnet masks too.

Parameters:
  • ip (str) – the IP as a string
  • opt (str) – the opt name
Raises:

ValueError – on invalid IP

static validate_ip(ip, opt)[source]

Validate an IP Address. Works for subnet masks too.

Parameters:
  • ip (str) – the IP as a string
  • opt (str) – the opt name
Raises:

ValueError – on invalid IP

validate_one(opt, validations, val)[source]

Not thorough validations... and quick coded.

Parameters:
  • opt (str) – key name of the option
  • validations (dict) – contains the validations to checks
  • val (any) – the option value
Raises:

ValueError – if there is a validation error

class debinterface.DnsmasqRange(path, backup_path=None, leases_path='/var/tmp/dnsmasq.leases')[source]

Bases: object

Basic dnsmasq conf of the more file which holds the ip ranges per interface. Made for handling very basic dhcp-range options

apply_changes()[source]

Write changes to fs and restart daemon

backup()[source]

return True/False, command output

backup_path = None
clear_leases()[source]

rm /var/tmp/dnsmasq.leases

config
static controlService(action)[source]

return True/False, command output

delete()[source]

return True/False, command output

get_itf_range(if_name)[source]

If no interface, return None

read(path=None)[source]
restore()[source]

return True/False, command output

rm_itf_range(if_name)[source]

Rm range info for the given interface

Parameters:if_name (str) – interface name
Returns:True if configuration was updated, False otherwise
Return type:bool
set(key, value)[source]
set_defaults()[source]

Defaults for my needs, you should probably override this one

update_range(interface, start, end, lease_time)[source]

Update existing range based on the interface name If does not exist will be created

Parameters:
  • interface (str) – interface name
  • start (str) – start ip of range
  • end (str) – end ip of range
  • lease_time (str) – lease_time
Returns:

True if configuration was updated or created,

False otherwise

Return type:

bool

validate()[source]
write(path=None)[source]
class debinterface.Hostapd(path, backup_path=None)[source]

Bases: object

basic hostapd conf file handling

backup()[source]

return True/False, command output

backup_path = None
config
static controlService(action)[source]

return True/False, command output

delete()[source]

return True/False, command output

read(path=None)[source]
restore()[source]

return True/False, command output

set(key, value)[source]
set_defaults()[source]

ssid and wpa_passphrase defaults to cashpad-FTED and cashpad-GH67

validate()[source]

Not sure which ones are really necessary for everyone, here are the ones I require. I created 4 groups of keys : basic must always be there, wireless if you want to be an AP, auth if you want to add some security, bridge for, well, bridging Not foul proof !

Returns:

True if everything went ok

Return type:

bool

Raises:
  • KeyError – missing key
  • ValueError – invalid data
write(path=None)[source]
class debinterface.Interfaces(update_adapters=True, interfaces_path='/etc/network/interfaces', backup_path=None, header_comment=None)[source]

Bases: object

By default read interface file on init

Parameters:
  • update_adapters (bool, optional) – load adapters from interface file. Default True
  • interfaces_path (str, optional) – default to /etc/network/interfaces
  • backup_path (str, optional) – default to /etc/network/interfaces.bak
  • header_comment (str, optional) – default to none, otherwise sets comments at the top of the interfaces file.
_set_paths(interfaces_path, backup_path)[source]

Either use user input or defaults

Parameters:
  • interfaces_path (str) – path to interfaces file
  • backup_path (str) – default to interfaces_path + .bak
adapters
addAdapter(options, index=None, interfaces_path=None)[source]

Insert a NetworkAdapter before the given index or at the end of the list. Options should be a string (name) or a dict

Parameters:
  • options (string or dict) – options to build a network adaptator
  • index (integer, optional) – index to insert the NetworkAdapter
  • interfaces_path (str, optional) – path to the source file of the adadpter.
Returns:

the new adapter

Return type:

NetworkAdapter

backup_path
static downAdapter(if_name)[source]

Uses ifdown

Parameters:if_name (str) – the name of the interface
Returns:True/False, command output.
Return type:bool, str
getAdapter(name)[source]

Find adapter by interface name

Parameters:name (str) – the name of the interface
Returns:the new adapter or None if not found
Return type:NetworkAdapter
header_comment
interfaces_path

Returns the path of the main interface file Others may come from the source directive. Adapters register the path

removeAdapter(index)[source]

Remove the adapter at the given index. TODO: handle file deletion of sourced paths

Args:
index (int): the position of the adapter
removeAdapterByName(name)[source]

Remove the adapter with the given name.

Parameters:name (str) – the name of the interface
static upAdapter(if_name)[source]

Uses ifup

Parameters:if_name (str) – the name of the interface
Returns:True/False, command output.
Return type:bool, str
updateAdapters()[source]

(re)read interfaces file and save adapters

writeInterfaces()[source]

write adapters to interfaces file

class debinterface.InterfacesReader(interfaces_path)[source]

Bases: object

Short lived class to read interfaces file

_read_auto(line)[source]

Identify which adapters are flagged auto.

_read_file(current_path)[source]

Open up the given interfaces file. Read only. If a source directive is found, it will call itself recursively

_read_hotplug(line)[source]

Identify which adapters are flagged allow-hotplug.

_read_sourced_path(line)[source]

Identify source path/to/file. If so will return the path to open it. Relative paths will be expanded from root path

Returns:
str: absolute path to the sourced file
adapters
header_comments
parse_interfaces(read_comments=False)[source]

Read /etc/network/interfaces (or specified file). Save adapters Return an array of networkAdapter instances.

class debinterface.InterfacesWriter(adapters, interfaces_path, backup_path=None, header_comment=None)[source]

Bases: object

Short lived class to write interfaces file

if backup_path is None => no backup

_backup_interfaces(adapters_paths)[source]

Backup interfaces file is the file exists

Returns:True/False, command output
Raises:IOError – if the copy fails and the source file exists
_check_interfaces(interfaces_path)[source]

Uses ifup to check interfaces file. If it is not in the default place, each interface must be checked one by one.

Parameters:interfaces_path (string) – the path to interfaces file
Raises:ValueError – if invalid network interfaces
_restore_interfaces(adapters_paths)[source]

Restore interfaces file is the file exists

Returns:True/False, command output
Raises:IOError – if the copy fails and the source file exists
_write_addrFam(interfaces, adapter, ifAttributes)[source]

Construct and write the iface declaration. The addrFam clause needs a little more processing.

_write_auto(interfaces, adapter, ifAttributes)[source]

Write if applicable

_write_bridge(interfaces, adapter, ifAttributes)[source]

Write the bridge information.

_write_callbacks(interfaces, adapter, ifAttributes)[source]

Write the up, down, pre-up, pre-down, post-up, and post-down clauses.

_write_hotplug(interfaces, adapter, ifAttributes)[source]

Write if applicable

_write_plugins(interfaces, adapter, ifAttributes)[source]

Write plugins options, currently hostapd.

_write_sourced_paths(interfaces, adapter, ifAttributes)[source]

Write sourced paths

_write_unknown(interfaces, adapter, ifAttributes)[source]

Write unknowns options

adapters
write_interfaces()[source]