Exemplo n.º 1
0
 def launch(self,
            instance_type='t1.micro',
            image_id='ami-ab36fbc2',
            key_name='picmobo',
            security_groups=('default', 'app_stack')):
     """
     launch an instance
     """
     image = self.connection.get_all_images(image_ids=(image_id, ))[0]
     logger.debug('Got image %s' % (str(image)))
     security_groups = self.connection.get_all_security_groups(
         security_groups)
     logger.debug('Got security groups %s' % (str(security_groups)))
     kwargs = {
         'instance_type': instance_type,
         'key_name': key_name,
         'security_groups': security_groups
     }
     logger.debug('Instantiating with kwargs = %s' % (str(kwargs)))
     reservation = image.run(**kwargs)
     instance = reservation.instances[0]
     while instance.state != 'running':
         logger.debug('State is %s, waiting...' % (instance.state, ))
         time.sleep(10)
         instance.update()
     logger.info('Creating volumes')
     vol = self.connection.create_volume(10, instance.placement)
     vol.attach(instance.id, '/dev/sdf')
     vol = self.connection.create_volume(10, instance.placement)
     vol.attach(instance.id, '/dev/sdg')
     logger.info('EC2 launch of %s complete at %s' %
                 (instance.id, instance.dns_name))
Exemplo n.º 2
0
 def launch(self, instance_type='t1.micro', 
            image_id='ami-ab36fbc2',
            key_name='picmobo-dev',
            security_groups=('default', 'app_stack')):
     """
     launch an instance
     """
     image = self.connection.get_all_images(image_ids=(image_id,))[0]
     logger.debug('Got image %s' %(str(image)))
     security_groups = self.connection.get_all_security_groups(security_groups)
     logger.debug('Got security groups %s' %(str(security_groups)))
     kwargs = { 'instance_type':     instance_type, 
                'key_name':          key_name,
                'security_groups':   security_groups
             }
     logger.debug('Instantiating with kwargs = %s' %(str(kwargs)))
     reservation = image.run(**kwargs)
     instance = reservation.instances[0]
     while instance.state != 'running':
         logger.debug('State is %s, waiting...' %(instance.state,))
         time.sleep(10)
         instance.update()
     logger.info('Creating volumes')
     vol = self.connection.create_volume(10, instance.placement)
     vol.attach(instance.id, '/dev/sdf')
     vol = self.connection.create_volume(10, instance.placement)
     vol.attach(instance.id, '/dev/sdg')
     logger.info('EC2 launch of %s complete at %s' %(instance.id,
                                                     instance.dns_name))
Exemplo n.º 3
0
 def launch_production_instance(self, 
                                instance_type='m1.large', 
                                image_id='ami-013f9768',
                                key_name='picmobo',
                                security_groups=('default', 'app_stack')):
     """
     launch an instance
     """
     image = self.connection.get_all_images(image_ids=(image_id,))[0]
     logger.debug('Got image %s' %(str(image)))
     security_groups = self.connection.get_all_security_groups(security_groups)
     logger.debug('Got security groups %s' %(str(security_groups)))
     kwargs = { 'instance_type':     instance_type, 
                'key_name':          key_name,
                'security_groups':   security_groups
             }
     logger.debug('Instantiating with kwargs = %s' %(str(kwargs)))
     reservation = image.run(**kwargs)
     instance = reservation.instances[0]
     while instance.state != 'running':
         logger.debug('State is %s, waiting...' %(instance.state,))
         time.sleep(10)
         instance.update()
     logger.info('EC2 launch of %s complete at %s' %(instance.id,
                                                     instance.dns_name))
Exemplo n.º 4
0
 def terminate(self, instance_id):
     """
     terminate an instance
     """
     instance = self.get_instance(instance_id)
     if instance:
         logger.debug('Successfully connected to instance %s' %(instance_id),)
         instance.terminate()
         logger.info('Instance %s terminated' %(instance_id,))
     else:
         logger.warning('Instance %s not found' %(instance_id,))
Exemplo n.º 5
0
    def _getConnection(self, region=None):
        """
        get a connection to the default region endpoint
        """
        if not region:
            regionName = self._defaultRegion

        for region in boto.ec2.regions():
            if region.name == regionName:
                self.region = region
                logger.info('using region %s' %(str(region.name)))
                return self.region.connect()
Exemplo n.º 6
0
    def _getConnection(self, region=None):
        """
        get a connection to the default region endpoint
        """
        if not region:
            regionName = self._defaultRegion

        for region in boto.ec2.regions():
            if region.name == regionName:
                self.region = region
                logger.info('using region %s' % (str(region.name)))
                return self.region.connect()
Exemplo n.º 7
0
 def terminate(self, instance_id):
     """
     terminate an instance
     """
     instance = self.get_instance(instance_id)
     if instance:
         logger.debug(
             'Successfully connected to instance %s' % (instance_id), )
         instance.terminate()
         logger.info('Instance %s terminated' % (instance_id, ))
     else:
         logger.warning('Instance %s not found' % (instance_id, ))