mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 06:09:39 +08:00
fix create form cdrom os type
This commit is contained in:
@@ -1199,16 +1199,16 @@ func fillDiskConfigByImage(ctx context.Context, userCred mcclient.TokenCredentia
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseIsoInfo(ctx context.Context, userCred mcclient.TokenCredential, info string) (string, error) {
|
||||
func parseIsoInfo(ctx context.Context, userCred mcclient.TokenCredential, info string) (*SImage, error) {
|
||||
image, err := CachedimageManager.getImageInfo(ctx, userCred, info, false)
|
||||
if err != nil {
|
||||
log.Errorf("getImageInfo fail %s", err)
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
if image.Status != IMAGE_STATUS_ACTIVE {
|
||||
return "", httperrors.NewInvalidStatusError("Image status is not active")
|
||||
return nil, httperrors.NewInvalidStatusError("Image status is not active")
|
||||
}
|
||||
return image.Id, nil
|
||||
return image, nil
|
||||
}
|
||||
|
||||
func (self *SDisk) fetchDiskInfo(diskConfig *SDiskConfig) {
|
||||
|
||||
@@ -732,6 +732,10 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m
|
||||
return nil, httperrors.NewBadRequestError("Snapshot error: disk index 0 but disk type is %s", diskConfig.DiskType)
|
||||
}
|
||||
|
||||
if len(diskConfig.ImageId) == 0 && len(diskConfig.SnapshotId) == 0 && !data.Contains("cdrom") {
|
||||
return nil, httperrors.NewBadRequestError("Miss operate system???")
|
||||
}
|
||||
|
||||
if len(diskConfig.Backend) == 0 {
|
||||
diskConfig.Backend = STORAGE_LOCAL
|
||||
}
|
||||
@@ -740,12 +744,26 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m
|
||||
data.Add(jsonutils.Marshal(diskConfig), "disk.0")
|
||||
|
||||
imgProperties := diskConfig.ImageProperties
|
||||
if imgProperties == nil || len(imgProperties) == 0 {
|
||||
if data.Contains("cdrom") {
|
||||
cdromStr, err := data.GetString("cdrom")
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("invalid cdrom device description %s", err)
|
||||
}
|
||||
image, err := parseIsoInfo(ctx, userCred, cdromStr)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("parse cdrom device info error %s", err)
|
||||
}
|
||||
data.Add(jsonutils.NewString(image.Id), "cdrom")
|
||||
if len(imgProperties) == 0 {
|
||||
imgProperties = image.Properties
|
||||
}
|
||||
}
|
||||
|
||||
if len(imgProperties) == 0 {
|
||||
imgProperties = map[string]string{"os_type": "Linux"}
|
||||
}
|
||||
|
||||
osType, _ := data.GetString("os_type")
|
||||
|
||||
osProf, err = osprofile.GetOSProfileFromImageProperties(imgProperties, hypervisor)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("Invalid root image: %s", err)
|
||||
@@ -894,18 +912,6 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m
|
||||
data.Set(fmt.Sprintf("isolated_device.%d", idx), jsonutils.Marshal(devConfig))
|
||||
}
|
||||
|
||||
if data.Contains("cdrom") {
|
||||
cdromStr, err := data.GetString("cdrom")
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("invalid cdrom device description %s", err)
|
||||
}
|
||||
cdromId, err := parseIsoInfo(ctx, userCred, cdromStr)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("parse cdrom device info error %s", err)
|
||||
}
|
||||
data.Add(jsonutils.NewString(cdromId), "cdrom")
|
||||
}
|
||||
|
||||
keypairId, _ := data.GetString("keypair")
|
||||
if len(keypairId) == 0 {
|
||||
keypairId, _ = data.GetString("keypair_id")
|
||||
|
||||
Reference in New Issue
Block a user