Class: XClarityClient::ManageRequestManagement

Inherits:
Services::XClarityService show all
Defined in:
lib/xclarity_client/services/manage_request_management.rb

Overview

manage request management class

Instance Method Summary collapse

Methods inherited from Services::XClarityService

#fetch_all, #get_headers_with_opts, #get_object, #get_object_with_id, #get_object_with_opts, #initialize

Methods included from Services::ResponseBuilderMixin

#build_response_with_resource_list

Methods included from Services::ListNameInterpreterMixin

#add_listname_on_body

Constructor Details

This class inherits a constructor from XClarityClient::Services::XClarityService

Instance Method Details

#fetch_manage_request(job_id) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/xclarity_client/services/manage_request_management.rb', line 50

def fetch_manage_request(job_id)
  response = @connection.do_get(ManageRequest::BASE_URI + '/jobs/' + job_id)
  return [] unless response.success?
  body = JSON.parse(response.body)
  body = { ManageRequest::LIST_NAME => body } if body.kind_of?(Array)
  mrql = ManageRequest::LIST_NAME
  body = { ManageRequest::LIST_NAME => [body] } unless body.key?(mrql)
  body[ManageRequest::LIST_NAME].map do |resource_params|
    ManageRequest.new(resource_params)
  end
end

#manage_discovered_devices(manage_request) ⇒ Object



8
9
10
11
# File 'lib/xclarity_client/services/manage_request_management.rb', line 8

def manage_discovered_devices(manage_request)
  @connection.do_post(ManageRequest::BASE_URI,
                      JSON.generate([manage_request]))
end

#parse_manage_request(manage_request, val) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/xclarity_client/services/manage_request_management.rb', line 23

def parse_manage_request(manage_request, val)
  return false unless val.kind_of?(Array) && !val.empty?
  manage_request[:managementPorts] = val[0]['managementPorts']
  manage_request[:type] = val[0]['type']
  manage_request[:uuid] = val[0]['uuid']
  discovery_ip_addr = val[0]['ipAddresses'][0]
  manage_request[:ipAddresses] = [discovery_ip_addr]
  manage_request[:os] = val[0]['os'] if val[0]['type'] == 'Rackswitch'
  populate_manage_req_with_security_descriptor(manage_request, val[0])
end

#populate_manage_req_with_security_descriptor(manage_request, val) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/xclarity_client/services/manage_request_management.rb', line 13

def populate_manage_req_with_security_descriptor(manage_request, val)
  security_descriptor = {}
  val = val['securityDescriptor']
  security_descriptor[:managedAuthEnabled] = val['managedAuthSupported']
  security_descriptor[:managedAuthSupported] = val['managedAuthSupported']
  res = security_descriptor[:managedAuthEnabled]
  security_descriptor[:storedCredentials] = val['storedCredentials'] if res
  manage_request[:securityDescriptor] = security_descriptor
end

#populate_manage_request_with_discovery_res(discovery_result, manage_request) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/xclarity_client/services/manage_request_management.rb', line 34

def populate_manage_request_with_discovery_res(discovery_result,
                                               manage_request)
  discovery_result.map do |req|
    req.instance_variables.each do |attr|
      val = req.instance_variable_get(attr)
      parse_manage_request(manage_request, val)
    end
  end
end

#update_manage_request(manage_request, force, discovery_result) ⇒ Object



44
45
46
47
48
# File 'lib/xclarity_client/services/manage_request_management.rb', line 44

def update_manage_request(manage_request, force, discovery_result)
  populate_manage_request_with_discovery_res(discovery_result,
                                             manage_request)
  manage_request[:forceManage] = true if force.casecmp('true')
end