-
Notifications
You must be signed in to change notification settings - Fork 25
/
opensearch_instance_data.go
71 lines (59 loc) · 2.64 KB
/
opensearch_instance_data.go
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
package ec2instancesinfo
import (
_ "embed"
"encoding/json"
"log"
"github.com/pkg/errors"
)
type OpenSearchInstanceData []OpenSearchInstance
type OpenSearchRegionPricing struct {
OnDemand float64 `json:"ondemand"`
Reserved OpenSearchReservedPricing `json:"reserved"`
}
type OpenSearchReservedPricing struct {
YrTerm3StandardPartialUpfront float64 `json:"yrTerm3Standard.partialUpfront"`
YrTerm1StandardPartialUpfront float64 `json:"yrTerm1Standard.partialUpfront"`
YrTerm3StandardAllUpfront float64 `json:"yrTerm3Standard.allUpfront"`
YrTerm1StandardNoUpfront float64 `json:"yrTerm1Standard.noUpfront"`
YrTerm3StandardNoUpfront float64 `json:"yrTerm3Standard.noUpfront"`
}
type OpenSearchInstance struct {
ServiceCode string `json:"servicecode"`
InstanceType string `json:"instanceType"`
CurrentGeneration string `json:"currentGeneration"`
InstanceFamily string `json:"instanceFamily"`
Vcpu int32 `json:"vcpu,string"`
MemoryGib float64 `json:"memoryGib,string"`
RegionCode string `json:"regionCode"`
Servicename string `json:"servicename"`
Family string `json:"family"`
Instance_type string `json:"instance_type"`
Pricing map[string]OpenSearchRegionPricing `json:"pricing"`
}
//go:embed data/opensearch-instances.json
var staticOpenSearchDataBody []byte
var openSearchDataBody, backupOpenSearchDataBody []byte
func OpenSearchData() (*OpenSearchInstanceData, error) {
var d OpenSearchInstanceData
// Replace the handling of RDS data with OpenSearch data.
if len(openSearchDataBody) > 0 {
log.Println("We have updated OpenSearch data, trying to unmarshal it")
err := json.Unmarshal(openSearchDataBody, &d)
if err != nil {
log.Printf("couldn't unmarshal the updated OpenSearch data, reverting to the backup OpenSearch data : %s", err.Error())
err := json.Unmarshal(backupOpenSearchDataBody, &d)
if err != nil {
return nil, errors.Errorf("couldn't unmarshal backup OpenSearch data: %s", err.Error())
}
backupOpenSearchDataBody = []byte{}
}
} else {
log.Println("Using the static OpenSearch instance type data")
err := json.Unmarshal(staticOpenSearchDataBody, &d)
if err != nil {
return nil, errors.Errorf("couldn't unmarshal OpenSearch data: %s", err.Error())
}
}
// Perform any OpenSearch-specific data processing here if needed.
return &d, nil
}