xclarity_client 0.6.5 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a94d8c6370c78465f0607a7ea7d5dece6ac95d94
4
- data.tar.gz: ce694e22536e0b68ee82ad13bc8e523a9e497b84
3
+ metadata.gz: 3de68cc1b07f9953dbefe5fda0b8b8e74df98f0a
4
+ data.tar.gz: 39e2effba3ca1815ec833c2a63ea36a1e8e03a3d
5
5
  SHA512:
6
- metadata.gz: '09cb4cfa48391846096107de5f4989d20246d8bd0edae3735264f304cf3d4df1b7d884ba0f9ad3f74f456aa971d83f5885e7fb8e503213f4356e1f5c607b503f'
7
- data.tar.gz: dbb35e325ad671c58f5431bec6d40577f4655a569008afd33b2df25d4a9866d05bd809767c137e962c37ae558699068ebf25d50ef9c4f8a2f027b10fe030152d
6
+ metadata.gz: fd9cdbe853931062976eb4ab76af736b258b5b2ce68900a131c1a93d95d1cc9c30bd8e4e333fbf6b2e0ff354ef45b01ca10b10334eb4e6dd537d45689c030195
7
+ data.tar.gz: 930d73b66b1e7548274b83101bfe44611327948bae00df63f413bde98d3025f6da70da8132e4d07b63bb5175011e83d8c8b835d35340346650dea13b749d649f
@@ -35,6 +35,7 @@ module XClarityClient
35
35
  include XClarityClient::Mixins::UpdateRepoMixin
36
36
  include XClarityClient::Mixins::UpdateCompMixin
37
37
  include XClarityClient::Mixins::UserMixin
38
+ include XClarityClient::Mixins::ManagementServerMixin
38
39
 
39
40
  def initialize(config)
40
41
  @config = config
@@ -3,6 +3,7 @@ require 'faraday-cookie_jar'
3
3
  require 'uri'
4
4
  require 'uri/https'
5
5
  require 'timeout'
6
+ require 'pp'
6
7
 
7
8
  module XClarityClient
8
9
  #
@@ -11,7 +12,6 @@ module XClarityClient
11
12
  #
12
13
  class Connection
13
14
  HEADER_MESSAGE = 'XClarityClient::Connection'.freeze
14
- #
15
15
  # @param [Hash] configuration - the data to create a connection with the LXCA
16
16
  # @option configuration [String] :host the LXCA host
17
17
  # @option configuration [String] :username the LXCA username
@@ -24,10 +24,10 @@ module XClarityClient
24
24
  #
25
25
  def initialize(configuration)
26
26
  @connection = build(configuration)
27
- @timeout = configuration.timeout
27
+ @connection_multipart = build(configuration, true)
28
+ @timeout = configuration.timeout
28
29
  end
29
30
 
30
- #
31
31
  # Does a GET request to an LXCA endpoint
32
32
  #
33
33
  # @param [String] uri - endpoint to do the request
@@ -49,42 +49,42 @@ module XClarityClient
49
49
  Faraday::Response.new
50
50
  end
51
51
 
52
- #
53
52
  # Does a POST request to an LXCA endpoint
54
53
  #
55
54
  # @param [String] uri - endpoint to do the request
56
55
  # @param [JSON] body - json to be sent in request body
57
56
  #
58
- def do_post(uri = '', body = '')
59
- build_request(:post, uri, body)
57
+ def do_post(uri = '', body = '', multipart = false)
58
+ build_request(:post, uri, body, multipart)
60
59
  end
61
60
 
62
- #
63
61
  # Does a PUT request to an LXCA endpoint
64
- #
65
62
  # @param [String] uri - endpoint to do the request
66
63
  # @param [JSON] body - json to be sent in request body
67
- #
68
64
  def do_put(uri = '', body = '')
69
65
  build_request(:put, uri, body)
70
66
  end
71
67
 
72
- #
73
68
  # Does a DELETE request to an LXCA endpoint
74
- #
75
69
  # @param [String] uri - endpoint to do the request
76
- #
77
70
  def do_delete(uri = '')
78
71
  build_request(:delete, uri)
