forked from rebuy-de/aws-nuke
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# This is a combination of 5 commits.
# This is the 1st commit message: Add AutoscalingPlans API # This is the commit message #2: Pending SDK fix # This is the commit message #3: Add Sagemaker with bgugs # This is the commit message #4: Split stop and delete, still not ready # This is the commit message #5: Move Instance stop to its own state
- Loading branch information
Showing
6 changed files
with
374 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/autoscalingplans" | ||
) | ||
|
||
type AutoScalingPlansScalingPlan struct { | ||
svc *autoscalingplans.AutoScalingPlans | ||
scalingPlanName *string | ||
scalingPlanVersion *int64 | ||
} | ||
|
||
func init() { | ||
register("AutoScalingPlansScalingPlan", ListAutoScalingPlansScalingPlans) | ||
} | ||
|
||
func ListAutoScalingPlansScalingPlans(sess *session.Session) ([]Resource, error) { | ||
svc := autoscalingplans.New(sess) | ||
resources := []Resource{} | ||
|
||
params := &autoscalingplans.DescribeScalingPlansInput{ | ||
MaxResults: aws.Int64(50), | ||
} | ||
|
||
for { | ||
output, err := svc.DescribeScalingPlans(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, scalingPlan := range output.ScalingPlans { | ||
resources = append(resources, &AutoScalingPlansScalingPlan{ | ||
svc: svc, | ||
scalingPlanName: scalingPlan.ScalingPlanName, | ||
scalingPlanVersion: scalingPlan.ScalingPlanVersion, | ||
}) | ||
} | ||
|
||
if output.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = output.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (f *AutoScalingPlansScalingPlan) Remove() error { | ||
|
||
_, err := f.svc.DeleteScalingPlan(&autoscalingplans.DeleteScalingPlanInput{ | ||
ScalingPlanName: f.scalingPlanName, | ||
ScalingPlanVersion: f.scalingPlanVersion, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *AutoScalingPlansScalingPlan) String() string { | ||
return *f.scalingPlanName | ||
} |
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,60 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/sagemaker" | ||
) | ||
|
||
type SageMakerEndpointConfig struct { | ||
svc *sagemaker.SageMaker | ||
endpointConfigName *string | ||
} | ||
|
||
func init() { | ||
register("SageMakerEndpointConfig", ListSageMakerEndpointConfigs) | ||
} | ||
|
||
func ListSageMakerEndpointConfigs(sess *session.Session) ([]Resource, error) { | ||
svc := sagemaker.New(sess) | ||
resources := []Resource{} | ||
|
||
params := &sagemaker.ListEndpointConfigsInput{ | ||
MaxResults: aws.Int64(30), | ||
} | ||
|
||
for { | ||
resp, err := svc.ListEndpointConfigs(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, endpointConfig := range resp.EndpointConfigs { | ||
resources = append(resources, &SageMakerEndpointConfig{ | ||
svc: svc, | ||
endpointConfigName: endpointConfig.EndpointConfigName, | ||
}) | ||
} | ||
|
||
if resp.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = resp.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (f *SageMakerEndpointConfig) Remove() error { | ||
|
||
_, err := f.svc.DeleteEndpointConfig(&sagemaker.DeleteEndpointConfigInput{ | ||
EndpointConfigName: f.endpointConfigName, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *SageMakerEndpointConfig) String() string { | ||
return *f.endpointConfigName | ||
} |
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,60 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/sagemaker" | ||
) | ||
|
||
type SageMakerEndpoint struct { | ||
svc *sagemaker.SageMaker | ||
endpointName *string | ||
} | ||
|
||
func init() { | ||
register("SageMakerEndpoint", ListSageMakerEndpoints) | ||
} | ||
|
||
func ListSageMakerEndpoints(sess *session.Session) ([]Resource, error) { | ||
svc := sagemaker.New(sess) | ||
resources := []Resource{} | ||
|
||
params := &sagemaker.ListEndpointsInput{ | ||
MaxResults: aws.Int64(30), | ||
} | ||
|
||
for { | ||
resp, err := svc.ListEndpoints(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, endpoint := range resp.Endpoints { | ||
resources = append(resources, &SageMakerEndpoint{ | ||
svc: svc, | ||
endpointName: endpoint.EndpointName, | ||
}) | ||
} | ||
|
||
if resp.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = resp.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (f *SageMakerEndpoint) Remove() error { | ||
|
||
_, err := f.svc.DeleteEndpoint(&sagemaker.DeleteEndpointInput{ | ||
EndpointName: f.endpointName, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *SageMakerEndpoint) String() string { | ||
return *f.endpointName | ||
} |
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,60 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/sagemaker" | ||
) | ||
|
||
type SageMakerModel struct { | ||
svc *sagemaker.SageMaker | ||
modelName *string | ||
} | ||
|
||
func init() { | ||
register("SageMakerModel", ListSageMakerModels) | ||
} | ||
|
||
func ListSageMakerModels(sess *session.Session) ([]Resource, error) { | ||
svc := sagemaker.New(sess) | ||
resources := []Resource{} | ||
|
||
params := &sagemaker.ListModelsInput{ | ||
MaxResults: aws.Int64(30), | ||
} | ||
|
||
for { | ||
resp, err := svc.ListModels(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, model := range resp.Models { | ||
resources = append(resources, &SageMakerModel{ | ||
svc: svc, | ||
modelName: model.ModelName, | ||
}) | ||
} | ||
|
||
if resp.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = resp.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (f *SageMakerModel) Remove() error { | ||
|
||
_, err := f.svc.DeleteModel(&sagemaker.DeleteModelInput{ | ||
ModelName: f.modelName, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *SageMakerModel) String() string { | ||
return *f.modelName | ||
} |
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,71 @@ | ||
package resources | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/sagemaker" | ||
) | ||
|
||
type SageMakerNotebookInstanceState struct { | ||
svc *sagemaker.SageMaker | ||
notebookInstanceName *string | ||
instanceStatus *string | ||
} | ||
|
||
func init() { | ||
register("SageMakerNotebookInstanceState", ListSageMakerNotebookInstanceStates) | ||
} | ||
|
||
func ListSageMakerNotebookInstanceStates(sess *session.Session) ([]Resource, error) { | ||
svc := sagemaker.New(sess) | ||
resources := []Resource{} | ||
|
||
params := &sagemaker.ListNotebookInstancesInput{ | ||
MaxResults: aws.Int64(30), | ||
} | ||
|
||
for { | ||
resp, err := svc.ListNotebookInstances(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, notebookInstance := range resp.NotebookInstances { | ||
resources = append(resources, &SageMakerNotebookInstanceState{ | ||
svc: svc, | ||
notebookInstanceName: notebookInstance.NotebookInstanceName, | ||
instanceStatus: notebookInstance.NotebookInstanceStatus, | ||
}) | ||
} | ||
|
||
if resp.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = resp.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (f *SageMakerNotebookInstanceState) Remove() error { | ||
|
||
_, err := f.svc.StopNotebookInstance(&sagemaker.StopNotebookInstanceInput{ | ||
NotebookInstanceName: f.notebookInstanceName, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *SageMakerNotebookInstanceState) String() string { | ||
return fmt.Sprintf("Status %s -> ID %s", *f.instanceStatus, *f.notebookInstanceName) | ||
} | ||
|
||
func (f *SageMakerNotebookInstanceState) Filter() error { | ||
if *f.instanceStatus == "Stopped" { | ||
return fmt.Errorf("already stopped") | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/sagemaker" | ||
) | ||
|
||
type SageMakerNotebookInstance struct { | ||
svc *sagemaker.SageMaker | ||
notebookInstanceName *string | ||
} | ||
|
||
func init() { | ||
register("SageMakerNotebookInstance", ListSageMakerNotebookInstances) | ||
} | ||
|
||
func ListSageMakerNotebookInstances(sess *session.Session) ([]Resource, error) { | ||
svc := sagemaker.New(sess) | ||
resources := []Resource{} | ||
|
||
params := &sagemaker.ListNotebookInstancesInput{ | ||
MaxResults: aws.Int64(30), | ||
} | ||
|
||
for { | ||
resp, err := svc.ListNotebookInstances(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, notebookInstance := range resp.NotebookInstances { | ||
resources = append(resources, &SageMakerNotebookInstance{ | ||
svc: svc, | ||
notebookInstanceName: notebookInstance.NotebookInstanceName, | ||
}) | ||
} | ||
|
||
if resp.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = resp.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (f *SageMakerNotebookInstance) Remove() error { | ||
|
||
_, err := f.svc.DeleteNotebookInstance(&sagemaker.DeleteNotebookInstanceInput{ | ||
NotebookInstanceName: f.notebookInstanceName, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *SageMakerNotebookInstance) String() string { | ||
return *f.notebookInstanceName | ||
} |