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.

createmulserverlogic.go 2.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. "k8s.io/apimachinery/pkg/util/json"
  12. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
  13. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
  14. "github.com/zeromicro/go-zero/core/logx"
  15. )
  16. type CreateMulServerLogic struct {
  17. logx.Logger
  18. ctx context.Context
  19. svcCtx *svc.ServiceContext
  20. }
  21. func NewCreateMulServerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateMulServerLogic {
  22. return &CreateMulServerLogic{
  23. Logger: logx.WithContext(ctx),
  24. ctx: ctx,
  25. svcCtx: svcCtx,
  26. }
  27. }
  28. // ServerLinks 表示服务器链接的结构体
  29. type ServerLinks struct {
  30. Href string `json:"href"` // 注意:在JSON中,"href "有一个额外的空格,需要移除
  31. Rel string `json:"rel"`
  32. }
  33. // SecurityGroup 表示安全组的结构体
  34. type SecurityGroup struct {
  35. Name string `json:"name"`
  36. }
  37. // Server 表示服务器的结构体
  38. type Server struct {
  39. ID string `json:"id"`
  40. Links []ServerLinks `json:"links"`
  41. OSDCFDiskConfig string `json:"OS_DCF_diskConfig"`
  42. SecurityGroups []SecurityGroup `json:"security_groups"`
  43. AdminPass string `json:"adminPass"`
  44. }
  45. // Response 表示整个响应的结构体
  46. type Response struct {
  47. Server Server `json:"server"`
  48. }
  49. func (l *CreateMulServerLogic) CreateMulServer(req *types.CreateMulServerReq) (resp *types.CreateMulServerResp, err error) {
  50. // todo: add your logic here and delete this line
  51. CreateServerReq := &openstack.CreateServerReq{}
  52. var response Response
  53. fmt.Println("请求入参:", req)
  54. for _, server := range req.CreateMulServer {
  55. fmt.Println("入参参数:", server)
  56. err = copier.CopyWithOption(CreateServerReq, server, copier.Option{Converters: utils.Converters})
  57. CreateServerResp, err := l.svcCtx.OpenstackRpc.CreateServer(l.ctx, CreateServerReq)
  58. fmt.Println("返回结果:", CreateServerResp)
  59. if err != nil {
  60. return nil, errors.Wrapf(xerr.NewErrMsg("Failed to create Server list"), "Failed to get db Server list err : %v ,req:%+v", err, req)
  61. }
  62. marshal, err := json.Marshal(&CreateServerResp)
  63. fmt.Println("返回结果b:", marshal)
  64. if err != nil {
  65. return nil, result.NewDefaultError(err.Error())
  66. }
  67. json.Unmarshal(marshal, &response)
  68. }
  69. err = copier.CopyWithOption(&resp, &response, copier.Option{Converters: utils.Converters})
  70. fmt.Println("返回结果c:", resp)
  71. return resp, err
  72. }

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.