79
72
  end
80
73
 
81
74
  private
82
75
 
83
- def build_request(method, url, body = '')
84
- @connection.send(method) do |request|
85
- request.url(url)
86
- request.headers['Content-Type'] = 'application/json'
87
- request.body = body
76
+ def build_request(method, url, body = '', multipart = false)
77
+ if multipart == true
78
+ @connection_multipart.send(method) do |request|
79
+ request.url(url)
80
+ request.body = body
81
+ end
82
+ else
83
+ @connection.send(method) do |request|
84
+ request.url(url)
85
+ request.headers['Content-Type'] = 'application/json'
86
+ request.body = body
87
+ end
88
88
  end
89
89
  rescue Faraday::Error::ConnectionFailed => e
90
90
  header = HEADER_MESSAGE + " do_#{method}"
@@ -95,32 +95,57 @@ module XClarityClient
95
95
  Faraday::Response.new
96
96
  end
97
97
 
98
- def build(configuration)
99
- header = HEADER_MESSAGE + ' build'
100
- $lxca_log.info(header, 'Building the connection')
101
-
102
- hostname = URI.parse(configuration.host)
103
-
104
- url = URI::HTTPS.build({ :host => hostname.scheme ? hostname.host : hostname.path,
105
- :port => configuration.port.to_i,
106
- :query => hostname.query,
107
- :fragment => hostname.fragment }).to_s
108
- $lxca_log.info(header, "Creating connection to #{url}")
98
+ def create_connection(connection, configuration)
99
+ user_agent_label = configuration.user_agent_label
100
+ agent_label = user_agent_label.nil? ? "" : user_agent_label
101
+ header = "LXCA via Ruby Client/#{XClarityClient::VERSION}"
102
+ connection.headers[:user_agent] = header + agent_label
103
+ basic_auth = configuration.auth_type == 'basic_auth'
104
+ username = configuration.username
105
+ password = configuration.password
106
+ connection.basic_auth(username, password) if basic_auth
107
+ $lxca_log.info(header, 'Connection created Successfuly')
108
+ connection
109
+ end
109
110
 
110
- connection = Faraday.new(url: url) do |faraday|
111
+ def create_faraday_multipart_obj(url, configuration)
112
+ Faraday.new(url: url) do |faraday|
113
+ faraday.request(:multipart) # multipart form data
111
114
  faraday.request(:url_encoded) # form-encode POST params
112
115
  faraday.response(:logger, $lxca_log.log) # log requests to log file
113
116
  faraday.use(:cookie_jar) if configuration.auth_type == 'token'
114
- faraday.adapter(:httpclient) # make requests with HTTPClient
117
+ faraday.adapter(:net_http) # make requests with net_http
115
118
  faraday.ssl[:verify] = configuration.verify_ssl == 'PEER'
116
119
  end
120
+ end
117
121
 
118
- connection.headers[:user_agent] = "LXCA via Ruby Client/#{XClarityClient::VERSION}" + (configuration.user_agent_label.nil? ? "" : " (#{configuration.user_agent_label})")
122
+ def create_faraday_obj(url, configuration)
123
+ Faraday.new(url: url) do |faraday|
124
+ faraday.request(:url_encoded) # form-encode POST params
125
+ faraday.response(:logger, $lxca_log.log) # log requests to log file
126
+ faraday.use(:cookie_jar) if configuration.auth_type == 'token'
127
+ faraday.adapter(:httpclient) # make request with httpclient
128
+ faraday.ssl[:verify] = configuration.verify_ssl == 'PEER'
129
+ end
130
+ end
119
131
 
120
- connection.basic_auth(configuration.username, configuration.password) if configuration.auth_type == 'basic_auth'
121
- $lxca_log.info(header, 'Connection created Successfuly')
132
+ def build_connection(url, configuration, multipart = false)
133
+ con_obj = create_faraday_multipart_obj(url, configuration) if multipart
134
+ con_obj = create_faraday_obj(url, configuration) unless multipart
135
+ create_connection(con_obj, configuration)
136
+ end
122
137
 
