feature: vm overview api service
Former-commit-id: aff2077cf031e94a892cf4de67d7a8fc5416f9a2
This commit is contained in:
parent
66082b4321
commit
167c8f29ed
|
@ -236,6 +236,11 @@ service pcm {
|
||||||
group : vm
|
group : vm
|
||||||
)
|
)
|
||||||
service pcm {
|
service pcm {
|
||||||
|
|
||||||
|
@handler GetComputeLimitsHandler
|
||||||
|
get /vm/getComputeLimits (GetComputeLimitsReq) returns (GetComputeLimitsResp)
|
||||||
|
@handler GetVolumeLimitsHandler
|
||||||
|
get /vm/getVolumeLimits (GetVolumeLimitsReq) returns (GetVolumeLimitsResp)
|
||||||
@handler ListServerHandler
|
@handler ListServerHandler
|
||||||
get /vm/listServer (ListServersReq) returns (ListServersResp)
|
get /vm/listServer (ListServersReq) returns (ListServersResp)
|
||||||
@handler ListServersDetailedHandler
|
@handler ListServersDetailedHandler
|
||||||
|
|
|
@ -7,8 +7,83 @@ info(
|
||||||
email: "1364512070@qq.com"
|
email: "1364512070@qq.com"
|
||||||
)
|
)
|
||||||
|
|
||||||
/****************** servers start*************************/
|
|
||||||
|
|
||||||
|
type (
|
||||||
|
Rate{
|
||||||
|
}
|
||||||
|
Absolute{
|
||||||
|
maxServerMeta int64 `form:"maxServerMeta,optional"`
|
||||||
|
maxPersonality int64 `form:"maxPersonality,optional"`
|
||||||
|
totalServerGroupsUsed int64 `form:"totalServerGroupsUsed,optional"`
|
||||||
|
maxImageMeta int64 `form:"maxImageMeta,optional"`
|
||||||
|
maxPersonalitySize int64 `form:"maxPersonalitySize,optional"`
|
||||||
|
maxTotalKeypairs int64 `form:"maxTotalKeypairs,optional"`
|
||||||
|
maxSecurityGroupRules int64 `form:"maxSecurityGroupRules,optional"`
|
||||||
|
maxServerGroups int64 `form:"maxServerGroups,optional"`
|
||||||
|
totalCoresUsed int64 `form:"totalCoresUsed,optional"`
|
||||||
|
totalRAMUsed int64 `form:"totalRAMUsed,optional"`
|
||||||
|
totalInstancesUsed int64 `form:"totalInstancesUsed,optional"`
|
||||||
|
maxSecurityGroups int64 `form:"maxSecurityGroups,optional"`
|
||||||
|
totalFloatingIpsUsed int64 `form:"totalFloatingIpsUsed,optional"`
|
||||||
|
maxTotalCores int64 `form:"maxTotalCores,optional"`
|
||||||
|
maxServerGroupMembers int64 `form:"maxServerGroupMembers,optional"`
|
||||||
|
maxTotalFloatingIps int64 `form:"maxTotalFloatingIps,optional"`
|
||||||
|
totalSecurityGroupsUsed int64 `form:"totalSecurityGroupsUsed,optional"`
|
||||||
|
maxTotalInstances int64 `form:"maxTotalInstances,optional"`
|
||||||
|
maxTotalRAMSize int64 `form:"maxTotalRAMSize,optional"`
|
||||||
|
}
|
||||||
|
Limits{
|
||||||
|
rate Rate `form:"rate,optional"`
|
||||||
|
absolute Absolute`form:"absolute,optional"`
|
||||||
|
}
|
||||||
|
GetComputeLimitsReq{
|
||||||
|
Limit int32 `form:"limit,optional"`
|
||||||
|
OffSet int32 `form:"offSet,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
GetComputeLimitsResp{
|
||||||
|
limits Limits `form:"limits,optional"`
|
||||||
|
Code int32 `json:"code,omitempty"`
|
||||||
|
Msg string `json:"msg,omitempty"`
|
||||||
|
ErrorMsg string `json:"errorMsg,omitempty"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
type (
|
||||||
|
VolumeRate{
|
||||||
|
}
|
||||||
|
VolumeAbsolute{
|
||||||
|
totalSnapshotsUsed int32 `form:"totalSnapshotsUsed,optional"`
|
||||||
|
maxTotalBackups int32 `form:"maxTotalBackups,optional"`
|
||||||
|
maxTotalVolumeGigabytes int32 `form:"maxTotalVolumeGigabytes,optional"`
|
||||||
|
maxTotalSnapshots int32 `form:"maxTotalSnapshots,optional"`
|
||||||
|
maxTotalBackupGigabytes int32 `form:"maxTotalBackupGigabytes,optional"`
|
||||||
|
totalBackupGigabytesUsed int32 `form:"totalBackupGigabytesUsed,optional"`
|
||||||
|
maxTotalVolumes int32 `form:"maxTotalVolumes,optional"`
|
||||||
|
totalVolumesUsed int32 `form:"totalVolumesUsed,optional"`
|
||||||
|
totalBackupsUsed int32 `form:"totalBackupsUsed,optional"`
|
||||||
|
totalGigabytesUsed int32 `form:"totalGigabytesUsed,optional"`
|
||||||
|
}
|
||||||
|
VolumeLimits{
|
||||||
|
rate VolumeRate `form:"rate,optional"`
|
||||||
|
absolute VolumeAbsolute`form:"absolute,optional"`
|
||||||
|
}
|
||||||
|
GetVolumeLimitsReq{
|
||||||
|
Limit int32 `form:"limit,optional"`
|
||||||
|
OffSet int32 `form:"offSet,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
GetVolumeLimitsResp{
|
||||||
|
limits VolumeLimits `form:"limits,optional"`
|
||||||
|
Code int32 `json:"code,omitempty"`
|
||||||
|
Msg string `json:"msg,omitempty"`
|
||||||
|
ErrorMsg string `json:"errorMsg,omitempty"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
/****************** servers start*************************/
|
||||||
type (
|
type (
|
||||||
ListServersReq {
|
ListServersReq {
|
||||||
Limit int32 `form:"limit,optional"`
|
Limit int32 `form:"limit,optional"`
|
||||||
|
|
|
@ -7,7 +7,7 @@ NacosConfig:
|
||||||
- IpAddr: nacos.jcce.dev
|
- IpAddr: nacos.jcce.dev
|
||||||
Port: 8848
|
Port: 8848
|
||||||
ClientConfig:
|
ClientConfig:
|
||||||
NamespaceId: test
|
NamespaceId: zhouqj
|
||||||
TimeoutMs: 5000
|
TimeoutMs: 5000
|
||||||
NotLoadCacheAtStart: true
|
NotLoadCacheAtStart: true
|
||||||
LogDir:
|
LogDir:
|
||||||
|
|
|
@ -340,6 +340,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
|
|
||||||
server.AddRoutes(
|
server.AddRoutes(
|
||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/vm/getComputeLimits",
|
||||||
|
Handler: vm.GetComputeLimitsHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/vm/getVolumeLimits",
|
||||||
|
Handler: vm.GetVolumeLimitsHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/vm/listServer",
|
Path: "/vm/listServer",
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package vm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/vm"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetComputeLimitsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.GetComputeLimitsReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := vm.NewGetComputeLimitsLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.GetComputeLimits(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package vm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/vm"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetVolumeLimitsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.GetVolumeLimitsReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := vm.NewGetVolumeLimitsLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.GetVolumeLimits(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package vm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/openstack"
|
||||||
|
"gitlink.org.cn/jcce-pcm/utils/result"
|
||||||
|
"gitlink.org.cn/jcce-pcm/utils/tool"
|
||||||
|
"gitlink.org.cn/jcce-pcm/utils/xerr"
|
||||||
|
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetComputeLimitsLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetComputeLimitsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetComputeLimitsLogic {
|
||||||
|
return &GetComputeLimitsLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetComputeLimitsLogic) GetComputeLimits(req *types.GetComputeLimitsReq) (resp *types.GetComputeLimitsResp, err error) {
|
||||||
|
GetComputeLimitsReq := &openstack.GetComputeLimitsReq{}
|
||||||
|
err = copier.CopyWithOption(GetComputeLimitsReq, req, copier.Option{Converters: tool.Converters})
|
||||||
|
GetComputeLimitsResp, err := l.svcCtx.OpenstackRpc.GetComputeLimits(l.ctx, GetComputeLimitsReq)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("Failed to get Servers list"), "Failed to get db Servers list err : %v ,req:%+v", err, req)
|
||||||
|
}
|
||||||
|
marshal, err := json.Marshal(&GetComputeLimitsResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, result.NewDefaultError(err.Error())
|
||||||
|
}
|
||||||
|
json.Unmarshal(marshal, &resp)
|
||||||
|
err = copier.CopyWithOption(&resp, &GetComputeLimitsResp, copier.Option{Converters: tool.Converters})
|
||||||
|
return resp, err
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package vm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/openstack"
|
||||||
|
"gitlink.org.cn/jcce-pcm/utils/result"
|
||||||
|
"gitlink.org.cn/jcce-pcm/utils/tool"
|
||||||
|
"gitlink.org.cn/jcce-pcm/utils/xerr"
|
||||||
|
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetVolumeLimitsLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetVolumeLimitsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetVolumeLimitsLogic {
|
||||||
|
return &GetVolumeLimitsLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetVolumeLimitsLogic) GetVolumeLimits(req *types.GetVolumeLimitsReq) (resp *types.GetVolumeLimitsResp, err error) {
|
||||||
|
GetVolumeLimitsReq := &openstack.GetVolumeLimitsReq{}
|
||||||
|
err = copier.CopyWithOption(GetVolumeLimitsReq, req, copier.Option{Converters: tool.Converters})
|
||||||
|
GetVolumeLimitsResp, err := l.svcCtx.OpenstackRpc.GetVolumeLimits(l.ctx, GetVolumeLimitsReq)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("Failed to get Servers list"), "Failed to get db Servers list err : %v ,req:%+v", err, req)
|
||||||
|
}
|
||||||
|
marshal, err := json.Marshal(&GetVolumeLimitsResp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, result.NewDefaultError(err.Error())
|
||||||
|
}
|
||||||
|
json.Unmarshal(marshal, &resp)
|
||||||
|
err = copier.CopyWithOption(&resp, &GetVolumeLimitsResp, copier.Option{Converters: tool.Converters})
|
||||||
|
return resp, err
|
||||||
|
}
|
|
@ -2102,6 +2102,81 @@ type CheckResp struct {
|
||||||
Exist bool `json:"exist"`
|
Exist bool `json:"exist"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Rate struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type Absolute struct {
|
||||||
|
MaxServerMeta int64 `form:"maxServerMeta,optional"`
|
||||||
|
MaxPersonality int64 `form:"maxPersonality,optional"`
|
||||||
|
TotalServerGroupsUsed int64 `form:"totalServerGroupsUsed,optional"`
|
||||||
|
MaxImageMeta int64 `form:"maxImageMeta,optional"`
|
||||||
|
MaxPersonalitySize int64 `form:"maxPersonalitySize,optional"`
|
||||||
|
MaxTotalKeypairs int64 `form:"maxTotalKeypairs,optional"`
|
||||||
|
MaxSecurityGroupRules int64 `form:"maxSecurityGroupRules,optional"`
|
||||||
|
MaxServerGroups int64 `form:"maxServerGroups,optional"`
|
||||||
|
TotalCoresUsed int64 `form:"totalCoresUsed,optional"`
|
||||||
|
TotalRAMUsed int64 `form:"totalRAMUsed,optional"`
|
||||||
|
TotalInstancesUsed int64 `form:"totalInstancesUsed,optional"`
|
||||||
|
MaxSecurityGroups int64 `form:"maxSecurityGroups,optional"`
|
||||||
|
TotalFloatingIpsUsed int64 `form:"totalFloatingIpsUsed,optional"`
|
||||||
|
MaxTotalCores int64 `form:"maxTotalCores,optional"`
|
||||||
|
MaxServerGroupMembers int64 `form:"maxServerGroupMembers,optional"`
|
||||||
|
MaxTotalFloatingIps int64 `form:"maxTotalFloatingIps,optional"`
|
||||||
|
TotalSecurityGroupsUsed int64 `form:"totalSecurityGroupsUsed,optional"`
|
||||||
|
MaxTotalInstances int64 `form:"maxTotalInstances,optional"`
|
||||||
|
MaxTotalRAMSize int64 `form:"maxTotalRAMSize,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Limits struct {
|
||||||
|
Rate Rate `form:"rate,optional"`
|
||||||
|
Absolute Absolute `form:"absolute,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetComputeLimitsReq struct {
|
||||||
|
Limit int32 `form:"limit,optional"`
|
||||||
|
OffSet int32 `form:"offSet,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetComputeLimitsResp struct {
|
||||||
|
Limits Limits `form:"limits,optional"`
|
||||||
|
Code int32 `json:"code,omitempty"`
|
||||||
|
Msg string `json:"msg,omitempty"`
|
||||||
|
ErrorMsg string `json:"errorMsg,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type VolumeRate struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type VolumeAbsolute struct {
|
||||||
|
TotalSnapshotsUsed int32 `form:"totalSnapshotsUsed,optional"`
|
||||||
|
MaxTotalBackups int32 `form:"maxTotalBackups,optional"`
|
||||||
|
MaxTotalVolumeGigabytes int32 `form:"maxTotalVolumeGigabytes,optional"`
|
||||||
|
MaxTotalSnapshots int32 `form:"maxTotalSnapshots,optional"`
|
||||||
|
MaxTotalBackupGigabytes int32 `form:"maxTotalBackupGigabytes,optional"`
|
||||||
|
TotalBackupGigabytesUsed int32 `form:"totalBackupGigabytesUsed,optional"`
|
||||||
|
MaxTotalVolumes int32 `form:"maxTotalVolumes,optional"`
|
||||||
|
TotalVolumesUsed int32 `form:"totalVolumesUsed,optional"`
|
||||||
|
TotalBackupsUsed int32 `form:"totalBackupsUsed,optional"`
|
||||||
|
TotalGigabytesUsed int32 `form:"totalGigabytesUsed,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type VolumeLimits struct {
|
||||||
|
Rate VolumeRate `form:"rate,optional"`
|
||||||
|
Absolute VolumeAbsolute `form:"absolute,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetVolumeLimitsReq struct {
|
||||||
|
Limit int32 `form:"limit,optional"`
|
||||||
|
OffSet int32 `form:"offSet,optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetVolumeLimitsResp struct {
|
||||||
|
Limits VolumeLimits `form:"limits,optional"`
|
||||||
|
Code int32 `json:"code,omitempty"`
|
||||||
|
Msg string `json:"msg,omitempty"`
|
||||||
|
ErrorMsg string `json:"errorMsg,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type ListServersReq struct {
|
type ListServersReq struct {
|
||||||
Limit int32 `form:"limit,optional"`
|
Limit int32 `form:"limit,optional"`
|
||||||
OffSet int32 `form:"offSet,optional"`
|
OffSet int32 `form:"offSet,optional"`
|
||||||
|
|
Loading…
Reference in New Issue