Merge pull request #1086 from zchee/ec2-add-monitoring-flag

[EC2] Add Monitoring flag
This commit is contained in:
Evan Hazlett 2015-05-13 10:49:14 -04:00
commit f29c5fc4dc
4 changed files with 22 additions and 4 deletions

View File

@ -987,6 +987,7 @@ Options:
- `--amazonec2-vpc-id`: **required** Your VPC ID to launch the instance in.
- `--amazonec2-zone`: The AWS zone launch the instance in (i.e. one of a,b,c,d,e). Default: `a`
- `--amazonec2-private-address-only`: Use the private IP address only
- `--amazonec2-monitoring`: Enable CloudWatch Monitoring.
By default, the Amazon EC2 driver will use a daily image of Ubuntu 14.04 LTS.

View File

@ -70,6 +70,7 @@ type Driver struct {
RequestSpotInstance bool
SpotPrice string
PrivateIPOnly bool
Monitoring bool
}
func init() {
@ -169,6 +170,10 @@ func GetCreateFlags() []cli.Flag {
Name: "amazonec2-private-address-only",
Usage: "Only use a private IP address",
},
cli.BoolFlag{
Name: "amazonec2-monitoring",
Usage: "Set this flag to enable CloudWatch monitoring",
},
}
}
@ -227,6 +232,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.SSHUser = flags.String("amazonec2-ssh-user")
d.SSHPort = 22
d.PrivateIPOnly = flags.Bool("amazonec2-private-address-only")
d.Monitoring = flags.Bool("amazonec2-monitoring")
if d.AccessKey == "" {
return fmt.Errorf("amazonec2 driver requires the --amazonec2-access-key option")
@ -357,7 +363,7 @@ func (d *Driver) Create() error {
log.Debugf("launching instance in subnet %s", d.SubnetId)
var instance amz.EC2Instance
if d.RequestSpotInstance {
spotInstanceRequestId, err := d.getClient().RequestSpotInstances(d.AMI, d.InstanceType, d.Zone, 1, d.SecurityGroupId, d.KeyName, d.SubnetId, bdm, d.IamInstanceProfile, d.SpotPrice)
spotInstanceRequestId, err := d.getClient().RequestSpotInstances(d.AMI, d.InstanceType, d.Zone, 1, d.SecurityGroupId, d.KeyName, d.SubnetId, bdm, d.IamInstanceProfile, d.SpotPrice, d.Monitoring)
if err != nil {
return fmt.Errorf("Error request spot instance: %s", err)
}
@ -378,7 +384,7 @@ func (d *Driver) Create() error {
return fmt.Errorf("Error get instance: %s", err)
}
} else {
inst, err := d.getClient().RunInstance(d.AMI, d.InstanceType, d.Zone, 1, 1, d.SecurityGroupId, d.KeyName, d.SubnetId, bdm, d.IamInstanceProfile, d.PrivateIPOnly)
inst, err := d.getClient().RunInstance(d.AMI, d.InstanceType, d.Zone, 1, 1, d.SecurityGroupId, d.KeyName, d.SubnetId, bdm, d.IamInstanceProfile, d.PrivateIPOnly, d.Monitoring)
if err != nil {
return fmt.Errorf("Error launching instance: %s", err)
}

View File

@ -81,6 +81,7 @@ func getDefaultTestDriverFlags() *DriverOptionsMock {
"amazonec2-request-spot-instance": false,
"amazonec2-spot-price": "",
"amazonec2-private-address-only": false,
"amazonec2-monitoring": false,
},
}
}

View File

@ -173,7 +173,7 @@ func (e *EC2) awsApiCall(v url.Values) (*http.Response, error) {
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) (EC2Instance, error) {
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")
@ -191,6 +191,11 @@ func (e *EC2) RunInstance(amiId string, instanceType string, zone string, minCou
} 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)
@ -229,7 +234,7 @@ func (e *EC2) RunInstance(amiId string, instanceType string, zone string, minCou
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) (string, error) {
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)
@ -242,6 +247,11 @@ func (e *EC2) RequestSpotInstances(amiId string, instanceType string, zone strin
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("Monitoring.Enabled", "1")
} else {
v.Set("Monitoring.Enabled", "0")
}
if len(role) > 0 {
v.Set("LaunchSpecification.IamInstanceProfile.Name", role)