123
- connection
138
+ def build(configuration, multipart = false)
139
+ header = HEADER_MESSAGE + ' build'
140
+ $lxca_log.info(header, 'Building the connection')
141
+ hostname = URI.parse(configuration.host)
142
+ host = hostname.scheme ? hostname.host : hostname.path
143
+ url = URI::HTTPS.build(:host => host,
144
+ :port => configuration.port.to_i,
145
+ :query => hostname.query,
146
+ :fragment => hostname.fragment).to_s
147
+ $lxca_log.info(header, "Creating connection to #{url}")
148
+ build_connection(url, configuration, multipart)
124
149
  end
125
150
  end
126
151
  end
@@ -36,3 +36,4 @@ require 'xclarity_client/endpoints/hostplatform'
36
36
  require 'xclarity_client/endpoints/osimage'
37
37
  require 'xclarity_client/endpoints/remotefileserver'
38
38
  require 'xclarity_client/endpoints/compliance_policy'
39
+ require 'xclarity_client/endpoints/management_server'
@@ -0,0 +1,5 @@
1
+ module XClarityClient
2
+ class ManagementServer < Endpoints::XclarityEndpoint
3
+ BASE_URI = '/managementServer/updates'.freeze
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+ module XClarityClient
2
+ #
3
+ # Exposes ManagementServerManagement features
4
+ #
5
+ module Mixins::ManagementServerMixin
6
+ def get_management_server_updates_info(key = nil)
7
+ obj = ManagementServerManagement.new(@config)
8
+ obj.get_management_server_updates_info(key)
9
+ end
10
+
11
+ def delete_management_server_updates(fixids)
12
+ return "parameter 'fixids' should be array" unless fixids.kind_of?(Array)
13
+ obj = ManagementServerManagement.new(@config)
14
+ obj.delete_management_server_updates(fixids)
15
+ end
16
+
17
+ def download_management_server_updates(fixids)
18
+ return "parameter 'fixids' should be array" unless fixids.kind_of?(Array)
19
+ obj = ManagementServerManagement.new(@config)
20
+ obj.download_management_server_updates(fixids)
21
+ end
22
+
23
+ def apply_management_server_updates(fixids)
24
+ return "parameter 'fixids' should be array" unless fixids.kind_of?(Array)
25
+ obj = ManagementServerManagement.new(@config)
26
+ obj.apply_management_server_updates(fixids)
27
+ end
28
+
29
+ def refresh_management_server_updates_catalog
30
+ obj = ManagementServerManagement.new(@config)
31
+ obj.refresh_management_server_updates_catalog
32
+ end
33
+
34
+ def import_management_server_updates(files)
35
+ return "parameter 'files' should be array" unless files.kind_of?(Array)
36
+ obj = ManagementServerManagement.new(@config)
37
+ obj.import_management_server_updates(files)
38
+ end
39
+ end
40
+ end
@@ -38,3 +38,4 @@ require 'xclarity_client/mixins/manage_request_mixin'
38
38
  require 'xclarity_client/mixins/update_repo_mixin'
39
39
  require 'xclarity_client/mixins/update_comp_mixin'
40
40
  require 'xclarity_client/mixins/user_mixin'
