How to use the boto.connect_ec2 function in boto

To help you get started, we’ve selected a few boto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eucalyptus / eucaconsole / tests / instances / test_instances.py View on Github external
def make_instance(image_id=None, **kwargs):
        ec2_conn = boto.connect_ec2('us-east')
        if image_id is None:
            image_id = 'ami-1234abcd'
        reservation = ec2_conn.run_instances(image_id, **kwargs)
        return reservation.instances[0]
github spulec / moto / tests / test_ec2 / test_instances.py View on Github external
def test_run_instance_with_instance_type():
    conn = boto.connect_ec2("the_key", "the_secret")
    reservation = conn.run_instances("ami-1234abcd", instance_type="t1.micro")
    instance = reservation.instances[0]

    instance.instance_type.should.equal("t1.micro")
github j2labs / quickness / scripts / ec2stop.py View on Github external
#!/usr/bin/env python

import argparse
import sys

import boto


aparser = argparse.ArgumentParser(description='Stop a quickness ec2 instance.')
aparser.add_argument('name', metavar='name', type=str,
                     help='Name of the quickness machine')
args = aparser.parse_args()


conn = boto.connect_ec2()

# Make sure quickness machine exists and if it does stop it
instances = conn.get_all_instances()
for res in instances:
    for instance in res.instances:
        if instance.tags.has_key('Quickness'):
            if args.name == instance.tags.get('Quickness'):
                print 'Stopping %s' % args.name
                instance.stop()
                sys.exit()
github j2labs / quickness / scripts / ec2search.py View on Github external
#!/usr/bin/env python

import argparse
import sys

import boto


aparser = argparse.ArgumentParser(description='Return the public_dns of one of your instances.')
aparser.add_argument('name', metavar='name', type=str,
                     help='Name of the quickness machine')
args = aparser.parse_args()


conn = boto.connect_ec2()

# Make sure quickness name is going to be unique
instances = conn.get_all_instances()
for res in instances:
    for instance in res.instances:
        if instance.tags.has_key('Quickness'):
            if args.name == instance.tags.get('Quickness'):
                print instance.public_dns_name
                sys.exit()
github rongoro / clusto / src / clusto / drivers / resourcemanagers / ec2vmmanager.py View on Github external
def _ec2_connection(self, region=None):
        c = boto.connect_ec2(aws_access_key_id=str(self.aws_access_key_id),
                             aws_secret_access_key=str(self.aws_secret_access_key))

        if not region or region == 'us-east-1':
            return c
        else:
            return boto.ec2.connect_to_region(region,
                                              aws_access_key_id=str(self.aws_access_key_id),
                                              aws_secret_access_key=str(self.aws_secret_access_key))
