template_unbinding_servers.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. "fmt"
  31. "yunion.io/x/jsonutils"
  32. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  33. "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
  34. "yunion.io/x/onecloud/pkg/devtool/models"
  35. )
  36. type TemplateUnbindingServers struct {
  37. taskman.STask
  38. }
  39. func init() {
  40. taskman.RegisterTask(TemplateUnbindingServers{})
  41. }
  42. func (self *TemplateUnbindingServers) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) {
  43. template := obj.(*models.SDevtoolTemplate)
  44. _, err := template.Unbinding(ctx, self.UserCred, nil, self.Params)
  45. if err != nil {
  46. self.SetStageFailed(ctx, jsonutils.NewString(fmt.Sprintf("TemplateUnBindingServers failed %s", err)))
  47. } else {
  48. self.SetStageComplete(ctx, nil)
  49. }
  50. }