Class: PxnxJruby::Connection
- Inherits:
-
Object
- Object
- PxnxJruby::Connection
- Defined in:
- lib/pxnx_jruby/connection.rb
Overview
This class handles to the pxGrid Controller.
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#grid ⇒ Object
Returns the value of attribute grid.
-
#recon ⇒ Object
Returns the value of attribute recon.
Instance Method Summary collapse
-
#connect ⇒ Object
Connects to Cisco ISE.
-
#disconnect ⇒ Object
Disconnects from Cisco ISE.
-
#get_option(option) ⇒ Object
Returns a configuration option, prioritising environment variables.
-
#initialize(options = {}) ⇒ Connection
constructor
Initializes all the needed variables for connecting to Cisco.
Constructor Details
#initialize(options = {}) ⇒ Connection
Initializes all the needed variables for connecting to Cisco.
Arguments
-
Options
- A Hash with information about the Cisco connection.
Options
-
:ise_url
- The URL for ISE. If several it also takes an Array of IPs -
:ise_username
- The username for ISE. -
:ise_password
- The password for ISE. We highly recommend setting this as an environment variable. -
:keystore_password
- The password for your keystore. We highly recommend setting this as an environment variable. -
:truststore_password
- The password for your truststore. We highly recommend setting this as an environment variable. -
Returns :
-
@config: A TLSConfiguration type object with all the configurations.
-
TODO: This method ABC is too high (c2.com/cgi/wiki?AbcMetric)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pxnx_jruby/connection.rb', line 27 def initialize( = {}) @log = LoggerFactory.getLogger(Connection.become_java!) @config = Java::com.cisco.pxgrid.TLSConfiguration.new @options = file_path = File.(File.dirname(__FILE__)) hosts = [get_option(:ise_url), get_option(:secondary_ise_url)] @config.setHosts(hosts.select { |h| !h.nil? }) @config.setUserName(get_option(:ise_username)) @config.setPassword(get_option(:ise_password)) @config.setKeystorePath("#{file_path}/../../keystore.jks") @config.setKeystorePassphrase(get_option(:keystore_password)) @config.setTruststorePath("#{file_path}/../../truststore.jks") @config.setTruststorePassphrase(get_option(:truststore_password)) @log.info("Listening for events, using username <#{@config.getUserName}>") @config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/pxnx_jruby/connection.rb', line 8 def config @config end |
#grid ⇒ Object
Returns the value of attribute grid.
8 9 10 |
# File 'lib/pxnx_jruby/connection.rb', line 8 def grid @grid end |
#recon ⇒ Object
Returns the value of attribute recon.
8 9 10 |
# File 'lib/pxnx_jruby/connection.rb', line 8 def recon @recon end |
Instance Method Details
#connect ⇒ Object
Connects to Cisco ISE.
-
Returns :
-
true if connection succeeds, false if there was a failure.
-
TODO: This method ABC is too high (c2.com/cgi/wiki?AbcMetric)
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pxnx_jruby/connection.rb', line 62 def connect @grid = Java.com.cisco.pxgrid.GridConnection.new(@config) @recon = Java.com.cisco.pxgrid.ReconnectionManager.new(@grid) @recon.setRetryMillisecond(2000) @log.info('Connecting...') begin @recon.start rescue => e @log.error("Could not connect: #{e.backtrace}") return false end @log.info('Connection complete!') true end |
#disconnect ⇒ Object
Disconnects from Cisco ISE.
78 79 80 81 82 |
# File 'lib/pxnx_jruby/connection.rb', line 78 def disconnect @log.info('Disconnecting...') @recon.stop unless @recon.nil? @log.info('Disconnection complete!') end |
#get_option(option) ⇒ Object
Returns a configuration option, prioritising environment variables.
-
Returns :
-
the configuration option value
-
49 50 51 52 53 54 |
# File 'lib/pxnx_jruby/connection.rb', line 49 def get_option(option) value = ENV[option.to_s.upcase] value ||= (@options[:pxg_data] || {})[option] unless @options.nil? @log.info("No configuration value found for #{option}") if value.nil? value end |