Class: VirtualMachineDevice::Disk
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.one_disk(id, one_res) ⇒ Object
Create the OpenNebula disk representation Allow us to create the class without vCenter representation example: attached disks not synced with vCenter.
-
.vc_disk(vc_res) ⇒ Object
Create the vCenter disk representation Allow us to create the class without OpenNebula representation example: detached disks that not exists in OpenNebula.
Instance Method Summary
collapse
Methods inherited from Device
#detached?, #exists?, #id, #initialize, #managed?, #no_exists?, #one?, #one_item, #raise_if_no_exists_in_one, #raise_if_no_exists_in_vcenter, #synced?, #unsynced?, #vc_item
Instance Attribute Details
#size ⇒ Object
Returns the value of attribute size.
21
22
23
|
# File 'lib/vm_disk.rb', line 21
def size
@size
end
|
Class Method Details
.one_disk(id, one_res) ⇒ Object
Create the OpenNebula disk representation Allow us to create the class without vCenter representation example: attached disks not synced with vCenter
26
27
28
|
# File 'lib/vm_disk.rb', line 26
def self.one_disk(id, one_res)
new(id, one_res, nil)
end
|
.vc_disk(vc_res) ⇒ Object
Create the vCenter disk representation Allow us to create the class without OpenNebula representation example: detached disks that not exists in OpenNebula
33
34
35
|
# File 'lib/vm_disk.rb', line 33
def self.vc_disk(vc_res)
new(nil, nil, vc_res)
end
|
Instance Method Details
#boot_dev ⇒ Object
140
141
142
143
144
145
146
147
148
|
# File 'lib/vm_disk.rb', line 140
def boot_dev
if cd?
RbVmomi::VIM.VirtualMachineBootOptionsBootableCdromDevice()
else
RbVmomi::VIM.VirtualMachineBootOptionsBootableDiskDevice(
:deviceKey => device.key
)
end
end
|
#cd? ⇒ Boolean
86
87
88
89
|
# File 'lib/vm_disk.rb', line 86
def cd?
raise_if_no_exists_in_vcenter
@vc_res[:type] == 'CDROM'
end
|
#change_size(size) ⇒ Object
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/vm_disk.rb', line 150
def change_size(size)
size = size.to_i
if @one_res['ORIGINAL_SIZE'] &&
@one_res['ORIGINAL_SIZE'].to_i >= size
raise "'disk-resize' cannot decrease the disk's size"
end
@size = size
end
|
#cloned? ⇒ Boolean
130
131
132
133
|
# File 'lib/vm_disk.rb', line 130
def cloned?
raise_if_no_exists_in_one
@one_res['SOURCE'] != @vc_res[:path_wo_ds]
end
|
#config(action) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/vm_disk.rb', line 91
def config(action)
raise_if_no_exists_in_vcenter
config = {}
case action
when :delete
if managed?
key = "opennebula.mdisk.#{@id}"
else
key = "opennebula.disk.#{@id}"
end
config[:key] = key
config[:value] = ''
when :resize
if new_size
d = device
d.capacityInKB = new_size
config[:device] = d
config[:operation] = :edit
end
when :attach
puts 'not supported'
end
config
end
|
#connected? ⇒ Boolean
135
136
137
138
|
# File 'lib/vm_disk.rb', line 135
def connected?
raise_if_no_exists_in_vcenter
@vc_res[:device].connectable.connected
end
|
#destroy ⇒ Object
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/vm_disk.rb', line 172
def destroy
return if cd?
raise_if_no_exists_in_vcenter
ds = VCenterDriver::Datastore.new(self.ds)
img_path = path
begin
img_dir = File.dirname(img_path)
search_params = ds.get_search_params(
ds['name'],
img_dir,
File.basename(img_path)
)
search_task = ds['browser']
.SearchDatastoreSubFolders_Task(search_params)
search_task.wait_for_completion
ds.delete_virtual_disk(img_path)
ds.rm_directory(img_dir) if ds.dir_empty?(img_dir)
rescue StandardError => e
if !e.message.start_with?('FileNotFound')
raise e.message
end
end
end
|
#device ⇒ Object
42
43
44
45
|
# File 'lib/vm_disk.rb', line 42
def device
raise_if_no_exists_in_vcenter
@vc_res[:device]
end
|
#ds ⇒ Object
57
58
59
60
|
# File 'lib/vm_disk.rb', line 57
def ds
raise_if_no_exists_in_vcenter
@vc_res[:datastore]
end
|
#file ⇒ Object
82
83
84
|
# File 'lib/vm_disk.rb', line 82
def file
path.split('/').last
end
|
#image_ds_ref ⇒ Object
62
63
64
65
|
# File 'lib/vm_disk.rb', line 62
def image_ds_ref
raise_if_no_exists_in_one
@one_res['VCENTER_DS_REF']
end
|
#key ⇒ Object
67
68
69
70
|
# File 'lib/vm_disk.rb', line 67
def key
raise_if_no_exists_in_vcenter
@vc_res[:key]
end
|
#new_size ⇒ Object
Shrink not supported (nil). Size is in KB
162
163
164
165
166
167
168
169
170
|
# File 'lib/vm_disk.rb', line 162
def new_size
return @size * 1024 if @size
return unless @one_res['ORIGINAL_SIZE']
osize = @one_res['ORIGINAL_SIZE'].to_i
nsize = @one_res['SIZE'].to_i
nsize > osize ? nsize * 1024 : nil
end
|
#node ⇒ Object
47
48
49
50
|
# File 'lib/vm_disk.rb', line 47
def node
raise_if_no_exists_in_vcenter
@vc_res[:tag]
end
|
#path ⇒ Object
52
53
54
55
|
# File 'lib/vm_disk.rb', line 52
def path
raise_if_no_exists_in_vcenter
@vc_res[:path_wo_ds]
end
|
#persistent? ⇒ Boolean
120
121
122
123
|
# File 'lib/vm_disk.rb', line 120
def persistent?
raise_if_no_exists_in_one
@one_res['PERSISTENT'] == 'YES'
end
|
#prefix ⇒ Object
72
73
74
75
|
# File 'lib/vm_disk.rb', line 72
def prefix
raise_if_no_exists_in_vcenter
@vc_res[:prefix]
end
|
#storpod? ⇒ Boolean
37
38
39
40
|
# File 'lib/vm_disk.rb', line 37
def storpod?
raise_if_no_exists_in_one
@one_res['VCENTER_DS_REF'].start_with?('group-')
end
|
#type ⇒ Object
77
78
79
80
|
# File 'lib/vm_disk.rb', line 77
def type
raise_if_no_exists_in_vcenter
@vc_res[:type]
end
|
#volatile? ⇒ Boolean
125
126
127
128
|
# File 'lib/vm_disk.rb', line 125
def volatile?
raise_if_no_exists_in_one
@one_res['TYPE'] && @one_res['TYPE'].downcase == 'fs'
end
|