41
+ require 'xclarity_client/mixins/management_server_mixin'
@@ -0,0 +1,87 @@
1
+ require 'json'
2
+ require 'pathname'
3
+ require 'pp'
4
+
5
+ module XClarityClient
6
+ # ManagementServerManagement class
7
+ class ManagementServerManagement < Services::XClarityService
8
+ manages_endpoint ManagementServer
9
+
10
+ private
11
+
12
+ def start_management_server_updates_import_job(file_type_dict, files, jobid)
13
+ url = "/files/#{ManagementServer::BASE_URI}?action=import&jobid=#{jobid}"
14
+ index = 0
15
+ payload = {}
16
+ files.each do |file_name|
17
+ type = file_type_dict[File.extname(file_name)]
18
+ key = 'file_' + (index += 1).to_s
19
+ payload[key.to_sym] = Faraday::UploadIO.new(file_name, type)
20
+ end
21
+ @connection.do_post(url, payload, true)
22
+ end
23
+
24
+ def populate_payload_files(files, file_type_dict)
25
+ payload_files = []
26
+ index = 0
27
+ files.each do |file|
28
+ name = File.basename(file)
29
+ payload_file = { :index => index += 1, :name => name.strip,
30
+ :type => file_type_dict[File.extname(name)].strip,
31
+ :size => File.size?(file) }
32
+ payload_files.push(payload_file)
33
+ end
34
+ payload_files
35
+ end
36
+
37
+ public
38
+
39
+ def get_management_server_updates_info(key = nil)
40
+ base_url = ManagementServer::BASE_URI
41
+ url = key.nil? ? base_url : "#{base_url}?key=#{key}"
42
+ msg = "input key=#{key}"
43
+ $lxca_log.info(self.class.to_s + ' ' + __method__.to_s, msg)
44
+ @connection.do_get(url)
45
+ end
46
+
47
+ def download_management_server_updates(fixids)
48
+ url = "#{ManagementServer::BASE_URI}?action=acquire"
49
+ opts = { :fixids => fixids }
50
+ request_body = JSON.generate(opts)
51
+ @connection.do_post(url, request_body)
52
+ end
53
+
54
+ def import_management_server_updates(files)
55
+ url = "#{ManagementServer::BASE_URI}?action=import"
56
+ file_type_dict = { '.txt' => 'text/plain', '.xml' => 'text/xml',
57
+ '.chg' => 'application/octet-stream',
58
+ '.tgz' => 'application/x-compressed' }
59
+ payload_files = populate_payload_files(files, file_type_dict)
60
+ request_body = JSON.generate(:files => payload_files)
61
+ response = @connection.do_post(url, request_body)
62
+ jobid = JSON.parse(response.body).to_hash['jobid']
63
+ $lxca_log.info(self.class.to_s + ' ' + __method__.to_s, "jobid: #{jobid}")
64
+ start_management_server_updates_import_job(file_type_dict, files, jobid)
65
+ end
66
+
67
+ def apply_management_server_updates(fixids)
68
+ url = "#{ManagementServer::BASE_URI}?action=apply"
69
+ opts = { :fixids => fixids }
70
+ request_body = JSON.generate(opts)
71
+ @connection.do_put(url, request_body)
72
+ end
73
+
74
+ def delete_management_server_updates(fixids)
75
+ fixids = fixids.join(',')
76
+ url = "#{ManagementServer::BASE_URI}/#{fixids}"
77
+ @connection.do_delete(url)
78
+ end
79
+
80
+ def refresh_management_server_updates_catalog
81
+ url = "#{ManagementServer::BASE_URI}?action=refresh"
82
+ opts = { :mts => ['lxca'] }
83
+ request_body = JSON.generate(opts)
84
+ @connection.do_post(url, request_body)
85
+ end
86
+ end
87
+ end
@@ -1,15 +1,17 @@
1
1
  require 'json'
2
2
 
3
3
  module XClarityClient
4
- class RemoteAccessManagement < XClarityBase
4
+ class RemoteAccessManagement
5
5
 
6
6
  def initialize(conf)
7
- super(conf, RemoteAccess::BASE_URI)
7
+ @connection = XClarityClient::Connection.new(conf)
8
8
  end
9
9
 
10
10
  def remote_control(uuid)
11
11
  raise 'UUID must not be blank' if uuid.nil? || uuid.empty?
12
- con = connection("#{RemoteAccess::BASE_URI}/remoteControl" , {:uuid => uuid})
12
+ con = @connection.do_get(
13
+ "#{RemoteAccess::BASE_URI}/remoteControl", :query => { :uuid => uuid }
14
+ )
13
15
 
14
16
  unless con.success?
15
17
  $lxca_log.error "XClarityClient::RemoteAccessManagement remote_control", "Request failed"
@@ -54,4 +56,4 @@ module XClarityClient
54
56
  })
55
57
  end
56
58
  end
57
- end
59
+ end
@@ -39,3 +39,4 @@ require 'xclarity_client/services/update_repo_management'
39
39
  require 'xclarity_client/services/update_comp_management'
