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.

listserverlogic.go 1.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package vm
  2. import (
  3. "context"
  4. "github.com/jinzhu/copier"
  5. "github.com/pkg/errors"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
  8. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
  9. error2 "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/repository/error"
  10. "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
  11. "gitlink.org.cn/jcce-pcm/pcm-participant-openstack/openstack"
  12. "gitlink.org.cn/jcce-pcm/utils/xerr"
  13. "k8s.io/apimachinery/pkg/util/json"
  14. )
  15. type ListServerLogic struct {
  16. logx.Logger
  17. ctx context.Context
  18. svcCtx *svc.ServiceContext
  19. }
  20. func NewListServerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListServerLogic {
  21. return &ListServerLogic{
  22. Logger: logx.WithContext(ctx),
  23. ctx: ctx,
  24. svcCtx: svcCtx,
  25. }
  26. }
  27. func (l *ListServerLogic) ListServer(req *types.ListServersReq) (resp *types.ListServersResp, err error) {
  28. // todo: add your logic here and delete this line
  29. ListServersReq := &openstack.ListServersReq{}
  30. err = copier.CopyWithOption(ListServersReq, req, copier.Option{Converters: utils.Converters})
  31. ListServersResp, err := l.svcCtx.OpenstackRpc.ListServers(l.ctx, ListServersReq)
  32. if err != nil {
  33. return nil, errors.Wrapf(xerr.NewErrMsg("Failed to get Servers list"), "Failed to get db Servers list err : %v ,req:%+v", err, req)
  34. }
  35. marshal, err := json.Marshal(&ListServersResp)
  36. if err != nil {
  37. return nil, error2.NewDefaultError(err.Error())
  38. }
  39. json.Unmarshal(marshal, &resp)
  40. err = copier.CopyWithOption(&resp, &ListServersResp, copier.Option{Converters: utils.Converters})
  41. return resp, err
  42. }

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.