53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/internal/common"
|
|
"gitlink.org.cn/jcce-pcm/utils/tool"
|
|
|
|
"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 ListVolumesDetailLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewListVolumesDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListVolumesDetailLogic {
|
|
return &ListVolumesDetailLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *ListVolumesDetailLogic) ListVolumesDetail(in *openstack.ListVolumesDetailReq) (*openstack.ListVolumesDetailResp, error) {
|
|
// todo: add your logic here and delete this line
|
|
var resp openstack.ListVolumesDetailResp
|
|
openstackUrl := l.svcCtx.Config.OpenstackVolumev2Url
|
|
token := common.GetToken()
|
|
statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.GET, openstackUrl+"/volumes/detail", 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
|
|
}
|