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_name ⇒ Object
Returns the value of attribute server_name.
Class Method Summary collapse
Instance Method Summary collapse
- #clone(new_server, version = self.version) ⇒ Object
- #completed? ⇒ Boolean
- #create ⇒ Object
- #delete ⇒ Object
- #destroy ⇒ Object
- #devs ⇒ Object
- #ec2_ids ⇒ Object
- #fetch_state ⇒ Object
- #get(key) ⇒ Object
- #group ⇒ Object
- #group_name ⇒ Object
-
#initialize(base, name, server_name) ⇒ Snapshot
constructor
A new instance of Snapshot.
- #server ⇒ Object
- #size(snap_id) ⇒ Object
- #state ⇒ Object
- #version ⇒ Object
- #version_desc ⇒ Object
Constructor Details
#initialize(base, name, server_name) ⇒ Snapshot
Returns a new instance of Snapshot.
9 10 11 12 13 |
# File 'lib/judo/snapshot.rb', line 9 def initialize(base, name, server_name) @base = base @name = name @server_name = server_name 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_name ⇒ Object
Returns the value of attribute server_name.
3 4 5 |
# File 'lib/judo/snapshot.rb', line 3 def server_name @server_name end |
Class Method Details
.domain ⇒ Object
5 6 7 |
# File 'lib/judo/snapshot.rb', line 5 def self.domain "judo_snapshots" end |
Instance Method Details
#clone(new_server, version = self.version) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/judo/snapshot.rb', line 51 def clone(new_server, version = self.version) raise JudoError, "cannot clone, snapshotting not complete" unless completed? server = @base.new_server(new_server, group_name) server.create( :version => version, :snapshots => devs) server.update "clone" => name ##, "secret" => rand(2 ** 128).to_s(36) ## cant change this till kuzushi knows about a post-clone operation end |
#completed? ⇒ Boolean
84 85 86 |
# File 'lib/judo/snapshot.rb', line 84 def completed? not @base.ec2_snapshots.select { |s| ec2_ids.include? s[:aws_id] }.detect { |s| s[:aws_status] != "completed" } end |
#create ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/judo/snapshot.rb', line 39 def create raise JudoError,"snapshot already exists" unless state.empty? raise JudoError,"server has no disks to clone: #{server.volumes}" if server.volumes.empty? 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(self.class.domain, name, { "version" => server.version, "devs" => devs, "server" => server.name, "group" => server.group.name }, :replace) server.add "snapshots", name end end |
#delete ⇒ Object
58 59 60 61 |
# File 'lib/judo/snapshot.rb', line 58 def delete @base.sdb.delete_attributes(self.class.domain, name) server.remove "snapshots", name end |
#destroy ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/judo/snapshot.rb', line 67 def destroy devs.each do |dev,snapshot_id| task("Deleting #{dev} #{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
35 36 37 |
# File 'lib/judo/snapshot.rb', line 35 def devs Hash[ (state["devs"] || []).map { |a| a.split(":") } ] end |
#ec2_ids ⇒ Object
80 81 82 |
# File 'lib/judo/snapshot.rb', line 80 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(self.class.domain, name)[:attributes] end |
#get(key) ⇒ Object
63 64 65 |
# File 'lib/judo/snapshot.rb', line 63 def get(key) state[key] && [state[key]].flatten.first end |
#group ⇒ Object
96 97 98 |
# File 'lib/judo/snapshot.rb', line 96 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 |
#server ⇒ Object
15 16 17 |
# File 'lib/judo/snapshot.rb', line 15 def server @server ||= @base.servers.detect { |s| s.name == @server_name } end |
#size(snap_id) ⇒ Object
88 89 90 |
# File 'lib/judo/snapshot.rb', line 88 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
31 32 33 |
# File 'lib/judo/snapshot.rb', line 31 def version get("version").to_i end |
#version_desc ⇒ Object
92 93 94 |
# File 'lib/judo/snapshot.rb', line 92 def version_desc group.version_desc(version) end |