Methods
public class
public instance
Included modules
- Rudy::Metadata
- Gibbler::Complex
Public class methods
new
(position=nil, path=nil, opts={})
If one argument is supplied:
- path is a an absolute filesystem path
- opts is a hash of disk options.
If two arguments are supplied:
- position
- path is a an absolute filesystem path
- opts is a hash of disk options.
Valid options are:
- :path is a an absolute filesystem path (overridden by path arg)
- :position (overridden by position arg)
- :size
- :device
[show source]
# File lib/rudy/metadata/disk.rb, line 44 44: def initialize(position=nil, path=nil, opts={}) 45: # Swap arg values if only one is supplied. 46: path, position = position, nil if !position.nil? && path.nil? 47: position ||= '01' 48: 49: opts = { 50: :size => 1, 51: :device => current_machine_os.to_s == 'windows' ? DEFAULT_WINDOWS_DEVICE : DEFAULT_LINUX_DEVICE 52: }.merge opts 53: 54: super Rudy::Disks::RTYPE, opts # Rudy::Metadata#initialize 55: 56: @position, @path = position, path 57: 58: # Defaults: 59: #datetime = Backup.format_timestamp(now).split(Rudy::DELIM) 60: @created = Time.now.utc 61: @mounted = false 62: postprocess 63: 64: end
Public instance methods
archive
()
[show source]
# File lib/rudy/metadata/disk.rb, line 97 97: def archive 98: raise Rudy::AWS::EC2::VolumeNotAvailable, @volid unless volume_attached? 99: back = Rudy::Backup.new @position, @path, self.descriptors 100: back.create 101: back.size, back.fstype = @size, @fstype 102: back.save :replace 103: back 104: end
backups
()
[show source]
# File lib/rudy/metadata/disk.rb, line 106 106: def backups 107: Rudy::Backups.list self.descriptors 108: end
create
(size=nil, zone=nil, snapshot=nil)
[show source]
# File lib/rudy/metadata/disk.rb, line 88 88: def create(size=nil, zone=nil, snapshot=nil) 89: raise DuplicateRecord, self.name if exists? && !@@global.force 90: vol = Rudy::AWS::EC2::Volumes.create(size || @size, zone || @zone, snapshot) 91: #vol = Rudy::AWS::EC2::Volumes.list(:available).first # debugging 92: @volid, @raw = vol.awsid, true 93: self.save :replace 94: self 95: end
descriptors
()
[show source]
# File lib/rudy/metadata/disk.rb, line 125 125: def descriptors 126: super :position, :path 127: end
destroy
(force=false)
[show source]
# File lib/rudy/metadata/disk.rb, line 111 111: def destroy(force=false) 112: if @volid && !volume_deleting? 113: if !force 114: raise Rudy::AWS::EC2::VolumeNotAvailable, @volid if volume_attached? 115: else 116: volume_detach if volume_exists? && volume_attached? 117: sleep 0.1 118: end 119: raise Rudy::AWS::EC2::VolumeNotAvailable, @volid if volume_in_use? 120: Rudy::AWS::EC2::Volumes.destroy(@volid) if volume_exists? && volume_available? 121: end 122: super() # quotes, otherwise Ruby will send this method's args 123: end
mounted?
()
[show source]
# File lib/rudy/metadata/disk.rb, line 150 150: def mounted? 151: @mounted == true 152: end
name
()
[show source]
# File lib/rudy/metadata/disk.rb, line 78 78: def name 79: sep = File::SEPARATOR 80: dirs = @path.split sep if @path && !@path.empty? 81: unless @path == File::SEPARATOR 82: dirs.shift while dirs && (dirs[0].nil? || dirs[0].empty?) 83: end 84: # Calls Rudy::Metadata#name with disk specific components 85: super *dirs 86: end
postprocess
()
sdb values are stored as strings. Some quick conversion.
[show source]
# File lib/rudy/metadata/disk.rb, line 67 67: def postprocess 68: @position = @position.to_s.rjust(2, '0') if @position.to_s.size == 1 69: @size &&= @size.to_i 70: @raw = true if @raw == "true" unless @raw.is_a?(TrueClass) 71: @mounted = (@mounted == "true") unless @mounted.is_a?(TrueClass) 72: end
raw?
()
[show source]
# File lib/rudy/metadata/disk.rb, line 146 146: def raw? 147: @raw == true 148: end
to_s
(*args)
[show source]
# File lib/rudy/metadata/disk.rb, line 74 74: def to_s(*args) 75: [self.name.bright, self.volid, self.size, self.fstype].join '; ' 76: end
valid?
()
[show source]
# File lib/rudy/metadata/disk.rb, line 131 131: def valid? 132: !@path.nil? && !@path.empty? 133: end
volume_attach
(instid)
[show source]
# File lib/rudy/metadata/disk.rb, line 136 136: def volume_attach(instid) 137: raise Rudy::Error, "No volume id" unless volume_exists? 138: vol = Rudy::AWS::EC2::Volumes.attach(@volid, instid, @device) 139: end
volume_detach
()
[show source]
# File lib/rudy/metadata/disk.rb, line 141 141: def volume_detach 142: raise Rudy::Error, "No volume id" unless volume_exists? 143: vol = Rudy::AWS::EC2::Volumes.detach(@volid) 144: end