forked from JointCloud/pcm-openstack
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"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"
|
|
"k8s.io/apimachinery/pkg/util/json"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type DeleteFlavorLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewDeleteFlavorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteFlavorLogic {
|
|
return &DeleteFlavorLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *DeleteFlavorLogic) DeleteFlavor(in *openstack.DeleteFlavorReq) (*openstack.DeleteFlavorResp, error) {
|
|
// todo: add your logic here and delete this line
|
|
var resp openstack.DeleteFlavorResp
|
|
platform, err := common.GetOpenstackConfWithPlatform(in.Platform)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
openstackUrl := platform.OpenstackImageUrl
|
|
reqByte, err := json.Marshal(in)
|
|
body, err := common.SendRequest("DELETE", openstackUrl, bytes.NewBuffer(reqByte), in.Platform)
|
|
json.Unmarshal(*body, &resp)
|
|
return &resp, nil
|
|
//token := common.GetToken()
|
|
/* statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.DELETE, openstackUrl+"/flavors/"+in.FlavorId, strings.NewReader(``), token)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if statusCode == 204 {
|
|
err := json.Unmarshal(body, &resp)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
resp.Code = 200
|
|
resp.Msg = "Success"
|
|
} else if statusCode != 204 {
|
|
json.Unmarshal(body, &resp)
|
|
resp.Code = 400
|
|
resp.Msg = "Failure"
|
|
}
|
|
return &resp, nil*/
|
|
}
|