yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/cloudpods/project.go (about)

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