Refactor Azure IMDS client and metadata

This commit is contained in:
katexochen 2022-08-29 11:54:30 +02:00 committed by Paul Meyer
parent f15605cb45
commit 69abe17c96
10 changed files with 312 additions and 250 deletions

View file

@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"regexp"
"strings"
)
var azureVMSSProviderIDRegexp = regexp.MustCompile(`^azure:///subscriptions/([^/]+)/resourceGroups/([^/]+)/providers/Microsoft.Compute/virtualMachineScaleSets/([^/]+)/virtualMachines/([^/]+)$`)
@ -18,19 +17,6 @@ func BasicsFromProviderID(providerID string) (subscriptionID, resourceGroup stri
return "", "", fmt.Errorf("providerID %v is malformatted", providerID)
}
// UIDFromProviderID extracts our own generated unique ID, which is the
// suffix at the resource group, e.g., resource-group-J18dB
// J18dB is the UID.
func UIDFromProviderID(providerID string) (string, error) {
_, resourceGroup, _, _, err := ScaleSetInformationFromProviderID(providerID)
if err != nil {
return "", err
}
parts := strings.Split(resourceGroup, "-")
return parts[len(parts)-1], nil
}
// ScaleSetInformationFromProviderID splits a provider's id belonging to an azure scaleset into core components.
// A providerID for scale set VMs is build after the following schema:
// - 'azure:///subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.Compute/virtualMachineScaleSets/<scale-set-name>/virtualMachines/<instance-id>'