Skip to content

Commit

Permalink
Merge pull request #1076 from ioito/automated-cherry-pick-of-#1074-up…
Browse files Browse the repository at this point in the history
…stream-release-3.11

Automated cherry pick of #1074: fix(aws): aws disk tag with server
  • Loading branch information
ioito authored Sep 18, 2024
2 parents ac1db0f + fbf69b3 commit eb79f61
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
15 changes: 13 additions & 2 deletions pkg/multicloud/aws/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,18 +756,20 @@ func (self *SRegion) CreateInstance(name string, image *SImage, instanceType str
zoneId string, desc string, disks []cloudprovider.SDiskInfo, ipAddr string,
keypair string, userData string, tags map[string]string, enableMonitorAgent bool,
) (*SInstance, error) {
params := map[string]string{}
params, devNames := map[string]string{}, image.GetBlockDeviceNames()
for i, disk := range disks {
deviceName := image.RootDeviceName
if i == 0 && len(deviceName) == 0 {
deviceName = "/dev/sda1"
devNames = append(devNames, deviceName)
}
if i > 0 {
var err error
deviceName, err = NextDeviceName(image.GetBlockDeviceNames())
deviceName, err = NextDeviceName(devNames)
if err != nil {
return nil, errors.Wrapf(err, "NextDeviceName")
}
devNames = append(devNames, deviceName)
}
params[fmt.Sprintf("BlockDeviceMapping.%d.DeviceName", i+1)] = deviceName
params[fmt.Sprintf("BlockDeviceMapping.%d.Ebs.DeleteOnTermination", i+1)] = "true"
Expand Down Expand Up @@ -804,6 +806,15 @@ func (self *SRegion) CreateInstance(name string, image *SImage, instanceType str
params[fmt.Sprintf("TagSpecification.1.Tag.%d.Value", tagIdx)] = v
tagIdx++
}

tagIdx = 1
for k, v := range tags {
params[fmt.Sprintf("TagSpecification.2.ResourceType")] = "volume"
params[fmt.Sprintf("TagSpecification.2.Tag.%d.Key", tagIdx)] = k
params[fmt.Sprintf("TagSpecification.2.Tag.%d.Value", tagIdx)] = v
tagIdx++
}

params["ImageId"] = image.ImageId
params["InstanceType"] = instanceType
params["MaxCount"] = "1"
Expand Down
30 changes: 9 additions & 21 deletions pkg/multicloud/aws/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,20 @@ func NextDeviceName(curDeviceNames []string) (string, error) {
currents = append(currents, strings.ToLower(item))
}

for i := 0; i < 25; i++ {
device := fmt.Sprintf("/dev/sd%c", byte(98+i))
found := false
for _, item := range currents {
if strings.HasPrefix(item, device) {
found = true
for _, prefix := range []string{"/dev/sd", "dev/vxd"} {
for s := rune('a'); s < rune('z'); s++ {
device := fmt.Sprintf("%s%c", prefix, s)
found := false
for _, item := range currents {
if strings.HasPrefix(item, device) {
found = true
}
}
}

if !found {
return device, nil
}
}

for i := 0; i < 25; i++ {
device := fmt.Sprintf("/dev/vxd%c", byte(98+i))
found := false
for _, item := range currents {
if !strings.HasPrefix(item, device) {
if !found {
return device, nil
}
}

if !found {
return device, nil
}
}

return "", fmt.Errorf("disk devicename out of index, current deivces: %s", currents)
Expand Down

0 comments on commit eb79f61

Please sign in to comment.