xclarity_client 0.6.5 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a94d8c6370c78465f0607a7ea7d5dece6ac95d94
4
- data.tar.gz: ce694e22536e0b68ee82ad13bc8e523a9e497b84
2
+ SHA256:
3
+ metadata.gz: 97e51a6b89b3d94948e74936c80cca4a97599549aeb7723eb290062aef58e582
4
+ data.tar.gz: 16c23bc24b5a013f0b53c538cf3b212e8f4d8565e676ec73e66ee8a90fc380b3
5
5
  SHA512:
6
- metadata.gz: '09cb4cfa48391846096107de5f4989d20246d8bd0edae3735264f304cf3d4df1b7d884ba0f9ad3f74f456aa971d83f5885e7fb8e503213f4356e1f5c607b503f'
7
- data.tar.gz: dbb35e325ad671c58f5431bec6d40577f4655a569008afd33b2df25d4a9866d05bd809767c137e962c37ae558699068ebf25d50ef9c4f8a2f027b10fe030152d
6
+ metadata.gz: e2274fa28d68f861a3a4d5d918d71087bb412e0330f07ad61c748a33ac41abbd025c5ed2b2219d75f68405424ab668e0e25c86c45dd2e108461cbe7c3f510d17
7
+ data.tar.gz: 6c9eba7601d7b2fb4aadb184de99b74a63c7b11399d20e4435341d36c5b3c211e239e5cc6f2afca7cccc36caa10a74060821e7b49f39ab66ceea5417793f64e6
@@ -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 'net/http'
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,20 +24,23 @@ 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
+ @connection_net_http = build(configuration, false, true)
29
+ @timeout = configuration.timeout
30
+ @configuration = configuration
28
31
  end
29
32
 
30
- #
31
33
  # Does a GET request to an LXCA endpoint
32
34
  #
33
35
  # @param [String] uri - endpoint to do the request
34
36
  # @param [Hash] query - params to query the endpoint resources
35
37
  # @param [Hash] headers - add headers to the request
36
38
  #
37
- def do_get(uri = "", query: {}, headers: {})
39
+ def do_get(uri = "", query: {}, headers: {}, n_http: false)
38
40
  url_query = query.size > 0 ? "?" + query.map {|k, v| "#{k}=#{v}"}.join("&") : ""
39
41
  Timeout.timeout(@timeout) do
40
- @connection.get do |req|
42
+ con = n_http ? @connection_net_http : @connection
43
+ con.get do |req|
41
44
  req.url(uri + url_query)
42
45
  headers.map { |key, value| req.headers[key] = value }
43
46
  end
@@ -49,41 +52,61 @@ module XClarityClient
49
52
  Faraday::Response.new
50
53
  end
51
54
 
52
- #
55
+ def do_get_file_download(url, file_path)
56
+ host = @configuration.host
57
+ username = @configuration.username
58
+ password = @configuration.password
59
+
60
+ uri = 'https://' + host + url unless host.include?('https')
61
+ uri = host + url if host.include?('https')
62
+
63
+ uri = URI(uri)
64
+ Net::HTTP.start(uri.host, uri.port,
65
+ :use_ssl => true,
66
+ :verify_mode => 0) do |http|
67
+
68
+ request = Net::HTTP::Get.new(uri.request_uri)
69
+ request.basic_auth(username, password)
70
+
71
+ http.request(request) do |response|
72
+ open file_path, 'wb' do |io|
73
+ response.read_body do |chunk|
74
+ io.write(chunk)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+
53
81
  # Does a POST request to an LXCA endpoint
54
82
  #
55
83
  # @param [String] uri - endpoint to do the request
56
84
  # @param [JSON] body - json to be sent in request body
57
85
  #
58
- def do_post(uri = '', body = '')
59
- build_request(:post, uri, body)
86
+ def do_post(uri = '', body = '', multipart = false)
87
+ build_request(:post, uri, body, multipart)
60
88
  end
61
89
 
62
- #
63
90
  # Does a PUT request to an LXCA endpoint
64
- #
65
91
  # @param [String] uri - endpoint to do the request
66
92
  # @param [JSON] body - json to be sent in request body
67
- #
68
93
  def do_put(uri = '', body = '')
69
94
  build_request(:put, uri, body)
70
95
  end
71
96
 
72
- #
73
97
  # Does a DELETE request to an LXCA endpoint
74
- #
75
98
  # @param [String] uri - endpoint to do the request
76
- #
77
99
  def do_delete(uri = '')
78
100
  build_request(:delete, uri)
79
101
  end
80
102
 
81
103
  private
82
104
 
83
- def build_request(method, url, body = '')
84
- @connection.send(method) do |request|
105
+ def build_request(method, url, body = '', multipart = false)
106
+ con = multipart ? @connection_multipart : @connection
107
+ con.send(method) do |request|
85
108
  request.url(url)
86
- request.headers['Content-Type'] = 'application/json'
109
+ request.headers['Content-Type'] = 'application/json' unless multipart
87
110
  request.body = body
88
111
  end
89
112
  rescue Faraday::Error::ConnectionFailed => e
@@ -95,32 +118,47 @@ module XClarityClient
95
118
  Faraday::Response.new
96
119
  end
97
120
 
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}")
121
+ def create_connection_obj(connection, configuration)
122
+ user_agent_label = configuration.user_agent_label
123
+ agent_label = user_agent_label.nil? ? "" : user_agent_label
124
+ header = "LXCA via Ruby Client/#{XClarityClient::VERSION}"
125
+ connection.headers[:user_agent] = header + agent_label
126
+ basic_auth = configuration.auth_type == 'basic_auth'
127
+ username = configuration.username
128
+ password = configuration.password
129
+ connection.basic_auth(username, password) if basic_auth
130
+ $lxca_log.info(header, 'Connection created Successfuly')
131
+ connection
132
+ end
109
133
 
110
- connection = Faraday.new(url: url) do |faraday|
134
+ def create_faraday_obj(url, configuration, multipart, n_http)
135
+ Faraday.new(url: url) do |faraday|
136
+ faraday.request(:multipart) if multipart # multipart form data
111
137
  faraday.request(:url_encoded) # form-encode POST params
112
138
  faraday.response(:logger, $lxca_log.log) # log requests to log file
113
139
  faraday.use(:cookie_jar) if configuration.auth_type == 'token'
114
- faraday.adapter(:httpclient) # make requests with HTTPClient
140
+ faraday.adapter(:httpclient) unless n_http || multipart
141
+ faraday.adapter(:net_http) if n_http || multipart # with net_http
115
142
  faraday.ssl[:verify] = configuration.verify_ssl == 'PEER'
116
143
  end
144
+ end
117
145
 
118
- connection.headers[:user_agent] = "LXCA via Ruby Client/#{XClarityClient::VERSION}" + (configuration.user_agent_label.nil? ? "" : " (#{configuration.user_agent_label})")
119
-
120
- connection.basic_auth(configuration.username, configuration.password) if configuration.auth_type == 'basic_auth'
121
- $lxca_log.info(header, 'Connection created Successfuly')
146
+ def build_connection(url, configuration, multipart = false, n_http = false)
147
+ con_obj = create_faraday_obj(url, configuration, multipart, n_http)
148
+ create_connection_obj(con_obj, configuration)
149
+ end
122
150
 
123
- connection
151
+ def build(configuration, multipart = false, n_http = false)
152
+ header = HEADER_MESSAGE + ' build'
153
+ $lxca_log.info(header, 'Building the connection')
154
+ hostname = URI.parse(configuration.host)
155
+ host = hostname.scheme ? hostname.host : hostname.path
156
+ url = URI::HTTPS.build(:host => host,
157
+ :port => configuration.port.to_i,
158
+ :query => hostname.query,
159
+ :fragment => hostname.fragment).to_s
160
+ $lxca_log.info(header, "Creating connection to #{url}")
161
+ build_connection(url, configuration, multipart, n_http)
124
162
  end
125
163
  end
126
164
  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
@@ -24,9 +24,5 @@ module XClarityClient
24
24
  def delete_job(id = '')
25
25
  JobManagement.new(@config).delete_job(id)
26
26
  end
27
-
28
- def get_job(job_id = '')
29
- JobManagement.new(@config).get_job(job_id)
30
- end
31
27
  end
32
28
  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'
@@ -57,8 +57,50 @@ module XClarityClient
57
57
  node_management.set_power_state(uuid, :bootToF1)
58
58
  end
59
59
 
60
+ def retrieve_mounted_media_details(uuid = '')
61
+ node_management.retrieve_mounted_media_details(uuid)
62
+ end
63
+
64
+ def enable_media_mount_support_thinkserver(uuid = '')
65
+ node_management.enable_media_mount_support(uuid)
66
+ end
67
+
68
+ def disable_media_mount_support_thinkserver(uuid = '')
69
+ node_management.disable_media_mount_support(uuid)
70
+ end
71
+
72
+ def remove_all_mounted_medias_thinksystem(uuid = '')
73
+ node_management.remove_all_mounted_medias(uuid)
74
+ end
75
+
76
+ def mount_media_thinkserver(uuid, opts)
77
+ validate_mount_media_params(opts, 'thinkserver')
78
+ node_management.mount_media(uuid, opts)
79
+ end
80
+
81
+ def mount_media_thinksystem(uuid, opts)
82
+ validate_mount_media_params(opts)
83
+ node_management.mount_media(uuid, opts)
84
+ end
85
+
86
+ def unmount_media_thinkserver(uuid, media_type = '')
87
+ node_management.unmount_media_thinkserver(uuid, media_type)
88
+ end
89
+
90
+ def unmount_media_thinksystem(uuid, media_uid = '')
91
+ node_management.unmount_media_thinksystem(uuid, media_uid)
92
+ end
93
+
60
94
  private
