def establish_session(self): ''' Take a onepk network device and go through the steps to establish a session. This method assumes that you are using a PIN_FILE Sets the following attributes self.network_application self.net_element self.session_config self.session_handle ''' # Create NetworkApplication instance self.network_application = NetworkApplication.get_instance() # Create NetworkElement instance self.net_element = self.network_application.get_network_element(self.ip) # Create SessionConfig instance session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS) session_config.ca_certs = None session_config.keyfile = None session_config.certfile = None session_config.port = self.port # Use existing pin_file (previously saved) so that remote certificate is accepted. session_config.set_tls_pinning(self.pin_file, None) self.session_config = session_config # Create a session handle object self.session_handle = self.net_element.connect(self.username, self.password, self.session_config)
def connect(self, application_name, **kwargs): network_application = NetworkApplication.get_instance() network_application.name = application_name self.network_element = network_application.get_network_element( self.element_hostname) if self.network_element is None: self.logger.error("Failed to get network element") sys.exit(1) self.logger.info("We have a NetworkElement : " + self.network_element.__str__()) session_config = SessionConfig( SessionConfig.SessionTransportMode.TLS) #default is TLS session_config.eventQueueSize = self.properties["eventQueueSize"] session_config.eventThreadPool = self.properties["eventThreadPool"] session_config.eventDropMode = self.properties["eventDropMode"] session_config.keepAliveIdleTime = self.properties["keepAliveIdleTime"] session_config._keepAliveInterval = self.properties[ "keepAliveInterval"] session_config.keepAliveRetryCount = self.properties[ "keepAliveRetryCount"] session_config.reconnectTimer = self.properties["reconnectTimer"] session_config.ca_certs = self.root_cert_path self.session_handle = self.network_element.connect( self.username, self.password, session_config) if self.session_handle is None: logging.error("Failed to connect to the network element") return False logging.info("successful in connecting to the network element") return True
def connect(self, applicationName): """ Obtains a NetworkApplication instance, sets the name to applicationName, gets a network element for the hostname or address in the command line arguments or tutorial.properties file and then tries to connect to the Network Element with the username and password supplied, or from the tutorial.properties file. @param applicationName: The NetworkApplication name is set to this value. @return True if the connection succeeded without exception, else false. @throws OnepException """ # START SNIPPET: init_myapp network_application = NetworkApplication.get_instance() # END SNIPPET: init_myapp # START SNIPPET: name_myapp network_application.name = applicationName # END SNIPPET: name_myapp # START SNIPPET: get_ne_opt1 self.network_element = network_application.get_network_element( self.element_hostname) # END SNIPPET: get_ne_opt1 if self.network_element == None: logger.error("Failed to get network element") sys.exit(1) logger.info("We have a NetworkElement : " + self.network_element.__str__()) # START SNIPPET: connect session_config = SessionConfig( SessionConfig.SessionTransportMode.TLS) #default is TLS if self.transport.lower() == "tipc" or self.transport == "2": session_config = SessionConfig( SessionConfig.SessionTransportMode.TIPC) #Set all the TLS properties in session_config session_config.ca_certs = self.root_cert_path session_config.keyfile = self.client_key_path session_config.certfile = self.client_cert_path session_config.set_tls_pinning(self.tls_pinning_file, PinningHandler(self.tls_pinning_file)) self.session_handle = self.network_element.connect( self.username, self.password, session_config) # END SNIPPET: connect if self.session_handle == None: # START SNIPPET: loggerError logger.error("Failed to connect to NetworkElement - ") # END SNIPPET: loggerError return False logger.info("Successful connection to NetworkElement - ") return True
def connect(self): ''' establish connection via onepk to network device ''' self.network_application = NetworkApplication.get_instance() self.net_element = self.network_application.get_network_element(self.ipaddr) # create SessionConfig session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS) session_config.ca_certs = None session_config.keyfile = None session_config.certfile = None session_config.port = self.port session_config.set_tls_pinning(self.pin_file, None) self.session_config = session_config self.session_handle = self.net_element.connect(self.username, self.password, self.session_config)
def establish_session(self): ''' Take a onepk network device and go through the steps to establish a session. This method assumes that you are using a PIN_FILE Sets the following attributes self.network_application self.net_element self.session_config self.session_handle ''' # Create NetworkApplication instance self.network_application = NetworkApplication.get_instance() # Create NetworkElement instance self.net_element = self.network_application.get_network_element( self.ip) # Create SessionConfig instance session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS) session_config.ca_certs = None session_config.keyfile = None session_config.certfile = None session_config.port = self.port # Use existing pin_file (previously saved) so that remote certificate is accepted. session_config.set_tls_pinning(self.pin_file, None) self.session_config = session_config # Create a session handle object self.session_handle = self.net_element.connect(self.username, self.password, self.session_config)
# ------- end of configuration settings --------- import time import dns.resolver from onep.element.NetworkApplication import NetworkApplication from onep.element import SessionConfig from onep.vty import VtyService class IPAttributes: ttl = defaultTTL insertedAt = 0 resolvedIPs={} networkApplication=NetworkApplication.get_instance() networkApplication.name = "DNSACL" ne = networkApplication.get_network_element(RouterIP) session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS) session_config.ca_certs = CertDirectory+CACertFile session_config.keyfile = CertDirectory+ClientKeyFile session_config.certfile = CertDirectory+ClientCertFile while True: currentTime=time.time() #update the list with new IPs or new TTLs for host in hostList: