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.6 kB

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

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.