Skip to content

Commit 62c8748

Browse files
authored
Merge pull request #1575 from powerkimhub/feature/priceinfo-simple-mode-multi-csp-fixes
[Priceinfo] Add vmspec info simple mode and fix multi-CSP issues
2 parents 61a6126 + 91f8b8b commit 62c8748

File tree

18 files changed

+600
-252
lines changed

18 files changed

+600
-252
lines changed

api-runtime/rest-runtime/PriceInfoRest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type ProductFamilyListResponse struct {
2828
// @ID list-product-family
2929
// @Summary List Product Families
3030
// @Description Retrieve a list of Product Families associated with a specific connection and region. 🕷️ [[Concept Guide](https://github.com/cloud-barista/cb-spider/wiki/Price-Info-and-Cloud-Driver-API)], 🕷️ [[User Guide](https://github.com/cloud-barista/cb-spider/wiki/RestAPI-Multi%E2%80%90Cloud-Price-Information-Guide)]
31-
// @Tags [Cloud Metadata] Price Info
31+
// @Tags [Cloud Metadata] VM Price Info
3232
// @Accept json
3333
// @Produce json
3434
// @Param ConnectionName query string true "The name of the Connection to list Product Families for"
@@ -78,7 +78,7 @@ type PriceInfoResponse struct {
7878
// @ID get-vmprice-info
7979
// @Summary Get VM Price Information
8080
// @Description Retrieve VM Price Information for a specific connection and region. 🕷️ [[User Guide](https://github.com/cloud-barista/cb-spider/wiki/VM-Price-Info-Guide)] <br> * example body: {"connectionName":"aws-connection","FilterList":[{"Key":"instanceType","Value":"t2.micro"}]}
81-
// @Tags [Cloud Metadata] Price Info
81+
// @Tags [Cloud Metadata] VM Price Info
8282
// @Accept json
8383
// @Produce json
8484
// @Param RegionName path string true "The name of the Region to retrieve vm price information for"

api-runtime/rest-runtime/admin-web/AdminWeb-PriceInfo-TableList.go

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ import (
2525

2626
var PRICEINFO_CACHE_PATH string = os.Getenv("CBSPIDER_ROOT") + "/cache/priceinfo"
2727

28+
// TemplateData structure to render the HTML template
29+
type TemplateData struct {
30+
Data cres.CloudPrice
31+
CachedFileName string
32+
TotalItems int
33+
SimpleMode string
34+
}
35+
2836
func init() {
2937
// Create cache directory for PriceInfo if not exists
3038
_, err := os.Stat(PRICEINFO_CACHE_PATH)
@@ -135,31 +143,51 @@ func PriceInfoTableList(c echo.Context) error {
135143

136144
json.Unmarshal([]byte(c.QueryParam("filterlist")), &info)
137145

146+
// Handle simplemode parameter and set environment variable
147+
simpleMode := c.QueryParam("simplemode")
148+
if simpleMode != "" {
149+
if simpleMode == "ON" || simpleMode == "OFF" {
150+
// Temporarily set the environment variable for this request
151+
originalMode := os.Getenv("VMSPECINFO_SIMPLE_MODE_IN_PRICEINFO")
152+
os.Setenv("VMSPECINFO_SIMPLE_MODE_IN_PRICEINFO", simpleMode)
153+
cblog.Infof("Set VMSPECINFO_SIMPLE_MODE_IN_PRICEINFO to: %s", simpleMode)
154+
155+
// Restore original value after processing (defer)
156+
defer func() {
157+
os.Setenv("VMSPECINFO_SIMPLE_MODE_IN_PRICEINFO", originalMode)
158+
cblog.Infof("Restored VMSPECINFO_SIMPLE_MODE_IN_PRICEINFO to: %s", originalMode)
159+
}()
160+
}
161+
}
162+
138163
var data cres.CloudPrice
139164
err := getPriceInfoJsonString(connConfig, "priceinfo", c.Param("ProductFamily"), c.Param("RegionName"), info.FilterList, &data)
140165
if err != nil {
141166
cblog.Error(err)
142167
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
143168
}
144169

145-
// TemplateData structure to render the HTML template
146-
type TemplateData struct {
147-
Data cres.CloudPrice
148-
CachedFileName string
149-
TotalItems int
150-
}
151-
152170
var cachedFileName string
153171
if cachedFileName, err = saveJSONToFile(data); err != nil {
154172
cblog.Error(err)
155173
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to save JSON file: "+err.Error())
156174
}
157175

176+
// Get current simple mode setting
177+
currentSimpleMode := os.Getenv("VMSPECINFO_SIMPLE_MODE_IN_PRICEINFO")
178+
if currentSimpleMode == "" {
179+
currentSimpleMode = "OFF" // default value
180+
}
181+
158182
tmplData := TemplateData{
159183
CachedFileName: cachedFileName,
160184
TotalItems: len(data.PriceList),
185+
SimpleMode: currentSimpleMode,
161186
}
162187

188+
// Debug logging
189+
cblog.Infof("TemplateData created: SimpleMode=%s, TotalItems=%d", tmplData.SimpleMode, tmplData.TotalItems)
190+
163191
// Limit PriceList items to 200
164192
if len(data.PriceList) > 200 {
165193
data.PriceList = data.PriceList[:200]
@@ -173,7 +201,7 @@ func PriceInfoTableList(c echo.Context) error {
173201
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to load HTML template")
174202
}
175203

176-
tmpl, err := addTemplateFuncs(template.New("cloudPrice")).Parse(cloudPriceTemplate)
204+
tmpl, err := addTemplateFuncs(template.New("cloudPrice"), currentSimpleMode).Parse(cloudPriceTemplate)
177205
if err != nil {
178206
cblog.Error(err)
179207
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
@@ -208,7 +236,7 @@ func getHtmlTemplate(filepath string) string {
208236
return string(content)
209237
}
210238

211-
func addTemplateFuncs(t *template.Template) *template.Template {
239+
func addTemplateFuncs(t *template.Template, simpleMode string) *template.Template {
212240
return t.Funcs(template.FuncMap{
213241
"json": func(v interface{}) string {
214242
a, _ := json.MarshalIndent(v, "", " ")
@@ -218,6 +246,10 @@ func addTemplateFuncs(t *template.Template) *template.Template {
218246
"inc": func(i int) int {
219247
return i + 1
220248
},
249+
250+
"simpleMode": func() string {
251+
return simpleMode
252+
},
221253
})
222254
}
223255

api-runtime/rest-runtime/admin-web/html/priceinfo-request-template.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ <h2>Multi-Cloud Price Info</h2>
144144
{{end}}
145145
</select>
146146
</div>
147+
<div class="form-group">
148+
<label for="simpleMode">VMSpec Display Mode</label>
149+
<select id="simpleMode" name="simpleMode">
150+
<option value="OFF">Detailed (Full VMSpecInfo)</option>
151+
<option value="ON">Simple (VMSpecName only)</option>
152+
</select>
153+
</div>
147154
</div>
148155
<div class="form-group">
149156
<div class="button-textarea-group">
@@ -227,12 +234,13 @@ <h2>Multi-Cloud Price Info</h2>
227234
var region = document.getElementById('region').value;
228235
var connectionName = document.getElementById('connectionName').value;
229236
var filterList = document.getElementById('filter').value;
237+
var simpleMode = document.getElementById('simpleMode').value;
230238

231239
var fetchOverlayContent = document.getElementById('fetchOverlayContent');
232240
document.getElementById('fetchOverlay').style.display = 'block';
233241
fetchOverlayContent.src = 'about:blank'; // clear the iframe content
234242

235-
var url = `/spider/adminweb/priceinfotablelist/vm/${region}/${connectionName}?filterlist=${filterList}`;
243+
var url = `/spider/adminweb/priceinfotablelist/vm/${region}/${connectionName}?filterlist=${filterList}&simplemode=${simpleMode}`;
236244

237245
// logging the fetch URL
238246
var hostname = window.location.hostname;

api-runtime/rest-runtime/admin-web/html/priceinfo-tablelist-template.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,13 @@ <h4 id="totalItems">Total Products: #{{.TotalItems}}</h4>
208208
{{ $fileName := .CachedFileName }}
209209

210210
<div class="cloudHeader">
211-
<h3>{{.Data.CloudName}}</h3>
211+
<h3>{{.Data.CloudName}}
212+
{{if eq .SimpleMode "ON"}}
213+
<span style="color: #0066cc; font-size: 14px;">[Simple Mode]</span>
214+
{{else}}
215+
<span style="color: #666; font-size: 14px;">[Detailed Mode]</span>
216+
{{end}}
217+
</h3>
212218
<button id="toggleButton-{{.Data.CloudName}}" onclick="toggleView('{{.Data.CloudName}}')">JSON View</button>
213219

214220
<button onclick="conditionalDownload('{{.Data.CloudName}}', '{{$totalNum}}', '{{$fileName}}')">JSON Download</button>
@@ -238,6 +244,7 @@ <h3>{{.Data.CloudName}}</h3>
238244
<td>
239245
<ul>
240246
{{if .ProductInfo.VMSpecInfo}}
247+
<!-- Detailed Mode: Full VMSpecInfo -->
241248
<li><strong>VMSpec: {{.ProductInfo.VMSpecInfo.Name}}</strong></li>
242249
<li>VCPU: {{.ProductInfo.VMSpecInfo.VCpu.Count}}</li>
243250
<li>Memory(MiB): {{.ProductInfo.VMSpecInfo.MemSizeMiB}}</li>
@@ -249,6 +256,12 @@ <h3>{{.Data.CloudName}}</h3>
249256
<li>GPU Total Memory(GB): {{.TotalMemSizeGB}}</li>
250257
{{end}}
251258
{{end}}
259+
{{else if .ProductInfo.VMSpecName}}
260+
<!-- Simple Mode: VMSpecName only -->
261+
<li><strong>VMSpec: {{.ProductInfo.VMSpecName}}</strong></li>
262+
<li><em>Simple mode - detailed specs not available</em></li>
263+
{{else}}
264+
<li><em>No VM specification information available</em></li>
252265
{{end}}
253266
</ul>
254267
</td>

api/docs.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5510,7 +5510,7 @@ const docTemplate = `{
55105510
"application/json"
55115511
],
55125512
"tags": [
5513-
"[Cloud Metadata] Price Info"
5513+
"[Cloud Metadata] VM Price Info"
55145514
],
55155515
"summary": "Get VM Price Information",
55165516
"operationId": "get-vmprice-info",
@@ -5569,7 +5569,7 @@ const docTemplate = `{
55695569
"application/json"
55705570
],
55715571
"tags": [
5572-
"[Cloud Metadata] Price Info"
5572+
"[Cloud Metadata] VM Price Info"
55735573
],
55745574
"summary": "List Product Families",
55755575
"operationId": "list-product-family",
@@ -10260,8 +10260,7 @@ const docTemplate = `{
1026010260
"type": "object",
1026110261
"required": [
1026210262
"CSPProductInfo",
10263-
"ProductId",
10264-
"VMSpecInfo"
10263+
"ProductId"
1026510264
],
1026610265
"properties": {
1026710266
"CSPProductInfo": {
@@ -10278,12 +10277,17 @@ const docTemplate = `{
1027810277
"example": "prod-123"
1027910278
},
1028010279
"VMSpecInfo": {
10281-
"description": "Information about the VM spec",
10280+
"description": "Information about the VM spec (used in detailed mode, default mode)",
1028210281
"allOf": [
1028310282
{
1028410283
"$ref": "#/definitions/spider.VMSpecInfo"
1028510284
}
1028610285
]
10286+
},
10287+
"VMSpecName": {
10288+
"description": "Name of the VM spec (used in simple mode)",
10289+
"type": "string",
10290+
"example": "t2.micro"
1028710291
}
1028810292
}
1028910293
},

api/swagger.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5507,7 +5507,7 @@
55075507
"application/json"
55085508
],
55095509
"tags": [
5510-
"[Cloud Metadata] Price Info"
5510+
"[Cloud Metadata] VM Price Info"
55115511
],
55125512
"summary": "Get VM Price Information",
55135513
"operationId": "get-vmprice-info",
@@ -5566,7 +5566,7 @@
55665566
"application/json"
55675567
],
55685568
"tags": [
5569-
"[Cloud Metadata] Price Info"
5569+
"[Cloud Metadata] VM Price Info"
55705570
],
55715571
"summary": "List Product Families",
55725572
"operationId": "list-product-family",
@@ -10257,8 +10257,7 @@
1025710257
"type": "object",
1025810258
"required": [
1025910259
"CSPProductInfo",
10260-
"ProductId",
10261-
"VMSpecInfo"
10260+
"ProductId"
1026210261
],
1026310262
"properties": {
1026410263
"CSPProductInfo": {
@@ -10275,12 +10274,17 @@
1027510274
"example": "prod-123"
1027610275
},
1027710276
"VMSpecInfo": {
10278-
"description": "Information about the VM spec",
10277+
"description": "Information about the VM spec (used in detailed mode, default mode)",
1027910278
"allOf": [
1028010279
{
1028110280
"$ref": "#/definitions/spider.VMSpecInfo"
1028210281
}
1028310282
]
10283+
},
10284+
"VMSpecName": {
10285+
"description": "Name of the VM spec (used in simple mode)",
10286+
"type": "string",
10287+
"example": "t2.micro"
1028410288
}
1028510289
}
1028610290
},

api/swagger.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,11 +1025,15 @@ definitions:
10251025
VMSpecInfo:
10261026
allOf:
10271027
- $ref: '#/definitions/spider.VMSpecInfo'
1028-
description: Information about the VM spec
1028+
description: Information about the VM spec (used in detailed mode, default
1029+
mode)
1030+
VMSpecName:
1031+
description: Name of the VM spec (used in simple mode)
1032+
example: t2.micro
1033+
type: string
10291034
required:
10301035
- CSPProductInfo
10311036
- ProductId
1032-
- VMSpecInfo
10331037
type: object
10341038
spider.RSType:
10351039
enum:
@@ -7041,7 +7045,7 @@ paths:
70417045
$ref: '#/definitions/spider.SimpleMsg'
70427046
summary: Get VM Price Information
70437047
tags:
7044-
- '[Cloud Metadata] Price Info'
7048+
- '[Cloud Metadata] VM Price Info'
70457049
/productfamily/{RegionName}:
70467050
get:
70477051
consumes:
@@ -7082,7 +7086,7 @@ paths:
70827086
$ref: '#/definitions/spider.SimpleMsg'
70837087
summary: List Product Families
70847088
tags:
7085-
- '[Cloud Metadata] Price Info'
7089+
- '[Cloud Metadata] VM Price Info'
70867090
/readyz:
70877091
get:
70887092
consumes:

0 commit comments

Comments
 (0)