-
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.
Merge pull request #179 from niuzhenguo/ecs-server
Add ECS instance v1 resource
- Loading branch information
Showing
21 changed files
with
1,548 additions
and
4 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
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,34 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/huaweicloud/golangsdk/openstack/ecs/v1/tags" | ||
) | ||
|
||
func setTagForInstance(d *schema.ResourceData, meta interface{}, instanceID string, tagmap map[string]interface{}) error { | ||
config := meta.(*Config) | ||
client, err := config.computeV1Client(GetRegion(d, config)) | ||
if err != nil { | ||
return fmt.Errorf("Error creating HuaweiCloud compute v1 client: %s", err) | ||
} | ||
|
||
rId := instanceID | ||
taglist := []tags.Tag{} | ||
for k, v := range tagmap { | ||
tag := tags.Tag{ | ||
Key: k, | ||
Value: v.(string), | ||
} | ||
taglist = append(taglist, tag) | ||
} | ||
|
||
createOpts := tags.BatchOpts{Action: tags.ActionCreate, Tags: taglist} | ||
createTags := tags.BatchAction(client, rId, createOpts) | ||
if createTags.Err != nil { | ||
return fmt.Errorf("Error creating HuaweiCloud instance tags: %s", createTags.Err) | ||
} | ||
|
||
return 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
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,55 @@ | ||
package huaweicloud | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strconv" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/huaweicloud/golangsdk/openstack/ecs/v1/auto_recovery" | ||
) | ||
|
||
func resourceECSAutoRecoveryV1Read(d *schema.ResourceData, meta interface{}, instanceID string) (bool, error) { | ||
config := meta.(*Config) | ||
client, err := config.computeV1Client(GetRegion(d, config)) | ||
if err != nil { | ||
return false, fmt.Errorf("Error creating HuaweiCloud client: %s", err) | ||
} | ||
|
||
rId := instanceID | ||
|
||
r, err := auto_recovery.Get(client, rId).Extract() | ||
if err != nil { | ||
return false, err | ||
} | ||
log.Printf("[DEBUG] Retrieved ECS-AutoRecovery:%#v of instance:%s", rId, r) | ||
return strconv.ParseBool(r.SupportAutoRecovery) | ||
} | ||
|
||
func setAutoRecoveryForInstance(d *schema.ResourceData, meta interface{}, instanceID string, ar bool) error { | ||
config := meta.(*Config) | ||
client, err := config.computeV1Client(GetRegion(d, config)) | ||
if err != nil { | ||
return fmt.Errorf("Error creating HuaweiCloud client: %s", err) | ||
} | ||
|
||
rId := instanceID | ||
|
||
updateOpts := auto_recovery.UpdateOpts{SupportAutoRecovery: strconv.FormatBool(ar)} | ||
|
||
timeout := d.Timeout(schema.TimeoutUpdate) | ||
|
||
log.Printf("[DEBUG] Setting ECS-AutoRecovery for instance:%s with options: %#v", rId, updateOpts) | ||
err = resource.Retry(timeout, func() *resource.RetryError { | ||
err := auto_recovery.Update(client, rId, updateOpts) | ||
if err != nil { | ||
return checkForRetryableError(err) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Error setting ECS-AutoRecovery for instance%s: %s", rId, err) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.