40
40
  require 'xclarity_client/services/user_management'
41
41
  require 'xclarity_client/services/virtual_appliance_management'
42
+ require 'xclarity_client/services/management_server_management'
@@ -1,5 +1,5 @@
1
1
  module XClarityClient
2
- class VirtualApplianceManagement < XClarityBase
2
+ class VirtualApplianceManagement
3
3
 
4
4
  BASE_URI = '/aicc'.freeze
5
5
  NETWORK_URI = '/network'.freeze
@@ -10,12 +10,11 @@ module XClarityClient
10
10
  SUBSCRIPTIONS_URI = '/subscriptions'.freeze
11
11
 
12
12
  def initialize(conf)
13
- super(conf, BASE_URI)
13
+ @connection = XClarityClient::Connection.new(conf)
14
14
  end
15
15
 
16
16
  def configuration_settings
17
- response = connection
18
- response
17
+ @connection.do_get(BASE_URI)
19
18
  end
20
19
 
21
20
  def configuration_settings=()
@@ -24,8 +23,8 @@ module XClarityClient
24
23
  def ip_enablement_state
25
24
  uri = BASE_URI+NETWORK_URI+IPDISABLE_URI
26
25
  $lxca_log.info "XclarityClient::VirtualApplianceManagement ip_enablement_state", "Action has been sent to #{uri}"
27
- response = connection(uri)
28
- response
26
+
27
+ @connection.do_get(uri)
29
28
  end
30
29
 
31
30
  def ip_enablement_state=()
@@ -35,8 +34,8 @@ module XClarityClient
35
34
  def host_settings
36
35
  uri = BASE_URI+NETWORK_URI+IPDISABLE_URI
37
36
  $lxca_log.info "XclarityClient::VirtualApplianceManagement host_settings", "Action has been sent to #{uri}"
38
- response = connection(uri)
39
- response
37
+
38
+ @connection.do_get(uri)
40
39
  end
41
40
 
42
41
  def host_settings=()
@@ -46,8 +45,8 @@ module XClarityClient
46
45
  def network_interface_settings(interface)
47
46
  uri = BASE_URI+NETWORK_URI+INTERFACES_URI+"/#{interface}"
48
47
  $lxca_log.info "XclarityClient::VirtualApplianceManagement network_interface_settings", "Action has been sent to #{uri}"
49
- response = connection(uri)
50
- response
48
+
49
+ @connection.do_get(uri)
51
50
  end
52
51
 
53
52
  def host_settings=()
@@ -57,8 +56,8 @@ module XClarityClient
57
56
  def route_settings
58
57
  uri = BASE_URI+NETWORK_URI+ROUTES_URI
59
58
  $lxca_log.info "XclarityClient::VirtualApplianceManagement route_settings", "Action has been sent to #{uri}"
60
- response = connection(uri)
61
- response
59
+
60
+ @connection.do_get(uri)
62
61
  end
63
62
 
64
63
  def route_settings=()
@@ -68,14 +67,12 @@ module XClarityClient
68
67
  def subscriptions
69
68
  uri = BASE_URI+SUBSCRIPTIONS_URI
70
69
  $lxca_log.info "XclarityClient::VirtualApplianceManagement subscriptions", "Action has been sent to #{uri}"
71
- response = connection(uri)
72
- response
70
+
71
+ @connection.do_get(uri)
73
72
  end
74
73
 
75
74
  def subscriptions=()
76
75
 
77
76
  end
78
-
79
-
80
77
  end
81
78
  end
@@ -1,3 +1,3 @@
1
1
  module XClarityClient
2
- VERSION = "0.6.5"
2
+ VERSION = "0.6.6"
3
3
  end
@@ -1,11 +1,11 @@
1
1
  require 'json'
2
2
 
3
3
  module XClarityClient
4
- class XClarityCredentialsValidator < XClarityBase
4
+ class XClarityCredentialsValidator
5
5
  BASE_URI = '/sessions'.freeze
6
6
 
7
7
  def initialize(conf)
8
- super(conf, BASE_URI)
8
+ @connection = XClarityClient::Connection.new(conf)
9
9
  @configuration = conf
