Skip to content

Commit

Permalink
feat: add region api
Browse files Browse the repository at this point in the history
Signed-off-by: jwcesign <jwcesign@cloudpilot.ai>
  • Loading branch information
jwcesign committed Oct 9, 2024
1 parent 93dab41 commit 2b52935
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hack/tools/demo/client-demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
)

func main() {
c, err := tools.NewQueryClient("https://pre-price.cloudpilot.ai", "alibabacloud", "cn-beijing")
c, err := tools.NewQueryClient("https://pre-price.cloudpilot.ai", "alibabacloud", "")
if err != nil {
panic(err)
}

regions := c.ListRegions()
fmt.Println(regions)
d := c.ListInstancesDetails("cn-beijing")
fmt.Println(d)
}
12 changes: 12 additions & 0 deletions pkg/tools/queryclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

type QueryClientInterface interface {
Run(ctx context.Context)
ListRegions() []string
ListInstancesDetails(region string) *apis.RegionalInstancePrice
GetInstanceDetails(region, instanceType string) *apis.InstanceTypePrice
TriggerRefreshData()
Expand Down Expand Up @@ -163,6 +164,17 @@ func (q *QueryClientImpl) refreshData() error {
return nil
}

func (q *QueryClientImpl) ListRegions() []string {
q.awsMutex.Lock()
defer q.awsMutex.Unlock()

var ret []string
for region := range q.priceData {
ret = append(ret, region)
}
return ret
}

func (q *QueryClientImpl) ListInstancesDetails(region string) *apis.RegionalInstancePrice {
q.awsMutex.Lock()
defer q.awsMutex.Unlock()
Expand Down

0 comments on commit 2b52935

Please sign in to comment.