bin/sta in wakame-vdc-agents-10.11.0 vs bin/sta in wakame-vdc-agents-10.12.0
- old
+ new
@@ -17,13 +17,17 @@
job :create_volume do
volume_id = request.args[0]
job = Dcmgr::Stm::VolumeContext.new(volume_id)
data = rpc.request('sta-collector', 'get_volume', volume_id)
- sdata = rpc.request('sta-collector', 'get_snapshot', data[:snapshot_id]) unless data[:snapshot_id].nil?
- logger.info("creating new volume #{volume_id}")
raise "Invalid volume state: #{data[:state]}" unless data[:state].to_s == 'registering'
+
+ unless data[:snapshot_id].nil?
+ sdata = rpc.request('sta-collector', 'get_snapshot', data[:snapshot_id])
+ raise "Invalid snapshot state: #{sdata[:state]}" unless sdata[:state].to_s == 'available'
+ end
+ logger.info("creating new volume #{volume_id}")
job.stm.state=data[:state].to_sym
job.stm.on_create
vol_path = "#{data[:storage_pool][:export_path]}/#{data[:export_path]}"
`zfs list #{File.dirname(vol_path)} > /dev/null 2>&1`
@@ -117,10 +121,11 @@
snapshot_id = request.args[0]
job = Dcmgr::Stm::SnapshotContext.new(snapshot_id)
sdata = rpc.request('sta-collector', 'get_snapshot', snapshot_id) unless snapshot_id.nil?
data = rpc.request('sta-collector', 'get_volume', sdata[:origin_volume_id])
logger.info("create new snapshot: #{snapshot_id}")
+ raise "Invalid volume state: #{data[:state]}" unless data[:state].to_s == 'available'
job.stm.state=sdata[:state].to_sym
job.stm.on_create
vol_path = "#{data[:storage_pool][:export_path]}/#{data[:export_path]}"
snap_dir = "#{data[:storage_pool][:snapshot_base_path]}/#{sdata[:account_id]}"
@@ -142,17 +147,19 @@
end
job :delete_snapshot do
snapshot_id = request.args[0]
job = Dcmgr::Stm::SnapshotContext.new(snapshot_id)
- sdata = rpc.request('sta-collector', 'get_snapshot', snapshot_id) unless snapshot_id.nil?
+ sdata = rpc.request('sta-collector', 'get_snapshot', snapshot_id)
data = rpc.request('sta-collector', 'get_volume', sdata[:origin_volume_id])
logger.info("deleting snapshot: #{snapshot_id}")
raise "Invalid snapshot state: #{sdata[:state]}" unless sdata[:state].to_s == 'deleting'
job.stm.state=sdata[:state].to_sym
job.stm.on_delete
- snap_delete = `rm -rf #{data[:storage_pool][:snapshot_base_path]}/#{sdata[:account_id]}/#{sdata[:uuid]}.zsnap`
+ system("rm -rf #{data[:storage_pool][:snapshot_base_path]}/#{sdata[:account_id]}/#{sdata[:uuid]}.zsnap")
+ raise "snapshot has not be deleted" if $?.exitstatus != 0
+
rpc.request('sta-collector', 'update_snapshot', job.to_hash)
logger.info("deleted snapshot: #{snapshot_id}")
end
def rpc