From b41ead67ecae8efd1cbebfc1d55c7604de3e798a Mon Sep 17 00:00:00 2001 From: Euan Date: Wed, 25 Nov 2015 01:41:24 -0800 Subject: [PATCH] Remove unneeded 'amz' package Deprecated by the conversion to the upstream SDK Signed-off-by: Euan --- Godeps/Godeps.json | 1 - drivers/amazonec2/amz/auth.go | 9 - drivers/amazonec2/amz/block_device_mapping.go | 9 - drivers/amazonec2/amz/describe_instances.go | 8 - drivers/amazonec2/amz/describe_keypairs.go | 6 - .../amazonec2/amz/describe_security_groups.go | 6 - .../amz/describe_spot_instance_requests.go | 11 - drivers/amazonec2/amz/describe_subnets.go | 15 - drivers/amazonec2/amz/ec2.go | 670 ------------------ drivers/amazonec2/amz/error.go | 9 - drivers/amazonec2/amz/error_codes.go | 5 - drivers/amazonec2/amz/filter.go | 6 - drivers/amazonec2/amz/ip_permission.go | 8 - drivers/amazonec2/amz/keypair.go | 18 - drivers/amazonec2/amz/security_group.go | 21 - drivers/amazonec2/amz/tags.go | 6 - 16 files changed, 808 deletions(-) delete mode 100644 drivers/amazonec2/amz/auth.go delete mode 100644 drivers/amazonec2/amz/block_device_mapping.go delete mode 100644 drivers/amazonec2/amz/describe_instances.go delete mode 100644 drivers/amazonec2/amz/describe_keypairs.go delete mode 100644 drivers/amazonec2/amz/describe_security_groups.go delete mode 100644 drivers/amazonec2/amz/describe_spot_instance_requests.go delete mode 100644 drivers/amazonec2/amz/describe_subnets.go delete mode 100644 drivers/amazonec2/amz/ec2.go delete mode 100644 drivers/amazonec2/amz/error.go delete mode 100644 drivers/amazonec2/amz/error_codes.go delete mode 100644 drivers/amazonec2/amz/filter.go delete mode 100644 drivers/amazonec2/amz/ip_permission.go delete mode 100644 drivers/amazonec2/amz/keypair.go delete mode 100644 drivers/amazonec2/amz/security_group.go delete mode 100644 drivers/amazonec2/amz/tags.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 5f970baf30..dccb2190f6 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -8,7 +8,6 @@ "github.com/docker/machine/commands/commandstest", "github.com/docker/machine/commands/mcndirs", "github.com/docker/machine/drivers/amazonec2", - "github.com/docker/machine/drivers/amazonec2/amz", "github.com/docker/machine/drivers/azure", "github.com/docker/machine/drivers/digitalocean", "github.com/docker/machine/drivers/errdriver", diff --git a/drivers/amazonec2/amz/auth.go b/drivers/amazonec2/amz/auth.go deleted file mode 100644 index 22291b5306..0000000000 --- a/drivers/amazonec2/amz/auth.go +++ /dev/null @@ -1,9 +0,0 @@ -package amz - -type Auth struct { - AccessKey, SecretKey, SessionToken string -} - -func GetAuth(accessKey, secretKey, sessionToken string) Auth { - return Auth{accessKey, secretKey, sessionToken} -} diff --git a/drivers/amazonec2/amz/block_device_mapping.go b/drivers/amazonec2/amz/block_device_mapping.go deleted file mode 100644 index 27c6cecf3d..0000000000 --- a/drivers/amazonec2/amz/block_device_mapping.go +++ /dev/null @@ -1,9 +0,0 @@ -package amz - -type BlockDeviceMapping struct { - DeviceName string - VirtualName string - VolumeSize int64 - DeleteOnTermination bool - VolumeType string -} diff --git a/drivers/amazonec2/amz/describe_instances.go b/drivers/amazonec2/amz/describe_instances.go deleted file mode 100644 index 34faa78bce..0000000000 --- a/drivers/amazonec2/amz/describe_instances.go +++ /dev/null @@ -1,8 +0,0 @@ -package amz - -type DescribeInstancesResponse struct { - RequestId string `xml:"requestId"` - ReservationSet []struct { - InstancesSet []EC2Instance `xml:"instancesSet>item"` - } `xml:"reservationSet>item"` -} diff --git a/drivers/amazonec2/amz/describe_keypairs.go b/drivers/amazonec2/amz/describe_keypairs.go deleted file mode 100644 index 802c8828e2..0000000000 --- a/drivers/amazonec2/amz/describe_keypairs.go +++ /dev/null @@ -1,6 +0,0 @@ -package amz - -type DescribeKeyPairsResponse struct { - RequestId string `xml:"requestId"` - KeySet []KeyPair `xml:"keySet>item"` -} diff --git a/drivers/amazonec2/amz/describe_security_groups.go b/drivers/amazonec2/amz/describe_security_groups.go deleted file mode 100644 index f03a9dd4b0..0000000000 --- a/drivers/amazonec2/amz/describe_security_groups.go +++ /dev/null @@ -1,6 +0,0 @@ -package amz - -type DescribeSecurityGroupsResponse struct { - RequestId string `xml:"requestId"` - SecurityGroupInfo []SecurityGroup `xml:"securityGroupInfo>item"` -} diff --git a/drivers/amazonec2/amz/describe_spot_instance_requests.go b/drivers/amazonec2/amz/describe_spot_instance_requests.go deleted file mode 100644 index 4682c562c5..0000000000 --- a/drivers/amazonec2/amz/describe_spot_instance_requests.go +++ /dev/null @@ -1,11 +0,0 @@ -package amz - -type DescribeSpotInstanceRequestsResponse struct { - RequestId string `xml:"requestId"` - SpotInstanceRequestSet []struct { - Status struct { - Code string `xml:"code"` - } `xml:"status"` - InstanceId string `xml:"instanceId"` - } `xml:"spotInstanceRequestSet>item"` -} diff --git a/drivers/amazonec2/amz/describe_subnets.go b/drivers/amazonec2/amz/describe_subnets.go deleted file mode 100644 index 1378be0aa8..0000000000 --- a/drivers/amazonec2/amz/describe_subnets.go +++ /dev/null @@ -1,15 +0,0 @@ -package amz - -type DescribeSubnetsResponse struct { - RequestId string `xml:"requestId"` - SubnetSet []Subnet `xml:"subnetSet>item"` -} - -type Subnet struct { - SubnetId string `xml:"subnetId"` - State string `xml:"state"` - VpcId string `xml:"vpcId"` - CidrBlock string `xml:"cidrBlock"` - AvailabilityZone string `xml:"availabilityZone"` - DefaultForAz bool `xml:"defaultForAz"` -} diff --git a/drivers/amazonec2/amz/ec2.go b/drivers/amazonec2/amz/ec2.go deleted file mode 100644 index 262b8dce64..0000000000 --- a/drivers/amazonec2/amz/ec2.go +++ /dev/null @@ -1,670 +0,0 @@ -package amz - -import ( - "encoding/base64" - "encoding/xml" - "fmt" - "io/ioutil" - "net/http" - "net/url" - "strconv" - - "github.com/docker/machine/libmachine/log" - "github.com/docker/machine/libmachine/mcnutils" - awsauth "github.com/smartystreets/go-aws-auth" -) - -type ( - EC2 struct { - Endpoint string - Auth Auth - Region string - } - - Instance struct { - info EC2Instance - } - - EC2Instance struct { - InstanceId string `xml:"instanceId"` - ImageId string `xml:"imageId"` - InstanceState struct { - Code int `xml:"code"` - Name string `xml:"name"` - } `xml:"instanceState"` - PrivateDnsName string `xml:"privateDnsName"` - DnsName string `xml:"dnsName"` - Reason string `xml:"reason"` - AmiLaunchIndex string `xml:"amiLaunchIndex"` - ProductCodes string `xml:"productCodes"` - InstanceType string `xml:"instanceType"` - LaunchTime string `xml:"launchTime"` - Placement struct { - AvailabilityZone string `xml:"availabilityZone"` - GroupName string `xml:"groupName"` - Tenancy string `xml:"tenancy"` - } `xml:"placement"` - KernelId string `xml:"kernelId"` - Monitoring struct { - State string `xml:"state"` - } `xml:"monitoring"` - SubnetId string `xml:"subnetId"` - VpcId string `xml:"vpcId"` - IpAddress string `xml:"ipAddress"` - PrivateIpAddress string `xml:"privateIpAddress"` - SourceDestCheck bool `xml:"sourceDestCheck"` - GroupSet []struct { - GroupId string `xml:"groupId"` - GroupName string `xml:"groupName"` - } `xml:"groupSet"` - StateReason struct { - Code string `xml:"code"` - Message string `xml:"message"` - } `xml:"stateReason"` - Architecture string `xml:"architecture"` - RootDeviceType string `xml:"rootDeviceType"` - RootDeviceName string `xml:"rootDeviceName"` - BlockDeviceMapping string `xml:"blockDeviceMapping"` - VirtualizationType string `xml:"virtualizationType"` - ClientToken string `xml:"clientToken"` - Hypervisor string `xml:"hypervisor"` - NetworkInterfaceSet []struct { - NetworkInterfaceId string `xml:"networkInterfaceId"` - SubnetId string `xml:"subnetId"` - VpcId string `xml:"vpcId"` - Description string `xml:"description"` - OwnerId string `xml:"ownerId"` - Status string `xml:"status"` - MacAddress string `xml:"macAddress"` - PrivateIpAddress string `xml:"privateIpAddress"` - PrivateDnsName string `xml:"privateDnsName"` - SourceDestCheck string `xml:"sourceDestCheck"` - GroupSet []struct { - GroupId string `xml:"groupId"` - GroupName string `xml:"groupName"` - } `xml:"groupSet>item"` - Attachment struct { - AttachmentId string `xml:"attachmentId"` - DeviceIndex string `xml:"deviceIndex"` - Status string `xml:"status"` - AttachTime string `xml:"attachTime"` - DeleteOnTermination bool `xml:"deleteOnTermination"` - } `xml:"attachment"` - PrivateIpAddressesSet []struct { - PrivateIpAddress string `xml:"privateIpAddress"` - PrivateDnsName string `xml:"privateDnsName"` - Primary bool `xml:"primary"` - } `xml:"privateIpAddressesSet>item"` - } `xml:"networkInterfaceSet>item"` - EbsOptimized bool `xml:"ebsOptimized"` - } - - RunInstancesResponse struct { - RequestId string `xml:"requestId"` - ReservationId string `xml:"reservationId"` - OwnerId string `xml:"ownerId"` - Instances []EC2Instance `xml:"instancesSet>item"` - } - - RequestSpotInstancesResponse struct { - RequestId string `xml:"requestId"` - SpotInstanceRequestSet []struct { - SpotInstanceRequestId string `xml:"spotInstanceRequestId"` - State string `xml:"state"` - } `xml:"spotInstanceRequestSet>item"` - } -) - -func newAwsApiResponseError(r http.Response) error { - var errorResponse ErrorResponse - if err := getDecodedResponse(r, &errorResponse); err != nil { - return fmt.Errorf("Error decoding error response: %s", err) - } - msg := "" - for _, e := range errorResponse.Errors { - msg += fmt.Sprintf("%s\n", e.Message) - } - return fmt.Errorf("Non-200 API response: code=%d message=%s", r.StatusCode, msg) -} - -func newAwsApiCallError(err error) error { - return fmt.Errorf("Problem with AWS API call: %s", err) -} - -func getDecodedResponse(r http.Response, into interface{}) error { - defer r.Body.Close() - if err := xml.NewDecoder(r.Body).Decode(into); err != nil { - return fmt.Errorf("Error decoding error response: %s", err) - } - return nil -} - -func NewEC2(auth Auth, region string) *EC2 { - endpoint := fmt.Sprintf("https://ec2.%s.amazonaws.com", region) - return &EC2{ - Endpoint: endpoint, - Auth: auth, - Region: region, - } -} - -func (e *EC2) awsApiCall(v url.Values) (*http.Response, error) { - v.Set("Version", "2014-06-15") - log.Debug("Making AWS API call with values:") - mcnutils.DumpVal(v) - client := &http.Client{} - finalEndpoint := fmt.Sprintf("%s?%s", e.Endpoint, v.Encode()) - req, err := http.NewRequest("GET", finalEndpoint, nil) - if err != nil { - return &http.Response{}, fmt.Errorf("error creating request from client") - } - req.Header.Add("Content-type", "application/json") - - awsauth.Sign4(req, awsauth.Credentials{ - AccessKeyID: e.Auth.AccessKey, - SecretAccessKey: e.Auth.SecretKey, - SecurityToken: e.Auth.SessionToken, - }) - resp, err := client.Do(req) - if err != nil { - fmt.Printf("client encountered error while doing the request: %s", err.Error()) - return resp, fmt.Errorf("client encountered error while doing the request: %s", err) - } - - if resp.StatusCode != http.StatusOK { - return resp, newAwsApiResponseError(*resp) - } - return resp, nil -} - -func (e *EC2) RunInstance(amiId string, instanceType string, zone string, minCount int, maxCount int, securityGroup string, keyName string, subnetId string, bdm *BlockDeviceMapping, role string, privateIPOnly bool, monitoring bool) (EC2Instance, error) { - instance := Instance{} - v := url.Values{} - v.Set("Action", "RunInstances") - v.Set("ImageId", amiId) - v.Set("Placement.AvailabilityZone", e.Region+zone) - v.Set("MinCount", strconv.Itoa(minCount)) - v.Set("MaxCount", strconv.Itoa(maxCount)) - v.Set("KeyName", keyName) - v.Set("InstanceType", instanceType) - v.Set("NetworkInterface.0.DeviceIndex", "0") - v.Set("NetworkInterface.0.SecurityGroupId.0", securityGroup) - v.Set("NetworkInterface.0.SubnetId", subnetId) - if privateIPOnly { - v.Set("NetworkInterface.0.AssociatePublicIpAddress", "0") - } else { - v.Set("NetworkInterface.0.AssociatePublicIpAddress", "1") - } - if monitoring { - v.Set("Monitoring.Enabled", "1") - } else { - v.Set("Monitoring.Enabled", "0") - } - - if len(role) > 0 { - v.Set("IamInstanceProfile.Name", role) - } - - if bdm != nil { - v.Set("BlockDeviceMapping.0.DeviceName", bdm.DeviceName) - v.Set("BlockDeviceMapping.0.VirtualName", bdm.VirtualName) - v.Set("BlockDeviceMapping.0.Ebs.VolumeSize", strconv.FormatInt(bdm.VolumeSize, 10)) - v.Set("BlockDeviceMapping.0.Ebs.VolumeType", bdm.VolumeType) - deleteOnTerm := 0 - if bdm.DeleteOnTermination { - deleteOnTerm = 1 - } - v.Set("BlockDeviceMapping.0.Ebs.DeleteOnTermination", strconv.Itoa(deleteOnTerm)) - } - - resp, err := e.awsApiCall(v) - - if err != nil { - return instance.info, newAwsApiCallError(err) - } - defer resp.Body.Close() - - contents, err := ioutil.ReadAll(resp.Body) - if err != nil { - return instance.info, fmt.Errorf("Error reading AWS response body") - } - unmarshalledResponse := RunInstancesResponse{} - err = xml.Unmarshal(contents, &unmarshalledResponse) - if err != nil { - return instance.info, fmt.Errorf("Error unmarshalling AWS response XML: %s", err) - } - - instance.info = unmarshalledResponse.Instances[0] - return instance.info, nil -} - -func (e *EC2) RequestSpotInstances(amiId string, instanceType string, zone string, instanceCount int, securityGroup string, keyName string, subnetId string, bdm *BlockDeviceMapping, role string, spotPrice string, monitoring bool) (string, error) { - v := url.Values{} - v.Set("Action", "RequestSpotInstances") - v.Set("LaunchSpecification.ImageId", amiId) - v.Set("LaunchSpecification.Placement.AvailabilityZone", e.Region+zone) - v.Set("InstanceCount", strconv.Itoa(instanceCount)) - v.Set("SpotPrice", spotPrice) - v.Set("LaunchSpecification.KeyName", keyName) - v.Set("LaunchSpecification.InstanceType", instanceType) - v.Set("LaunchSpecification.NetworkInterface.0.DeviceIndex", "0") - v.Set("LaunchSpecification.NetworkInterface.0.SecurityGroupId.0", securityGroup) - v.Set("LaunchSpecification.NetworkInterface.0.SubnetId", subnetId) - v.Set("LaunchSpecification.NetworkInterface.0.AssociatePublicIpAddress", "1") - if monitoring { - v.Set("LaunchSpecification.Monitoring.Enabled", "1") - } else { - v.Set("LaunchSpecification.Monitoring.Enabled", "0") - } - - if len(role) > 0 { - v.Set("LaunchSpecification.IamInstanceProfile.Name", role) - } - - if bdm != nil { - v.Set("LaunchSpecification.BlockDeviceMapping.0.DeviceName", bdm.DeviceName) - v.Set("LaunchSpecification.BlockDeviceMapping.0.VirtualName", bdm.VirtualName) - v.Set("LaunchSpecification.BlockDeviceMapping.0.Ebs.VolumeSize", strconv.FormatInt(bdm.VolumeSize, 10)) - v.Set("LaunchSpecification.BlockDeviceMapping.0.Ebs.VolumeType", bdm.VolumeType) - deleteOnTerm := 0 - if bdm.DeleteOnTermination { - deleteOnTerm = 1 - } - v.Set("LaunchSpecification.BlockDeviceMapping.0.Ebs.DeleteOnTermination", strconv.Itoa(deleteOnTerm)) - } - - resp, err := e.awsApiCall(v) - - if err != nil { - return "", newAwsApiCallError(err) - } - defer resp.Body.Close() - contents, err := ioutil.ReadAll(resp.Body) - if err != nil { - return "", fmt.Errorf("Error reading AWS response body") - } - unmarshalledResponse := RequestSpotInstancesResponse{} - err = xml.Unmarshal(contents, &unmarshalledResponse) - if err != nil { - return "", fmt.Errorf("Error unmarshalling AWS response XML: %s", err) - } - return unmarshalledResponse.SpotInstanceRequestSet[0].SpotInstanceRequestId, nil -} - -func (e *EC2) DescribeSpotInstanceRequests(spotInstanceRequestId string) (string, string, error) { - v := url.Values{} - v.Set("Action", "DescribeSpotInstanceRequests") - v.Set("SpotInstanceRequestId.0", spotInstanceRequestId) - - resp, err := e.awsApiCall(v) - - if err != nil { - return "", "", newAwsApiCallError(err) - } - defer resp.Body.Close() - - contents, err := ioutil.ReadAll(resp.Body) - if err != nil { - return "", "", fmt.Errorf("Error reading AWS response body") - } - unmarshalledResponse := DescribeSpotInstanceRequestsResponse{} - err = xml.Unmarshal(contents, &unmarshalledResponse) - if err != nil { - return "", "", fmt.Errorf("Error unmarshalling AWS response XML: %s", err) - } - if code := unmarshalledResponse.SpotInstanceRequestSet[0].Status.Code; code != "fulfilled" { - return code, "", nil - } - return "fulfilled", unmarshalledResponse.SpotInstanceRequestSet[0].InstanceId, nil -} - -func (e *EC2) DeleteKeyPair(name string) error { - v := url.Values{} - v.Set("Action", "DeleteKeyPair") - v.Set("KeyName", name) - - _, err := e.awsApiCall(v) - if err != nil { - return fmt.Errorf("Error making API call to delete keypair :%s", err) - } - return nil -} - -func (e *EC2) CreateKeyPair(name string) ([]byte, error) { - v := url.Values{} - v.Set("Action", "CreateKeyPair") - v.Set("KeyName", name) - resp, err := e.awsApiCall(v) - if err != nil { - return nil, fmt.Errorf("Error trying API call to create keypair: %s", err) - } - defer resp.Body.Close() - contents, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, fmt.Errorf("Error reading AWS response body") - } - - unmarshalledResponse := CreateKeyPairResponse{} - if xml.Unmarshal(contents, &unmarshalledResponse); err != nil { - return nil, fmt.Errorf("Error unmarshalling AWS response XML: %s", err) - } - - key := unmarshalledResponse.KeyMaterial - - return key, nil -} - -func (e *EC2) ImportKeyPair(name, publicKey string) error { - keyMaterial := base64.StdEncoding.EncodeToString([]byte(publicKey)) - - v := url.Values{} - v.Set("Action", "ImportKeyPair") - v.Set("KeyName", name) - v.Set("PublicKeyMaterial", keyMaterial) - - resp, err := e.awsApiCall(v) - if err != nil { - return fmt.Errorf("Error trying API call to create keypair: %s", err) - } - - defer resp.Body.Close() - contents, err := ioutil.ReadAll(resp.Body) - if err != nil { - return fmt.Errorf("Error reading AWS response body") - } - - unmarshalledResponse := ImportKeyPairResponse{} - if xml.Unmarshal(contents, &unmarshalledResponse); err != nil { - return fmt.Errorf("Error unmarshalling AWS response XML: %s", err) - } - - return nil -} - -func (e *EC2) CreateTags(id string, tags map[string]string) error { - v := url.Values{} - v.Set("Action", "CreateTags") - v.Set("ResourceId.1", id) - - counter := 1 - for k, val := range tags { - v.Set(fmt.Sprintf("Tag.%d.Key", counter), k) - v.Set(fmt.Sprintf("Tag.%d.Value", counter), val) - - counter += 1 - } - - resp, err := e.awsApiCall(v) - defer resp.Body.Close() - if err != nil { - return err - } - - createTagsResponse := &CreateTagsResponse{} - - if err := getDecodedResponse(*resp, &createTagsResponse); err != nil { - return fmt.Errorf("Error decoding create tags response: %s", err) - } - - return nil -} - -func (e *EC2) CreateSecurityGroup(name string, description string, vpcId string) (*SecurityGroup, error) { - v := url.Values{} - v.Set("Action", "CreateSecurityGroup") - v.Set("GroupName", name) - v.Set("GroupDescription", url.QueryEscape(description)) - v.Set("VpcId", vpcId) - - resp, err := e.awsApiCall(v) - defer resp.Body.Close() - if err != nil { - // ugly hack since API has no way to check if SG already exists - if resp.StatusCode == http.StatusBadRequest { - var errorResponse ErrorResponse - if err := getDecodedResponse(*resp, &errorResponse); err != nil { - return nil, fmt.Errorf("Error decoding error response: %s", err) - } - if errorResponse.Errors[0].Code == ErrorDuplicateGroup { - return nil, nil - } - } - return nil, fmt.Errorf("Error making API call to create security group: %s", err) - } - - createSecurityGroupResponse := CreateSecurityGroupResponse{} - - if err := getDecodedResponse(*resp, &createSecurityGroupResponse); err != nil { - return nil, fmt.Errorf("Error decoding create security groups response: %s", err) - } - - group := &SecurityGroup{ - GroupId: createSecurityGroupResponse.GroupId, - VpcId: vpcId, - } - return group, nil -} - -func (e *EC2) AuthorizeSecurityGroup(groupId string, permissions []IpPermission) error { - v := url.Values{} - v.Set("Action", "AuthorizeSecurityGroupIngress") - v.Set("GroupId", groupId) - - for index, perm := range permissions { - n := index + 1 // amazon starts counting from 1 not 0 - v.Set(fmt.Sprintf("IpPermissions.%d.IpProtocol", n), perm.IpProtocol) - v.Set(fmt.Sprintf("IpPermissions.%d.FromPort", n), strconv.Itoa(perm.FromPort)) - v.Set(fmt.Sprintf("IpPermissions.%d.ToPort", n), strconv.Itoa(perm.ToPort)) - v.Set(fmt.Sprintf("IpPermissions.%d.IpRanges.1.CidrIp", n), perm.IpRange) - } - resp, err := e.awsApiCall(v) - defer resp.Body.Close() - if err != nil { - return fmt.Errorf("Error making API call to authorize security group ingress: %s", err) - } - return nil -} - -func (e *EC2) DeleteSecurityGroup(groupId string) error { - v := url.Values{} - v.Set("Action", "DeleteSecurityGroup") - v.Set("GroupId", groupId) - - resp, err := e.awsApiCall(v) - defer resp.Body.Close() - if err != nil { - return fmt.Errorf("Error making API call to delete security group: %s", err) - } - - deleteSecurityGroupResponse := DeleteSecurityGroupResponse{} - - if err := getDecodedResponse(*resp, &deleteSecurityGroupResponse); err != nil { - return fmt.Errorf("Error decoding delete security groups response: %s", err) - } - - return nil -} - -func (e *EC2) GetSecurityGroups() ([]SecurityGroup, error) { - sgs := []SecurityGroup{} - resp, err := e.performStandardAction("DescribeSecurityGroups") - if err != nil { - return sgs, err - } - defer resp.Body.Close() - contents, err := ioutil.ReadAll(resp.Body) - if err != nil { - return sgs, fmt.Errorf("Error reading AWS response body: %s", err) - } - - unmarshalledResponse := DescribeSecurityGroupsResponse{} - if err = xml.Unmarshal(contents, &unmarshalledResponse); err != nil { - return sgs, fmt.Errorf("Error unmarshalling AWS response XML: %s", err) - } - - sgs = unmarshalledResponse.SecurityGroupInfo - - return sgs, nil -} - -func (e *EC2) GetSecurityGroupById(id string) (*SecurityGroup, error) { - groups, err := e.GetSecurityGroups() - if err != nil { - return nil, err - } - - for _, g := range groups { - if g.GroupId == id { - return &g, nil - } - } - return nil, nil -} - -func (e *EC2) GetSubnets(filters []Filter) ([]Subnet, error) { - subnets := []Subnet{} - v := url.Values{} - v.Set("Action", "DescribeSubnets") - - for idx, filter := range filters { - n := idx + 1 // amazon starts counting from 1 not 0 - v.Set(fmt.Sprintf("Filter.%d.Name", n), filter.Name) - v.Set(fmt.Sprintf("Filter.%d.Value", n), filter.Value) - } - - resp, err := e.awsApiCall(v) - defer resp.Body.Close() - - contents, err := ioutil.ReadAll(resp.Body) - if err != nil { - return subnets, fmt.Errorf("Error reading AWS response body: %s", err) - } - - unmarshalledResponse := DescribeSubnetsResponse{} - if err = xml.Unmarshal(contents, &unmarshalledResponse); err != nil { - return subnets, fmt.Errorf("Error unmarshalling AWS response XML: %s", err) - } - - subnets = unmarshalledResponse.SubnetSet - - return subnets, nil -} - -func (e *EC2) GetKeyPairs() ([]KeyPair, error) { - keyPairs := []KeyPair{} - resp, err := e.performStandardAction("DescribeKeyPairs") - if err != nil { - return keyPairs, err - } - defer resp.Body.Close() - contents, err := ioutil.ReadAll(resp.Body) - if err != nil { - return keyPairs, fmt.Errorf("Error reading AWS response body: %s", err) - } - - unmarshalledResponse := DescribeKeyPairsResponse{} - if err = xml.Unmarshal(contents, &unmarshalledResponse); err != nil { - return keyPairs, fmt.Errorf("Error unmarshalling AWS response XML: %s", err) - } - - keyPairs = unmarshalledResponse.KeySet - - return keyPairs, nil -} - -func (e *EC2) GetKeyPair(name string) (*KeyPair, error) { - keyPairs, err := e.GetKeyPairs() - if err != nil { - return nil, err - } - - for _, key := range keyPairs { - if key.KeyName == name { - return &key, nil - } - } - return nil, nil -} - -func (e *EC2) GetInstance(instanceId string) (EC2Instance, error) { - ec2Instance := EC2Instance{} - resp, err := e.performInstanceAction(instanceId, "DescribeInstances", nil) - if err != nil { - return ec2Instance, err - } - defer resp.Body.Close() - contents, err := ioutil.ReadAll(resp.Body) - if err != nil { - return ec2Instance, fmt.Errorf("Error reading AWS response body: %s", err) - } - - unmarshalledResponse := DescribeInstancesResponse{} - if err = xml.Unmarshal(contents, &unmarshalledResponse); err != nil { - return ec2Instance, fmt.Errorf("Error unmarshalling AWS response XML: %s", err) - } - - if len(unmarshalledResponse.ReservationSet) > 0 { - reservationSet := unmarshalledResponse.ReservationSet[0] - ec2Instance = reservationSet.InstancesSet[0] - } - return ec2Instance, nil -} - -func (e *EC2) StartInstance(instanceId string) error { - if _, err := e.performInstanceAction(instanceId, "StartInstances", nil); err != nil { - return err - } - return nil -} - -func (e *EC2) RestartInstance(instanceId string) error { - if _, err := e.performInstanceAction(instanceId, "RebootInstances", nil); err != nil { - return err - } - return nil -} - -func (e *EC2) StopInstance(instanceId string, force bool) error { - vars := make(map[string]string) - if force { - vars["Force"] = "1" - } - - if _, err := e.performInstanceAction(instanceId, "StopInstances", &vars); err != nil { - return err - } - return nil -} - -func (e *EC2) TerminateInstance(instanceId string) error { - if _, err := e.performInstanceAction(instanceId, "TerminateInstances", nil); err != nil { - return err - } - return nil -} - -func (e *EC2) performStandardAction(action string) (*http.Response, error) { - v := url.Values{} - v.Set("Action", action) - resp, err := e.awsApiCall(v) - if err != nil { - return resp, newAwsApiCallError(err) - } - return resp, nil -} - -func (e *EC2) performInstanceAction(instanceId, action string, extraVars *map[string]string) (*http.Response, error) { - v := url.Values{} - v.Set("Action", action) - v.Set("InstanceId.1", instanceId) - if extraVars != nil { - for k, val := range *extraVars { - v.Set(k, val) - } - } - resp, err := e.awsApiCall(v) - if err != nil { - return resp, newAwsApiCallError(err) - } - return resp, nil -} diff --git a/drivers/amazonec2/amz/error.go b/drivers/amazonec2/amz/error.go deleted file mode 100644 index b8cd98b828..0000000000 --- a/drivers/amazonec2/amz/error.go +++ /dev/null @@ -1,9 +0,0 @@ -package amz - -type ErrorResponse struct { - Errors []struct { - Code string - Message string - } `xml:"Errors>Error"` - RequestID string -} diff --git a/drivers/amazonec2/amz/error_codes.go b/drivers/amazonec2/amz/error_codes.go deleted file mode 100644 index a4de953b4e..0000000000 --- a/drivers/amazonec2/amz/error_codes.go +++ /dev/null @@ -1,5 +0,0 @@ -package amz - -const ( - ErrorDuplicateGroup = "InvalidGroup.Duplicate" -) diff --git a/drivers/amazonec2/amz/filter.go b/drivers/amazonec2/amz/filter.go deleted file mode 100644 index 96c4f4db55..0000000000 --- a/drivers/amazonec2/amz/filter.go +++ /dev/null @@ -1,6 +0,0 @@ -package amz - -type Filter struct { - Name string - Value string -} diff --git a/drivers/amazonec2/amz/ip_permission.go b/drivers/amazonec2/amz/ip_permission.go deleted file mode 100644 index fe3a9df346..0000000000 --- a/drivers/amazonec2/amz/ip_permission.go +++ /dev/null @@ -1,8 +0,0 @@ -package amz - -type IpPermission struct { - IpProtocol string `xml:"ipProtocol"` - FromPort int `xml:"fromPort"` - ToPort int `xml:"toPort"` - IpRange string `xml:"ipRanges"` -} diff --git a/drivers/amazonec2/amz/keypair.go b/drivers/amazonec2/amz/keypair.go deleted file mode 100644 index b14d5977ed..0000000000 --- a/drivers/amazonec2/amz/keypair.go +++ /dev/null @@ -1,18 +0,0 @@ -package amz - -type CreateKeyPairResponse struct { - KeyName string `xml:"keyName"` - KeyFingerprint string `xml:"keyFingerprint"` - KeyMaterial []byte `xml:"keyMaterial"` -} - -type ImportKeyPairResponse struct { - KeyName string `xml:"keyName"` - KeyFingerprint string `xml:"keyFingerprint"` - KeyMaterial []byte `xml:"keyMaterial"` -} - -type KeyPair struct { - KeyFingerprint string `xml:"keyFingerprint"` - KeyName string `xml:"keyName"` -} diff --git a/drivers/amazonec2/amz/security_group.go b/drivers/amazonec2/amz/security_group.go deleted file mode 100644 index 2893206b98..0000000000 --- a/drivers/amazonec2/amz/security_group.go +++ /dev/null @@ -1,21 +0,0 @@ -package amz - -type CreateSecurityGroupResponse struct { - RequestId string `xml:"requestId"` - Return bool `xml:"return"` - GroupId string `xml:"groupId"` -} - -type DeleteSecurityGroupResponse struct { - RequestId string `xml:"requestId"` - Return bool `xml:"return"` -} - -type SecurityGroup struct { - GroupName string `xml:"groupName"` - GroupId string `xml:"groupId"` - VpcId string `xml:"vpcId"` - OwnerId string `xml:"ownerId"` - IpPermissions []IpPermission `xml:"ipPermissions>item,omitempty"` - IpPermissionsEgress []IpPermission `xml:"ipPermissionsEgress>item,omitempty"` -} diff --git a/drivers/amazonec2/amz/tags.go b/drivers/amazonec2/amz/tags.go deleted file mode 100644 index 0d25e90474..0000000000 --- a/drivers/amazonec2/amz/tags.go +++ /dev/null @@ -1,6 +0,0 @@ -package amz - -type CreateTagsResponse struct { - RequestId string `xml:"requestId"` - Return bool `xml:"return"` -}