61
95
 
96
+ def validate_mount_media_params(opts, server_type = '')
97
+ msg = "parameter 'opts' should be of type hash"
98
+ raise(msg) unless opts.kind_of?(Hash)
99
+ err_msg = ':mediaType is mandatory field in input hash for thinkserver'
100
+ raise(err_msg) if server_type == 'thinkserver' &&
101
+ !opts.keys.include?(:mediaType)
102
+ end
103
+
62
104
  def node_management
63
105
  NodeManagement.new(@config)
64
106
  end
@@ -11,23 +11,123 @@ module XClarityClient
11
11
  UpdateRepoManagement.new(@config).read_update_repo
12
12
  end
13
13
 
14
- def refresh_update_repo(scope, mt, os)
15
- UpdateRepoManagement.new(@config).refresh_update_repo(scope, mt, os)
14
+ def refresh_update_repo_catalog(scope, machine_types)
15
+ mt = machine_types
16
+ msg = 'Parameter machine_types should be of type Array'
17
+ raise msg unless mt.kind_of?(Array)
18
+ UpdateRepoManagement.new(@config).refresh_update_repo_catalog(scope, mt)
16
19
  end
17
20
 
18
- def acquire_firmware_updates(scope, fixids, mt)
19
- UpdateRepoManagement.new(@config).acquire_firmware_updates(scope,
20
- fixids, mt)
21
+ def refresh_uxsp_update_repo_catalog(scope, machine_types)
22
+ mt = machine_types
23
+ msg = 'Parameter machine_types should be of type Array'
24
+ raise msg unless mt.kind_of?(Array)
25
+ UpdateRepoManagement.new(@config).refresh_uxsp_update_repo_catalog(scope,
26
+ mt)
21
27
  end
22
28
 
23
- def delete_firmware_updates(file_types, fixids)
29
+ def updates_info_by_machine_types(machine_types)
30
+ mt = machine_types
31
+ msg = 'Parameter machine_types should be of type Array'
32
+ raise msg unless mt.kind_of?(Array)
33
+ UpdateRepoManagement.new(@config).updates_info_by_machine_types(mt)
34
+ end
35
+
36
+ def uxsp_updates_info_by_machine_types(machine_types)
37
+ mt = machine_types
38
+ msg = 'Parameter machine_types should be of type Array'
39
+ raise msg unless mt.kind_of?(Array)
40
+ UpdateRepoManagement.new(@config).uxsp_updates_info_by_machine_types(mt)
41
+ end
42
+
43
+ def acquire_firmware_updates(machine_types, fixids)
44
+ mt = machine_types
45
+ msg = 'Parameter machine_types & fixids should be of type Array'
46
+ raise msg unless mt.kind_of?(Array) || fixids.kind_of?(Array)
47
+ UpdateRepoManagement.new(@config).acquire_firmware_updates(mt, fixids)
48
+ end
49
+
50
+ def delete_firmware_updates(file_types, fixids = [])
51
+ validate_inputs(file_types, fixids)
24
52
  UpdateRepoManagement.new(@config).delete_firmware_updates(file_types,
25
53
  fixids)
26
54
  end
27
55
 
28
- def export_firmware_updates(file_types, fixids)
56
+ def export_firmware_updates(file_types, fixids = [])
57
+ validate_inputs(file_types, fixids)
29
58
  UpdateRepoManagement.new(@config).export_firmware_updates(file_types,
30
59
  fixids)
31
60
  end
