예제 #1
0
파일: instances.py 프로젝트: jesco39/c3
 def analyze_state(self, desired_state='up'):
     ''' Find out if we're done (0), waiting (1), or screwed (2) '''
     result = None
     state = self.get_state()
     if state:
         logging.debug(
             'Analyze state %s is %s' % (self._instance.id, state),
             self.verbose)
         pending_up = ['pending']
         pending_down = ['shutting-down', 'stopping']
         ec2_up = 'running'
         ec2_down = ['terminated', 'stopped']
         if desired_state is 'up':
             if state in pending_up:
                 result = 1
             elif state in pending_down:
                 result = 2
             elif state == ec2_up:
                 self.finalize_start()
                 result = 0
         else:
             if state in pending_down:
                 result = 1
             elif state == ec2_up:
                 result = 2
             elif state in ec2_down:
                 result = 0
         return result
     else:
         logging.error('Unable to get status for %s' % self._instance.id)
         return False
예제 #2
0
파일: elb.py 프로젝트: jesco39/c3
 def get_hc(self):
     ''' Return the healtcheck object '''
     try:
         return self.elb.health_check
     except BotoServerError, msg:
         logging.error(msg.message)
         return None
예제 #3
0
파일: instances.py 프로젝트: jesco39/c3
 def get_associated_eip(self):
     ''' Return EIP associated with EC2 instance '''
     try:
         eips = self.conn.get_all_addresses()
     except EC2ResponseError, msg:
         logging.error(msg.message)
         return None
예제 #4
0
파일: elb.py 프로젝트: jesco39/c3
 def destroy(self):
     ''' Destroy an ELB '''
     try:
         return self.elb.delete()
     except BotoServerError, msg:
         logging.error(msg.message)
         return None
예제 #5
0
파일: elb.py 프로젝트: jesco39/c3
 def add_instances(self, instances):
     ''' Add instances to ELB '''
     logging.debug('Adding instances to ELB: %s' % instances, self.verbose)
     try:
         self.elb.register_instances(instances)
     except BotoServerError, msg:
         logging.error(msg.message)
예제 #6
0
파일: config.py 프로젝트: CityGrid/c3
 def get_ini(self, section, name, castf, fallback=None):
     ''' Get a setting from the ini files '''
     try:
         return castf(self.ini.get(section, name))
     except ConfigParser.NoSectionError, msg:
         logging.error(msg)
         return fallback
예제 #7
0
파일: instances.py 프로젝트: jesco39/c3
 def get_eip_by_addr(self, myip):
     ''' Return an EIP address '''
     try:
         eips = self.conn.get_all_addresses()
     except EC2ResponseError, msg:
         logging.error(msg.message)
         return None
예제 #8
0
파일: ebs.py 프로젝트: CityGrid/c3
 def delete_snapshot(self, snap_id):
     ''' Delete a snapshot '''
     logging.info('Deleting snapshot: %s' % snap_id)
     try:
         return self.conn.delete_snapshot(snap_id)
     except EC2ResponseError, msg:
         logging.error(msg.message)
         return None
예제 #9
0
파일: ebs.py 프로젝트: CityGrid/c3
 def delete_volume(self, volid):
     """ Delete unnattached EBS volume """
     try:
         self.conn.delete_volume(volid)
         return True
     except EC2ResponseError, msg:
         logging.error(msg.message)
         return None
예제 #10
0
파일: ebs.py 프로젝트: CityGrid/c3
 def create_snapshot(self, vol_id, desc):
     """ Creates an EBS Snapshot """
     logging.info('Creating Snapshot from %s' % vol_id)
     try:
         snap = self.conn.create_snapshot(vol_id, description=desc)
     except EC2ResponseError, msg:
         logging.error(msg.message)
         return None
예제 #11
0
 def create(self):
     """ Creates a new Security Group """
     desc = "%s C3 SG auto group" % self.name
     try:
         return self.conn.create_security_group(self.name, desc)
     except EC2ResponseError, msg:
         logging.error(msg.message)
         return None
