forked from JointCloud/pcm-openstack
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/internal/common"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/internal/svc"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/openstack"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetComputeLimitsLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGetComputeLimitsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetComputeLimitsLogic {
|
|
return &GetComputeLimitsLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *GetComputeLimitsLogic) GetComputeLimits(in *openstack.GetComputeLimitsReq) (*openstack.GetComputeLimitsResp, error) {
|
|
var resp openstack.GetComputeLimitsResp
|
|
platform, err := common.GetOpenstackConfWithPlatform(in.Platform)
|
|
openstackUrl := platform.OpenstackLimitsUrl
|
|
//openstackUrl := l.svcCtx.Config.OpenstackConfig.OpenstackLimitsUrl
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
reqByte, err := json.Marshal(in)
|
|
body, err := common.SendRequest("DELETE", openstackUrl+"/types/", bytes.NewBuffer(reqByte), in.Platform)
|
|
json.Unmarshal(*body, &resp)
|
|
return &resp, nil
|
|
// token := common.GetToken()
|
|
/* statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.GET, openstackUrl+"/v2/limits", nil, token)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if statusCode == 200 {
|
|
err := json.Unmarshal(body, &resp)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
resp.Code = 200
|
|
resp.Msg = "Success"
|
|
} else if statusCode != 200 {
|
|
json.Unmarshal(body, &resp)
|
|
resp.Code = 400
|
|
resp.Msg = "Failure"
|
|
}
|
|
return &resp, nil*/
|
|
}
|