yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/zstack/cluster.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 zstack
    16  
    17  import "net/url"
    18  
    19  type SCluster struct {
    20  	ZStackBasic
    21  	Description    string `json:"description"`
    22  	State          string `json:"State"`
    23  	HypervisorType string `json:"hypervisorType"`
    24  	ZStackTime
    25  	ZoneUUID string `json:"zoneUuid"`
    26  	Type     string `json:"type"`
    27  }
    28  
    29  func (region *SRegion) GetClusters() ([]SCluster, error) {
    30  	clusters := []SCluster{}
    31  	params := url.Values{}
    32  	if SkipEsxi {
    33  		params.Set("q", "type!=vmware")
    34  	}
    35  	return clusters, region.client.listAll("clusters", params, &clusters)
    36  }
    37  
    38  func (region *SRegion) GetClusterIds() ([]string, error) {
    39  	clusters, err := region.GetClusters()
    40  	if err != nil {
    41  		return nil, err
    42  	}
    43  	clusterIds := []string{}
    44  	for i := 0; i < len(clusters); i++ {
    45  		clusterIds = append(clusterIds, clusters[i].UUID)
    46  	}
    47  	return clusterIds, nil
    48  }