Hi all,
I have recently started going through the onePK Python tutorial examples from the all in one downloadable VM and have had a reasonbly painless experience thus far. The tutorial examples are intuitive enough but they leave me questioning the Python API documentation and progress of API coverage. Exploring this currently in 'learner/n00b mode', currently I want to do basic things like change the hostname of the network element just to prove out that setting and getting properties works. Also it's something that most people who would like to see a demo want to see i.e. something safe. So, my first question: Does the Python onePK library support the setting of element properties? If so, does anyone have an example? Third question: Presuming that the Python library supports the setting of properties as well as getting of, is there a referenceable document which covers this? I can't find anything. Perhaps it's down to me being a bit new with onePK and not knowing my way around (yet)!
Thanks in advance.
David
The python API is less complete than java which is less complete than the one for C.
It seems that python is not a priority event if it's supported.
I've check as you and I don't see in the doc something about setting the hostname. Even in Java.
It's possible via VTY but is not portable.
As a safe test you could set the location of the networkElement and read it just after ?
get_location(self)
Gets a Location object associated with the network element.
set_location(self, location)
Sets location information for the network element.
Or doing some test with interfaces that you don't use.
Hope it's help.
Jc
OnePK is not [yet] an API to do configuration deployments. Something like changing the hostname is a configuration change. All of onePK changes are designed to be transient. That is, they only last as long as the application is connected to the network element. There are some exceptions (i.e., ACLs can be made persistent by setting their lifetime), but in general, nothing from onePK will be placed in the running configuration.
So the short answer to your question is, no. You cannot change the hostname. You can, however, apply dynamic ACLs, QoS policies, gather statistics, and react to cert events using the Python API.
There is an "workaround" for what you want to do, though. Look at the VTY Service Service (com.cisco.onep.vty). This Service Set lets you pass raw CLI commands over the onePK channel. You need to enable the VTY SS on the device first using:
onep
service set vty
But after that, config t CLI you pass over this channel will be placed in the running config just as with manual CLI.
Jc & Joe,
Thanks for both responding so quickly.
Joe - makes perfect sense and I feel like I've just had the blinkers widened. Thanks. Feel a bit dumb now for asking! Hopefully this thread will be of use for someone who starts out down the same path of thinking the same as I have.
Jc - thanks for responding so quickly and helpfully.
Thanks again,
David
Python API 1.1.0
1) Yes, I use it for setting ACL, Class maps and route-maps(VTY service set) and routing listeners.
3) API has not all features, which are in documentations. For example: some features not exist in policymap (ZBFW, PBR,...)
2)
very small example:
'''
Very small example
onepk 1.1.0 - python API
'''
import GosiaParse
import NetworkElement
import onep.interfaces.InterfaceFilter as onepInterfaceFilter
#Load configuration for connect to device
devices = GosiaParse.ParserOperation("GosiaJson.json")
#Crate element and connect on it
testnode = NetworkElement.NetworkElement(**devices.get_device_router_connect_info_v4("1"))
testnode.connect()
#get onePK element => onepk.element
element = testnode.get_network_element()
#get properties of element
element_properties = element.properties
print element_properties
#get interfaces of device
list_of_interfaces = element.get_interface_dict(onepInterfaceFilter())
for interface in list_of_interfaces:
print interface
#disconnect
testnode.disconnect()
I develop only with ipython and documentations.