Class: XClarityClient::OsImageManagement

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

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

#import_osimage(server_id, path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/xclarity_client/services/osimage_management.rb', line 8

def import_osimage(server_id, path)
  msg="inputs serverId=#{server_id},path=#{path}"
  $lxca_log.info self.class.to_s+" "+__method__.to_s, msg
  opts = { :Action => "Init" }
  request_body = JSON.generate(opts)
  response = @connection.do_post("#{OsImage::BASE_URI}?imageType=OS",
                                 request_body)
  response = JSON.load(response.body).to_hash
  job_id = response["jobId"]
  opts = { :serverId => server_id, :path => path }
  request_body = JSON.generate(opts)
  image_name = path.split(File::SEPARATOR).last
  begin
    response = @connection.do_post('/files'\
                                   + '#{OsImage::BASE_URI}?jobId=#{job_id}'\
                                   '&imageType=OS&imageName=' + image_name,
                                   request_body)
    response
  rescue Faraday::TimeoutError => e
    result = {
      :result => "importing image is in progress with jobId #{job_id}"
    }
    result
  end
end