10
10
  end
11
11
 
@@ -33,19 +33,16 @@ module XClarityClient
33
33
  end
34
34
 
35
35
  def build_session(conf)
36
- @response = @conn.post do |request|
37
- request.headers['Content-Type'] = 'application/json'
38
- request.body = { :UserId => conf.username,
39
- :password => conf.password }.to_json
40
- end
36
+ @response = @connection.do_post(BASE_URI, {
37
+ :UserId => conf.username,
38
+ :password => conf.password
39
+ }.to_json)
40
+
41
41
  raise Faraday::Error::ConnectionFailed unless @response.success?
42
42
  end
43
43
 
44
44
  def close_session(id_session)
45
- @conn.delete do |request|
46
- request.url "#{BASE_URI}/#{id_session}"
47
- request.headers['Content-Type'] = 'application/json'
48
- end
45
+ @connection.do_delete("#{BASE_URI}/#{id_session}")
49
46
  end
50
47
  end
51
48
  end
@@ -8,7 +8,6 @@ end
8
8
  require 'xclarity_client/errors/errors'
9
9
 
10
10
  require 'xclarity_client/configuration'
11
- require 'xclarity_client/xclarity_base'
12
11
  require 'xclarity_client/xclarity_credentials_validator'
13
12
  require 'xclarity_client/discover'
14
13
  require 'xclarity_client/endpoints/endpoints'
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_development_dependency "bundler", "~> 1.12"
20
+ spec.add_development_dependency('bundler', '>= 1.12')
21
21
  spec.add_development_dependency "rake", "~> 10.0"
22
22
  spec.add_development_dependency "rspec", "~> 3.0"
23
23
  spec.add_development_dependency "apib-mock_server", "~> 1.0.3"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xclarity_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manasa Rao
@@ -9,20 +9,20 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-10-22 00:00:00.000000000 Z
12
+ date: 2019-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '1.12'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.12'
28
28
  - !ruby/object:Gem::Dependency
@@ -245,6 +245,7 @@ files:
245
245
  - lib/xclarity_client/endpoints/hostplatform.rb
246
246
  - lib/xclarity_client/endpoints/job.rb
247
247
  - lib/xclarity_client/endpoints/manage_request.rb
248
+ - lib/xclarity_client/endpoints/management_server.rb
248
249
  - lib/xclarity_client/endpoints/node.rb
249
250
  - lib/xclarity_client/endpoints/osimage.rb
250
251
  - lib/xclarity_client/endpoints/persisted_result.rb
@@ -284,6 +285,7 @@ files:
284
285
  - lib/xclarity_client/mixins/host_platform_mixin.rb
285
286
  - lib/xclarity_client/mixins/job_mixin.rb
286
287
  - lib/xclarity_client/mixins/manage_request_mixin.rb
288
+ - lib/xclarity_client/mixins/management_server_mixin.rb
287
289
  - lib/xclarity_client/mixins/mixins.rb
288
290
  - lib/xclarity_client/mixins/node_mixin.rb
289
291
  - lib/xclarity_client/mixins/os_image_mixin.rb
@@ -318,6 +320,7 @@ files:
318
320
  - lib/xclarity_client/services/hostplatform_management.rb
319
321
  - lib/xclarity_client/services/job_management.rb
320
322
  - lib/xclarity_client/services/manage_request_management.rb
323
+ - lib/xclarity_client/services/management_server_management.rb
321
324
  - lib/xclarity_client/services/mixins/endpoint_manager_mixin.rb
322
325
  - lib/xclarity_client/services/mixins/list_name_interpreter_mixin.rb
323
326
  - lib/xclarity_client/services/mixins/power_action_sender_mixin.rb
@@ -340,7 +343,6 @@ files:
340
343
  - lib/xclarity_client/services/xclarity_management_mixin.rb
341
344
  - lib/xclarity_client/services/xclarity_service.rb
342
345
  - lib/xclarity_client/version.rb
343
- - lib/xclarity_client/xclarity_base.rb
344
346
  - lib/xclarity_client/xclarity_credentials_validator.rb
345
347
  - xclarity_client.gemspec
