All example scripts are for lmishell. See it’s documentation on OpenLMI page.
We also assume that lmishell is connected to the CIMOM and the connection is stored in connection variable:
connection = connect("server", "username", "password")
Obtaining a list of network devices can be done by executing following commands in lmishell:
for device in connection.root.cimv2.LMI_IPNetworkConnection.instances():
print device.ElementName
Obtaining parameters of network device might be a little bit tricky. DMTF standards split network device to three classes and one might need to traverse between them through associations, see Networking API concepts.
Following example prints name, its status, MAC address, link technology and maximal speed for each device.
MAC address is not in the LMI_IPNetworkConnection class and must be accessed through LMI_EndpointForIPNetworkConnection association to LMI_LANEndpoint class, same for MaxSpeed and LinkTechnology, those are in CIM_NetworkPort subclasses, associated through LMI_NetworkDeviceSAPImplementation class:
for device in connection.root.cimv2.LMI_IPNetworkConnection.instances():
# print device name
print device.ElementName,
# print operating status
print connection.root.cimv2.LMI_IPNetworkConnection.OperatingStatusValues.value_name(device.OperatingStatus),
# MAC address in not part of LMI_IPNetworkConnection but LMI_LANEndpoint class,
# which is associated through LMI_EndpointForIPNetworkConnection
lanendpoint = device.first_associator(AssocClass="LMI_EndpointForIPNetworkConnection")
# print MAC address
print lanendpoint.MACAddress,
# LinkTechnology is part of CIM_NetworkPort subclasses, we need to traverse
# through LMI_NetworkDeviceSAPImplementation association
networkport = lanendpoint.first_associator(AssocClass="LMI_NetworkDeviceSAPImplementation")
# print link technology
print connection.root.cimv2.CIM_NetworkPort.LinkTechnologyValues.value_name(networkport.LinkTechnology),
# network speed might not be defined
if networkport.MaxSpeed:
# Convert bps to Mbps
print "%dMbps" % (networkport.MaxSpeed // (1024*1024)),
else:
print "unknown",
print
Current IP addresses are in the LMI_IPProtocolEndpoint class associated to given :ref:LMI_IPNetworkConnection<LMI-IPNetworkConnection>`:
device = connection.root.cimv2.LMI_IPNetworkConnection.first_instance({'ElementName': 'eth0'})
for endpoint in device.associators(AssocClass="LMI_NetworkSAPSAPDependency", ResultClass="LMI_IPProtocolEndpoint"):
if endpoint.ProtocolIFType == connection.root.cimv2.LMI_IPProtocolEndpoint.ProtocolIFTypeValues.IPv4:
print "IPv4: %s/%s" % (endpoint.IPv4Address, endpoint.SubnetMask)
elif endpoint.ProtocolIFType == connection.root.cimv2.LMI_IPProtocolEndpoint.ProtocolIFTypeValues.IPv6:
print "IPv6: %s/%d" % (endpoint.IPv6Address, endpoint.IPv6SubnetPrefixLength)
# TODO: Work in progress (IPv4 and IPv6 addresses, default gateways, DNS)
Bring up / take down a network device Enumerate available settings (configurations for network device) Create new setting with independent IPv4 and IPv6 configuration (static addresses, DHCP(v6), Stateless, disabled), default gateway Set DNS servers for given setting Manage static routes for given setting Apply setting to network device: * Multiple modes: immediate activation and/or setting it as permanent * Immediate applying is done asynchronously (can take quite a long time)
Delete setting Bridging/bonding: * Create bridge/bond setting * Enslave network device * Delete bridge/bond Notification about changes in network devices and settings (created, modified, deleted)