Skip to content

Commit

Permalink
# This is a combination of 5 commits.
Browse files Browse the repository at this point in the history
# 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
tomvachon committed Mar 21, 2018
1 parent b8f6adc commit d6f6e6d
Show file tree
Hide file tree
Showing 6 changed files with 374 additions and 0 deletions.
63 changes: 63 additions & 0 deletions resources/autoscalingplans-scalingplans.go
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
}
60 changes: 60 additions & 0 deletions resources/sagemaker-endpointconfigs.go
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
}
60 changes: 60 additions & 0 deletions resources/sagemaker-endpoints.go
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
}
60 changes: 60 additions & 0 deletions resources/sagemaker-models.go
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
}
71 changes: 71 additions & 0 deletions resources/sagemaker-notebookeinstancestates.go
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
}
60 changes: 60 additions & 0 deletions resources/sagemaker-notebookinstances.go
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
}

0 comments on commit d6f6e6d

Please sign in to comment.