fix(region): aws create root device name fix

This commit is contained in:
TangBin
2020-12-15 13:58:42 +08:00
parent 6591c5a750
commit fc64ea3252
3 changed files with 15 additions and 8 deletions
+1 -1
View File
@@ -263,7 +263,7 @@ func (self *SHost) _createVM(name, imgId string, sysDisk cloudprovider.SDiskInfo
// 创建实例
if len(instanceType) > 0 {
log.Debugf("Try instancetype : %s", instanceType)
vmId, err := self.zone.region.CreateInstance(name, imgId, instanceType, networkId, secgroupId, self.zone.ZoneId, desc, disks, ipAddr, keypair, userData, tags)
vmId, err := self.zone.region.CreateInstance(name, img, instanceType, networkId, secgroupId, self.zone.ZoneId, desc, disks, ipAddr, keypair, userData, tags)
if err != nil {
log.Errorf("Failed for %s: %s", instanceType, err)
return "", fmt.Errorf("Failed to create specification %s.%s", instanceType, err.Error())
+3 -1
View File
@@ -92,7 +92,8 @@ type SImage struct {
Status ImageStatusType
OwnerType string
// Usage string
RootDevice RootDevice
RootDevice RootDevice
RootDeviceName string
Public bool
Hypervisor string
@@ -510,6 +511,7 @@ func (self *SRegion) getImages(status ImageStatusType, owners []TImageOwnerType,
OwnerType: *image.ImageOwnerAlias,
EnaSupport: *image.EnaSupport,
Platform: *image.Platform,
RootDeviceName: *image.RootDeviceName,
Status: ImageStatusType(*image.State),
CreationTime: createTime,
SizeGB: size,
+11 -6
View File
@@ -494,7 +494,7 @@ func (self *SInstance) RebuildRoot(ctx context.Context, desc *cloudprovider.SMan
userdata = base64.StdEncoding.EncodeToString([]byte(data))
}
diskId, err := self.host.zone.region.ReplaceSystemDisk(ctx, self.InstanceId, desc.ImageId, desc.SysSizeGB, keypairName, userdata)
diskId, err := self.host.zone.region.ReplaceSystemDisk(ctx, self.InstanceId, image, desc.SysSizeGB, keypairName, userdata)
if err != nil {
return "", err
}
@@ -722,7 +722,7 @@ func (self *SRegion) GetInstanceIdByImageId(imageId string) (string, error) {
return "", fmt.Errorf("instance launch with image %s not found", imageId)
}
func (self *SRegion) CreateInstance(name string, imageId string, instanceType string, SubnetId string, securityGroupId string,
func (self *SRegion) CreateInstance(name string, image *SImage, instanceType string, SubnetId string, securityGroupId string,
zoneId string, desc string, disks []SDisk, ipAddr string,
keypair string, userData string, ntags map[string]string,
) (string, error) {
@@ -747,7 +747,11 @@ func (self *SRegion) CreateInstance(name string, imageId string, instanceType st
VolumeType: &disk.Category,
}
deviceName = fmt.Sprintf("/dev/sda1")
if len(image.RootDeviceName) > 0 {
deviceName = image.RootDeviceName
} else {
deviceName = fmt.Sprintf("/dev/sda1")
}
} else {
var size int64
size = int64(disk.Size)
@@ -804,8 +808,9 @@ func (self *SRegion) CreateInstance(name string, imageId string, instanceType st
return "", err
}
imgId := image.GetId()
params := ec2.RunInstancesInput{
ImageId: &imageId,
ImageId: &imgId,
InstanceType: &instanceType,
MaxCount: &count,
MinCount: &count,
@@ -967,7 +972,7 @@ func (self *SRegion) UpdateVM(instanceId string, hostname string) error {
return fmt.Errorf("aws not support change hostname.")
}
func (self *SRegion) ReplaceSystemDisk(ctx context.Context, instanceId string, imageId string, sysDiskSizeGB int, keypair string, userdata string) (string, error) {
func (self *SRegion) ReplaceSystemDisk(ctx context.Context, instanceId string, image *SImage, sysDiskSizeGB int, keypair string, userdata string) (string, error) {
instance, err := self.GetInstance(instanceId)
if err != nil {
return "", err
@@ -998,7 +1003,7 @@ func (self *SRegion) ReplaceSystemDisk(ctx context.Context, instanceId string, i
// create tmp server
tempName := fmt.Sprintf("__tmp_%s", instance.GetName())
_id, err := self.CreateInstance(tempName,
imageId,
image,
instance.InstanceType,
subnetId,
"",