Networking Script python reference

Main interface functions wrapped with lmi commands are:

All of these accept ns object as the first argument. It is an instance of lmi.shell.LMINamespace.

Networking Module API

LMI networking provider client library.

lmi.scripts.networking.SETTING_IP_METHOD_DHCP = 4

IP configuration obtained from DHCP server

lmi.scripts.networking.SETTING_IP_METHOD_DHCPv6 = 7

IP configuration obtained from DHCPv6 server

lmi.scripts.networking.SETTING_IP_METHOD_DISABLED = 0

Disabled IP configuration

lmi.scripts.networking.SETTING_IP_METHOD_STATELESS = 9

Stateless IPv6 configuration

lmi.scripts.networking.SETTING_IP_METHOD_STATIC = 3

Static IP address configuration

lmi.scripts.networking.SETTING_TYPE_BOND_MASTER = 4

Configuration for bond master

lmi.scripts.networking.SETTING_TYPE_BOND_SLAVE = 40

Configuration for bond slave

lmi.scripts.networking.SETTING_TYPE_BRIDGE_MASTER = 5

Configuration for bridge master

lmi.scripts.networking.SETTING_TYPE_BRIDGE_SLAVE = 50

Configuration for bridge slave

lmi.scripts.networking.SETTING_TYPE_ETHERNET = 1

Configuration for ethernet

lmi.scripts.networking.SETTING_TYPE_UNKNOWN = 0

Unknown type of setting

lmi.scripts.networking.activate(ns, setting, device=None)

Activate network setting on given device

Parameters:
  • setting (LMI_IPAssignmentSettingData) – Setting to be activated.
  • device (LMI_IPNetworkConnection or None) – Device to activate the setting on or None for autodetection
lmi.scripts.networking.add_dns_server(ns, setting, address)

Add a dns server to the given setting.

Parameters:
  • setting (LMI_IPAssignmentSettingData) – network setting.
  • address (str) – IPv4 or IPv6 address.
lmi.scripts.networking.add_ip_address(ns, setting, address, prefix, gateway=None)

Add an IP address to the given static setting.

Parameters:
  • setting (LMI_IPAssignmentSettingData) – network setting.
  • address (str) – IPv4 or IPv6 address.
  • prefix (int) – network prefix.
  • gateway (str or None) – default gateway or None
lmi.scripts.networking.add_static_route(ns, setting, address, prefix, metric=None, next_hop=None)

Add a static route to the given setting.

Parameters:
  • setting (LMI_IPAssignmentSettingData) – network setting.
  • address (str) – IPv4 or IPv6 address.
  • prefix (int) – network prefix.
  • metric – metric for the route or None
  • next_hop (str or None) – IPv4 or IPv6 address for the next hop of the route or None
lmi.scripts.networking.create_setting(ns, caption, device, type, ipv4method, ipv6method)

Create new network setting.

Parameters:
  • caption (str) – Caption for the new setting.
  • device (LMI_IPNetworkConnection) – Device for which the setting will be.
  • type (SETTING_TYPE_* constant) – Type of the setting.
  • ipv4method (SETTING_IP_METHOD_* constant) – Method for obtaining IPv4 address.
  • ipv4method – Method for obtaining IPv6 address.
lmi.scripts.networking.deactivate(ns, setting, device=None)

Deactivate network setting.

Parameters:
  • setting (LMI_IPAssignmentSettingData) – Setting to deactivate.
  • device (LMI_IPNetworkConnection or None) – Device to deactivate the setting on
lmi.scripts.networking.delete_setting(ns, setting)

Delete existing network setting.

Parameters:setting (LMI_IPAssignmentSettingData) – network setting.
lmi.scripts.networking.enslave(ns, master_setting, device)

Create slave setting of the master_setting with given device.

Parameters:
  • master_setting (LMI_IPAssignmentSettingData) – Master setting to use
  • device (LMI_IPNetworkConnection) – Device to enslave
lmi.scripts.networking.get_active_settings(ns, device)

Get a list of settings that are currently active on the device

Parameters:device (LMI_IPNetworkConnection) – network device
Returns:Settings that are active on the device
Return type:list of LMI_IPAssignmentSettingData
lmi.scripts.networking.get_applicable_devices(ns, setting)

Get list of network devices that this setting can be applied to.

Parameters:setting (LMI_IPAssignmentSettingData) – network setting
Returns:devices that the setting can be applied to
Return type:list of LMI_IPNetworkConnection
lmi.scripts.networking.get_autoconnect(ns, setting, device=None)

Return True if device is activated automatically.

Parameters:setting (LMI_IPAssignmentSettingData) – Setting whose autoconnection status will be read
lmi.scripts.networking.get_available_settings(ns, device)

Get a list of settings that can be applied to given device

Parameters:device (LMI_IPNetworkConnection) – network device
Returns:Settings applicable to the device
Return type:list of LMI_IPAssignmentSettingData
lmi.scripts.networking.get_default_gateways(ns, device)

Get a list of default gateways assigned to given device

Parameters:device (LMI_IPNetworkConnection) – network device
Returns:Default gateways assigned to the device
Return type:list of str
lmi.scripts.networking.get_device_by_name(ns, device_name)

Get instance of LMI_IPNetworkConnection class by the device name.

Parameters:device_name (str) – Name of the device.
Returns:LMI_IPNetworkConnection representing the device.
Return type:LMI_IPNetworkConnection or None if not found
lmi.scripts.networking.get_dns_servers(ns, device)

Get a list of DNS servers assigned to given device

Parameters:device (LMI_IPNetworkConnection) – network device
Returns:DNS servers assigned to the device
Return type:list of str
lmi.scripts.networking.get_ip_addresses(ns, device)

