Ejemplo n.º 1
0
def sampleapp():
    appname = raw_input('Enter name of application : ')

    session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS) #default is TLS
    if transport.lower() == "tipc" or transport == 2:
        session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
    session_config.ca_certs = root_cert_path
    session_config.certfile = client_cert_path
    session_config.keyfile = client_key_path

    ne = NetworkElement(switchIP, appname)
    con = ne.connect(username, password, session_config)
    print 'Connected to host'

    print "System Name:            ", ne.properties.sys_name
    print "System Uptime:          ", ne.properties.sys_uptime
    print "Total System Memory:    ", ne.total_system_memory
    print "Free System Memory:     ", ne.free_system_memory
    print "System CPU Utilization: ", ne.system_cpu_utilization, "%\n"
    print "System Connect Time:    ", ne.get_connect_time()
    print "System Disonnect Time:  ", ne.get_disconnect_time()
    print "System __str__ Method:  ", ne
    print "Host Content String:\n",   ne.properties.content_string

    ne.disconnect()
Ejemplo n.º 2
0
    def jconnect(self):

        session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
        session_config.ca_certs = "/home/cisco/ca.pem"
        ne = self.myapp.get_network_element(self.address)

        if not ne.is_connected():
            try:
                # print 'Trying to connect...'
                session_handle = ne.connect(self.username, self.password, session_config)
                # print 'Connection made to ' + self.address + ' successfully.'
            except OnepDuplicateElementException, e:
                # print e
                existing = e.get_original_network_element()
                # print existing
                print "Unable to connect to device."
            except Exception, e:
                # print e
                print "Could not connect to " + self.address + ".  Please validate reachability."
                return "DNE"
Ejemplo n.º 3
0
		def jconnect(self):

			session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
			session_config.ca_certs = "/home/cisco/ca.pem"
			ne = self.myapp.get_network_element(self.address)

			if not ne.is_connected():
				try:
					#print 'Trying to connect...'
					session_handle = ne.connect(self.username, self.password, session_config)
					#print 'Connection made to ' + self.address + ' successfully.'
				except  OnepDuplicateElementException, e:
				    #print e
				    existing = e.get_original_network_element()
				    #print existing
				    print 'Unable to connect to device.'
				except  Exception, e:
				    #print e
				    print 'Could not connect to ' + self.address + '.  Please validate reachability.'
				    return 'DNE'
Ejemplo n.º 4
0
        def connect(self):

            session_config = SessionConfig(
                SessionConfig.SessionTransportMode.TLS)
            session_config.ca_certs = "/usr/local/certs/csr1kv-01.pem"
            ne = self.myapp.get_network_element(self._host)

            if not ne.is_connected():
                try:
                    session_handle = ne.connect(
                        self._username, self._password, session_config)
                    self._connected = True
                except OnepDuplicateElementException, e:
                    # print e
                    existing = e.get_original_network_element()
                    # print existing
                    print ('Unable to connect to device.')
                except Exception, e:
                    # print e
                    print('Could not connect to  {0} Please validate reachability.'.format(self._host))
                    return 'DNE'
Ejemplo n.º 5
0
def scaleNotification():

    for switch in switches:
        switchIP = switch[0]
        appName = switch[1]
        user = switch[2]
        pswd = switch[3]

        #
        # Set up session connection configuration and connect to the switch
        #
        ne = NetworkElement(switchIP, appName)
        if transport == 'TLS':
            session_config = SessionConfig(
                SessionConfig.SessionTransportMode.TLS)
            session_config.ca_certs = cert
            ne.connect(user, pswd, session_config)
        elif transport == 'TIPC':
            session_config = SessionConfig(
                SessionConfig.SessionTransportMode.TIPC)
            ne.connect(user, pswd, session_config)
        else:
            print "Please set-up a valid transport type: TIPC or TLS"
            exit(0)

        vty = VtyService(ne)
        vty.open()
        vlan_summary = vty.write("sh vlan summary")
        vty.close()

        vlan_sum = re.search('(?<=vlansum-all-vlan\t)(.*)', vlan_summary)

        if int(vlan_sum.group(0)) > int(scale_limits["max_vlans"]):
            string_print = "Vlan scale exceeded. Max vlan recommended:", scale_limits[
                "max_vlans"], "vlan being used :", vlan_sum.group(0)
            print string_print
            ne.create_syslog_message(
                ne.OnepSyslogSeverity.ONEP_SYSLOG_CRITICAL, str(string_print))
        print "Disconnecting from NE: ", switchIP
        ne.disconnect()
