Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add forced delete parameter #330

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions ecs/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ func (client *Client) ModifyInstanceAutoReleaseTime(instanceId, time string) err

type DeleteInstanceArgs struct {
InstanceId string
Force bool
}

type DeleteInstanceResponse struct {
Expand All @@ -473,8 +474,8 @@ type DeleteInstanceResponse struct {
// DeleteInstance deletes instance
//
// You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/instance&deleteinstance
func (client *Client) DeleteInstance(instanceId string) error {
args := DeleteInstanceArgs{InstanceId: instanceId}
func (client *Client) DeleteInstance(instanceId string, forceDelete bool) error {
args := DeleteInstanceArgs{InstanceId: instanceId, Force: forceDelete}
response := DeleteInstanceResponse{}
err := client.Invoke("DeleteInstance", &args, &response)
return err
Expand Down
6 changes: 3 additions & 3 deletions ecs/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func ExampleClient_DeleteInstance() {

client := NewTestClient()

err := client.DeleteInstance(TestInstanceId)
err := client.DeleteInstance(TestInstanceId, false)

if err != nil {
fmt.Printf("Failed to delete Instance %s vnc url: %v \n", TestInstanceId, err)
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestECSInstanceCreationAndDeletion(t *testing.T) {
}
t.Logf("Instance %s is stopped successfully.", instanceId)

err = client.DeleteInstance(instanceId)
err = client.DeleteInstance(instanceId, false)

if err != nil {
t.Errorf("Failed to delete instance %s: %v", instanceId, err)
Expand Down Expand Up @@ -280,7 +280,7 @@ func TestLocationECSClient(t *testing.T) {
t.Logf("InstanceAttribute is %++v", attr)

//DeleteInstance
err = client.DeleteInstance(instanceId)
err = client.DeleteInstance(instanceId, false)
if err != nil {
t.Fatalf("Failed to delete instance %++v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion ecs/vpcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestVPCCreationAndDeletion(t *testing.T) {
}
t.Logf("Instance %s is stopped successfully.", instanceId)
}
err = client.DeleteInstance(instanceId)
err = client.DeleteInstance(instanceId, false)

if err != nil {
t.Errorf("Failed to delete instance %s: %v", instanceId, err)
Expand Down