Class: Dcmgr::Rpc::StaHandler

Inherits:
EndpointBuilder
  • Object
show all
Includes:
Helpers::CliHelper, Logger
Defined in:
lib/dcmgr/rpc/sta_handler.rb

Instance Method Summary collapse

Methods included from Helpers::CliHelper

#sh, #tryagain

Methods included from Logger

create, default_logdev, included

Instance Method Details

#eventObject



206
207
208
# File 'lib/dcmgr/rpc/sta_handler.rb', line 206

def event
  @event ||= Isono::NodeModules::EventChannel.new(@node)
end

#jobreqObject



202
203
204
# File 'lib/dcmgr/rpc/sta_handler.rb', line 202

def jobreq
  @jobreq ||= Isono::NodeModules::JobChannel.new(@node)
end

#rpcObject



198
199
200
# File 'lib/dcmgr/rpc/sta_handler.rb', line 198

def rpc
  @rpc ||= Isono::NodeModules::RpcChannel.new(@node)
end

#select_backing_storeObject



12
13
14
15
# File 'lib/dcmgr/rpc/sta_handler.rb', line 12

def select_backing_store
  backing_store = @node.manifest.config.backing_store 
  @backing_store = Dcmgr::Drivers::BackingStore.select_backing_store(backing_store)
end

#select_iscsi_targetObject



17
18
19
20
# File 'lib/dcmgr/rpc/sta_handler.rb', line 17

def select_iscsi_target
  iscsi_target = @node.manifest.config.iscsi_target
  @iscsi_target = Dcmgr::Drivers::IscsiTarget.select_iscsi_target(iscsi_target, @node)
end

#setup_and_export_volumeObject

Setup volume file from snapshot storage and register to sotrage target.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dcmgr/rpc/sta_handler.rb', line 24

def setup_and_export_volume
  snapshot_file = nil 
  unless @volume[:snapshot_id].nil?
    @snapshot = rpc.request('sta-collector', 'get_snapshot', @volume[:snapshot_id])
    raise "Invalid snapshot state: #{@snapshot[:state]}" unless @snapshot[:state].to_s == 'available'
    snap_filename = @destination[:filename] 
    
    begin
      storage_service = Dcmgr::StorageService.new(@destination[:driver], {
        :account_id => @snapshot[:account_id],
        :access_key => @destination[:access_key], 
        :secret_key => @destination[:secret_key],
      })
      snapshot_storage = storage_service.snapshot_storage(@destination[:bucket], @destination[:path]) 
      snapshot_storage.download(snap_filename)
      snapshot_file = snapshot_storage.snapshot(snap_filename)
      logger.info("download to #{@destination[:driver]}: #{snap_filename}")
    rescue => e
      logger.error(e)
      raise "snapshot not downloaded"
    end
  end

  logger.info("creating new volume #{@volume_id}")

  rpc.request('sta-collector', 'update_volume', @volume_id, {:state=>:creating, :export_path=>@volume[:uuid]})

  select_backing_store
  @backing_store.create_volume(StaContext.new(self), snapshot_file)
  
  unless @volume[:snapshot_id].nil?
    snapshot_storage.clear
  end

  select_iscsi_target
  opt = @iscsi_target.create(StaContext.new(self))
  rpc.request('sta-collector', 'update_volume', @volume_id, {:state=>:available, :transport_information=>opt})
  logger.info("registered iscsi target: #{@volume_id}")
end