61
+
62
+ def download_exported_firmware_updates(file_name, dir_path_for_download)
63
+ dir = dir_path_for_download
64
+ validate_file_name_dir_path(file_name, dir)
65
+ UpdateRepoManagement.new(@config)
66
+ .download_exported_firmware_updates(file_name, dir)
67
+ end
68
+
69
+ def validate_import_updates(file_path)
70
+ validate_file_path(file_path)
71
+ UpdateRepoManagement.new(@config).validate_import_updates(file_path)
72
+ end
73
+
74
+ def import_firmware_updates(file_path)
75
+ validate_file_path(file_path)
76
+ UpdateRepoManagement.new(@config).import_firmware_updates(file_path)
77
+ end
78
+
79
+ def track_task_status(taskid, tasktype)
80
+ UpdateRepoManagement.new(@config).track_task_status(taskid, tasktype)
81
+ end
82
+
83
+ def supported_machine_types_detail
84
+ UpdateRepoManagement.new(@config).supported_machine_types_detail
85
+ end
86
+
87
+ def retrieve_compliance_policy_list
88
+ UpdateRepoManagement.new(@config).retrieve_compliance_policy_list
89
+ end
90
+
91
+ def export_compliance_policies(policy_names)
92
+ msg = 'Parameter policy_names should be of type Array'
93
+ raise msg unless policy_names.kind_of?(Array)
94
+ UpdateRepoManagement.new(@config).export_compliance_policies(policy_names)
95
+ end
96
+
97
+ def download_exported_compliance_policies(file_name, dir_path_for_download)
98
+ dir = dir_path_for_download
99
+ validate_file_name_dir_path(file_name, dir)
100
+ UpdateRepoManagement.new(@config)\
101
+ .download_exported_compliance_policies(file_name, dir)
102
+ end
103
+
104
+ def import_compliance_policies(file_path)
105
+ validate_file_path(file_path)
106
+ UpdateRepoManagement.new(@config).import_compliance_policies(file_path)
107
+ end
108
+
109
+ private
110
+
111
+ def validate_inputs(file_types, fixids)
112
+ msg = 'Invalid value for argument file_types. Allowed values are'\
113
+ + ' - all and payloads'
114
+ raise msg unless %w(payloads all).include?(file_types)
115
+ msg = 'Parameter fixids should be of type Array'
116
+ raise msg unless fixids.kind_of?(Array)
117
+ raise msg if file_types == 'payloads' && !fixids.any?
118
+ end
119
+
120
+ def validate_file_name_dir_path(file_name, dir_path_for_download)
121
+ msg = 'Parameter file_name and dir_path_for_download,'\
122
+ + 'should be of type String'
123
+ raise msg unless file_name.kind_of?(String)
124
+ dir = dir_path_for_download
125
+ msg = dir + ' directory doesnt exists'
126
+ raise msg unless File.directory?(dir)
127
+ end
128
+
129
+ def validate_file_path(file_path)
130
+ raise "file #{file_path} doesn't exists" unless File.file?(file_path)
131
+ end
32
132
  end
33
133
  end
@@ -6,13 +6,11 @@ module XClarityClient
6
6
 
7
7
  def cancel_job(uuid='')
8
8
  cancelReq = JSON.generate(cancelRequest: 'true')
9
- response = @connection.do_put(managed_resource::BASE_URI + '/' + uuid, cancelReq)
10
- response
9
+ @connection.do_put(managed_resource::BASE_URI + '/' + uuid, cancelReq)
11
10
  end
12
11
 
13
12
  def delete_job(uuid='')
14
- response = @connection.do_delete(managed_resource::BASE_URI + '/' + uuid)
15
- response
13
+ @connection.do_delete(managed_resource::BASE_URI + '/' + uuid)
16
14
  end
17
15
  end
18
16
  end
