# -*- coding: utf-8 -*- require 'isono' module Dcmgr module NodeModules class StaCollector < Isono::NodeModules::Base initialize_hook do app = Isono::Rack::ObjectMethod.new(myinstance) rpc = Isono::NodeModules::RpcChannel.new(node) rpc.register_endpoint('sta-collector', Isono::Rack.build do use Isono::Rack::DataStore run proc { |req, res| Thread.current[Models::BaseNew::LOCK_TABLES_KEY] = {} app.call(req, res) } end) end terminate_hook do end def get_volume(volume_id) Models::Volume.lock! v = Dcmgr::Models::Volume[volume_id] v.merge_pool_data end def get_snapshot(snapshot_id) Models::VolumeSnapshot.lock! vs = Dcmgr::Models::VolumeSnapshot[snapshot_id] vs.to_hash_document end def update_volume(data) Models::Volume.lock! v = Dcmgr::Models::Volume[data[:volume_id]] column = case data[:state] when :creating [:state, :export_path] when :available if !data[:transport_information].nil? [:state, :transport_information] else [:state, :host_device_name, :instance_id, :detached_at] end when :attaching [:state, :host_device_name] when :attached [:state, :guest_device_name, :attached_at] when :detaching [:state, :guest_device_name] else [:state] end v.set_fields(data, column).save # do not respond model object. nil end def update_snapshot(data) Models::VolumeSnapshot.lock! vs = Dcmgr::Models::VolumeSnapshot[data[:snapshot_id]] vs.set_fields(data, [:state]).save # do not respond model object. nil end end end end