pynos package

Subpackages

Submodules

pynos.device module

Copyright 2015 Brocade Communications Systems, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class pynos.device.Device(**kwargs)[source]

Bases: object

Device object holds the state for a single NOS device.

bgp

BGP related actions and attributes.

interface

Interface related actions and attributes.

snmp

SNMP related actions and attributes.

lldp

LLDP related actions and attributes.

system

System level actions and attributes.

close()[source]

Close NETCONF session.

Parameters:None
Returns:None
Raises:None

Examples

>>> import pynos.device
>>> conn = ('10.24.39.211', '22')
>>> auth = ('admin', 'password')
>>> dev = pynos.device.Device(conn=conn, auth=auth)
>>> dev.connection
True
>>> dev.close() 
<?xml...<rpc-reply...<ok/>...
>>> dev.connection
False
connection

Poll if object is still connected to device in question.

Parameters:None
Returns:True if connected, False if not.
Return type:bool
Raises:None
find_interface_by_mac(**kwargs)[source]

Find the interface through which a MAC can be reached.

Parameters:mac_address (str) – A MAC address in ‘xx:xx:xx:xx:xx:xx’ format.
Returns:a list of mac table data.
Return type:list[dict]
Raises:KeyError – if mac_address is not specified.

Examples

>>> from pprint import pprint
>>> import pynos.device
>>> conn = ('10.24.39.211', '22')
>>> auth = ('admin', 'password')
>>> with pynos.device.Device(conn=conn, auth=auth) as dev:
...     x = dev.find_interface_by_mac(
...     mac_address='10:23:45:67:89:ab')
...     pprint(x) 
[{'interface'...'mac_address'...'state'...'type'...'vlan'...}]
firmware_version

Returns firmware version.

Parameters:None
Returns:Dictionary
Raises:None
mac_table

list[dict] – the MAC table of the device.

reconnect()[source]

Reconnect session with device.

Parameters:None
Returns:True if reconnect succeeds, False if not.
Return type:bool
Raises:None
exception pynos.device.DeviceCommError[source]

Bases: exceptions.Exception

Error with device communication.

pynos.utilities module

Copyright 2015 Brocade Communications Systems, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

pynos.utilities.merge_xml(first_doc, second_doc)[source]

Merges two XML documents.

Parameters:
  • first_doc (str) – First XML document. second_doc is merged into this document.
  • second_doc (str) – Second XML document. It is merged into the first.
Returns:

The merged document.

Return type:

XML Document

Raises:

None

Example

>>> import pynos.utilities
>>> import lxml
>>> import xml
>>> x = xml.etree.ElementTree.fromstring('<config />')
>>> y = lxml.etree.fromstring('<config><hello /></config>')
>>> x = pynos.utilities.merge_xml(x, y)
pynos.utilities.print_xml_string(element_tree)[source]

Prints the string representation of an XML Element.

Parameters:element_tree (Element) – XML Element to be returned. If sent as a str, this function will attempt to convert it to an Element.
Returns:An XML Element.
Return type:Element
Raises:AttributeError – if element_tree is not of type Element.

Examples

>>> import pynos.utilities
>>> import xml.etree.ElementTree as ET
>>> pynos.utilities.print_xml_string(ET.Element('config'))
<config />
>>> pynos.utilities.print_xml_string(
... ['hodor']) 
Traceback (most recent call last):
AttributeError
pynos.utilities.return_xml(element_tree)[source]

Return an XML Element.

Parameters:element_tree (Element) – XML Element to be returned. If sent as a str, this function will attempt to convert it to an Element.
Returns:An XML Element.
Return type:Element
Raises:TypeError – if element_tree is not of type Element and it cannot be converted from a str.

Examples

>>> import pynos.utilities
>>> import xml.etree.ElementTree as ET
>>> ele = pynos.utilities.return_xml(ET.Element('config'))
>>> assert isinstance(ele, ET.Element)
>>> ele = pynos.utilities.return_xml('<config />')
>>> assert isinstance(ele, ET.Element)
>>> ele = pynos.utilities.return_xml(
... ['hodor']) 
Traceback (most recent call last):
TypeError
pynos.utilities.valid_interface(int_type, name)[source]

Validates an interface type and name.

Parameters:
  • int_type (str) – Interface type. Examples: gigabitethernet, tengigabitethernet, port_channel.
  • name (str) – Port designator. Examples: 225/0/1, 1/0/1, 1.
Returns:

True if it is a valid interface. False if not.

Return type:

bool

Raises:

None

Examples

>>> import pynos.utilities
>>> int_type = 'tengigabitethernet'
>>> name = '225/0/1'
>>> pynos.utilities.valid_interface(int_type, name)
True
>>> name = '5/0'
>>> pynos.utilities.valid_interface(int_type, name)
False
>>> int_type = 'port_channel'
>>> name = '1'
>>> pynos.utilities.valid_interface(int_type, name)
True
>>> int_type = 'port_channel'
>>> name = '1/0'
>>> pynos.utilities.valid_interface(int_type, name)
False
pynos.utilities.valid_physical_name(name)[source]

Validates a physical interface.

Do not use this method directly. Use valid_interface instead.

Parameters:name (str) – Port designator. Examples: 225/0/1, 1/0/1.
Returns:True if it is a valid physical interface. False if not.
Return type:bool
Raises:None
pynos.utilities.valid_port_channel_name(name)[source]

Validates a Port-Channel.

Do not use this method directly. Use valid_interface instead.

Parameters:name (str) – Port designator. Examples: 1, 768, 3476.
Returns:True if it is a valid port-channel. False if not.
Return type:bool
Raises:None
pynos.utilities.valid_vlan_id(vlan_id, extended=True)[source]

Validates a VLAN ID.

Parameters:
  • vlan_id (integer) – VLAN ID to validate. If passed as str, it will be cast to int.
  • extended (bool) – If the VLAN ID range should be considered extended for Virtual Fabrics.
Returns:

True if it is a valid VLAN ID. False if not.

Return type:

bool

Raises:

None

Examples

>>> import pynos.utilities
>>> vlan = '565'
>>> pynos.utilities.valid_vlan_id(vlan)
True
>>> extended = False
>>> vlan = '6789'
>>> pynos.utilities.valid_vlan_id(vlan, extended=extended)
False
>>> pynos.utilities.valid_vlan_id(vlan)
True

Module contents

Copyright 2015 Brocade Communications Systems, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.