예제 #12
0
파일: ebs.py 프로젝트: CityGrid/c3
 def attach_volume(self, vol_id, instance_id, ebs_device):
     """ Attach a volume to an instance that was created """
     try:
         self.conn.attach_volume(vol_id, instance_id, ebs_device)
         return True
     except EC2ResponseError, msg:
         logging.error(msg.message)
         return None
예제 #13
0
파일: elb.py 프로젝트: jesco39/c3
 def check_elb_exists(self):
     ''' Check to see if ELB exists '''
     try:
         return self.conn.get_all_load_balancers(
             load_balancer_names=[self.name])
     except BotoServerError, msg:
         logging.error(msg.message)
         return None
예제 #14
0
파일: elb.py 프로젝트: jesco39/c3
 def remove_instances(self, instances):
     ''' Remove instances from ELB '''
     logging.debug(
         "Removing instances from ELB: %s" % instances, self.verbose)
     try:
         self.elb.deregister_instances(instances)
     except BotoServerError, msg:
         logging.error(msg.message)
예제 #15
0
파일: instances.py 프로젝트: jesco39/c3
 def set_eip(self, address):
     ''' Set the EIP for the instance '''
     try:
         self.eip = self.get_eip_by_addr(address)
         return True
     except EC2ResponseError, msg:
         logging.error(msg.message)
         return None
예제 #16
0
파일: ebs.py 프로젝트: CityGrid/c3
 def detach_volume(self, vol_id, instance_id, ebs_device):
     """ Detach a volume to from an instance """
     try:
         self.conn.detach_volume(vol_id, instance_id, ebs_device)
         return True
     except EC2ResponseError, msg:
         logging.error(msg.message)
         return None
예제 #17
0
파일: c3ec2.py 프로젝트: CityGrid/c3
 def check_config_types(self):
     """ Check if there is an assigned ssh key. """
     if self.cconfig.get_count() and not self.cconfig.get_ssh_key():
         logging.error("You're trying to start instances, " "but don't have an SSH key set")
         sys.exit(1)
     node_db = nv_connect(self.opts.nv_ini)
     if not self.cconfig.get_resolved_ami(node_db):
         logging.error("Getting AMI failed, exiting")
         sys.exit(1)
예제 #18
0
파일: c3ec2.py 프로젝트: CityGrid/c3
 def puppet_whitelist(self):
     """ Add the puppet whitelists. """
     conn_sqs = self.aws_conn("sqs")
     qurl = self.cconfig.get_whitelist_url()
     try:
         sqsq = boto.sqs.queue.Queue(conn_sqs, url=qurl)
     except SQSError, msg:
         logging.error(msg.message)
         sys.exit(1)
예제 #19
0
파일: c3ec2.py 프로젝트: CityGrid/c3
 def elb_connection(self, find_only=True):
     """ Get a connection to the ELB service. """
     conn_elb = self.aws_conn("elb")
     try:
         c3elb = c3.aws.ec2.elb.C3ELB(
             conn_elb, self.cconfig.get_elb_name(), self.cconfig.get_elb_config(), find_only=find_only
         )
     except EC2ResponseError, msg:
         logging.error(msg.message)
예제 #20
0
파일: graphite.py 프로젝트: CityGrid/c3
 def connect(self):
     ''' Create socket connection to graphite. '''
     try:
         self._sock = socket.create_connection(
             (self.server, self.port), timeout=10)
         self._sock_status = True
     except (socket.gaierror, socket.timeout, socket.error), msg:
         self._sock_status = False
         logging.error(msg)
예제 #21
0
파일: instances.py 프로젝트: jesco39/c3
 def new_eip(self):
     ''' Allocates a new EIP address to an EC2 instance '''
     logging.debug('Allocating a new EIP!', self.verbose)
     self.allocateeips = False
     try:
         eip = self.conn.allocate_address()
     except EC2ResponseError, msg:
         logging.error(msg.message)
         return None
