Class: Rudy::MetaData::Disk
- Inherits:
-
Storable
- Object
- Storable
- Rudy::MetaData::Disk
show all
- Includes:
- ObjectBase
- Defined in:
- lib/rudy/metadata/disk.rb
Instance Method Summary
collapse
Methods included from ObjectBase
#==, #initialize, #liner_note, #refresh, #save
Methods included from Huxtable
change_environment, change_position, change_region, change_role, change_zone, #check_keys, #config_dirname, create_domain, #current_group_name, #current_machine_address, #current_machine_count, #current_machine_group, #current_machine_hostname, #current_machine_image, #current_machine_name, #current_machine_size, #current_user, #current_user_keypairpath, debug?, #debug?, domain, domain_exists?, #group_metadata, #has_keypair?, #has_keys?, #has_pem_keys?, #has_root_keypair?, keypair_path_to_name, #known_machine_group?, #root_keypairname, #root_keypairpath, #switch_user, update_config, update_global, update_logger, #user_keypairname, #user_keypairpath
Instance Method Details
#attach(instid) ⇒ Object
110
111
112
113
|
# File 'lib/rudy/metadata/disk.rb', line 110
def attach(instid)
raise "No volume id" unless exists?
vol = @rvol.attach(@awsid, instid, @device)
end
|
#backup ⇒ Object
90
91
92
93
94
95
96
|
# File 'lib/rudy/metadata/disk.rb', line 90
def backup
raise "No volume to backup" unless @awsid
bup = Rudy::MetaData::Backup.new(@awsid, @path, @position)
bup.size = @size || 1
bup.fstype = @fstype || 'ext3'
bup.create
end
|
#create(size = nil, zone = nil, snapshot = nil) ⇒ Object
81
82
83
84
85
86
87
88
|
# File 'lib/rudy/metadata/disk.rb', line 81
def create(size=nil, zone=nil, snapshot=nil)
raise "#{name} already exists" if exists?
vol = @rvol.create(size || @size, zone || @zone, snapshot)
@awsid = vol.awsid
@raw = true
self.save
self
end
|
#destroy(force = false) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/rudy/metadata/disk.rb', line 120
def destroy(force=false)
if @awsid && !deleting?
if !force
raise Rudy::AWS::EC2::VolumeNotAvailable, @awsid if attached?
else
detach if exists? && attached?
sleep 0.1
end
raise Rudy::AWS::EC2::VolumeNotAvailable, @awsid if in_use?
@rvol.destroy(@awsid) if exists? && available?
end
super() end
|
#detach ⇒ Object
115
116
117
118
|
# File 'lib/rudy/metadata/disk.rb', line 115
def detach
raise "No volume id" unless exists?
vol = @rvol.detach(@awsid)
end
|
#init(path = nil, size = nil, device = nil, position = nil) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/rudy/metadata/disk.rb', line 31
def init(path=nil, size=nil, device=nil, position=nil)
@path, @size, @device = path, size, device
@rtype = 'disk'
@region = @@global.region
@zone = @@global.zone
@environment = @@global.environment
@role = @@global.role
@position = position || @@global.position
@mounted = false
now = Time.now.utc
datetime = Backup.format_timestamp(now).split(Rudy::DELIM)
@created = now.to_i
postprocess
end
|
#inspect ⇒ Object
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/rudy/metadata/disk.rb', line 63
def inspect
lines = []
lines << liner_note
field_names.each do |key|
next unless self.respond_to?(key)
val = self.send(key)
lines << sprintf(" %22s: %s", key, (val.is_a?(Array) ? val.join(', ') : val))
end
lines.join($/)
end
|
#list_backups ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/rudy/metadata/disk.rb', line 98
def list_backups
rback = Rudy::Backups.new
props = {
:environment => @environment,
:role => @role,
:zone => @zone,
:region => @region,
:position => @position
}
rback.list([], [], props)
end
|
#mounted? ⇒ Boolean
164
165
166
|
# File 'lib/rudy/metadata/disk.rb', line 164
def mounted?
@mounted && @mounted == true
end
|
#name ⇒ Object
74
75
76
77
78
79
|
# File 'lib/rudy/metadata/disk.rb', line 74
def name
sep=File::SEPARATOR
dirs = @path.split sep if @path && !@path.empty?
dirs.shift while dirs && (dirs[0].nil? || dirs[0].empty?)
super("disk", @zone, @environment, @role, @position, *dirs)
end
|
#postprocess ⇒ Object
48
49
50
51
|
# File 'lib/rudy/metadata/disk.rb', line 48
def postprocess
@size &&= @size.to_i
@mounted = true if @mounted == "true"
end
|
#to_query(more = [], less = []) ⇒ Object
148
149
150
|
# File 'lib/rudy/metadata/disk.rb', line 148
def to_query(more=[], less=[])
super([:path, *more], less) end
|
#to_s(with_titles = true) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/rudy/metadata/disk.rb', line 53
def to_s(with_titles=true)
update
mtd = @mounted == true ? "mounted" : @status
if @size && @device
"%s; %3sGB; %s; %s" % [liner_note, @size, @device, mtd]
else
liner_note
end
end
|
#to_select(more = [], less = []) ⇒ Object
152
153
154
|
# File 'lib/rudy/metadata/disk.rb', line 152
def to_select(more=[], less=[])
super([:path, *more], less)
end
|
#update ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/rudy/metadata/disk.rb', line 134
def update
@awsid = nil if @awsid && @awsid.empty?
@volume = @rvol.get(@awsid) if @awsid
if @volume.is_a?(Rudy::AWS::EC2::Volume)
@status = @volume.status
@instid = @volume.instid
save
else
@awsid, @status, @instid = nil, nil, nil
@mounted = false end
end
|
#valid? ⇒ Boolean
Does this disk have enough info to be saved or used? The test is based on the same criteria for building SimpleDB queries.
159
160
161
162
|
# File 'lib/rudy/metadata/disk.rb', line 159
def valid?
criteria = build_criteria([:path]).flatten
criteria.size == criteria.compact.size
end
|