mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Automatic merge from release/2.1.0 -> release/2.2.0
* commit 'f41931f252648ba7e28b63934ce5955725ad1135': 修复磁盘类型颠倒问题
This commit is contained in:
@@ -17,7 +17,6 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/seclib2"
|
||||
"yunion.io/x/pkg/util/secrules"
|
||||
)
|
||||
|
||||
type SAliyunGuestDriver struct {
|
||||
@@ -69,76 +68,15 @@ func (self *SAliyunGuestDriver) ValidateCreateData(ctx context.Context, userCred
|
||||
return data, nil
|
||||
}
|
||||
|
||||
type SAliyunVMCreateConfig struct {
|
||||
Name string
|
||||
ExternalImageId string
|
||||
OsDistribution string
|
||||
OsVersion string
|
||||
Cpu int
|
||||
Memory int
|
||||
ExternalNetworkId string
|
||||
IpAddr string
|
||||
Description string
|
||||
StorageType string
|
||||
SysDiskSize int
|
||||
DataDisks []int
|
||||
PublicKey string
|
||||
SecGroupId string
|
||||
SecGroupName string
|
||||
SecRules []secrules.SecurityRule
|
||||
}
|
||||
|
||||
func (self *SAliyunGuestDriver) GetJsonDescAtHost(ctx context.Context, guest *models.SGuest, host *models.SHost) jsonutils.JSONObject {
|
||||
config := SAliyunVMCreateConfig{}
|
||||
config.Name = guest.Name
|
||||
config.Cpu = int(guest.VcpuCount)
|
||||
config.Memory = guest.VmemSize
|
||||
config.Description = guest.Description
|
||||
|
||||
if len(guest.KeypairId) > 0 {
|
||||
config.PublicKey = guest.GetKeypairPublicKey()
|
||||
}
|
||||
|
||||
nics := guest.GetNetworks()
|
||||
net := nics[0].GetNetwork()
|
||||
config.ExternalNetworkId = net.ExternalId
|
||||
config.IpAddr = nics[0].IpAddr
|
||||
|
||||
config.SecGroupId = guest.SecgrpId
|
||||
config.SecGroupName = guest.GetSecgroupName()
|
||||
config.SecRules = guest.GetSecRules()
|
||||
|
||||
disks := guest.GetDisks()
|
||||
config.DataDisks = make([]int, len(disks)-1)
|
||||
|
||||
for i := 0; i < len(disks); i += 1 {
|
||||
disk := disks[i].GetDisk()
|
||||
if i == 0 {
|
||||
storage := disk.GetStorage()
|
||||
config.StorageType = storage.StorageType
|
||||
cache := storage.GetStoragecache()
|
||||
imageId := disk.GetTemplateId()
|
||||
scimg := models.StoragecachedimageManager.GetStoragecachedimage(cache.Id, imageId)
|
||||
config.ExternalImageId = scimg.ExternalId
|
||||
img := scimg.GetCachedimage()
|
||||
config.OsDistribution, _ = img.Info.GetString("properties", "os_distribution")
|
||||
config.OsVersion, _ = img.Info.GetString("properties", "os_version")
|
||||
|
||||
config.SysDiskSize = disk.DiskSize / 1024 // MB => GB
|
||||
} else {
|
||||
config.DataDisks[i-1] = disk.DiskSize / 1024 // MB => GB
|
||||
}
|
||||
}
|
||||
return jsonutils.Marshal(&config)
|
||||
}
|
||||
|
||||
type SDiskInfo struct {
|
||||
DiskType string
|
||||
Size int
|
||||
Uuid string
|
||||
|
||||
Metadata map[string]string
|
||||
}
|
||||
|
||||
func fetchIVMinfo(desc SAliyunVMCreateConfig, iVM cloudprovider.ICloudVM, guestId string, passwd string) *jsonutils.JSONDict {
|
||||
func fetchIVMinfo(desc SManagedVMCreateConfig, iVM cloudprovider.ICloudVM, guestId string, passwd string) *jsonutils.JSONDict {
|
||||
data := jsonutils.NewDict()
|
||||
|
||||
data.Add(jsonutils.NewString(iVM.GetOSType()), "os")
|
||||
@@ -169,6 +107,7 @@ func fetchIVMinfo(desc SAliyunVMCreateConfig, iVM cloudprovider.ICloudVM, guestI
|
||||
dinfo := SDiskInfo{}
|
||||
dinfo.Uuid = idisks[i].GetGlobalId()
|
||||
dinfo.Size = idisks[i].GetDiskSizeMB()
|
||||
dinfo.DiskType = idisks[i].GetDiskType()
|
||||
if metaData := idisks[i].GetMetadata(); metaData != nil {
|
||||
dinfo.Metadata = make(map[string]string, 0)
|
||||
if err := metaData.Unmarshal(dinfo.Metadata); err != nil {
|
||||
@@ -212,7 +151,7 @@ func (self *SAliyunGuestDriver) RequestDeployGuestOnHost(ctx context.Context, gu
|
||||
return err
|
||||
}
|
||||
|
||||
desc := SAliyunVMCreateConfig{}
|
||||
desc := SManagedVMCreateConfig{}
|
||||
err = config.Unmarshal(&desc, "desc")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -448,6 +387,7 @@ func (self *SAliyunGuestDriver) OnGuestDeployTaskDataReceived(ctx context.Contex
|
||||
_, err = disk.GetModelManager().TableSpec().Update(disk, func() error {
|
||||
disk.DiskSize = diskInfo[i].Size
|
||||
disk.ExternalId = diskInfo[i].Uuid
|
||||
disk.DiskType = diskInfo[i].DiskType
|
||||
disk.Status = models.DISK_READY
|
||||
if len(diskInfo[i].Metadata) > 0 {
|
||||
for key, value := range diskInfo[i].Metadata {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/pkg/util/secrules"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -17,6 +18,70 @@ type SManagedVirtualizedGuestDriver struct {
|
||||
SVirtualizedGuestDriver
|
||||
}
|
||||
|
||||
type SManagedVMCreateConfig struct {
|
||||
Name string
|
||||
ExternalImageId string
|
||||
OsDistribution string
|
||||
OsVersion string
|
||||
Cpu int
|
||||
Memory int
|
||||
ExternalNetworkId string
|
||||
IpAddr string
|
||||
Description string
|
||||
StorageType string
|
||||
SysDiskSize int
|
||||
DataDisks []int
|
||||
PublicKey string
|
||||
SecGroupId string
|
||||
SecGroupName string
|
||||
SecRules []secrules.SecurityRule
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizedGuestDriver) GetJsonDescAtHost(ctx context.Context, guest *models.SGuest, host *models.SHost) jsonutils.JSONObject {
|
||||
config := SManagedVMCreateConfig{}
|
||||
config.Name = guest.Name
|
||||
config.Cpu = int(guest.VcpuCount)
|
||||
config.Memory = guest.VmemSize
|
||||
config.Description = guest.Description
|
||||
|
||||
if len(guest.KeypairId) > 0 {
|
||||
config.PublicKey = guest.GetKeypairPublicKey()
|
||||
}
|
||||
|
||||
nics := guest.GetNetworks()
|
||||
net := nics[0].GetNetwork()
|
||||
config.ExternalNetworkId = net.ExternalId
|
||||
config.IpAddr = nics[0].IpAddr
|
||||
|
||||
config.SecGroupId = guest.SecgrpId
|
||||
config.SecGroupName = guest.GetSecgroupName()
|
||||
config.SecRules = guest.GetSecRules()
|
||||
|
||||
disks := guest.GetDisks()
|
||||
config.DataDisks = make([]int, len(disks)-1)
|
||||
|
||||
for i := 0; i < len(disks); i += 1 {
|
||||
disk := disks[i].GetDisk()
|
||||
if i == 0 {
|
||||
storage := disk.GetStorage()
|
||||
config.StorageType = storage.StorageType
|
||||
cache := storage.GetStoragecache()
|
||||
imageId := disk.GetTemplateId()
|
||||
//避免因同步过来的instance没有对应的imagecache信息,重置密码时引发空指针访问
|
||||
if scimg := models.StoragecachedimageManager.GetStoragecachedimage(cache.Id, imageId); scimg != nil {
|
||||
config.ExternalImageId = scimg.ExternalId
|
||||
img := scimg.GetCachedimage()
|
||||
config.OsDistribution, _ = img.Info.GetString("properties", "os_distribution")
|
||||
config.OsVersion, _ = img.Info.GetString("properties", "os_version")
|
||||
}
|
||||
config.SysDiskSize = disk.DiskSize / 1024 // MB => GB
|
||||
} else {
|
||||
config.DataDisks[i-1] = disk.DiskSize / 1024 // MB => GB
|
||||
}
|
||||
}
|
||||
return jsonutils.Marshal(&config)
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizedGuestDriver) RequestGuestCreateAllDisks(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
|
||||
diskCat := guest.CategorizeDisks()
|
||||
var imageId string
|
||||
@@ -160,4 +225,4 @@ func (self *SManagedVirtualizedGuestDriver) RequestRebuildRootDisk(ctx context.C
|
||||
}
|
||||
subtask.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user