Skip to content

Commit

Permalink
Add links to 'Connection Name' in the Dashboard Management page
Browse files Browse the repository at this point in the history
powerkimhub committed Jan 26, 2025
1 parent fd786e1 commit 4e53fcd
Showing 4 changed files with 60 additions and 32 deletions.
39 changes: 39 additions & 0 deletions api-runtime/rest-runtime/admin-web/AdminWeb-Common.go
Original file line number Diff line number Diff line change
@@ -319,3 +319,42 @@ func genLoggingResult2(response string) string {

return htmlStr
}

// Fetch regions and map them to RegionName -> "Region / Zone"
func fetchRegions() (map[string]string, error) {
resp, err := http.Get("http://localhost:1024/spider/region")
if err != nil {
return nil, fmt.Errorf("error fetching regions: %v", err)
}
defer resp.Body.Close()

var regions struct {
Regions []struct {
RegionName string `json:"RegionName"`
KeyValueInfoList []struct {
Key string `json:"Key"`
Value string `json:"Value"`
} `json:"KeyValueInfoList"`
} `json:"region"`
}
if err := json.NewDecoder(resp.Body).Decode(&regions); err != nil {
return nil, fmt.Errorf("error decoding regions: %v", err)
}

regionMap := make(map[string]string)
for _, region := range regions.Regions {
var regionValue, zoneValue string
for _, kv := range region.KeyValueInfoList {
if kv.Key == "Region" {
regionValue = kv.Value
} else if kv.Key == "Zone" {
zoneValue = kv.Value
}
}
if zoneValue == "" {
zoneValue = "N/A"
}
regionMap[region.RegionName] = fmt.Sprintf("%s / %s", regionValue, zoneValue)
}
return regionMap, nil
}
31 changes: 0 additions & 31 deletions api-runtime/rest-runtime/admin-web/AdminWeb-Connection.go
Original file line number Diff line number Diff line change
@@ -639,37 +639,6 @@ func fetchProviders() ([]string, error) {
return providers.Providers, nil
}

func fetchRegions() (map[string]string, error) {
resp, err := http.Get("http://localhost:1024/spider/region")
if err != nil {
return nil, fmt.Errorf("error fetching regions: %v", err)
}
defer resp.Body.Close()

var regions Regions
if err := json.NewDecoder(resp.Body).Decode(&regions); err != nil {
return nil, fmt.Errorf("error decoding regions: %v", err)
}

regionMap := make(map[string]string)
for _, region := range regions.Regions {
var regionValue, zoneValue string
for _, keyValue := range region.KeyValueInfoList {
if keyValue.Key == "Region" {
regionValue = keyValue.Value
} else if keyValue.Key == "Zone" {
zoneValue = keyValue.Value
}
}
if zoneValue == "" {
zoneValue = "NA"
}
regionMap[region.RegionName] = fmt.Sprintf("%s / %s", regionValue, zoneValue)
}

return regionMap, nil
}

func fetchDrivers() (map[string]string, error) {
resp, err := http.Get("http://localhost:1024/spider/driver")
if err != nil {
9 changes: 9 additions & 0 deletions api-runtime/rest-runtime/admin-web/AdminWeb-Dashboard.go
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ import (
// ResourceCounts holds the counts for various resources
type ResourceCounts struct {
ConnectionName string `json:"connectionName"`
RegionName string `json:"regionName"`
VPCs int `json:"vpcs"`
Subnets int `json:"subnets"`
SecurityGroups int `json:"securityGroups"`
@@ -42,6 +43,7 @@ type DashboardData struct {
ConnectionsByCloud map[string]int
Providers []string
ResourceCounts map[string][]ResourceCounts
Regions map[string]string
ShowEmpty bool
}

@@ -77,6 +79,7 @@ func fetchResourceCounts(config ConnectionConfig, provider string, wg *sync.Wait

var counts ResourceCounts
counts.ConnectionName = config.ConfigName
counts.RegionName = config.RegionName

baseURL := "http://localhost:1024/spider"
resources := []string{"vpc", "subnet", "securitygroup", "vm", "keypair", "disk", "nlb", "cluster", "myimage"}
@@ -199,10 +202,16 @@ func Dashboard(c echo.Context) error {
})
}

regionMap, err := fetchRegions()
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}

data := DashboardData{
ServerIP: serverIP,
Providers: providers,
ResourceCounts: resourceCounts,
Regions: regionMap,
ShowEmpty: showEmpty,
}

13 changes: 12 additions & 1 deletion api-runtime/rest-runtime/admin-web/html/dashboard.html
Original file line number Diff line number Diff line change
@@ -204,6 +204,15 @@
refreshDashboard();
}

function setTopMenu(configName, provider, regionZone) {
window.parent.postMessage({
type: 'updateTopMenu',
configName: configName,
provider: provider,
region: regionZone
}, '*');
}

document.addEventListener('DOMContentLoaded', function() {
toggleRefresh();
});
@@ -246,7 +255,9 @@ <h2>{{$provider}}</h2>
{{if index $.ResourceCounts $provider}}
{{range $count := index $.ResourceCounts $provider}}
<tr>
<td>{{$count.ConnectionName}}</td>
<td><a href="javascript:void(0)" onclick="setTopMenu('{{$count.ConnectionName}}', '{{$provider}}', '{{index $.Regions $count.RegionName}}')">
{{$count.ConnectionName}}
</a></td>
<td class="{{if gt $count.VPCs 0}}highlight{{end}}"><a href="#" onclick="openOverlay('http://{{$.ServerIP}}/spider/adminweb/vpc/{{$count.ConnectionName}}'); return false;">{{$count.VPCs}}</a></td>
<td class="{{if gt $count.Subnets 0}}highlight{{end}}">{{$count.Subnets}}</td>
<td class="{{if gt $count.SecurityGroups 0}}highlight{{end}}"><a href="#" onclick="openOverlay('http://{{$.ServerIP}}/spider/adminweb/securitygroup/{{$count.ConnectionName}}'); return false;">{{$count.SecurityGroups}}</a></td>

0 comments on commit 4e53fcd

Please sign in to comment.