52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/internal/svc"
|
|
"gitlink.org.cn/jcce-pcm/pcm-participant-openstack/openstack"
|
|
"gitlink.org.cn/jcce-pcm/utils/tool"
|
|
"k8s.io/apimachinery/pkg/util/json"
|
|
"strings"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ShowNetworkDetailsLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewShowNetworkDetailsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowNetworkDetailsLogic {
|
|
return &ShowNetworkDetailsLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// network
|
|
func (l *ShowNetworkDetailsLogic) ShowNetworkDetails(in *openstack.ShowNetworkDetailsReq) (*openstack.ShowNetworkDetailsResp, error) {
|
|
// todo: add your logic here and delete this line
|
|
var resp openstack.ShowNetworkDetailsResp
|
|
openstackUrl := l.svcCtx.Config.OpenstackNetworkUrl
|
|
statusCode, body, err := tool.HttpClientWithScreen(tool.GET, openstackUrl+"/v2.0/networks/"+in.NetworkId, strings.NewReader(``))
|
|
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 &openstack.ShowNetworkDetailsResp{}, nil
|
|
}
|