@@ -0,0 +1,86 @@
1
+ require 'json'
2
+ require 'pathname'
3
+
4
+ module XClarityClient
5
+ # ManagementServerManagement class
6
+ class ManagementServerManagement < Services::XClarityService
7
+ manages_endpoint ManagementServer
8
+
9
+ private
10
+
11
+ def start_management_server_updates_import_job(file_type_dict, files, jobid)
12
+ url = "/files#{ManagementServer::BASE_URI}?action=import&jobid=#{jobid}"
13
+ index = 0
14
+ payload = {}
15
+ files.each do |file_name|
16
+ type = file_type_dict[File.extname(file_name)]
17
+ key = 'file_' + (index += 1).to_s
18
+ payload[key.to_sym] = Faraday::UploadIO.new(file_name, type)
19
+ end
20
+ @connection.do_post(url, payload, true)
21
+ end
22
+
23
+ def populate_payload_files(files, file_type_dict)
24
+ payload_files = []
25
+ index = 0
26
+ files.each do |file|
27
+ name = File.basename(file)
28
+ payload_file = { :index => index += 1, :name => name.strip,
29
+ :type => file_type_dict[File.extname(name)].strip,
30
+ :size => File.size?(file) }
31
+ payload_files.push(payload_file)
32
+ end
33
+ payload_files
34
+ end
35
+
36
+ public
37
+
38
+ def get_management_server_updates_info(key = nil)
39
+ base_url = ManagementServer::BASE_URI
40
+ url = key.nil? ? base_url : "#{base_url}?key=#{key}"
41
+ msg = "input key=#{key}"
42
+ $lxca_log.info(self.class.to_s + ' ' + __method__.to_s, msg)
43
+ @connection.do_get(url)
44
+ end
45
+
46
+ def download_management_server_updates(fixids)
47
+ url = "#{ManagementServer::BASE_URI}?action=acquire"
48
+ opts = { :fixids => fixids }
49
+ request_body = JSON.generate(opts)
50
+ @connection.do_post(url, request_body)
51
+ end
52
+
53
+ def import_management_server_updates(files)
54
+ url = "#{ManagementServer::BASE_URI}?action=import"
55
+ file_type_dict = { '.txt' => 'text/plain', '.xml' => 'text/xml',
56
+ '.chg' => 'application/octet-stream',
57
+ '.tgz' => 'application/x-compressed' }
58
+ payload_files = populate_payload_files(files, file_type_dict)
59
+ request_body = JSON.generate(:files => payload_files)
60
+ response = @connection.do_post(url, request_body)
61
+ jobid = JSON.parse(response.body)['jobid']
62
+ $lxca_log.info(self.class.to_s + ' ' + __method__.to_s, "jobid: #{jobid}")
63
+ start_management_server_updates_import_job(file_type_dict, files, jobid)
64
+ end
65
+
66
+ def apply_management_server_updates(fixids)
67
+ url = "#{ManagementServer::BASE_URI}?action=apply"
68
+ opts = { :fixids => fixids }
69
+ request_body = JSON.generate(opts)
70
+ @connection.do_put(url, request_body)
71
+ end
72
+
73
+ def delete_management_server_updates(fixids)
74
+ fixids = fixids.join(',')
75
+ url = "#{ManagementServer::BASE_URI}/#{fixids}"
76
+ @connection.do_delete(url)
77
+ end
78
+
79
+ def refresh_management_server_updates_catalog
80
+ url = "#{ManagementServer::BASE_URI}?action=refresh"
81
+ opts = { :mts => ['lxca'] }
82
+ request_body = JSON.generate(opts)
83
+ @connection.do_post(url, request_body)
84
+ end
85
+ end
86
+ end
@@ -20,5 +20,51 @@ module XClarityClient
20
20
 
21
21
  send_power_request(managed_resource::BASE_URI + '/' + uuid + '/bmc', requested_state)
22
22
  end
23
+
24
+ def retrieve_mounted_media_details(uuid)
25
+ uri = Node::BASE_URI + "/#{uuid}/" + 'mediaMount'
26
+ @connection.do_get(uri)
27
+ end
28
+
29
+ def enable_media_mount_support(uuid)
30
+ uri = Node::BASE_URI + "/#{uuid}/" + 'mediaMount'
31
+ req_body = JSON.generate(:action => 'enableMountMedia')
32
+ @connection.do_put(uri, req_body)
33
+ end
34
+
35
+ def disable_media_mount_support(uuid)
36
+ uri = Node::BASE_URI + "/#{uuid}/" + 'mediaMount'
37
+ req_body = JSON.generate(:action => 'disableMountMedia')
38
+ @connection.do_put(uri, req_body)
39
+ end
40
+
41
+ def remove_all_mounted_medias(uuid)
42
+ uri = Node::BASE_URI + "/#{uuid}/" + 'mediaMount'
43
+ req_body = JSON.generate(:action => 'reset')
44
+ @connection.do_put(uri, req_body)
45
+ end
46
+
47
+ def mount_media(uuid, opts)
48
+ uri = Node::BASE_URI + "/#{uuid}/" + 'mediaMount'
49
+ opts[:action] = 'mount'
50
+ req_body = JSON.generate(opts)
51
+ @connection.do_put(uri, req_body)
52
+ end
53
+
54
+ def unmount_media_thinkserver(uuid, media_type)
55
+ uri = Node::BASE_URI + "/#{uuid}/" + 'mediaMount'
56
+ opts = { :action => 'unmount',
57
+ :mediaType => media_type }
58
+ req_body = JSON.generate(opts)
59
+ @connection.do_put(uri, req_body)
60
+ end
61
+
62
+ def unmount_media_thinksystem(uuid, media_uid)
63
+ uri = Node::BASE_URI + "/#{uuid}/" + 'mediaMount'
64
+ opts = { :action => 'unmount',
65
+ :UID => media_uid }
66
+ req_body = JSON.generate(opts)
67
+ @connection.do_put(uri, req_body)
68
+ end
23
69
  end
