-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add service level to the sdkClient * add resource of cdm cluster * fix bugs
- Loading branch information
1 parent
befa2d7
commit 7414b2b
Showing
14 changed files
with
2,033 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package huaweicloud | ||
|
||
func expandCdmClusterV1CreateAutoRemind(d interface{}, arrayIndex map[string]int) (interface{}, error) { | ||
email, _ := navigateValue(d, []string{"email"}, nil) | ||
e, eok := email.([]interface{}) | ||
|
||
phone, _ := navigateValue(d, []string{"phone_num"}, nil) | ||
p, pok := phone.([]interface{}) | ||
|
||
return (eok && len(e) > 0) || (pok && len(p) > 0), nil | ||
} | ||
|
||
func expandCdmClusterV1CreateClusterIsScheduleBootOff(d interface{}, arrayIndex map[string]int) (interface{}, error) { | ||
on, _ := navigateValue(d, []string{"schedule_boot_time"}, nil) | ||
on1, ok1 := on.(string) | ||
|
||
off, _ := navigateValue(d, []string{"schedule_off_time"}, nil) | ||
off1, ok2 := off.(string) | ||
|
||
return (ok1 && on1 != "") || (ok2 && off1 != ""), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/huaweicloud/golangsdk" | ||
) | ||
|
||
func dataSourceCdmFlavorV1() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceCdmFlavorV1Read, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"region": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
}, | ||
"version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"flavors": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceCdmFlavorV1Read(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
client, err := config.sdkClient(GetRegion(d, config), "cdm", serviceProjectLevel) | ||
if err != nil { | ||
return fmt.Errorf("Error creating sdk client, err=%s", err) | ||
} | ||
|
||
dsid, err := getCdmDatastoreV1ID(client) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
version, fs, err := getCdmFlavorV1(client, dsid) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(version) | ||
d.Set("version", version) | ||
d.Set("flavors", fs) | ||
return nil | ||
} | ||
|
||
func getCdmDatastoreV1ID(client *golangsdk.ServiceClient) (string, error) { | ||
url := client.ServiceURL("datastores") | ||
r := golangsdk.Result{} | ||
_, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ | ||
MoreHeaders: map[string]string{ | ||
"Content-Type": "application/json", | ||
"X-Language": "en-us", | ||
}}) | ||
if r.Err != nil { | ||
return "", r.Err | ||
} | ||
|
||
v, err := navigateValue(r.Body, []string{"datastores"}, nil) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
ds, ok := v.([]interface{}) | ||
if !ok { | ||
return "", fmt.Errorf("can not find datastore") | ||
} | ||
|
||
for _, item := range ds { | ||
name, err := navigateValue(item, []string{"name"}, nil) | ||
if err != nil { | ||
return "", err | ||
} | ||
if "cdm" == name.(string) { | ||
dsid, err := navigateValue(item, []string{"id"}, nil) | ||
if err != nil { | ||
return "", err | ||
} | ||
return dsid.(string), nil | ||
} | ||
} | ||
|
||
return "", fmt.Errorf("didn't find the datastore id") | ||
} | ||
|
||
func getCdmFlavorV1(client *golangsdk.ServiceClient, dsid string) (string, interface{}, error) { | ||
url := client.ServiceURL("datastores", dsid, "flavors") | ||
r := golangsdk.Result{} | ||
_, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ | ||
MoreHeaders: map[string]string{ | ||
"Content-Type": "application/json", | ||
"X-Language": "en-us", | ||
}}) | ||
if r.Err != nil { | ||
return "", nil, r.Err | ||
} | ||
|
||
v, err := navigateValue(r.Body, []string{"versions"}, nil) | ||
if err != nil { | ||
return "", nil, err | ||
} | ||
vs, ok := v.([]interface{}) | ||
if !ok { | ||
return "", nil, fmt.Errorf("can not find flavor") | ||
} | ||
for _, item := range vs { | ||
version, err := navigateValue(item, []string{"name"}, nil) | ||
if err != nil { | ||
return "", nil, err | ||
} | ||
flavors, err := navigateValue(item, []string{"flavors"}, nil) | ||
if err != nil { | ||
return "", nil, err | ||
} | ||
|
||
fs, ok := flavors.([]interface{}) | ||
if !ok { | ||
return "", nil, fmt.Errorf("can not find flavor") | ||
} | ||
num := len(fs) | ||
r := make([]interface{}, num, num) | ||
for i := 0; i < num; i++ { | ||
item := fs[i] | ||
name, err := navigateValue(item, []string{"name"}, nil) | ||
if err != nil { | ||
return "", nil, err | ||
} | ||
fid, err := navigateValue(item, []string{"str_id"}, nil) | ||
if err != nil { | ||
return "", nil, err | ||
} | ||
|
||
r[i] = map[string]interface{}{ | ||
"id": fid, | ||
"name": name, | ||
} | ||
} | ||
return version.(string), r, nil | ||
} | ||
|
||
return "", nil, fmt.Errorf("can not find flavor") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.