You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

getnetworknumlogic.go 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package vm
  2. import (
  3. "context"
  4. "github.com/jinzhu/copier"
  5. "github.com/pkg/errors"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/helper/xerr"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
  9. "gitlink.org.cn/JointCloud/pcm-openstack/openstack"
  10. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  11. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type GetNetworkNumLogic struct {
  15. logx.Logger
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. }
  19. func NewGetNetworkNumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetNetworkNumLogic {
  20. return &GetNetworkNumLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. }
  25. }
  26. func (l *GetNetworkNumLogic) GetNetworkNum(req *types.ListNetworksReq) (resp *types.NetworkNum, err error) {
  27. // todo: add your logic here and delete this line
  28. resp = &types.NetworkNum{}
  29. ListNetworksReq := &openstack.ListNetworksReq{}
  30. err = copier.CopyWithOption(ListNetworksReq, req, copier.Option{Converters: utils.Converters})
  31. ListNetworksResp, err := l.svcCtx.OpenstackRpc.ListNetworks(l.ctx, ListNetworksReq)
  32. if err != nil {
  33. return nil, errors.Wrapf(xerr.NewErrMsg("Failed to get Networks list"), "Failed to get db Servers list err : %v ,req:%+v", err, req)
  34. }
  35. var count int = len(ListNetworksResp.Networks)
  36. resp.NetworkNum = int32(count)
  37. if err != nil {
  38. return nil, result.NewDefaultError(err.Error())
  39. }
  40. return resp, err
  41. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.