guestforward.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package guesthandlers
  15. import (
  16. "context"
  17. "yunion.io/x/jsonutils"
  18. hostapis "yunion.io/x/onecloud/pkg/apis/host"
  19. "yunion.io/x/onecloud/pkg/hostman/guestman"
  20. "yunion.io/x/onecloud/pkg/httperrors"
  21. "yunion.io/x/onecloud/pkg/mcclient"
  22. )
  23. func guestOpenForward(ctx context.Context, userCred mcclient.TokenCredential, sid string, body jsonutils.JSONObject) (interface{}, error) {
  24. req := &hostapis.GuestOpenForwardRequest{}
  25. if err := body.Unmarshal(req); err != nil {
  26. return nil, httperrors.NewInputParameterError("unmarshal: %v", err)
  27. }
  28. gm := guestman.GetGuestManager()
  29. resp, err := gm.OpenForward(ctx, sid, req)
  30. if err != nil {
  31. return nil, httperrors.NewGeneralError(err)
  32. }
  33. return jsonutils.Marshal(resp), nil
  34. }
  35. func guestListForward(ctx context.Context, userCred mcclient.TokenCredential, sid string, body jsonutils.JSONObject) (interface{}, error) {
  36. req := &hostapis.GuestListForwardRequest{}
  37. if err := body.Unmarshal(req); err != nil {
  38. return nil, httperrors.NewInputParameterError("unmarshal: %v", err)
  39. }
  40. gm := guestman.GetGuestManager()
  41. resp, err := gm.ListForward(ctx, sid, req)
  42. if err != nil {
  43. return nil, httperrors.NewGeneralError(err)
  44. }
  45. return jsonutils.Marshal(resp), nil
  46. }
  47. func guestCloseForward(ctx context.Context, userCred mcclient.TokenCredential, sid string, body jsonutils.JSONObject) (interface{}, error) {
  48. req := &hostapis.GuestCloseForwardRequest{}
  49. if err := body.Unmarshal(req); err != nil {
  50. return nil, httperrors.NewInputParameterError("unmarshal: %v", err)
  51. }
  52. gm := guestman.GetGuestManager()
  53. resp, err := gm.CloseForward(ctx, sid, req)
  54. if err != nil {
  55. return nil, httperrors.NewGeneralError(err)
  56. }
  57. return jsonutils.Marshal(resp), nil
  58. }