28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/fog/vsphere/models/compute/cdrom.rb', line 28
def save
requires :instance_uuid
if unit_number.nil?
used_unit_numbers = server.cdroms.map(&:unit_number)
max_unit_number = used_unit_numbers.max
self.unit_number = if max_unit_number > server.cdroms.size
max_unit_number.times.to_a.find { |i| used_unit_numbers.exclude?(i) }
else
max_unit_number + 1
end
else
if server.cdroms.any? { |cdrom| cdrom.unit_number == unit_number && cdrom.id != id }
raise "A cdrom already exists with that unit_number, so we can't save the new cdrom"
end
end
data = service.add_vm_cdrom(self)
if data['task_state'] == 'success'
created = server.cdroms.get(unit_number)
self.key = created.key
self.filename = created.filename
self.unit_number = created.unit_number
true
else
false
end
end
|