mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(esxi): determine whether the disk is a root disk more reasonably
The order of the device is often sorted according to the size of the key. The disk pointed to by the smallest key is not necessarily the root disk or the first disk which often has the label of 'Hard disk 1'. We try to find the label, if not, use the Key again to determine who is the root disk.
This commit is contained in:
@@ -48,12 +48,15 @@ type SVirtualDisk struct {
|
||||
multicloud.SDisk
|
||||
|
||||
SVirtualDevice
|
||||
IsRoot bool
|
||||
}
|
||||
|
||||
func NewVirtualDisk(vm *SVirtualMachine, dev types.BaseVirtualDevice, index int) SVirtualDisk {
|
||||
isRoot := dev.GetVirtualDevice().DeviceInfo.GetDescription().Label == rootDiskMark
|
||||
return SVirtualDisk{
|
||||
multicloud.SDisk{},
|
||||
NewVirtualDevice(vm, dev, index),
|
||||
isRoot,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,7 +381,7 @@ func (disk *SVirtualDisk) GetTemplateId() string {
|
||||
}
|
||||
|
||||
func (disk *SVirtualDisk) GetDiskType() string {
|
||||
if disk.index == 0 {
|
||||
if disk.IsRoot {
|
||||
return api.DISK_TYPE_SYS
|
||||
}
|
||||
return api.DISK_TYPE_DATA
|
||||
|
||||
@@ -254,7 +254,6 @@ func (self *SVirtualMachine) getIHost() cloudprovider.ICloudHost {
|
||||
|
||||
func (self *SVirtualMachine) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
|
||||
idisks := make([]cloudprovider.ICloudDisk, len(self.vdisks))
|
||||
sort.Sort(byDiskType(self.vdisks))
|
||||
for i := 0; i < len(self.vdisks); i += 1 {
|
||||
idisks[i] = &(self.vdisks[i])
|
||||
}
|
||||
@@ -770,13 +769,24 @@ func (self *SVirtualMachine) fetchHardwareInfo() error {
|
||||
vdev := NewVirtualDevice(self, dev, 0)
|
||||
self.devs[vdev.getKey()] = vdev
|
||||
}
|
||||
// sort disk based on index
|
||||
sort.Slice(self.vdisks, func(i, j int) bool {
|
||||
return self.vdisks[i].GetIndex() < self.vdisks[j].GetIndex()
|
||||
})
|
||||
self.rigorous()
|
||||
sort.Sort(byDiskType(self.vdisks))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVirtualMachine) rigorous() {
|
||||
hasRoot := false
|
||||
for i := range self.vdisks {
|
||||
if self.vdisks[i].IsRoot {
|
||||
hasRoot = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasRoot && len(self.vdisks) > 0 {
|
||||
self.vdisks[0].IsRoot = true
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SVirtualMachine) getVdev(key int32) SVirtualDevice {
|
||||
return self.devs[key]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user