Skip to content

Commit

Permalink
ddc add get machine info
Browse files Browse the repository at this point in the history
  • Loading branch information
yangxin16 committed Mar 18, 2022
1 parent a0f1a0b commit 73cb3ea
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bce/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// Constants and default values for the package bce
const (
SDK_VERSION = "0.9.109"
SDK_VERSION = "0.9.110"
URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path
DEFAULT_DOMAIN = "baidubce.com"
DEFAULT_PROTOCOL = "http"
Expand Down
23 changes: 23 additions & 0 deletions doc/DDCv2.md
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,29 @@ for _, diskItem := range disk.Response.Items {
}
```

## 获取物理机资源信息
使用以下代码可以获取指定实例所在物理机资源信息。
```go
// import ddcrds "github.com/baidubce/bce-sdk-go/services/ddc/v2"

machine, err := client.GetMachineInfo(instanceId)
if err != nil {
fmt.Printf("get machine info error: %+v\n", err)
return
}
fmt.Println("get machine info success.")
for _, machine := range machine.Response.Items {
fmt.Println("instance id: ", machine.InstanceID)
fmt.Println("instance role: ", machine.Role)
fmt.Println("cpu(core): ", machine.CPUInCore)
fmt.Println("cpu(core) free: ", machine.FreeCPUInCore)
fmt.Println("memory(MB): ", machine.MemSizeInMB)
fmt.Println("memory(MB) free: ", machine.FreeMemSizeInMB)
fmt.Println("disk info: ", machine.SizeInGB)
fmt.Println("----------------------")
}
```

## 删除实例
使用以下代码可以批量删除实例,RDS产品将删除实例,DDC产品会将实例放入回收站。
```go
Expand Down
21 changes: 20 additions & 1 deletion services/ddc/v2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
POOL = "xdb_005a2d79-a4f4-4bfb-8284-0ffe9ddaa307_pool"
PNETIP = "100.88.65.121"
DEPLOY_ID = "ab89d829-9068-d88e-75bc-64bb6367d036"
DDC_INSTANCE_ID = "ddc-mtu45cvm"
DDC_INSTANCE_ID = "ddc-mqv3e72u"
RDS_INSTANCE_ID = "rds-OtTkC1OD"
ETAG = "v0"
)
Expand Down Expand Up @@ -1468,6 +1468,25 @@ func TestClient_GetDisk(t *testing.T) {
}
}

func TestClient_GetMachineInfo(t *testing.T) {
machine, err := client.GetMachineInfo(instanceId)
if err != nil {
fmt.Printf("get machine info error: %+v\n", err)
return
}
fmt.Println("get machine info success.")
for _, machine := range machine.Response.Items {
fmt.Println("instance id: ", machine.InstanceID)
fmt.Println("instance role: ", machine.Role)
fmt.Println("cpu(core): ", machine.CPUInCore)
fmt.Println("cpu(core) free: ", machine.FreeCPUInCore)
fmt.Println("memory(MB): ", machine.MemSizeInMB)
fmt.Println("memory(MB) free: ", machine.FreeMemSizeInMB)
fmt.Println("disk info: ", machine.SizeInGB)
fmt.Println("----------------------")
}
}

func TestClient_GetResidual(t *testing.T) {
residual, err := client.GetResidual(POOL)
if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions services/ddc/v2/ddc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,29 @@ func (c *DDCClient) GetDisk(instanceId string) (*Disk, error) {
return result, err
}

// GetMachineInfo - get machine info of instance
//
// PARAMS:
// - instanceId: id of instance
// RETURNS:
// - *MachineInfo:info of machine resource
// - error: nil if success otherwise the specific error
func (c *DDCClient) GetMachineInfo(instanceId string) (*MachineInfo, error) {
if len(instanceId) < 1 {
return nil, fmt.Errorf("unset instanceId")
}

result := &MachineInfo{}

err := bce.NewRequestBuilder(c).
WithMethod(http.GET).
WithURL(getDdcUriWithInstanceId(instanceId)+"/machine").
WithHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE).
WithResult(result).
Do()
return result, err
}

// GetResidual - get residual of pool
//
// PARAMS:
Expand Down
14 changes: 14 additions & 0 deletions services/ddc/v2/ddcrds.go
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,20 @@ func (c *Client) LazyDropDeleteHardLink(instanceId, dbName, tableName string) (*
return c.ddcClient.LazyDropDeleteHardLink(instanceId, dbName, tableName)
}

// GetMachineInfo - get machine detail of instance
//
// PARAMS:
// - instanceId: id of instance
// RETURNS:
// - *MachineInfo:info of machine resource
// - error: nil if success otherwise the specific error
func (c *Client) GetMachineInfo(instanceId string) (*MachineInfo, error) {
if !isDDCId(instanceId) {
return nil, RDSNotSupportError()
}
return c.ddcClient.GetMachineInfo(instanceId)
}

// GetDisk - get disk detail of instance
//
// PARAMS:
Expand Down
19 changes: 19 additions & 0 deletions services/ddc/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,25 @@ type Disk struct {
} `json:"Response"`
}

type MachineInfo struct {
Response struct {
Items []struct {
InstanceID string `json:"instanceId"`
Role string `json:"role"`
CPUInCore int `json:"cpuInCore"`
FreeCPUInCore int `json:"freeCpuInCore"`
MemSizeInMB int `json:"memSizeInMB"`
FreeMemSizeInMB int `json:"freeMemSizeInMB"`
SizeInGB []struct {
FreeSizeInGB int `json:"freeSizeInGB"`
Label map[string]string `json:"label"`
Path string `json:"path"`
SizeInGB int `json:"sizeInGB"`
} `json:"sizeInGB"`
} `json:"Items"`
} `json:"Response"`
}

type GetResidualResult struct {
Residual map[string]ResidualOfZone `json:"residual"`
}
Expand Down

0 comments on commit 73cb3ea

Please sign in to comment.