xclarity_client 0.6.3 → 0.6.8

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.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/docs/apib/discover_request.apib +3 -1
  3. data/docs/apib/event.apib +0 -1
  4. data/docs/apib/manage_request.apib +359 -0
  5. data/docs/apib/storages.apib +3 -3
  6. data/docs/apib/update_comp.apib +426 -0
  7. data/docs/apib/update_repo.apib +0 -57
  8. data/lib/xclarity_client.rb +0 -1
  9. data/lib/xclarity_client/client.rb +3 -0
  10. data/lib/xclarity_client/connection/connection.rb +73 -35
  11. data/lib/xclarity_client/endpoints/endpoints.rb +3 -0
  12. data/lib/xclarity_client/endpoints/manage_request.rb +11 -0
  13. data/lib/xclarity_client/endpoints/management_server.rb +5 -0
  14. data/lib/xclarity_client/endpoints/storage.rb +7 -6
  15. data/lib/xclarity_client/endpoints/update_comp.rb +18 -0
  16. data/lib/xclarity_client/mixins/job_mixin.rb +0 -4
  17. data/lib/xclarity_client/mixins/manage_request_mixin.rb +54 -0
  18. data/lib/xclarity_client/mixins/management_server_mixin.rb +40 -0
  19. data/lib/xclarity_client/mixins/mixins.rb +3 -0
  20. data/lib/xclarity_client/mixins/node_mixin.rb +42 -0
  21. data/lib/xclarity_client/mixins/update_comp_mixin.rb +37 -0
  22. data/lib/xclarity_client/mixins/update_repo_mixin.rb +107 -7
  23. data/lib/xclarity_client/services/job_management.rb +2 -4
  24. data/lib/xclarity_client/services/manage_request_management.rb +62 -0
  25. data/lib/xclarity_client/services/management_server_management.rb +86 -0
  26. data/lib/xclarity_client/services/node_management.rb +46 -0
  27. data/lib/xclarity_client/services/osimage_management.rb +3 -2
  28. data/lib/xclarity_client/services/remote_access_management.rb +6 -4
  29. data/lib/xclarity_client/services/services.rb +3 -0
  30. data/lib/xclarity_client/services/update_comp_management.rb +111 -0
  31. data/lib/xclarity_client/services/update_repo_management.rb +100 -47
  32. data/lib/xclarity_client/services/virtual_appliance_management.rb +13 -16
  33. data/lib/xclarity_client/services/xclarity_service.rb +2 -3
  34. data/lib/xclarity_client/version.rb +1 -1
  35. data/lib/xclarity_client/xclarity_credentials_validator.rb +8 -11
  36. data/xclarity_client.gemspec +2 -2
  37. metadata +26 -11
  38. data/lib/xclarity_client/xclarity_base.rb +0 -88
@@ -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
@@ -34,6 +34,9 @@ require 'xclarity_client/services/scalable_complex_management'
34
34
  require 'xclarity_client/services/switch_management'
35
35
  require 'xclarity_client/services/storage_management'
36
36
  require 'xclarity_client/services/unmanage_request_management'
37
+ require 'xclarity_client/services/manage_request_management'
37
38
  require 'xclarity_client/services/update_repo_management'
39
+ require 'xclarity_client/services/update_comp_management'
38
40
  require 'xclarity_client/services/user_management'
39
41
  require 'xclarity_client/services/virtual_appliance_management'
