fix:增加openstack查询详情接口到C端

Former-commit-id: 05031382fd376bc4753ddc26f9d0d1aeae0ea4a4
This commit is contained in:
qiwang 2023-10-19 15:16:38 +08:00
parent 15ff42cedd
commit 1935ca84b6
8 changed files with 173 additions and 32 deletions

View File

@ -306,6 +306,8 @@ service pcm {
put /vm/updateNetwork (UpdateNetworkReq) returns (UpdateNetworkResp)
@handler BulkCreateNetworksHandler
post /vm/bulkCreateNetworks (BulkCreateNetworksReq) returns (BulkCreateNetworksResp)
//volumn 卷
@handler UpdateVolumeHandler
put /vm/updateVolume (UpdateVolumeReq) returns (UpdateVolumeResp)
@handler CreateVolumeTypesHandler
@ -314,6 +316,8 @@ service pcm {
delete /vm/deleteVolumeType (DeleteVolumeTypeReq) returns (DeleteVolumeTypeResp)
@handler ListVolumesHandler
get /vm/listVolumes (ListVolumesReq) returns (ListVolumesResp)
@handler GetVolumeDetailedByIdHandler
get /vm/getVolumeDetailedById (GetVolumeDetailedByIdReq) returns (GetVolumeDetailedByIdResp)
// Bare Metal
@handler ListNodesHandler

View File

@ -122,7 +122,7 @@ type (
}
ServersDetailed {
created string `json:"created" copier:"created"`
//created string `json:"created" copier:"created"`
id string `json:"id" copier:"id"`
key_name string `json:"key_name" copier:"key_name"`
locked bool `json:"locked" copier:"locked"`
@ -571,13 +571,12 @@ type (
type(
ShowNetworkDetailsReq{
NetworkId string `json:"network_id" copier:"NetworkId"`
Fields string `json:"fields" copier:"Fields"`
NetworkId string `form:"network_id" copier:"NetworkId"`
}
ShowNetworkDetailsResp{
Network Networkdetail `json:"network" copier:"Network"`
msg string `json:"msg" copier:"msg"`
code int32 `json:"code" copier:"code"`
Msg string `json:"msg" copier:"Msg"`
Code int32 `json:"code" copier:"Code"`
ErrorMsg string `json:"error_msg" copier:"ErrorMsg"`
}
Networkdetail {
@ -590,22 +589,21 @@ type(
Ipv4AddressScope string `json:"ipv4_address_scope" copier:"Ipv4AddressScope"`
Ipv6AddressScope string `json:"ipv6_address_scope" copier:"Ipv6AddressScope"`
L2Adjacency bool `json:"l2_adjacency" copier:"L2Adjacency"`
Mtu string `json:"mtu" copier:"Mtu"`
Mtu int64 `json:"mtu" copier:"Mtu"`
Name string `json:"name" copier:"Name"`
PortSecurityEnabled string `json:"port_security_enabled" copier:"PortSecurityEnabled"`
PortSecurityEnabled bool `json:"port_security_enabled" copier:"PortSecurityEnabled"`
ProjectId string `json:"project_id" copier:"ProjectId"`
ProviderNetworkType string `json:"provider_network_type" copier:"ProviderNetworkType"`
QosPolicyId string `json:"qos_policy_id" copier:"QosPolicyId"`
RevisionNumber string `json:"revision_number" copier:"RevisionNumber"`
RevisionNumber int64 `json:"revision_number" copier:"RevisionNumber"`
Segments Segment `json:"segments" copier:"Segment"`
Shared bool `json:"shared" copier:"Shared"`
Status bool `json:"status" copier:"Status"`
Subnets []bool `json:"subnets" copier:"Subnets"`
Status string `json:"status" copier:"Status"`
Subnets []string `json:"subnets" copier:"Subnets"`
TenantId string `json:"tenant_id" copier:"TenantId"`
VlanTransparent bool `json:"vlan_transparent" copier:"VlanTransparent"`
Description string `json:"description" copier:"Description"`
IsDefault bool `json:"is_default" copier:"IsDefault"`
Tags string `json:"tags" copier:"Tags"`
Tags []string `json:"tags" copier:"Tags"`
}
Segment{
@ -759,6 +757,37 @@ type(
}
)
type(
GetVolumeDetailedByIdReq {
VolumeId string `form:"volume_id" copier:"VolumeId"`
}
GetVolumeDetailedByIdResp {
Volume VolumeDetailed `json:"volume" copier:"Volume"`
Code int32 `json:"code,omitempty" copier:"Code"`
Msg string `json:"msg,omitempty" copier:"Msg"`
ErrorMsg string `json:"errorMsg,omitempty" copier:"ErrorMsg"`
}
VolumeDetailed {
CreatedAt string `json:"created_at" copier:"CreatedAt"`
Id string `json:"id" copier:"Id"`
AvailabilityZone string `json:"availability_zone" copier:"AvailabilityZone"`
Encrypted bool `json:"encrypted" copier:"Encrypted"`
Name string `json:"name" copier:"Name"`
Size int32 `json:"size" copier:"Size"`
Status string `json:"status" copier:"Status"`
TenantId string `json:"tenant_id" copier:"TenantId"`
Updated string `json:"updated" copier:"Updated"`
UserId string `json:"user_id" copier:"UserId"`
Description string `json:"description" copier:"Description"`
Multiattach bool `json:"multiattach" copier:"Multiattach"`
Bootable string `json:"bootable" copier:"Bootable"`
VolumeType string `json:"volume_type" copier:"VolumeType"`
Count int32 `json:"count" copier:"Count"`
SharedTargets bool `json:"shared_targets" copier:"SharedTargets"`
ConsumesQuota bool `json:"consumes_quota" copier:"ConsumesQuota"`
}
)
type(
CreateVolumeTypeReq {
VolumeType VolumeType `json:"volume_type" copier:"VolumeType"`

View File

@ -526,6 +526,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/vm/listVolumes",
Handler: vm.ListVolumesHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/vm/getVolumeDetailedById",
Handler: vm.GetVolumeDetailedByIdHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/vm/listNodes",

View File

@ -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 GetVolumeDetailedByIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetVolumeDetailedByIdReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := vm.NewGetVolumeDetailedByIdLogic(r.Context(), svcCtx)
resp, err := l.GetVolumeDetailedById(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -0,0 +1,48 @@
package vm
import (
"context"
"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"
"k8s.io/apimachinery/pkg/util/json"
"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 GetVolumeDetailedByIdLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetVolumeDetailedByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetVolumeDetailedByIdLogic {
return &GetVolumeDetailedByIdLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetVolumeDetailedByIdLogic) GetVolumeDetailedById(req *types.GetVolumeDetailedByIdReq) (resp *types.GetVolumeDetailedByIdResp, err error) {
// todo: add your logic here and delete this line
GetVolumeDetailedByIdReq := &openstack.GetVolumeDetailedByIdReq{}
err = copier.CopyWithOption(GetVolumeDetailedByIdReq, req, copier.Option{Converters: tool.Converters})
GetVolumeDetailedByIdResp, err := l.svcCtx.OpenstackRpc.GetVolumeDetailedById(l.ctx, GetVolumeDetailedByIdReq)
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(&GetVolumeDetailedByIdResp)
if err != nil {
return nil, result.NewDefaultError(err.Error())
}
json.Unmarshal(marshal, &resp)
err = copier.CopyWithOption(&resp, &GetVolumeDetailedByIdResp, copier.Option{Converters: tool.Converters})
return resp, err
}

View File

@ -2281,7 +2281,6 @@ type ListServersDetailedResp struct {
}
type ServersDetailed struct {
Created string `json:"created" copier:"created"`
Id string `json:"id" copier:"id"`
Key_name string `json:"key_name" copier:"key_name"`
Locked bool `json:"locked" copier:"locked"`
@ -2712,14 +2711,13 @@ type Allocation_pools struct {
}
type ShowNetworkDetailsReq struct {
NetworkId string `json:"network_id" copier:"NetworkId"`
Fields string `json:"fields" copier:"Fields"`
NetworkId string `form:"network_id" copier:"NetworkId"`
}
type ShowNetworkDetailsResp struct {
Network Networkdetail `json:"network" copier:"Network"`
Msg string `json:"msg" copier:"msg"`
Code int32 `json:"code" copier:"code"`
Msg string `json:"msg" copier:"Msg"`
Code int32 `json:"code" copier:"Code"`
ErrorMsg string `json:"error_msg" copier:"ErrorMsg"`
}
@ -2733,22 +2731,21 @@ type Networkdetail struct {
Ipv4AddressScope string `json:"ipv4_address_scope" copier:"Ipv4AddressScope"`
Ipv6AddressScope string `json:"ipv6_address_scope" copier:"Ipv6AddressScope"`
L2Adjacency bool `json:"l2_adjacency" copier:"L2Adjacency"`
Mtu string `json:"mtu" copier:"Mtu"`
Mtu int64 `json:"mtu" copier:"Mtu"`
Name string `json:"name" copier:"Name"`
PortSecurityEnabled string `json:"port_security_enabled" copier:"PortSecurityEnabled"`
PortSecurityEnabled bool `json:"port_security_enabled" copier:"PortSecurityEnabled"`
ProjectId string `json:"project_id" copier:"ProjectId"`
ProviderNetworkType string `json:"provider_network_type" copier:"ProviderNetworkType"`
QosPolicyId string `json:"qos_policy_id" copier:"QosPolicyId"`
RevisionNumber string `json:"revision_number" copier:"RevisionNumber"`
RevisionNumber int64 `json:"revision_number" copier:"RevisionNumber"`
Segments Segment `json:"segments" copier:"Segment"`
Shared bool `json:"shared" copier:"Shared"`
Status bool `json:"status" copier:"Status"`
Subnets []bool `json:"subnets" copier:"Subnets"`
Status string `json:"status" copier:"Status"`
Subnets []string `json:"subnets" copier:"Subnets"`
TenantId string `json:"tenant_id" copier:"TenantId"`
VlanTransparent bool `json:"vlan_transparent" copier:"VlanTransparent"`
Description string `json:"description" copier:"Description"`
IsDefault bool `json:"is_default" copier:"IsDefault"`
Tags string `json:"tags" copier:"Tags"`
Tags []string `json:"tags" copier:"Tags"`
}
type Segment struct {
@ -2893,6 +2890,37 @@ type UpdateVolumeResp struct {
ErrorMsg string `json:"errorMsg,omitempty" copier:"ErrorMsg"`
}
type GetVolumeDetailedByIdReq struct {
VolumeId string `form:"volume_id" copier:"VolumeId"`
}
type GetVolumeDetailedByIdResp struct {
Volume VolumeDetailed `json:"volume" copier:"Volume"`
Code int32 `json:"code,omitempty" copier:"Code"`
Msg string `json:"msg,omitempty" copier:"Msg"`
ErrorMsg string `json:"errorMsg,omitempty" copier:"ErrorMsg"`
}
type VolumeDetailed struct {
CreatedAt string `json:"created_at" copier:"CreatedAt"`
Id string `json:"id" copier:"Id"`
AvailabilityZone string `json:"availability_zone" copier:"AvailabilityZone"`
Encrypted bool `json:"encrypted" copier:"Encrypted"`
Name string `json:"name" copier:"Name"`
Size int32 `json:"size" copier:"Size"`
Status string `json:"status" copier:"Status"`
TenantId string `json:"tenant_id" copier:"TenantId"`
Updated string `json:"updated" copier:"Updated"`
UserId string `json:"user_id" copier:"UserId"`
Description string `json:"description" copier:"Description"`
Multiattach bool `json:"multiattach" copier:"Multiattach"`
Bootable string `json:"bootable" copier:"Bootable"`
VolumeType string `json:"volume_type" copier:"VolumeType"`
Count int32 `json:"count" copier:"Count"`
SharedTargets bool `json:"shared_targets" copier:"SharedTargets"`
ConsumesQuota bool `json:"consumes_quota" copier:"ConsumesQuota"`
}
type CreateVolumeTypeReq struct {
VolumeType VolumeType `json:"volume_type" copier:"VolumeType"`
}

5
go.mod
View File

@ -9,13 +9,13 @@ require (
github.com/aws/aws-sdk-go v1.44.325
github.com/bwmarrin/snowflake v0.3.0
github.com/docker/docker v24.0.5+incompatible
github.com/go-redis/redis v6.15.9+incompatible
github.com/go-redis/redis/v8 v8.11.5
github.com/go-resty/resty/v2 v2.7.0
github.com/go-sql-driver/mysql v1.7.1
github.com/jinzhu/copier v0.3.5
github.com/nacos-group/nacos-sdk-go/v2 v2.2.3
github.com/pkg/errors v0.9.1
github.com/redis/go-redis/v9 v9.2.1
github.com/robfig/cron/v3 v3.0.1
github.com/shopspring/decimal v1.3.1
github.com/zeromicro/go-queue v1.1.8
@ -25,7 +25,7 @@ require (
gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes v0.0.0-20230830120334-bf6d99c715ef
gitlink.org.cn/jcce-pcm/pcm-participant-modelarts v0.0.0-20230719015658-08a29549d86a
gitlink.org.cn/jcce-pcm/pcm-participant-octopus v0.0.0-20231011071802-c6a7637b74e4
gitlink.org.cn/jcce-pcm/pcm-participant-openstack v0.0.0-20231012071552-57fd38592ad2
gitlink.org.cn/jcce-pcm/pcm-participant-openstack v0.0.0-20231019045136-d2e46b766c7c
gitlink.org.cn/jcce-pcm/pcm-participant-slurm v0.0.0-20230714030125-a52fa198ddf4
gitlink.org.cn/jcce-pcm/utils v0.0.2
go.opentelemetry.io/otel/trace v1.14.0
@ -99,7 +99,6 @@ require (
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/redis/go-redis/v9 v9.2.1 // indirect
github.com/segmentio/kafka-go v0.4.38 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.9 // indirect

8
go.sum
View File

@ -441,6 +441,8 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
@ -570,8 +572,6 @@ github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
@ -1041,8 +1041,8 @@ gitlink.org.cn/jcce-pcm/pcm-participant-modelarts v0.0.0-20230719015658-08a29549
gitlink.org.cn/jcce-pcm/pcm-participant-modelarts v0.0.0-20230719015658-08a29549d86a/go.mod h1:BhOgwM1LC+BD46DjTaQyYQVZs1CikwI5Pl/6qzKUexc=
gitlink.org.cn/jcce-pcm/pcm-participant-octopus v0.0.0-20231011071802-c6a7637b74e4 h1:iv78VZ5+j6/VNkEyD/GSmTJ96rpxzpKDUNknAoXsAmg=
gitlink.org.cn/jcce-pcm/pcm-participant-octopus v0.0.0-20231011071802-c6a7637b74e4/go.mod h1:uyvpVqG1jHDXX+ubXI0RBwnWXzVykD/mliqGQIDvRoo=
gitlink.org.cn/jcce-pcm/pcm-participant-openstack v0.0.0-20231012071552-57fd38592ad2 h1:0r3AU7o7+kASjV9yqFMZznqDboUTMavY8FdqoFEbfqk=
gitlink.org.cn/jcce-pcm/pcm-participant-openstack v0.0.0-20231012071552-57fd38592ad2/go.mod h1:zFMf8Rx4jHD9MmFHqVADPa6m9aTQPrAA4om6jjYvJOk=
gitlink.org.cn/jcce-pcm/pcm-participant-openstack v0.0.0-20231019045136-d2e46b766c7c h1:a/qBta+xwUSDjc2KOd+XzWYAHa4qcAwKgUVLgZrLvUU=
gitlink.org.cn/jcce-pcm/pcm-participant-openstack v0.0.0-20231019045136-d2e46b766c7c/go.mod h1:zFMf8Rx4jHD9MmFHqVADPa6m9aTQPrAA4om6jjYvJOk=
gitlink.org.cn/jcce-pcm/pcm-participant-slurm v0.0.0-20230714030125-a52fa198ddf4 h1:r2hBP5G/bbkPpDTPk3ENnQxD82vkoYMSeNHYhNAVRX4=
gitlink.org.cn/jcce-pcm/pcm-participant-slurm v0.0.0-20230714030125-a52fa198ddf4/go.mod h1:zRdVJiv4r4jgBli2xpYGmV0n6Gmz8fkZ5pJaNK2MbTU=
gitlink.org.cn/jcce-pcm/utils v0.0.2 h1:Stif8W9C9TOCS2hw4g+OlOywDrsVYNrkiyKfBrWkT0w=