Method: Cisco::Client.create
- Defined in:
- lib/cisco_node_utils/client/client.rb
.create(environment_name = nil) ⇒ Object
Try to create an instance of an appropriate subclass
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/cisco_node_utils/client/client.rb', line 85 def self.create(environment_name=nil) fail 'No client implementations available!' if clients.empty? debug "Trying to establish client connection. clients = #{clients}" environment = Cisco::Environment.environment(environment_name) host = environment[:host] errors = [] clients.each do |client_class| begin debug "Trying to connect to #{host} as #{client_class}" client = client_class.new(**environment) debug "#{client_class} connected successfully" return client rescue Cisco::ClientError, TypeError, ArgumentError => e debug "Unable to connect to #{host} as #{client_class}: #{e.}" debug e.backtrace.join("\n ") errors << e end end handle_errors(errors) end |