Class: Judo::Snapshot
- Inherits:
-
Object
- Object
- Judo::Snapshot
- Defined in:
- lib/judo/snapshot.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#server_id ⇒ Object
Returns the value of attribute server_id.
Instance Method Summary collapse
- #animate(new_server_name) ⇒ Object
- #completed? ⇒ Boolean
- #create ⇒ Object
- #created_at ⇒ Object
- #delete ⇒ Object
- #destroy ⇒ Object
- #devs ⇒ Object
- #ec2_data ⇒ Object
- #ec2_ids ⇒ Object
- #fetch_state ⇒ Object
- #get(key) ⇒ Object
- #group ⇒ Object
- #group_name ⇒ Object
-
#initialize(base, name, server_id) ⇒ Snapshot
constructor
A new instance of Snapshot.
- #metadata ⇒ Object
- #progress ⇒ Object
- #server ⇒ Object
- #server_name ⇒ Object
- #size(snap_id) ⇒ Object
- #state ⇒ Object
- #version ⇒ Object
- #version_desc ⇒ Object
- #virgin ⇒ Object
Constructor Details
#initialize(base, name, server_id) ⇒ Snapshot
Returns a new instance of Snapshot.
5 6 7 8 9 |
# File 'lib/judo/snapshot.rb', line 5 def initialize(base, name, server_id) @base = base @name = name @server_id = server_id end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/judo/snapshot.rb', line 3 def name @name end |
#server_id ⇒ Object
Returns the value of attribute server_id.
3 4 5 |
# File 'lib/judo/snapshot.rb', line 3 def server_id @server_id end |
Instance Method Details
#animate(new_server_name) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/judo/snapshot.rb', line 71 def animate(new_server_name) raise JudoError, "cannot animate, snapshotting not complete" unless completed? @base.create_server(new_server_name, group_name, :version => version, :snapshots => devs, :virgin => virgin, :metadata => , :clone => name, :instance_type => server.instance_type) end |
#completed? ⇒ Boolean
108 109 110 |
# File 'lib/judo/snapshot.rb', line 108 def completed? not ec2_data.detect { |s| s[:aws_status] != "completed" } end |
#create ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/judo/snapshot.rb', line 52 def create raise JudoError,"snapshot already exists" unless state.empty? raise JudoError,"server has no disks to clone: #{server.volumes}" if server.volumes.empty? @base.task("Snapshotting #{server.name}") do devs = server.volumes.map do |dev,vol| "#{dev}:#{@base.ec2.create_snapshot(vol)[:aws_id]}" end @base.sdb.put_attributes(@base.snapshot_domain, name, { "version" => server.version, "virgin" => server.virgin?, "metadata_json" => server.get("metadata_json"), "devs" => devs, "server" => server.id, "group" => server.group.name, "created_at" => Time.now.to_i.to_s }, :replace) end end |
#created_at ⇒ Object
31 32 33 |
# File 'lib/judo/snapshot.rb', line 31 def created_at Time.at(get("created_at").to_i) end |
#delete ⇒ Object
78 79 80 81 |
# File 'lib/judo/snapshot.rb', line 78 def delete raise JudoError, "cannot delete, snapshotting not complete" unless completed? @base.sdb.delete_attributes(@base.snapshot_domain, name) end |
#destroy ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/judo/snapshot.rb', line 87 def destroy devs.each do |dev,snapshot_id| @base.task("Deleting snapshot #{snapshot_id}") do begin @base.ec2.delete_snapshot(snapshot_id) rescue Object => e puts "Error destrotying snapshot #{e.}" end end end delete end |
#devs ⇒ Object
48 49 50 |
# File 'lib/judo/snapshot.rb', line 48 def devs (state["devs"] || []).inject({}) { |out, kv| k, v = kv.split(':'); out[k] = v; out } end |
#ec2_data ⇒ Object
104 105 106 |
# File 'lib/judo/snapshot.rb', line 104 def ec2_data @base.ec2_snapshots.select { |s| ec2_ids.include? s[:aws_id] } end |
#ec2_ids ⇒ Object
100 101 102 |
# File 'lib/judo/snapshot.rb', line 100 def ec2_ids devs.values end |
#fetch_state ⇒ Object
19 20 21 |
# File 'lib/judo/snapshot.rb', line 19 def fetch_state @base.sdb.get_attributes(@base.snapshot_domain, name)[:attributes] end |
#get(key) ⇒ Object
83 84 85 |
# File 'lib/judo/snapshot.rb', line 83 def get(key) state[key] && [state[key]].flatten.first end |
#group ⇒ Object
125 126 127 |
# File 'lib/judo/snapshot.rb', line 125 def group @group ||= @base.groups.detect { |g| g.name == group_name } end |
#group_name ⇒ Object
27 28 29 |
# File 'lib/judo/snapshot.rb', line 27 def group_name get("group") end |
#metadata ⇒ Object
39 40 41 42 |
# File 'lib/judo/snapshot.rb', line 39 def = get("metadata_json") JSON.load() if end |
#progress ⇒ Object
112 113 114 115 |
# File 'lib/judo/snapshot.rb', line 112 def progress min_percent = ec2_data.map { |s| s[:aws_progress].to_i }.min "#{min_percent}%" end |
#server ⇒ Object
15 16 17 |
# File 'lib/judo/snapshot.rb', line 15 def server @server ||= @base.servers.detect { |s| s.id == server_id } end |
#server_name ⇒ Object
11 12 13 |
# File 'lib/judo/snapshot.rb', line 11 def server_name server.name rescue '(deleted)' end |
#size(snap_id) ⇒ Object
117 118 119 |
# File 'lib/judo/snapshot.rb', line 117 def size(snap_id) @base.ec2_snapshots.detect { |s| s[:aws_id] == snap_id } end |
#state ⇒ Object
23 24 25 |
# File 'lib/judo/snapshot.rb', line 23 def state @base.snapshots_state[name] ||= fetch_state end |
#version ⇒ Object
35 36 37 |
# File 'lib/judo/snapshot.rb', line 35 def version get("version").to_i end |
#version_desc ⇒ Object
121 122 123 |
# File 'lib/judo/snapshot.rb', line 121 def version_desc group.version_desc(version) end |
#virgin ⇒ Object
44 45 46 |
# File 'lib/judo/snapshot.rb', line 44 def virgin get("virgin").to_s == "true" end |