Method: OvirtSDK4::Connection#initialize
- Defined in:
- lib/ovirtsdk4/connection.rb
#initialize(opts = {}) ⇒ Connection
Creates a new connection to the API server.
connection = OvirtSDK4::Connection.new(
url: 'https://engine.example.com/ovirt-engine/api',
username: 'admin@internal',
password: '...',
ca_file:'/etc/pki/ovirt-engine/ca.pem'
)
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/ovirtsdk4/connection.rb', line 109 def initialize(opts = {}) # Get the values of the parameters and assign default values: @url = opts[:url] @username = opts[:username] @password = opts[:password] @token = opts[:token] @insecure = opts[:insecure] || false @ca_file = opts[:ca_file] @ca_certs = opts[:ca_certs] @debug = opts[:debug] || false @log = opts[:log] @kerberos = opts[:kerberos] || false @timeout = opts[:timeout] || 0 @connect_timeout = opts[:connect_timeout] || 0 @compress = opts[:compress] || true @proxy_url = opts[:proxy_url] @proxy_username = opts[:proxy_username] @proxy_password = opts[:proxy_password] @headers = opts[:headers] @connections = opts[:connections] || 1 @pipeline = opts[:pipeline] || 0 # Check that the URL has been provided: raise ArgumentError, "The 'url' option is mandatory" unless @url # Automatically disable compression when debug is enabled, as otherwise the debug output generated by # libcurl is also compressed, and that isn't useful for debugging: @compress = false if @debug # Create a temporary file to store the CA certificates, and populate it with the contents of the 'ca_file' and # 'ca_certs' options. The file will be removed when the connection is closed. @ca_store = nil if @ca_file || @ca_certs @ca_store = Tempfile.new('ca_store') @ca_store.write(::File.read(@ca_file)) if @ca_file if @ca_certs @ca_certs.each do |ca_cert| @ca_store.write(ca_cert) end end @ca_store.close end # Create the mutex that will be used to prevents simultaneous access to the same HTTP client by multiple threads: @mutex = Mutex.new # Create the HTTP client: @client = HttpClient.new( insecure: @insecure, ca_file: @ca_store ? @ca_store.path : nil, debug: @debug, log: @log, timeout: @timeout, connect_timeout: @connect_timeout, compress: @compress, proxy_url: @proxy_url, proxy_username: @proxy_username, proxy_password: @proxy_password, connections: @connections, pipeline: @pipeline ) end |