class Sarchive::Sacloud
Public Class Methods
new(token, secret, logger)
click to toggle source
# File lib/sarchive/sacloud.rb, line 6 def initialize(token, secret, logger) @sarchive_tag = 'sarchive_' @api = Saklient::Cloud::API::authorize(token, secret) @logger = logger end
Public Instance Methods
create_archive(disk_id)
click to toggle source
# File lib/sarchive/sacloud.rb, line 16 def create_archive(disk_id) disk = get_disk(disk_id) unless disk fail("対象のディスク[id=#{disk_id}]が見つかりません。アーカイブの作成をスキップします") end created_at = Time.now.strftime("%Y-%m-%d %H:%M:%S") archive = @api.archive.create archive.name = disk.name archive.description = "Created by sarchive at #{created_at}" archive.tags = [@sarchive_tag] archive.source = disk archive.save unless archive.sleep_while_copying fail("ディスク[id=#{disk.id}, name=#{disk.name}]からアーカイブへのコピーがタイムアウトまたは失敗しました。コントロールパネルでステータスを確認してください") end archive rescue => e @logger.error(e.message) nil end
delete_archive(disk_id)
click to toggle source
# File lib/sarchive/sacloud.rb, line 43 def delete_archive(disk_id) archive = @api.archive.get_by_id(disk_id.to_s) rescue nil unless archive fail("削除対象のアーカイブ[id=#{disk_id}]が見つかりません。アーカイブの削除をスキップします") end archive.destroy archive rescue => e @logger.error(e.message) nil end
find_stored_archives(disk_id)
click to toggle source
# File lib/sarchive/sacloud.rb, line 58 def find_stored_archives(disk_id) @api.archive. filter_by('SourceDisk.ID', disk_id.to_s). with_tag(@sarchive_tag). find rescue nil end
set_zone(zone)
click to toggle source
# File lib/sarchive/sacloud.rb, line 12 def set_zone(zone) @api = @api.in_zone(zone) end
Private Instance Methods
get_disk(disk_id)
click to toggle source
# File lib/sarchive/sacloud.rb, line 69 def get_disk(disk_id) @api.disk.get_by_id(disk_id.to_s) rescue nil end