Get a list of IP addresses assigned to given device

Parameters:device (LMI_IPNetworkConnection) – network device
Returns:IP addresses with subnet masks (IPv4) or prefixes (IPv6) that is assigned to the device.
Return type:list of tuple (IPAddress, SubnetMask/Prefix)
lmi.scripts.networking.get_ipv4_addresses(ns, device)

Get a list of IPv4 addresses assigned to given device

Parameters:device (LMI_IPNetworkConnection) – network device
Returns:IPv4 addresses with subnet masks that is assigned to the device.
Return type:list of tuple (IPAddress, SubnetMask)
lmi.scripts.networking.get_ipv6_addresses(ns, device)

Get a list of IPv6 addresses assigned to given device

Parameters:device (LMI_IPNetworkConnection) – network device
Returns:IPv6 addresses with prefixes that is assigned to the device.
Return type:list of tuple (IPAddress, Prefix)
lmi.scripts.networking.get_mac(ns, device)

Get a MAC address for given device.

Parameters:device (LMI_IPNetworkConnection) – network device
Returns:MAC address of given device or 00:00:00:00:00:00 when no MAC is found.
Return type:str
lmi.scripts.networking.get_setting_by_caption(ns, caption)

Get instance of LMI_IPAssignmentSettingData class by the caption.

Parameters:caption (str) – Caption of the setting.
Returns:LMI_IPAssignmentSettingData representing the setting.
Return type:LMI_IPAssignmentSettingData or None if not found
lmi.scripts.networking.get_setting_ip4_method(ns, setting)

Get method of obtaining IPv4 configuration on given setting

Parameters:setting (LMI_IPAssignmentSettingData) – network setting
Returns:IPv4 method
Return type:SETTING_IP_METHOD_* constant
lmi.scripts.networking.get_setting_ip6_method(ns, setting)

Get method of obtaining IPv6 configuration on given setting

Parameters:setting (LMI_IPAssignmentSettingData) – network setting
Returns:IPv6 method
Return type:SETTING_IP_METHOD_* constant
lmi.scripts.networking.get_setting_type(ns, setting)

Get type of the setting

Parameters:setting (LMI_IPAssignmentSettingData) – network setting
Returns:type of setting
Return type:SETTING_TYPE_* constant
lmi.scripts.networking.get_static_routes(ns, setting)

Return list of static routes for given setting

Parameters:setting (LMI_IPAssignmentSettingData) – network setting
Returns:list of static routes
Return type:list of LMI_IPRouteSettingData
lmi.scripts.networking.get_sub_setting(ns, setting)

Get list of detailed configuration setting for each part of the setting.

Parameters:setting (LMI_IPAssignmentSettingData) – network setting
Returns:detailed setting
Return type:list of LMI_IPAssignmentSettingData subclasses
lmi.scripts.networking.is_setting_active(ns, setting)

Return true if the setting is currently active

Parameters:setting (LMI_IPAssignmentSettingData) – network setting
Retval True:setting is currently active
Retval False:setting is not currently active
Return type:bool
lmi.scripts.networking.list_devices(ns, device_names=None)

Get a list of network devices.

Parameters:device_name (list of str) – List of device names that will be used as filter for devices.
Returns:List of instances of LMI_IPNetworkConnection
Return type:list of LMI_IPNetworkConnection
lmi.scripts.networking.list_settings(ns, captions=None)

Get a list of network settings.

Parameters:captions (list of str) – List of setting captions that will be used as filter for settings.
Returns:Settings that matches given captions
Return type:list of LMI_IPAssignmentSettingData
lmi.scripts.networking.remove_dns_server(ns, setting, address)

Remove dns server from given setting.

Parameters:
  • setting (LMI_IPAssignmentSettingData) – network setting.
  • address (str) – IPv4 or IPv6 address.
lmi.scripts.networking.remove_ip_address(ns, setting, address)

Remove the IP address from given static setting.

Parameters:
  • setting (LMI_IPAssignmentSettingData) – network setting.
  • address (str) – IPv4 or IPv6 address.
lmi.scripts.networking.remove_static_route(ns, setting, address)

Remove static route to the given setting.

Parameters:
  • setting (LMI_IPAssignmentSettingData) – network setting.
  • address (str) – IPv4 or IPv6 address.
lmi.scripts.networking.replace_dns_server(ns, setting, address)

Remove all dns servers and add given dns server to the given setting.

Parameters:
  • setting (LMI_IPAssignmentSettingData) – network setting.
  • address (str) – IPv4 or IPv6 address.
lmi.scripts.networking.replace_ip_address(ns, setting, address, prefix, gateway=None)

Remove all IP addresses from given static setting and add new IP address.

Parameters:
  • setting (LMI_IPAssignmentSettingData) – network setting.
  • address (str) – IPv4 or IPv6 address.
  • prefix (int) – network prefix.
  • gateway (str or None) – default gateway or None
lmi.scripts.networking.replace_static_route(ns, setting, address, prefix, metric=None, next_hop=None)

Remove all static routes and add given static route to the given setting.

Parameters:
  • setting (LMI_IPAssignmentSettingData) – network setting.
  • address (str) – IPv4 or IPv6 address.
  • prefix (int) – network prefix.
  • metric – metric for the route or None
  • next_hop (str or None) – IPv4 or IPv6 address for the next hop of the route or None
lmi.scripts.networking.set_autoconnect(ns, setting, device=None, state=True)

Enable/disable automatical activation of the setting.

Parameters:
  • setting (LMI_IPAssignmentSettingData) – Setting that will be affected
  • state (bool) – True for autoconnection activation, False for deactivation