Examples: Inventory Items
Creating (importing) and managing inventory items such as TWAMP reflectors and Y.1731 MEPs is done in a similar way as for Test Agents. Below is XML and NETCONF code for defining such entities in Paragon Active Assurance through the NETCONF & YANG API and for retrieving lists of the items defined.
Creating a TWAMP Reflector
with manager.connect(host=args.host, port=args.port, username=args.username, password=args.password, hostkey_verify=False) as m: # Create TWAMP reflector in account xml = """<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <accounts xmlns="http://ncc.netrounds.com"> <account> <name>{account}</name> <twamp-reflectors> <twamp-reflector> <name>{name}</name> <address>{address}</address> <port>{port}</port> <control-port>{control}</control-port> </twamp-reflector> </twamp-reflectors> </account> </accounts> </config>""".format(account=args.netrounds_account, name='My TWAMP Reflector', address='192.168.6.113', port=21000, control=862) monitor = m.edit_config(target='running', config=xml)
Creating a Y.1731 MEP
with manager.connect(host=args.host, port=args.port, username=args.username, password=args.password, hostkey_verify=False) as m: # Create Y.1731 MEP in account xml = """<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <accounts xmlns="http://ncc.netrounds.com"> <account> <name>{account}</name> <y1731-meps> <y1731-mep> <name>{y1731_mep}</name> <mac>{mac}</mac> <meg-level>{meg_level}</meg-level> </y1731-mep> </y1731-meps> </account> </accounts> </config>""".format(account=args.netrounds_account, y1731_mep='Y1731', mac='08:00:27:aa:95:d1', meg_level=2) monitor = m.edit_config(target='running', config=xml)
Creating an IPTV Channel
with manager.connect(host=args.host, port=args.port, username=args.username, password=args.password, hostkey_verify=False) as m: # Create IPTV channel in account xml = """<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <accounts xmlns="http://ncc.netrounds.com"> <account> <name>(account}</name> <iptv-channels> <iptv-channel> <name>{iptv_channel_name}</name> <ip>{ip}</ip> <source>{source}</source> <port>{port}</port> <pnum>{pnum}</pnum> </iptv-channel> </iptv-channels> </account> </accounts> </config>""".format(account=args.netrounds_account, iptv_channel_name='My TV Channel', ip='226.226.226.0', source='226.226.226.0', port=123, pnum=123) monitor = m.edit_config(target='running', config=xml)
Creating a Ping Host
with manager.connect(host=args.host, port=args.port, username=args.username, password=args.password, hostkey_verify=False) as m: # Create Ping host in account xml = """<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <accounts xmlns="http://ncc.netrounds.com"> <account> <name>{account}</name> <ping-hosts> <ping-host> <name>{name}</name> <host>{host}</host> <gps-lat>{gps_lat}</gps-lat> <gps-long>{gps_long}</gps-long> </ping-host> </ping-hosts> </account> </accounts> </config>""".format(account=args.netrounds_account, name='My Ping Host', host='192.168.6.113', gps_lat=22.11, gps_long=-40.40)
Creating a SIP Account
with manager.connect(host=args.host, port=args.port, username=args.username, password=args.password, hostkey_verify=False) as m: # Create SIP account in product account xml = """<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <accounts xmlns="http://ncc.netrounds.com"> <account> <name>{account}</name> <sip-accounts> <sip-account> <sip-address>{sip_address}</sip-address> <password>{password}</password> <registrar>{registrar}</registrar> <proxy>{proxy}</proxy> <user-auth>{user_auth}</user-auth> <uri-rewrite>{uri_rewrite}</uri-rewrite> </sip-account> </sip-accounts> </account> </accounts> </config>""".format(account=args.netrounds_account, sip_address='user_name@example.com', password='my_password', registrar='8.8.8.8', proxy='example.com', user_auth='my_auth_id', uri_rewrite='abc') monitor = m.edit_config(target='running', config=xml)
Retrieving Inventory Items
Below is Python code for retrieving all inventory items defined in an account. (All
types of inventory items are fetched in one go here in order to avoid some
repetition in the document. Naturally, any subset of inventory items can be fetched
by leaving out some of the lines under account
below.)
with manager.connect(host=args.host, port=args.port, username=args.username, password=args.password, hostkey_verify = False) as m: # Get inventory items from account xml = """<accounts xmlns="http://ncc.netrounds.com"> <account> <name>{account}</name> <twamp-reflectors></twamp-reflectors> <y1731-meps></y1731-meps> <iptv-channels></iptv-channels> <sip-accounts></sip-accounts> </account> </accounts>""".format(account=args.netrounds_account) # Convert to ElementTree object ele = to_ele(m.get_config(source='running', filter=('subtree', xml)).data_xml) # Convert back to XML string and print print to_xml(ele, encoding='UTF-8', pretty_print=True)
Running this code gives output like that below:
<?xml version="1.0" ?> <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"> <accounts xmlns="http://ncc.netrounds.com"> <account> <name xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">demo</name> <twamp-reflectors> <twamp-reflector> <name>My TWAMP Reflector</name> <address>192.168.6.113</address> <port>21000</port> <control-port>862</control-port> </twamp-reflector> </twamp-reflectors> <y1731-meps> <y1731-mep> <name>Y1731</name> <mac>08:00:27:aa:95:d1</mac> <meg-level>2</meg-level> </y1731-mep> </y1731-meps> <iptv-channels> <iptv-channel> <name>My TV Channel</name> <ip>226.226.226.0</ip> <source>226.226.226.0</source> <port>123</port> <pnum>123</pnum> </iptv-channel> </iptv-channels> <sip-accounts> <sip-account> <sip-address>user_name@example.com</sip-address> <password>my_password</password> <registrar>8.8.8.8</registrar> <proxy>example.com</proxy> <user-auth>my_auth_id</user-auth> <uri-rewrite>abc</uri-rewrite> </sip-account> </sip-accounts> </account> </accounts> </data>