project.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 cloudpods
  15. import (
  16. "yunion.io/x/cloudmux/pkg/cloudprovider"
  17. "yunion.io/x/cloudmux/pkg/multicloud"
  18. "yunion.io/x/onecloud/pkg/apis/compute"
  19. api "yunion.io/x/onecloud/pkg/apis/identity"
  20. modules "yunion.io/x/onecloud/pkg/mcclient/modules/identity"
  21. )
  22. type SProject struct {
  23. multicloud.SProjectBase
  24. CloudpodsTags
  25. cli *SCloudpodsClient
  26. api.ProjectDetails
  27. }
  28. func (self *SProject) GetName() string {
  29. return self.Name
  30. }
  31. func (self *SProject) GetId() string {
  32. return self.Id
  33. }
  34. func (self *SProject) GetGlobalId() string {
  35. return self.Id
  36. }
  37. func (self *SProject) GetStatus() string {
  38. return compute.EXTERNAL_PROJECT_STATUS_AVAILABLE
  39. }
  40. func (self *SCloudpodsClient) GetProjects() ([]SProject, error) {
  41. ret := []SProject{}
  42. params := map[string]interface{}{
  43. "scope": "system",
  44. "limit": 1024,
  45. }
  46. return ret, self.list(&modules.Projects, params, &ret)
  47. }
  48. func (self *SCloudpodsClient) GetIProjects() ([]cloudprovider.ICloudProject, error) {
  49. projects, err := self.GetProjects()
  50. if err != nil {
  51. return nil, err
  52. }
  53. ret := []cloudprovider.ICloudProject{}
  54. for i := range projects {
  55. projects[i].cli = self
  56. ret = append(ret, &projects[i])
  57. }
  58. return ret, nil
  59. }