-
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.
Support for creating/deleting volumes (#24)
* add support for creating volumes * add support for deleting volumes * fixup * update modules
- Loading branch information
Showing
11 changed files
with
466 additions
and
27 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,50 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/YaleSpinup/apierror" | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/awsutil" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func (o *ec2Orchestrator) createVolume(ctx context.Context, req *Ec2VolumeCreateRequest) (string, error) { | ||
if req == nil { | ||
return "", apierror.New(apierror.ErrBadRequest, "invalid input", nil) | ||
} | ||
|
||
log.Debugf("got request to create volume: %s", awsutil.Prettify(req)) | ||
|
||
input := &ec2.CreateVolumeInput{ | ||
AvailabilityZone: req.AZ, | ||
Encrypted: req.Encrypted, | ||
Iops: req.Iops, | ||
KmsKeyId: req.KmsKeyId, | ||
Size: req.Size, | ||
SnapshotId: req.SnapshotId, | ||
VolumeType: req.Type, | ||
} | ||
|
||
out, err := o.ec2Client.CreateVolume(ctx, input) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return aws.StringValue(out.VolumeId), nil | ||
} | ||
|
||
func (o *ec2Orchestrator) deleteVolume(ctx context.Context, id string) error { | ||
if id == "" { | ||
return apierror.New(apierror.ErrBadRequest, "invalid input", nil) | ||
} | ||
|
||
log.Debugf("got request to delete volume %s", id) | ||
|
||
if err := o.ec2Client.DeleteVolume(ctx, id); err != nil { | ||
return 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
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
Oops, something went wrong.