github hep-gc / cloud-scheduler / cloudscheduler / ec2cluster.py View on Github external
_get_connection - get a boto connection object to this cluster

            returns a boto connection object, or none in the case of an error
        """

        connection = None
        if len(self.regions) > 0:
            region_name = self.regions[0]
        else:
            region_name = self.name

        if self.cloud_type == "AmazonEC2":
            try:
                region = boto.ec2.regioninfo.RegionInfo(name=region_name,
                                                 endpoint=self.network_address)
                connection = boto.connect_ec2(
                                   aws_access_key_id=self.access_key_id,
                                   aws_secret_access_key=self.secret_access_key,
                                   region=region
                                   )
                log.verbose("Created a connection to Amazon EC2")

            except boto.exception.EC2ResponseError, e:
                log.error("Couldn't connect to Amazon EC2 because: %s" %
                                                                e.error_message)

        elif self.cloud_type == "Eucalyptus":
            try:
                region = boto.ec2.regioninfo.RegionInfo(name=region_name,
                                                 endpoint=self.network_address)
                connection = boto.connect_ec2(
                                   aws_access_key_id=self.access_key_id,
github nimbusproject / cloudinit.d / cloudboot / cb_iaas.py View on Github external
orig_secret = secret
    # look up key and secret in env if needed
    key = cloudboot.get_env_val(key)
    secret = cloudboot.get_env_val(secret)
    if not key:
        raise ConfigException("IaaS key %s not in env" % (orig_key))
    if not secret:
        raise ConfigException("IaaS key %s not in env" % (orig_secret))
    
    if not iaashostname:
        if not iaas:
            raise ConfigException("There is no 'iaas' or 'iaas_hostname' configuration, you need one of these.")
        region = boto.ec2.get_region(iaas)
        if not region:
            raise ConfigException("The 'iaas' configuration '%s' does not specify a valid boto EC2 region." % iaas)
        con =  boto.connect_ec2(key, secret, region=region)
    else:
        region = RegionInfo(iaashostname)
        if not iaasport:
            con =  boto.connect_ec2(key, secret, region=region)
        else:
            con =  boto.connect_ec2(key, secret, port=iaasport, region=region)

    return con
github hep-gc / cloud-scheduler / cloudscheduler / ec2cluster.py View on Github external
for obj_key in obj.keys():
                if obj_key == 'Regions':
                    regions = obj[obj_key];
                if obj_key == 'ZONES':
                    zones = obj[obj_key];
                if obj_key == 'InstanceTypes':
                    inst_types = obj[obj_key];
                if obj_key == 'ImageTypes':
                    image_types = obj[obj_key];
        
        for region in regions:
            #check zones 
            #conn = boto.ec2.connect_to_region(self.access_key_id,self.secret_access_key,region)
            region = boto.ec2.regioninfo.RegionInfo(name=self.regions,
                                                 endpoint='ec2.us-west-2.amazonaws.com')
            conn = boto.connect_ec2(
                                   aws_access_key_id=self.access_key_id,
                                   aws_secret_access_key=self.secret_access_key,
                                   region=region)
            
            #conn = connection
            if len(zones) > 0:
                #for each zone do calls for each image and eash instance type   
                for zone in zones:
                    for inst in inst_types:
                        for img in image_types:
                            
                            start_time = json_req['start_time']
                            end_time = json_req['end_time']
                            
                            instance_type=inst
                            product_description = img
github radlab / sparrow / deploy / ec2 / probe_ratio.py View on Github external
for sample_ratio in sample_ratios:
        for utilization in utilizations:
            arrival_rate_s = utilization * full_utilization_rate_s

            # This is a little bit of a hacky way to pass args to the ec2 script.
            (opts, args) = ec2_exp.parse_args(False)
            opts.identity_file = private_ssh_key
            opts.arrival_rate = arrival_rate_s
            opts.branch = sparrow_branch
            opts.sample_ratio  = sample_ratio
            opts.sample_ratio_constrained = sample_ratio_constrained
            opts.tasks_per_job = tasks_per_job
            opts.num_preferred_nodes = num_preferred_nodes
            opts.cpus = cores_per_backend

            conn = boto.connect_ec2()
            frontends, backends = ec2_exp.find_existing_cluster(conn, opts, cluster)

            print ("********Launching experiment at utilization %s with sample ratio %s..." %
                   (utilization, sample_ratio))

            print ("********Deploying with arrival rate %s and warmup arrival rate %s"
                   % (arrival_rate_s, warmup_arrival_rate_s))
            ec2_exp.deploy_cluster(frontends, backends, opts, warmup_arrival_rate_s, warmup_s,
                                   post_warmup_s, nm_task_scheduler)
            ec2_exp.start_sparrow(frontends, backends, opts)

            print "*******Sleeping after starting Sparrow"
            time.sleep(10)
            print "********Starting prototype frontends and backends"
            ec2_exp.start_proto(frontends, backends, opts)
            time.sleep(trial_length)
github opentripplanner / OTPSetup / otpsetup / client / manage_ec2.py View on Github external
def stop_instance(request):
    conn = connect_ec2(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_KEY)
    instance_id = request.REQUEST['instance_id']
    action = request.REQUEST['action']
    if action == 'Terminate instance':
        conn.terminate_instances([instance_id])
    else:
        conn.stop_instances([instance_id])
    return redirect('/manage_ec2')