Ejemplo n.º 6
0
        def connect(self):

            session_config = SessionConfig(
                SessionConfig.SessionTransportMode.TLS)
            session_config.ca_certs = "/usr/local/certs/csr1kv-01.pem"
            ne = self.myapp.get_network_element(self._host)

            if not ne.is_connected():
                try:
                    session_handle = ne.connect(self._username, self._password,
                                                session_config)
                    self._connected = True
                except OnepDuplicateElementException, e:
                    # print e
                    existing = e.get_original_network_element()
                    # print existing
                    print('Unable to connect to device.')
                except Exception, e:
                    # print e
                    print(
                        'Could not connect to  {0} Please validate reachability.'
                        .format(self._host))
                    return 'DNE'
Ejemplo n.º 7
0
def scaleNotification():

    for switch in switches:
        switchIP = switch[0]
        appName  = switch[1]
        user     = switch[2]
        pswd     = switch[3]

        #
        # Set up session connection configuration and connect to the switch
        #
        ne = NetworkElement(switchIP, appName)
        if  transport == 'TLS':
            session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
            session_config.ca_certs = cert
            ne.connect(user, pswd, session_config)
        elif transport == 'TIPC':
            session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
            ne.connect(user, pswd, session_config)
        else:
            print "Please set-up a valid transport type: TIPC or TLS"
            exit(0)

        vty = VtyService(ne)
        vty.open()
        vlan_summary = vty.write("sh vlan summary")
        vty.close()

        vlan_sum = re.search('(?<=vlansum-all-vlan\t)(.*)',vlan_summary)

        if int(vlan_sum.group(0)) > int(scale_limits["max_vlans"]):
            string_print = "Vlan scale exceeded. Max vlan recommended:",scale_limits["max_vlans"],"vlan being used :", vlan_sum.group(0)
            print string_print
            ne.create_syslog_message (ne.OnepSyslogSeverity.ONEP_SYSLOG_CRITICAL,
                                      str(string_print));
        print "Disconnecting from NE: ",switchIP
        ne.disconnect()
transport= 'TLS'
cert     = '<path>/cacert.pem'
appName  = "intf_properties_cn"
switchIP = "<ip>"
user     = "******"
pswd     = "<pswd>"

#####################################################################

#
# Set up session connection configuration and connect to the switch
#
ne = NetworkElement(switchIP, appName)
if  transport == 'TLS':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
    session_config.ca_certs = cert
    ne.connect(user, pswd, session_config)
elif transport == 'TIPC':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
    ne.connect(user, pswd, session_config)
else:
    print "Please set-up a valid transport type: TIPC or TLS"
    exit(0)


RX_BYTES = InterfaceStatistics.InterfaceStatisticsParameter.ONEP_IF_STAT_RX_BYTES
FILTER =  InterfaceFilter(None, NetworkInterface.InterfaceTypes.ONEP_IF_TYPE_ETHERNET)

print "Getting Interface Statistics on", switchIP

intf_list_ne = ne.get_interface_list(FILTER)
Ejemplo n.º 9
0
#            transport
# appName  - OnePK application Name
# switchIP - management Switch IP address
# user     - switch userID
pswd = "<pswd>"

logMsg = "syslog generated by onePK"
#####################################################################

#
# Set up session connection configuration and connect to the switch
#
ne = NetworkElement(switchIP, appName)
if transport == 'TLS':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
    session_config.ca_certs = cert
    ne.connect(user, pswd, session_config)
elif transport == 'TIPC':
    session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
    ne.connect(user, pswd)
else:
    print "Please set-up a valid transport type: TIPC or TLS"
    exit(0)

#
# Create the syslog messange and disconnect from the device
#
print "Generating Syslog message."
ne.create_syslog_message(ne.OnepSyslogSeverity.ONEP_SYSLOG_CRITICAL, logMsg)
print "Check on switch logs using \"sh log log duration 00:05:00\" cli"