template_binding_servers.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // Copyright 2019 Yunion
  15. //
  16. // Licensed under the Apache License, Version 2.0 (the "License");
  17. // you may not use this file except in compliance with the License.
  18. // You may obtain a copy of the License at
  19. //
  20. // http://www.apache.org/licenses/LICENSE-2.0
  21. //
  22. // Unless required by applicable law or agreed to in writing, software
  23. // distributed unde3r the License is distributed on an "AS IS" BASIS,
  24. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. // See the License for the specific language governing permissions and
  26. // limitations under the License.
  27. package tasks
  28. import (
  29. "context"
  30. "yunion.io/x/jsonutils"
  31. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  32. "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
  33. "yunion.io/x/onecloud/pkg/devtool/models"
  34. )
  35. type TemplateBindingServers struct {
  36. taskman.STask
  37. }
  38. func init() {
  39. taskman.RegisterTask(TemplateBindingServers{})
  40. }
  41. func (self *TemplateBindingServers) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) {
  42. template := obj.(*models.SDevtoolTemplate)
  43. _, err := template.Binding(ctx, self.UserCred, nil, self.Params)
  44. if err != nil {
  45. self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
  46. } else {
  47. self.SetStageComplete(ctx, nil)
  48. }
  49. }