346
348
  homepage: https://github.com/lenovo/xclarity_client
@@ -362,7 +364,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
362
364
  version: '0'
363
365
  requirements: []
364
366
  rubyforge_project:
365
- rubygems_version: 2.6.14
367
+ rubygems_version: 2.6.14.3
366
368
  signing_key:
367
369
  specification_version: 4
368
370
  summary: Lenovo XClarity API Client
@@ -1,88 +0,0 @@
1
- require 'faraday'
2
- require 'faraday-cookie_jar'
3
- require 'uri'
4
- require 'uri/https'
5
-
6
- module XClarityClient
7
- class XClarityBase
8
-
9
- attr_reader :conn
10
-
11
- def initialize(conf, uri)
12
- connection_builder(conf, uri)
13
- end
14
-
15
- def connection_builder(conf, uri)
16
- $lxca_log.info "XClarityClient::XClarityBase connection_builder", "Building the url"
17
- #Building configuration
18
- hostname = URI.parse(conf.host)
19
- url = URI::HTTPS.build({ :host => hostname.scheme ? hostname.host : hostname.path,
20
- :port => conf.port.to_i,
21
- :path => uri,
22
- :query => hostname.query,
23
- :fragment => hostname.fragment }).to_s
24
-
25
- $lxca_log.info "XClarityClient::XClarityBase connection_builder", "Creating connection to #{url}"
26
-
27
- @conn = Faraday.new(url: url) do |faraday|
28
- faraday.request :url_encoded # form-encode POST params
29
- faraday.response :logger, $lxca_log.log # log requests to STDOUT -- This line, should be uncommented if you wanna inspect the URL Request
30
- faraday.use :cookie_jar if conf.auth_type == 'token'
31
- faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
32
- faraday.ssl[:verify] = conf.verify_ssl == 'PEER'
33
- end
34
-
35
- @conn.headers[:user_agent] = "LXCA via Ruby Client/#{XClarityClient::VERSION}" + (conf.user_agent_label.nil? ? "" : " (#{conf.user_agent_label})")
36
- @conn.basic_auth(conf.username, conf.password) if conf.auth_type == 'basic_auth'
37
- $lxca_log.info "XClarityClient::XclarityBase connection_builder", "Connection created Successfuly"
38
- @conn
39
- end
40
-
41
- private
42
-
43
- def connection(uri = "", opts = {})
44
- query = opts.size > 0 ? "?" + opts.map {|k, v| "#{k}=#{v}"}.join(",") : ""
45
- begin
46
- @conn.get(uri + query)
47
- rescue Faraday::Error::ConnectionFailed => e
48
- $lxca_log.error "XClarityClient::XclarityBase connection", "Error trying to send a GET to #{uri + query}"
49
- Faraday::Response.new
50
- end
51
- end
52
-
53
- def do_post(uri="", request = {})
54
- begin
55
- @conn.post do |req|
56
- req.url uri
57
- req.headers['Content-Type'] = 'application/json'
58
- req.body = request
59
- end
60
- rescue Faraday::Error::ConnectionFailed => e
61
- $lxca_log.error "XClarityClient::XclarityBase do_post", "Error trying to send a POST to #{uri}"
62
- $lxca_log.error "XClarityClient::XclarityBase do_post", "Request sent: #{request}"
63
- Faraday::Response.new
64
- end
65
- end
66
-
67
- def do_put (uri="", request = {})
68
- begin
69
- @conn.put do |req|
70
- req.url uri
71
- req.headers['Content-Type'] = 'application/json'
72
- req.body = request
73
- end
74
- rescue Faraday::Error::ConnectionFailed => e
75
- $lxca_log.error "XClarityClient::XclarityBase do_put", "Error trying to send a PUT to #{uri}"
76
- $lxca_log.error "XClarityClient::XclarityBase do_put", "Request sent: #{request}"
77
- Faraday::Response.new
78
- end
79
- end
80
-
81
- def do_delete (uri="")
82
- @conn.delete do |req|
83
- req.url uri
84
- req.headers['Content-Type'] = 'application/json'
85
- end
86
- end
87
- end
88
- end