Skip to content

improve VM image mapping logic and subnet naming#2282

Merged
cb-github-robot merged 4 commits intocloud-barista:mainfrom
leehyeoklee:improve-registration
Jan 21, 2026
Merged

improve VM image mapping logic and subnet naming#2282
cb-github-robot merged 4 commits intocloud-barista:mainfrom
leehyeoklee:improve-registration

Conversation

@leehyeoklee
Copy link
Copy Markdown
Contributor

Description
This PR improves the resource registration logic for VM images and Subnets.

1. Enhanced Image Registration Logic

  • Before: If an image (whether Public or Custom) was not found in Tumblebug during VM registration, it was simply marked as unknown.
  • After: The logic now dynamically handles missing images:
    • It first attempts to lookup the image as a Public Image on the CSP. If found, it is automatically registered and mapped.
    • If not found, it registers and maps it as a Custom Image.
    • This eliminates the ambiguous unknown status.

2. Corrected Subnet Naming

  • Before: Subnet IDs/Names were assigned using a hardcoded format (e.g., reg-01).
  • After: Updated to use the actual CSP-provided IDs (spSubnetInfo.IId.SystemId and spSubnetInfo.IId.NameId) for accurate identification.

Comment on lines +3434 to +3475
// Try to lookup and register the image from CSP
log.Info().Msgf("Image not found in TB, attempting to lookup from CSP: %s", targetImageName)

handleImageRegistration := func(img model.ImageInfo, err error, imageType string, isCustom bool) {
if err != nil {
log.Error().Err(err).Msgf("Failed to register %s: %s", imageType, targetImageName)
errMsg := fmt.Sprintf("Dependency Missing: Cannot find or register Image (CSP ID: %s) in TB.", targetImageName)
log.Error().Msg(errMsg)
} else {
if isCustom {
customImageFlag = true
}
vmInfoData.ImageId = img.Id
log.Info().Msgf("Successfully registered %s: %s as %s", imageType, targetImageName, img.Id)
}
}

// First, try to lookup as public image
_, lookupErr := resource.LookupImage(requestBody.ConnectionName, targetImageName)
if lookupErr == nil {
log.Info().Msgf("Public image found in CSP: %s, registering to TB", targetImageName)

imageReq := &model.ImageReq{
Name: targetImageName,
ConnectionName: requestBody.ConnectionName,
CspImageName: targetImageName,
Description: "Auto-registered from existing VM",
}
registeredImage, regErr := resource.RegisterImageWithId(model.SystemCommonNs, imageReq, false, false)
handleImageRegistration(registeredImage, regErr, model.StrImage, false)
} else {
// Public image lookup failed, try to register as custom image
log.Info().Msgf("Public image not found, attempting to register as custom image: %s", targetImageName)

customImageReq := &model.CustomImageReq{
Name: targetImageName,
ConnectionName: requestBody.ConnectionName,
CspResourceId: targetImageName,
}
registeredImage, regErr := resource.RegisterCustomImageWithId(nsId, customImageReq)
handleImageRegistration(registeredImage, regErr, model.StrCustomImage, true)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @leehyeoklee
Thanks for the contribution. Could you check func EnsureImageAvailable(nsId, connectionName, imageId string) (model.ImageInfo, bool, error) { can be reusable here?
I think both logics are very similar.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion!
I checked EnsureImageAvailable and it covers exactly what I needed. Since the necessary logic was already implemented there, I was able to significantly reduce the code size

Comment on lines +1487 to +1488
Id: fmt.Sprintf("reg-%s", spSubnetInfo.IId.SystemId),
Name: fmt.Sprintf("reg-%s", spSubnetInfo.IId.NameId),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Id: fmt.Sprintf("reg-%s", spSubnetInfo.IId.SystemId),
Name: fmt.Sprintf("reg-%s", spSubnetInfo.IId.NameId),
Id: fmt.Sprintf("%s", spSubnetInfo.IId.SystemId),
Name: fmt.Sprintf("%s", spSubnetInfo.IId.NameId),

minor suggestion. :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seokho-son
Copy link
Copy Markdown
Member

/approve

@github-actions github-actions bot added the approved This PR is approved and will be merged soon. label Jan 21, 2026
@cb-github-robot cb-github-robot merged commit 48a9a8e into cloud-barista:main Jan 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved This PR is approved and will be merged soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants