From 2c04b0156fa28f7e5001f775e0815e1c83b729ac Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Sat, 31 Oct 2020 11:45:16 +0800 Subject: [PATCH] Only returns available flavors for specified az (#621) This updates flavors data source to filter abandon and sellout flavors for specified az. --- go.mod | 2 +- go.sum | 4 ++-- .../data_source_huaweicloud_compute_flavors.go | 18 ++++++++++++++++++ .../openstack/ecs/v1/flavors/results.go | 6 ++++++ vendor/modules.txt | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 71b8ae30b2..db7955e469 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/go-cleanhttp v0.5.1 github.com/hashicorp/terraform-plugin-sdk v1.13.0 - github.com/huaweicloud/golangsdk v0.0.0-20201027014306-5ff7dac952b3 + github.com/huaweicloud/golangsdk v0.0.0-20201030072716-cb31520416ba github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a github.com/mitchellh/go-homedir v1.1.0 github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect diff --git a/go.sum b/go.sum index 10efa2b6a4..457434e6d6 100644 --- a/go.sum +++ b/go.sum @@ -129,8 +129,8 @@ github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= -github.com/huaweicloud/golangsdk v0.0.0-20201027014306-5ff7dac952b3 h1:OM0O1p/gea9E3fQGca1gBrM/f10IZQ38w4MGhupar8c= -github.com/huaweicloud/golangsdk v0.0.0-20201027014306-5ff7dac952b3/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0= +github.com/huaweicloud/golangsdk v0.0.0-20201030072716-cb31520416ba h1:HYHfyOIFOG8Y3y1XZoiyFhsTUxkg56IxPn+D9ME60pE= +github.com/huaweicloud/golangsdk v0.0.0-20201030072716-cb31520416ba/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0= github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a h1:FyS/ubzBR5xJlnJGRTwe7GUHpJOR4ukYK3y+LFNffuA= github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a/go.mod h1:uoIMjNxUfXi48Ci40IXkPRbghZ1vbti6v9LCbNqRgHY= github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= diff --git a/huaweicloud/data_source_huaweicloud_compute_flavors.go b/huaweicloud/data_source_huaweicloud_compute_flavors.go index 93337d29b7..b78aa2821e 100644 --- a/huaweicloud/data_source_huaweicloud_compute_flavors.go +++ b/huaweicloud/data_source_huaweicloud_compute_flavors.go @@ -3,6 +3,7 @@ package huaweicloud import ( "fmt" "strconv" + "strings" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/huaweicloud/golangsdk/openstack/ecs/v1/flavors" @@ -72,6 +73,7 @@ func dataSourceEcsFlavorsRead(d *schema.ResourceData, meta interface{}) error { mem := int64(d.Get("memory_size").(int)) pType := d.Get("performance_type").(string) gen := d.Get("generation").(string) + az := d.Get("availability_zone").(string) var ids []string for _, flavor := range allFlavors { @@ -92,6 +94,22 @@ func dataSourceEcsFlavorsRead(d *schema.ResourceData, meta interface{}) error { continue } + if az != "" { + status := flavor.OsExtraSpecs.OperationStatus + azStatusRaw := flavor.OsExtraSpecs.OperationAz + azStatusList := strings.Split(azStatusRaw, ",") + if strings.Contains(azStatusRaw, az) { + for i := 0; i < len(azStatusList); i++ { + azStatus := azStatusList[i] + if azStatus == (az+"(abandon)") || azStatus == (az+"(sellout)") || azStatus == (az+"obt_sellout") { + continue + } + } + } else if status == "abandon" || strings.Contains(status, "sellout") { + continue + } + } + ids = append(ids, flavor.ID) } diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/ecs/v1/flavors/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/ecs/v1/flavors/results.go index 6e86776c7f..57d309fcd6 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/ecs/v1/flavors/results.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/ecs/v1/flavors/results.go @@ -82,6 +82,12 @@ type OsExtraSpecs struct { // Indicates the model and quantity of passthrough-enabled GPUs on P1 ECSs. PciPassthroughAlias string `json:"pci_passthrough:alias"` + + // Indicates the status of the flavor in region level. + OperationStatus string `json:"cond:operation:status"` + + // Indicates the status of the flavor in az level. + OperationAz string `json:"cond:operation:az"` } // FlavorsPage is the page returned by a pager when traversing over a diff --git a/vendor/modules.txt b/vendor/modules.txt index 1958cb2f85..ed64324167 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -186,7 +186,7 @@ github.com/hashicorp/terraform-svchost/auth github.com/hashicorp/terraform-svchost/disco # github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d github.com/hashicorp/yamux -# github.com/huaweicloud/golangsdk v0.0.0-20201027014306-5ff7dac952b3 +# github.com/huaweicloud/golangsdk v0.0.0-20201030072716-cb31520416ba ## explicit github.com/huaweicloud/golangsdk github.com/huaweicloud/golangsdk/internal