From 4a6a4922815b2010ac5379a6f5ac873aafe9f0d9 Mon Sep 17 00:00:00 2001 From: Sami Wagiaalla Date: Mon, 22 Jun 2015 12:29:33 -0400 Subject: [PATCH] Use instance availability zone for AWS EBS Signed-off-by: Sami Wagiaalla --- examples/aws_ebs/aws-ebs-web.yaml | 4 ++-- pkg/cloudprovider/aws/aws.go | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/aws_ebs/aws-ebs-web.yaml b/examples/aws_ebs/aws-ebs-web.yaml index 088e921fed0..56667f53830 100644 --- a/examples/aws_ebs/aws-ebs-web.yaml +++ b/examples/aws_ebs/aws-ebs-web.yaml @@ -16,6 +16,6 @@ spec: volumes: - name: html-volume awsElasticBlockStore: - # Enter the volume region and ID below - volumeID: aws://{region}/{volume ID} + # Enter the volume ID below + volumeID: volume_ID fsType: ext4 diff --git a/pkg/cloudprovider/aws/aws.go b/pkg/cloudprovider/aws/aws.go index 30d302f5050..7637d78ed46 100644 --- a/pkg/cloudprovider/aws/aws.go +++ b/pkg/cloudprovider/aws/aws.go @@ -1096,7 +1096,10 @@ type awsDisk struct { az string } -func newAWSDisk(ec2 EC2, name string) (*awsDisk, error) { +func newAWSDisk(aws *AWSCloud, name string) (*awsDisk, error) { + if !strings.HasPrefix(name, "aws://") { + name = "aws://" + aws.availabilityZone + "/" + name + } // name looks like aws://availability-zone/id url, err := url.Parse(name) if err != nil { @@ -1123,7 +1126,7 @@ func newAWSDisk(ec2 EC2, name string) (*awsDisk, error) { if az == "" { return nil, fmt.Errorf("Invalid format for AWS volume (%s)", name) } - disk := &awsDisk{ec2: ec2, name: name, awsID: awsID, az: az} + disk := &awsDisk{ec2: aws.ec2, name: name, awsID: awsID, az: az} return disk, nil } @@ -1246,7 +1249,7 @@ func (aws *AWSCloud) getAwsInstance(instanceName string) (*awsInstance, error) { // Implements Volumes.AttachDisk func (aws *AWSCloud) AttachDisk(instanceName string, diskName string, readOnly bool) (string, error) { - disk, err := newAWSDisk(aws.ec2, diskName) + disk, err := newAWSDisk(aws, diskName) if err != nil { return "", err } @@ -1301,7 +1304,7 @@ func (aws *AWSCloud) AttachDisk(instanceName string, diskName string, readOnly b // Implements Volumes.DetachDisk func (aws *AWSCloud) DetachDisk(instanceName string, diskName string) error { - disk, err := newAWSDisk(aws.ec2, diskName) + disk, err := newAWSDisk(aws, diskName) if err != nil { return err } @@ -1355,7 +1358,7 @@ func (aws *AWSCloud) CreateVolume(volumeOptions *VolumeOptions) (string, error) // Implements Volumes.DeleteVolume func (aws *AWSCloud) DeleteVolume(volumeName string) error { - awsDisk, err := newAWSDisk(aws.ec2, volumeName) + awsDisk, err := newAWSDisk(aws, volumeName) if err != nil { return err }