24
70
  end
@@ -18,8 +18,9 @@ module XClarityClient
18
18
  request_body = JSON.generate(opts)
19
19
  image_name = path.split(File::SEPARATOR).last
20
20
  begin
21
- response = @connection.do_post("#{OsImage::BASE_URI}?jobId=#{job_id}"\
22
- "&imageType=OS&imageName=#{image_name}",
21
+ response = @connection.do_post('/files'\
22
+ + '#{OsImage::BASE_URI}?jobId=#{job_id}'\
23
+ '&imageType=OS&imageName=' + image_name,
23
24
  request_body)
24
25
  response
25
26
  rescue Faraday::TimeoutError => e
@@ -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'
@@ -13,11 +13,8 @@ module XClarityClient
13
13
  err_missing_key = 'Option key must be provided for update_repo resource'
14
14
  err_wrong_key = 'The value for option key should be one of these : '\
15
15
  "#{allowed_keys.join(', ')}"
16
-
17
16
  raise err_missing_key if opts.empty? || !(opts[:key] || opts['key'])
18
-
19
17
  repo_key = opts[:key] || opts['key']
20
-
21
18
  raise err_wrong_key unless allowed_keys.include?(repo_key)
22
19
  end
23
20
 
@@ -36,60 +33,116 @@ module XClarityClient
36
33
 
37
34
  public
38
35
 
39
- def check_file_types(file_types)
40
- x = 'Invalid value for argument file_types. Allowed values are'\
41
- + ' - all and payloads'
42
- raise x unless file_types.casecmp('payloads').zero? ||
43
- file_types.casecmp('all').zero?
36
+ def track_task_status(taskid, tasktype)
37
+ uri = UpdateRepo::BASE_URI + '/status' + '?tasktype=' + tasktype\
38
+ + '&taskid=' + taskid.to_s
39
+ @connection.do_get(uri)
40
+ end
41
+
42
+ def download_exported_firmware_updates(fname, dir_path_to_download)
43
+ uri = UpdateRepo::BASE_URI + '?action=export&exportRepoFilename=' + fname
44
+ file_path = File.join(dir_path_to_download, fname)
45
+ @connection.do_get_file_download(uri, file_path)
44
46
  end
45
47
 
46
48
  def read_update_repo
47
- response = @connection.do_put(UpdateRepo::BASE_URI + '?action=read')
48
- response.body
49
+ @connection.do_put(UpdateRepo::BASE_URI + '?action=read')
49
50
  end
50
51
 
51
- def refresh_update_repo(scope, mt, os)
52
- if scope.casecmp('all') != 0 && scope.casecmp('latest') != 0
52
+ def refresh_update_repo_catalog(scope, mt, uxsp = false)
53
+ unless %w(all latest).include?(scope)
53
54
  raise 'Invalid argument combination of action and scope. Action'\
54
55
  + ' refresh can have scope as either all or latest'
55
56
  end
56
- refresh_req = JSON.generate(:mt => mt, :os => os, :type => 'catalog')
57
- response = @connection.do_put(UpdateRepo::BASE_URI\
58
- + '?action=refresh&with='\
59
- + scope.downcase, refresh_req)
60
- response.body
57
+ req_body = JSON.generate(:mt => mt, :os => '', :type => 'catalog')
58
+ uri = UpdateRepo::BASE_URI
59
+ uri += '/uxsps' if uxsp
60
+ uri += '?action=refresh&with=' + scope
61
+ @connection.do_put(uri, req_body)
61
62
  end
62
63
 
63
- def acquire_firmware_updates(scope, fixids, mt)
64
- if scope.casecmp('payloads') != 0
65
- raise 'Invalid argument combination of action and scope. Action'\
66
- + ' acquire can have scope as payloads'
67
- end
68
- acquire_req = JSON.generate(:mt => mt, :fixids => fixids,
69
- :type => 'latest')
70
- response = @connection.do_put(UpdateRepo::BASE_URI\
71
- + '?action=acquire&with='\
72
- + scope.downcase, acquire_req)
73
- response.body
74
- end
75
-
76
- def delete_firmware_updates(file_types, fixids)
77
- check_file_types(file_types)
78
- delete_req = JSON.generate(:fixids => fixids)
79
- response = @connection.do_put(UpdateRepo::BASE_URI + '?action='\
80
- + 'delete&filetypes=' + file_types.downcase,
81
- delete_req)
82
- response.body
83
- end
84
-
85
- def export_firmware_updates(file_types, fixids)
86
- check_file_types(file_types)
87
-
88
- export_req = JSON.generate(:fixids => fixids)
89
- response = @connection.do_put(UpdateRepo::BASE_URI\
90
- + '?action=export&filetypes='\
91
- + file_types.downcase, export_req)
92
- response.body
64
+ def refresh_uxsp_update_repo_catalog(scope, mt)
65
+ refresh_update_repo_catalog(scope, mt, true)
66
+ end
67
+
68
+ def updates_info_by_machine_types(mt, uxsp = false)
69
+ mt = mt.join(',').to_str
70
+ uri = UpdateRepo::BASE_URI
71
+ uri += '/uxsps' if uxsp
72
+ key = 'uxspsByMt' if uxsp
73
+ key = 'updatesByMt' unless uxsp
74
+ uri += '?key=' + key + '&with=all&payload&mt=' + mt
75
+ @connection.do_get(uri)
76
+ end
77
+
78
+ def uxsp_updates_info_by_machine_types(mt)
79
+ updates_info_by_machine_types(mt, true)
80
+ end
81
+
82
+ def supported_machine_types_detail
83
+ @connection.do_get(UpdateRepo::BASE_URI + '?key=supportedMts')
84
+ end
85
+
86
+ def acquire_firmware_updates(mt, fixids)
87
+ req_body = JSON.generate(:mt => mt, :fixids => fixids, :type => 'latest')
88
+ @connection.do_put(UpdateRepo::BASE_URI\
89
+ + '?action=acquire&with=payloads', req_body)
90
+ end
91
+
92
+ def delete_firmware_updates(file_types, fixids = [])
93
+ req_body = JSON.generate(:fixids => fixids)
94
+ @connection.do_put(UpdateRepo::BASE_URI + '?action='\
95
+ + 'delete&filetypes=' + file_types.downcase,
96
+ req_body)
97
+ end
98
+
99
+ def export_firmware_updates(file_types, fixids = [])
100
+ req_body = JSON.generate(:fixids => fixids)
101
+ @connection.do_put(UpdateRepo::BASE_URI\
102
+ + '?action=export&filetypes='\
103
+ + file_types.downcase, req_body)
104
+ end
105
+
106
+ def validate_import_updates(file_path)
107
+ type = 'application/x-zip-compressed'
108
+ fname = File.basename(file_path)
109
+ opts = { :index => 0, :name => fname,
110
+ :type => type,
111
+ :size => File.size?(file_path) }
112
+ req_body = JSON.generate(opts)
113
+ uri = '/files/updateRepositories/firmware/import/validate'
114
+ @connection.do_post(uri, req_body)
115
+ end
116
+
117
+ def import_firmware_updates(file_path)
118
+ uri = '/files/updateRepositories/firmware/import'
119
+ type = 'application/x-zip-compressed'
120
+ opts = { :upload_file => Faraday::UploadIO.new(file_path, type) }
121
+ @connection.do_post(uri, opts, true)
122
+ end
123
+
124
+ def retrieve_compliance_policy_list
125
+ uri = '/compliancePolicies'
126
+ @connection.do_get(uri)
127
+ end
128
+
129
+ def export_compliance_policies(policy_names)
130
+ uri = '/compliancePolicies?action=export'
131
+ req_body = JSON.generate(:export => policy_names)
132
+ @connection.do_put(uri, req_body)
133
+ end
134
+
135
+ def download_exported_compliance_policies(fname, dir_path_for_download)
136
+ uri = '/compliancePolicies?exportDownload=' + fname
137
+ file_path = File.join(dir_path_for_download, fname)
138
+ @connection.do_get_file_download(uri, file_path)
139
+ end
140
+
141
+ def import_compliance_policies(file_path)
142
+ uri = '/files/compliancePolicies?action=import'
143
+ type = 'application/x-zip-compressed'
144
+ opts = { :upload_file => Faraday::UploadIO.new(file_path, type) }
145
+ @connection.do_post(uri, opts, true)
93
146
  end
94
147
  end
95
148
  end
@@ -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.9'.freeze
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,15 +17,15 @@ 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.11.2')
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"
24
24
  spec.add_development_dependency "webmock", "~> 2.1.0"
25
- spec.add_dependency "faraday", "~> 0.9"
25
+ spec.add_development_dependency "faker", "~> 1.8.3"
26
+ spec.add_dependency "faraday", '>= 0.9', '< 2.0.0'
26
27
  spec.add_dependency "faraday-cookie_jar", "~> 0.0.6"
27
28
  spec.add_dependency "httpclient", "~>2.8.3"
28
29
  spec.add_dependency "uuid", "~> 2.3.8"
29
- spec.add_dependency "faker", "~> 1.8.3"
30
30
  spec.add_dependency "json-schema", "~> 2.8.0"
31
31
  end
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.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manasa Rao
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-10-22 00:00:00.000000000 Z
12
+ date: 2022-02-15 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
- version: '1.12'
20
+ version: 1.11.2
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
- version: '1.12'
27
+ version: 1.11.2
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -82,19 +82,39 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: 2.1.0
84
84
  - !ruby/object:Gem::Dependency
85
- name: faraday
85
+ name: faker
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 1.8.3
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 1.8.3
98
+ - !ruby/object:Gem::Dependency
99
+ name: faraday
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
89
103
  - !ruby/object:Gem::Version
90
104
  version: '0.9'
105
+ - - "<"
106
+ - !ruby/object:Gem::Version
107
+ version: 2.0.0
91
108
  type: :runtime
92
109
  prerelease: false
93
110
  version_requirements: !ruby/object:Gem::Requirement
94
111
  requirements:
95
- - - "~>"
112
+ - - ">="
96
113
  - !ruby/object:Gem::Version
97
114
  version: '0.9'
115
+ - - "<"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.0.0
98
118
  - !ruby/object:Gem::Dependency
99
119
  name: faraday-cookie_jar
100
120
  requirement: !ruby/object:Gem::Requirement
@@ -137,20 +157,6 @@ dependencies:
137
157
  - - "~>"
138
158
  - !ruby/object:Gem::Version
139
159
  version: 2.3.8
140
- - !ruby/object:Gem::Dependency
141
- name: faker
142
- requirement: !ruby/object:Gem::Requirement
143
- requirements:
144
- - - "~>"
145
- - !ruby/object:Gem::Version
146
- version: 1.8.3
147
- type: :runtime
148
- prerelease: false
149
- version_requirements: !ruby/object:Gem::Requirement
150
- requirements:
151
- - - "~>"
152
- - !ruby/object:Gem::Version
153
- version: 1.8.3
154
160
  - !ruby/object:Gem::Dependency
155
161
  name: json-schema
156
162
  requirement: !ruby/object:Gem::Requirement
@@ -245,6 +251,7 @@ files:
245
251
  - lib/xclarity_client/endpoints/hostplatform.rb
246
252
  - lib/xclarity_client/endpoints/job.rb
247
253
  - lib/xclarity_client/endpoints/manage_request.rb
254
+ - lib/xclarity_client/endpoints/management_server.rb
248
255
  - lib/xclarity_client/endpoints/node.rb
249
256
  - lib/xclarity_client/endpoints/osimage.rb
250
257
  - lib/xclarity_client/endpoints/persisted_result.rb
@@ -284,6 +291,7 @@ files:
284
291
  - lib/xclarity_client/mixins/host_platform_mixin.rb
285
292
  - lib/xclarity_client/mixins/job_mixin.rb
286
293
  - lib/xclarity_client/mixins/manage_request_mixin.rb
294
+ - lib/xclarity_client/mixins/management_server_mixin.rb
287
295
  - lib/xclarity_client/mixins/mixins.rb
288
296
  - lib/xclarity_client/mixins/node_mixin.rb
289
297
  - lib/xclarity_client/mixins/os_image_mixin.rb
@@ -318,6 +326,7 @@ files:
318
326
  - lib/xclarity_client/services/hostplatform_management.rb
319
327
  - lib/xclarity_client/services/job_management.rb
320
328
  - lib/xclarity_client/services/manage_request_management.rb
329
+ - lib/xclarity_client/services/management_server_management.rb
321
330
  - lib/xclarity_client/services/mixins/endpoint_manager_mixin.rb
322
331
  - lib/xclarity_client/services/mixins/list_name_interpreter_mixin.rb
323
332
  - lib/xclarity_client/services/mixins/power_action_sender_mixin.rb
@@ -340,7 +349,6 @@ files:
340
349
  - lib/xclarity_client/services/xclarity_management_mixin.rb
341
350
  - lib/xclarity_client/services/xclarity_service.rb
342
351
  - lib/xclarity_client/version.rb
343
- - lib/xclarity_client/xclarity_base.rb
344
352
  - lib/xclarity_client/xclarity_credentials_validator.rb
345
353
  - xclarity_client.gemspec
346
354
  homepage: https://github.com/lenovo/xclarity_client
@@ -361,8 +369,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
361
369
  - !ruby/object:Gem::Version
362
370
  version: '0'
363
371
  requirements: []
364
- rubyforge_project:
365
- rubygems_version: 2.6.14
372
+ rubygems_version: 3.1.2
366
373
  signing_key:
367
374
  specification_version: 4
368
375
  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