42
+ require 'xclarity_client/services/management_server_management'
@@ -0,0 +1,111 @@
1
+ require 'json'
2
+
3
+ module XClarityClient
4
+ # update component management class
5
+ class UpdateCompManagement < Services::XClarityService
6
+ manages_endpoint UpdateComp
7
+
8
+ def updatable_device_comp
9
+ response = @connection.do_get(UpdateComp::BASE_URI\
10
+ + '?action=getComponents')
11
+ return [] unless response.success?
12
+ body = JSON.parse(response.body)
13
+ body = { UpdateComp::LIST_NAME => body } if body.kind_of?(Array)
14
+ j = body.key?(UpdateComp::LIST_NAME)
15
+ body = { UpdateComp::LIST_NAME => [body] } unless j
16
+ body[UpdateComp::LIST_NAME].map do |resource_params|
17
+ UpdateComp.new(resource_params)
18
+ end
19
+ end
20
+
21
+ def apply_firmware_update(opts, activation_mode, force_update_mode,
22
+ onerror_mode)
23
+ validate_arguments(activation_mode, force_update_mode, onerror_mode)
24
+
25
+ uri = create_uri(activation_mode, force_update_mode, onerror_mode)
26
+
27
+ apply_req = create_req_json(opts['server'], opts['switch'],
28
+ opts['storage'], opts['cmm'])
29
+ response = @connection.do_put(UpdateComp::BASE_URI + '?action=apply'\
30
+ + uri, apply_req)
31
+ response.body
32
+ end
33
+
34
+ def cancel_firmware_update(server, switch, storage, cmm)
35
+ cancel_req = create_req_json(server, switch, storage, cmm)
36
+ response = @connection.do_put(UpdateComp::BASE_URI\
37
+ + '?action=cancelApply',
38
+ cancel_req)
39
+ response.body
40
+ end
41
+
42
+ def modify_power_state(server, switch, storage, cmm)
43
+ power_state_req = create_req_json(server, switch, storage, cmm)
44
+ response = @connection.do_put(UpdateComp::BASE_URI + '?action=powerState',
45
+ power_state_req)
46
+ response.body
47
+ end
48
+
49
+ def validate_activation_mode(activation_mode)
50
+ if !activation_mode.nil? && !activation_mode.casecmp('immediate').zero? &&
51
+ !activation_mode.casecmp('delayed').zero?
52
+
53
+ raise 'Invalid argument specified. Operation apply_firmware_update'\
54
+ + ' can have activationMode as either immediare or delayed.'
55
+ end
56
+ end
57
+
58
+ def validate_forceupdate_mode(forceupdate_mode)
59
+ if !forceupdate_mode.nil? && !forceupdate_mode.casecmp('true').zero? &&
60
+ !forceupdate_mode.casecmp('false').zero?
61
+
62
+ raise 'Invalid argument specified. Value for forceUpdateMode on'\
63
+ + ' operation apply_firmware_update should have a value'\
64
+ + ' of either true or false'
65
+ end
66
+ end
67
+
68
+ def validate_onerror_mode(onerror_mode)
69
+ if !onerror_mode.nil? && !onerror_mode.eql?('stopOnError') &&
70
+ !onerror_mode.eql?('stopdeviceOnError') &&
71
+ !onerror_mode.eql?('continueOnError')
72
+
73
+ raise 'Invalid argument specified. Operation apply_firmware_update'\
74
+ + " should have onErrorMode as : 'stopOnError' or"\
75
+ + " 'stopdeviceOnError' or 'continueOnError'"
76
+ end
77
+ end
78
+
79
+ def validate_arguments(activation_mode, forceupdate_mode, onerror_mode)
80
+ validate_activation_mode(activation_mode)
81
+ validate_forceupdate_mode(forceupdate_mode)
82
+ validate_onerror_mode(onerror_mode)
83
+ end
84
+
85
+ # splitted create_uri just to fix codeclimate error
86
+ def add_uri(force_update_mode, onerror_mode, uri)
87
+ fmode = force_update_mode.nil?
88
+ uri += '&forceUpdateMode=' + force_update_mode unless fmode
89
+ uri += '&onErrorMode=' + onerror_mode unless onerror_mode.nil?
90
+ uri
91
+ end
92
+
93
+ def create_uri(activation_mode, force_update_mode, onerror_mode)
94
+ uri = ''
95
+ amode = activation_mode.nil?
96
+ uri += '&activationMode=' + activation_mode unless amode
97
+ add_uri(force_update_mode, onerror_mode, uri)
98
+ end
99
+
100
+ def create_req_json(server, switch, storage, cmm)
101
+ server_json = JSON.generate(:ServerList => server)
102
+ switch_json = JSON.generate(:SwitchList => switch)
103
+ storage_json = JSON.generate(:StorageList => storage)
104
+ cmm_json = JSON.generate(:CMMList => cmm)
105
+
106
+ req_json = "{\"DeviceList\": [#{server_json},#{switch_json},"\
107
+ + "#{storage_json},#{cmm_json}]}"
108
+ req_json
109
+ end
110
+ end
111
+ end
@@ -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
@@ -85,9 +85,8 @@ module XClarityClient
85
85
  end
86
86
 
87
87
  def do_request_with_opts(uri, opts)
88
- allowed_query_keys = %w(type sort)
89
- query = opts.select { |key| allowed_query_keys.include?(key) }
90
- headers = opts['headers'] || Hash.new(0)
88
+ query = opts.reject { |key| 'headers'.eql?(key) }
89
+ headers = opts['headers'] || {}
91
90
 
92
91
  @connection.do_get(uri, :query => query, :headers => headers)
93
92
  end
@@ -1,3 +1,3 @@
1
1
  module XClarityClient
2
- VERSION = "0.6.3"
2
+ VERSION = '0.6.8'.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