예제 #22
0
파일: config.py 프로젝트: CityGrid/c3
def get_account_from_conf(conf=None):
    ''' Loads config only so we can get the account for ClusterConfig. '''
    scp = SafeConfigParser()
    scp.read(conf)
    try:
        return scp.get('cluster', 'aws_account')
    except (ConfigParser.NoSectionError, ConfigParser.NoOptionError), msg:
        logging.error(msg)
        return None
예제 #23
0
파일: c3ec2.py 프로젝트: CityGrid/c3
 def cluster_retag(self):
     """ Retag the cluster. """
     logging.info("Retagging cluster %s" % self.cconfig.get_primary_sg())
     cgc = self.cluster()
     tagger = cluster_tagger(self.conn, verbose=self.opts.verbose)
     if not tagger.add_tags(cgc.get_instance_ids(), self.cconfig.get_tagset()):
         logging.error("Problem addings tags")
         sys.exit(1)
     logging.info("Retag cluster complete")
     sys.exit(0)
예제 #24
0
파일: config.py 프로젝트: CityGrid/c3
 def limit_azs(self, limit):
     ''' Limit the number of AZs to use '''
     if limit > 0:
         oldazs = self.get_azs()
         newazs = oldazs[:limit]
         self.set_azs(','.join(newazs))
         return len(oldazs) - len(newazs)
     else:
         logging.error("Trying to limit AZs to %d" % limit)
     return 0
예제 #25
0
파일: naming.py 프로젝트: CityGrid/c3
def get_network_data():
    ''' Parse the network file for use by other methods '''
    nets = dict()
    names = dict()
    net_file = '%s/%s' % (os.getenv('AWS_CONF_DIR'), '/networks.txt')
    try:
        nfile = open(net_file, 'r')
    except IOError, msg:
        logging.error(msg)
        return False
예제 #26
0
파일: elb.py 프로젝트: jesco39/c3
 def create_elb(self):
     ''' Create an ELB '''
     logging.debug('Create ELB %s' % self.name, self.verbose)
     try:
         self.elb = self.conn.create_load_balancer(
             self.name, self.azs_used, self.elb_listeners)
         logging.info('Created %s: %s' % (self.name, self.elb))
         self.created = True
     except BotoServerError, msg:
         logging.error(msg.message)
예제 #27
0
파일: accounts.py 프로젝트: CityGrid/c3
def translate_account(account_id=None, account_name=None, mapfile=None):
    ''' Translate account id to account name and back again. '''
    if not mapfile:
        mapfile = '%s/%s' % (
            os.getenv('AWS_CONF_DIR'), 'account_aliases_map.txt')
    try:
        mfile = open(mapfile, 'r')
    except IOError, msg:
        logging.error(msg)
        return False
예제 #28
0
파일: tagger.py 프로젝트: CityGrid/c3
 def tag_s3_bucket(self, rid, tagset):
     ''' Tags S3 buckets with complicated s3 tagging shenanigans '''
     new_tags = list()
     failed = 0
     logging.info('Tagging S3 bucket %s' % rid)
     try:
         bucket = self.conn.get_bucket(rid)
     except S3ResponseError, msg:
         logging.error(msg.message)
         failed += 1
예제 #29
0
파일: instances.py 프로젝트: jesco39/c3
 def get_eip(self, steal=False):
     ''' Figure out if my hostname is an EIP '''
     if self.eip:
         return self.eip
     data = self.node_db.get_node_by_instance_id(self.inst_id)[0]
     try:
         myip = socket.gethostbyname(data['ec2_public_hostname'])
     except socket.gaierror, msg:
         logging.error(msg)
         return None
예제 #30
0
파일: elb.py 프로젝트: jesco39/c3
 def set_azs(self):
     ''' Ensure AZs add to ELB from config '''
     azs = self.azs_used
     logging.debug("Trying to add AZs to ELB: %s" % azs, self.verbose)
     for zone in azs:
         if zone not in self.elb.availability_zones:
             logging.debug("Adding %s to ELB" % azs, self.verbose)
             try:
                 self.elb.enable_zones(zone)
             except BotoServerError, msg:
                 logging.error(msg.message)