-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathadmin_openshiftcluster_vmsizelist.go
More file actions
72 lines (58 loc) · 2.17 KB
/
admin_openshiftcluster_vmsizelist.go
File metadata and controls
72 lines (58 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package frontend
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
"encoding/json"
"fmt"
"net/http"
"path/filepath"
"slices"
"strings"
"github.com/go-chi/chi/v5"
"github.com/sirupsen/logrus"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
"github.com/Azure/ARO-RP/pkg/frontend/middleware"
)
// /admin/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}/skus
func (f *frontend) getAdminOpenShiftClusterVMResizeOptions(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
log := ctx.Value(middleware.ContextKeyLog).(*logrus.Entry)
r.URL.Path = filepath.Dir(r.URL.Path)
resType, resName, resGroupName := chi.URLParam(r, "resourceType"), chi.URLParam(r, "resourceName"), chi.URLParam(r, "resourceGroupName")
resourceID := strings.TrimPrefix(r.URL.Path, "/admin")
b, err := f._getAdminOpenShiftClusterVMResizeOptions(ctx, resType, resName, resGroupName, resourceID, log)
adminReply(log, w, nil, b, err)
}
func (f *frontend) _getAdminOpenShiftClusterVMResizeOptions(ctx context.Context, resType, resName, resGroupName, resourceID string, log *logrus.Entry) ([]byte, error) {
dbOpenShiftClusters, err := f.dbGroup.OpenShiftClusters()
if err != nil {
return nil, api.NewCloudError(http.StatusInternalServerError, api.CloudErrorCodeInternalServerError, "", err.Error())
}
doc, err := dbOpenShiftClusters.Get(ctx, resourceID)
switch {
case cosmosdb.IsErrorStatusCode(err, http.StatusNotFound):
return nil, api.NewCloudError(http.StatusNotFound, api.CloudErrorCodeResourceNotFound, "",
fmt.Sprintf(
"The Resource '%s/%s' under resource group '%s' was not found.",
resType, resName, resGroupName))
case err != nil:
return nil, err
}
subscriptionDoc, err := f.getSubscriptionDocument(ctx, doc.Key)
if err != nil {
return nil, err
}
a, err := f.azureActionsFactory(log, f.env, doc.OpenShiftCluster, subscriptionDoc)
if err != nil {
return nil, err
}
skus, err := a.VMSizeList(ctx)
if err != nil {
return nil, err
}
// Sort for stability
slices.Sort(skus)
return json.Marshal(skus)
}