Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[+Price] Implement Azure's PriceInfoHandler #990

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions cloud-control-manager/cloud-driver/call-log/calllogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,26 @@ type RES_TYPE string

const (
//=========== CloudOS (ref: cb-spider/cloud-driver-libs/cloudos.yaml)
AWS CLOUD_OS = "AWS"
AZURE CLOUD_OS = "AZURE"
GCP CLOUD_OS = "GCP"
ALIBABA CLOUD_OS = "ALIBABA"
TENCENT CLOUD_OS = "TENCENT"
IBM CLOUD_OS = "IBM"
OPENSTACK CLOUD_OS = "OPENSTACK"
CLOUDIT CLOUD_OS = "CLOUDIT"
NCP CLOUD_OS = "NCP"
NCPVPC CLOUD_OS = "NCPVPC"
NHNCLOUD CLOUD_OS = "NHNCLOUD"
KTCLOUD CLOUD_OS = "KTCLOUD"
KTCLOUDVPC CLOUD_OS = "KTCLOUDVPC"
DOCKER CLOUD_OS = "DOCKER"
MOCK CLOUD_OS = "MOCK"
CLOUDTWIN CLOUD_OS = "CLOUDTWIN"
AWS CLOUD_OS = "AWS"
AZURE CLOUD_OS = "AZURE"
GCP CLOUD_OS = "GCP"
ALIBABA CLOUD_OS = "ALIBABA"
TENCENT CLOUD_OS = "TENCENT"
IBM CLOUD_OS = "IBM"
OPENSTACK CLOUD_OS = "OPENSTACK"
CLOUDIT CLOUD_OS = "CLOUDIT"
NCP CLOUD_OS = "NCP"
NCPVPC CLOUD_OS = "NCPVPC"
NHNCLOUD CLOUD_OS = "NHNCLOUD"
KTCLOUD CLOUD_OS = "KTCLOUD"
KTCLOUDVPC CLOUD_OS = "KTCLOUDVPC"
DOCKER CLOUD_OS = "DOCKER"
MOCK CLOUD_OS = "MOCK"
CLOUDTWIN CLOUD_OS = "CLOUDTWIN"

//=========== ResourceType
REGIONZONE RES_TYPE = "REGIONZONE"
PRICEINFO RES_TYPE = "PRICEINFO"
VMIMAGE RES_TYPE = "VMIMAGE"
VMSPEC RES_TYPE = "VMSPEC"
VPCSUBNET RES_TYPE = "VPC/SUBNET"
Expand All @@ -62,7 +63,7 @@ const (
NLB RES_TYPE = "NETWORKLOADBALANCER"

//=========== PMKS: Provider-Managed K8S
CLUSTER RES_TYPE = "CLUSTER"
CLUSTER RES_TYPE = "CLUSTER"
)

type CALLLogger struct {
Expand Down Expand Up @@ -194,7 +195,7 @@ func getFormatter(loggerName string) *calllogformatter.Formatter {
return callFormatter
}

//=========================
// =========================
type CLOUDLOGSCHEMA struct {
CloudOS CLOUD_OS // ex) AWS | AZURE | ALIBABA | GCP | OPENSTACK | CLOUDTWIN | CLOUDIT | DOCKER | NCP | MOCK | IBM
RegionZone string // ex) us-east1/us-east1-c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (AzureDriver) GetDriverCapability() idrv.DriverCapabilityInfo {
drvCapabilityInfo.DiskHandler = true
drvCapabilityInfo.MyImageHandler = true
drvCapabilityInfo.RegionZoneHandler = true
drvCapabilityInfo.PriceInfoHandler = true
drvCapabilityInfo.ClusterHandler = true

return drvCapabilityInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ func (cloudConn *AzureCloudConnection) CreateRegionZoneHandler() (irs.RegionZone
return &regionZoneHandler, nil
}

func (cloudConn *AzureCloudConnection) CreatePriceInfoHandler() (irs.PriceInfoHandler, error) {
cblogger.Info("Azure Cloud Driver: called CreatePriceInfoHandler()!")
priceInfoHandler := azrs.AzurePriceInfoHandler{
CredentialInfo: cloudConn.CredentialInfo,
Region: cloudConn.Region,
Ctx: cloudConn.Ctx,
ResourceSkusClient: cloudConn.ResourceSkusClient,
}
return &priceInfoHandler, nil
}

func (cloudConn *AzureCloudConnection) IsConnected() (bool, error) {
return true, nil
}
Expand Down Expand Up @@ -219,7 +230,3 @@ func (cloudConn *AzureCloudConnection) CreateClusterHandler() (irs.ClusterHandle
func (cloudConn *AzureCloudConnection) CreateAnyCallHandler() (irs.AnyCallHandler, error) {
return nil, errors.New("Azure Driver: not implemented")
}

func (*AzureCloudConnection) CreatePriceInfoHandler() (irs.PriceInfoHandler, error) {
return nil, errors.New("Alibaba Driver: not implemented")
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bufio"
"errors"
"fmt"
cblog "github.com/cloud-barista/cb-log"
Expand All @@ -12,6 +13,7 @@ import (
"gopkg.in/yaml.v3"
"io/ioutil"
"os"
"strings"
"time"
)

Expand Down Expand Up @@ -160,8 +162,9 @@ func showTestHandlerInfo() {
cblogger.Info("8. DiskHandler")
cblogger.Info("9. MyImageHandler")
cblogger.Info("10. RegionZoneHandler")
cblogger.Info("11. ClusterHandler")
cblogger.Info("12. Exit")
cblogger.Info("11. PriceInfoHandler")
cblogger.Info("12. ClusterHandler")
cblogger.Info("13. Exit")
cblogger.Info("==========================================================")
}

Expand Down Expand Up @@ -205,6 +208,8 @@ func getResourceHandler(resourceType string, config Config) (interface{}, error)
resourceHandler, err = cloudConnection.CreateMyImageHandler()
case "regionzone":
resourceHandler, err = cloudConnection.CreateRegionZoneHandler()
case "price":
resourceHandler, err = cloudConnection.CreatePriceInfoHandler()
case "cluster":
resourceHandler, err = cloudConnection.CreateClusterHandler()
}
Expand Down Expand Up @@ -1306,6 +1311,109 @@ Loop:
}
}

func testPriceInfoHandlerListPrint() {
cblogger.Info("Test PriceInfoHandler")
cblogger.Info("0. Print Menu")
cblogger.Info("1. ListProductFamily()")
cblogger.Info("2. GetPriceInfo()")
cblogger.Info("3. Exit")
}

func testPriceInfoHandler(config Config) {
resourceHandler, err := getResourceHandler("price", config)
if err != nil {
cblogger.Error(err)
return
}
priceInfoHandler := resourceHandler.(irs.PriceInfoHandler)

testPriceInfoHandlerListPrint()
Loop:
for {
var commandNum int
inputCnt, err := fmt.Scan(&commandNum)
if err != nil {
cblogger.Error(err)
}

if inputCnt == 1 {
switch commandNum {
case 0:
testPriceInfoHandlerListPrint()
case 1:
cblogger.Info("Start ListProductFamily() ...")
var region string
fmt.Print("Enter Region Name: ")
if _, err := fmt.Scanln(&region); err != nil {
cblogger.Error(err)
}
if listProductFamily, err := priceInfoHandler.ListProductFamily(region); err != nil {
cblogger.Error(err)
} else {
spew.Dump(listProductFamily)
}
cblogger.Info("Finish ListProductFamily()")
case 2:
cblogger.Info("Start GetPriceInfo() ...")
fmt.Println("=== Enter Product Familiy ===")
in := bufio.NewReader(os.Stdin)
productFamiliy, err := in.ReadString('\n')
if err != nil {
cblogger.Error(err)
}

productFamiliy = strings.TrimSpace(productFamiliy)
var region string
fmt.Print("Enter Region Name: ")
if _, err := fmt.Scanln(&region); err != nil {
cblogger.Error(err)
}

var addFilterList string
var filterList []irs.KeyValue
for {
fmt.Print("Add filter list? (y/N): ")
_, err := fmt.Scanln(&addFilterList)
if err != nil || strings.ToLower(addFilterList) == "n" {
break
}

fmt.Println("=== Enter key to filter ===")
in = bufio.NewReader(os.Stdin)
key, err := in.ReadString('\n')
if err != nil {
cblogger.Error(err)
}
key = strings.TrimSpace(key)

fmt.Println("=== Enter value to filter ===")
in = bufio.NewReader(os.Stdin)
value, err := in.ReadString('\n')
if err != nil {
cblogger.Error(err)
}
value = strings.TrimSpace(value)

filterList = append(filterList, irs.KeyValue{
Key: key,
Value: value,
})
}

if priceInfo, err := priceInfoHandler.GetPriceInfo(productFamiliy, region, filterList); err != nil {
cblogger.Error(err)
} else {
spew.Dump(priceInfo)
}
cblogger.Info("Finish GetPriceInfo()")
case 3:
cblogger.Info("Exit")
break Loop
}
}
}
}

func testClusterHandlerListPrint() {
cblogger.Info("Test ClusterHandler")
cblogger.Info("0. Print Menu")
Expand Down Expand Up @@ -1869,9 +1977,12 @@ Loop:
testRegionZoneHandler(config)
showTestHandlerInfo()
case 11:
testClusterHandler(config)
testPriceInfoHandler(config)
showTestHandlerInfo()
case 12:
testClusterHandler(config)
showTestHandlerInfo()
case 13:
cblogger.Info("Exit Test ResourceHandler Program")
break Loop
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
irs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources"
"math/rand"
"net"
"sort"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -301,3 +302,20 @@ func overlapCheckCidr(cidr1 string, cidr2 string) (bool, error) {
check2 := cidr2IPnet.Contains(cidr1IP)
return !check1 && !check2, nil
}

func removeDuplicateStr(array []string) []string {
if len(array) < 1 {
return array
}

sort.Strings(array)
prev := 1
for curr := 1; curr < len(array); curr++ {
if array[curr-1] != array[curr] {
array[prev] = array[curr]
prev++
}
}

return array[:prev]
}
Loading
Loading