예제 #1
0
    def do_emit(self, tmpfile_path=None):
        if not tmpfile_path:
            return
        aws_access_key_id = config.get_access_key_id()
        aws_secret_access_key = config.get_secret_access_key()
        security_token = config.get_security_token()
        conn = boto.connect_s3(
            aws_access_key_id=aws_access_key_id,
            aws_secret_access_key=aws_secret_access_key,
            security_token=security_token,
            is_secure=False,
            port=config.get_webservice_port(),
            path='/services/objectstorage',
            host=config.get_objectstorage_service_host(),
            calling_format='boto.s3.connection.OrdinaryCallingFormat')
        if not conn:
            raise Exception('Could not connect to object storage (S3) service')

        key_name = self.generate_log_file_name()
        bucket = conn.get_bucket(self.bucket_name, validate=False)
        k = Key(bucket)
        k.key = key_name
        k.set_contents_from_filename(tmpfile_path,
                                     policy='bucket-owner-full-control')
        servo.log.debug(
            'Access logs were emitted successfully: s3://%s/%s' %
            (urllib2.quote(self.bucket_name), urllib2.quote(key_name)))
예제 #2
0
    def run(self):
        # HaproxyConfBuilder 
        # from the current haproxy config
        # update config
        # replace the config
        
        #def add(self, protocol, port, instances=[]):
        #instance = {hostname , port, protocol=None )
        builder = ConfBuilderHaproxy(CONF_FILE, self.__listener.loadbalancer()) 
        instances = []

        for host in self.__listener.instances():
            instance = {'hostname':host, 'port': self.__listener.instance_port(), 'protocol': self.__listener.instance_protocol()}
            instances.append(instance)

        #in case of https/ssl protocol, download server certificate from EUARE
        if (self.__listener.protocol() == 'https' or self.__listener.protocol() == 'ssl') and self.__listener.ssl_cert_arn() != None:
            try:
                f = FloppyCredential() 
            except Exception, err:
                raise Exception('failed to get credentials from floppy: %s' % err)
 
            try:
                access_key_id = config.get_access_key_id()
                secret_access_key = config.get_secret_access_key()
                security_token = config.get_security_token()
                con = servo.ws.connect_euare(aws_access_key_id = access_key_id, aws_secret_access_key=secret_access_key, security_token=security_token)
                cert_arn = self.__listener.ssl_cert_arn().strip()
                cert= con.download_server_certificate(f.get_instance_pub_key(), f.get_instance_pk(), f.get_iam_pub_key(), f.get_iam_token(), cert_arn)
            except Exception, err:
                raise Exception('failed to download the server certificate: %s' % err)
예제 #3
0
    def do_emit(self):
        servo.log.debug('Trying to emit access log of %d entries' % len(self._logs))
        print 'Trying to emit access log of %d entries' % len(self._logs)
        aws_access_key_id = config.get_access_key_id()
        aws_secret_access_key = config.get_secret_access_key()
        security_token = config.get_security_token()
        conn = boto.connect_s3(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, security_token=security_token, is_secure=False, port=8773, path='/services/objectstorage', host= config.get_objectstorage_service_host(), calling_format='boto.s3.connection.OrdinaryCallingFormat')
        if not conn:
            raise Exception('Could not connect to object storage (S3) service') 

        key_name = self.generate_log_file_name()
        tmpfile = tempfile.mkstemp()
        fd = os.fdopen(tmpfile[0],'w')
        tmpfile_path = tmpfile[1]
	for line in self._logs:
            fd.write(line+'\n')
        fd.close()
        
        bucket = conn.get_bucket(self.bucket_name)
        k = Key(bucket)
        k.key = key_name
        k.set_contents_from_filename(tmpfile_path)
        k.add_user_grant('FULL_CONTROL', config.get_owner_account_id())

        os.unlink(tmpfile_path)
        servo.log.debug('Access logs were emitted successfully: s3://%s/%s'  % (self.bucket_name,key_name))
예제 #4
0
def download_cert():
    host = config.get_clc_host()
    access_key_id = config.get_access_key_id()
    secret_access_key = config.get_secret_access_key()
    security_token = config.get_security_token()
    con = servo.ws.connect_euare(host_name=host, aws_access_key_id = access_key_id, aws_secret_access_key=secret_access_key, security_token=security_token)
    cert_arn = "arn:aws:iam::450510498576:server-certificate/mycert"
    f = FloppyCredential() 
    cert= con.download_server_certificate(f.get_instance_pub_key(), f.get_instance_pk(), f.get_iam_pub_key(), f.get_iam_token(), cert_arn)
    print cert.get_certificate()
    print cert.get_private_key()
예제 #5
0
def download_cert(cert_arn = None):
    host = config.get_clc_host()
    access_key_id = config.get_access_key_id()
    secret_access_key = config.get_secret_access_key()
    security_token = config.get_security_token()
    con = servo.ws.connect_euare(host_name=host, aws_access_key_id = access_key_id, aws_secret_access_key=secret_access_key, security_token=security_token)
    if not cert_arn:
        cert_arn = "arn:aws:iam::450510498576:server-certificate/mycert"
    f = FloppyCredential() 
    cert= con.download_server_certificate(f.get_instance_pub_key(), f.get_instance_pk(), f.get_iam_pub_key(), f.get_iam_token(), cert_arn)
    print cert.get_certificate()
    print cert.get_private_key()
예제 #6
0
    def do_emit(self, tmpfile_path=None):
        if not tmpfile_path:
            return
        aws_access_key_id = config.get_access_key_id()
        aws_secret_access_key = config.get_secret_access_key()
        security_token = config.get_security_token()
        conn = boto.connect_s3(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, security_token=security_token, is_secure=False, port=config.get_webservice_port(), path='/services/objectstorage', host= config.get_objectstorage_service_host(), calling_format='boto.s3.connection.OrdinaryCallingFormat')
        if not conn:
            raise Exception('Could not connect to object storage (S3) service') 

        key_name = self.generate_log_file_name()
        bucket = conn.get_bucket(self.bucket_name, validate=False)
        k = Key(bucket)
        k.key = key_name
        k.set_contents_from_filename(tmpfile_path, policy='bucket-owner-full-control')
        servo.log.debug('Access logs were emitted successfully: s3://%s/%s'  % (urllib2.quote(self.bucket_name),urllib2.quote(key_name)))
예제 #7
0
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None
        healthy_count = 0
        unhealthy_count = 0
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error(
                    'could not find the ipaddress of the instance %s' %
                    self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()
            con = servo.ws.connect_elb(
                host_name=elb_host,
                aws_access_key_id=aws_access_key_id,
                aws_secret_access_key=aws_secret_access_key,
                security_token=security_token)

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)
            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:
                healthy_count += 1
                unhealthy_count = 0
                if healthy_count >= health_check_config.healthy_threshold:
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('Reported %s InService' % self.instance_id)
                    try:
                        con.put_instance_health(servo_instance_id, [instance])
                    except Exception, err:
                        servo.log.error('failed to post servo states: %s' %
                                        err)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id,
                                                'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('Reported %s OutOfService' %
                                    self.instance_id)
                    try:
                        con.put_instance_health(servo_instance_id, [instance])
                    except Exception, err:
                        servo.log.error('failed to post servo states: %s' %
                                        err)
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None
        healthy_count = 0
        unhealthy_count = 0
        last_inservice_reported = dt.min
        last_outofservice_reported = dt.min
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error(
                    'could not find the ipaddress of the instance %s' %
                    self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)

            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:  # passed one check
                healthy_count += 1
                unhealthy_count = 0
                if not self.initially_reported or healthy_count >= health_check_config.healthy_threshold:
                    self.initially_reported = True
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('%s: InService' % self.instance_id)
                    elapsed = dt.now() - last_inservice_reported
                    if self.report_elb and elapsed.seconds > config.PUT_BACKEND_INSTANCE_HEALTH_PERIOD_SEC:
                        try:
                            con = servo.ws.connect_elb(
                                aws_access_key_id=aws_access_key_id,
                                aws_secret_access_key=aws_secret_access_key,
                                security_token=security_token)
                            con.put_instance_health(servo_instance_id,
                                                    [instance])
                            servo.log.debug('%s: InService status reported' %
                                            self.instance_id)
                            last_inservice_reported = dt.now()
                            last_outofservice_reported = dt.min
                        except Exception, err:
                            servo.log.error('failed to post servo states: %s' %
                                            err)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    self.initially_reported = True
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id,
                                                'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('%s: OutOfService' % self.instance_id)
                    elapsed = dt.now() - last_outofservice_reported
                    if self.report_elb and elapsed.seconds > config.PUT_BACKEND_INSTANCE_HEALTH_PERIOD_SEC:
                        try:
                            con = servo.ws.connect_elb(
                                aws_access_key_id=aws_access_key_id,
                                aws_secret_access_key=aws_secret_access_key,
                                security_token=security_token)
                            con.put_instance_health(servo_instance_id,
                                                    [instance])
                            servo.log.debug(
                                '%s: OutOfService status reported' %
                                self.instance_id)
                            last_outofservice_reported = dt.now()
                            last_inservice_reported = dt.min
                        except Exception, err:
                            servo.log.error('failed to post servo states: %s' %
                                            err)
예제 #9
0
    def run(self):
        if health_check_config is None:
            servo.log.error("health check config is not set")
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None
        healthy_count = 0
        unhealthy_count = 0
        while self.running:
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error("could not find the ipaddress of the instance %s" % self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith("HTTPS"):
                result = self.check_https(target)
            elif target.upper().startswith("TCP"):
                result = self.check_tcp(target)
            elif target.upper().startswith("HTTP"):
                result = self.check_http(target)
            elif target.upper().startswith("SSL"):
                result = self.check_ssl(target)
            else:
                servo.log.error("unknown target: %s" % target)
            # print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:
                healthy_count += 1
                unhealthy_count = 0
                if healthy_count >= health_check_config.healthy_threshold:
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, "InService")
                    self.inst_status = "InService"
                    servo.log.debug("%s: InService" % self.instance_id)
                    if self.report_elb:
                        try:
                            con = servo.ws.connect_elb(
                                aws_access_key_id=aws_access_key_id,
                                aws_secret_access_key=aws_secret_access_key,
                                security_token=security_token,
                            )
                            con.put_instance_health(servo_instance_id, [instance])
                            servo.log.debug("%s: InService status reported" % self.instance_id)
                        except Exception, err:
                            servo.log.error("failed to post servo states: %s" % err)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id, "OutOfService")
                    self.inst_status = "OutOfService"
                    servo.log.debug("%s: OutOfService" % self.instance_id)
                    if self.report_elb:
                        try:
                            con = servo.ws.connect_elb(
                                aws_access_key_id=aws_access_key_id,
                                aws_secret_access_key=aws_secret_access_key,
                                security_token=security_token,
                            )
                            con.put_instance_health(servo_instance_id, [instance])
                            servo.log.debug("%s: OutOfService status reported" % self.instance_id)
                        except Exception, err:
                            servo.log.error("failed to post servo states: %s" % err)
예제 #10
0
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None
        healthy_count = 0
        unhealthy_count = 0
        last_inservice_reported = dt.min
        last_outofservice_reported = dt.min
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error(
                    'could not find the ipaddress of the instance %s' %
                    self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)

            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:  # passed one check
                healthy_count += 1
                unhealthy_count = 0
                if not self.initially_reported or healthy_count >= health_check_config.healthy_threshold:
                    self.initially_reported = True
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('%s: InService' % self.instance_id)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    self.initially_reported = True
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id,
                                                'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('%s: OutOfService' % self.instance_id)

            if healthy_count > health_check_config.healthy_threshold:
                healthy_count = 0
            if unhealthy_count > health_check_config.unhealthy_threshold:
                unhealthy_count = 0
            health_check_delay = health_check_config.interval
            while health_check_delay > 0 and self.running:
                time.sleep(1)
                health_check_delay -= 1
예제 #11
0
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None 
        healthy_count = 0
        unhealthy_count = 0
        last_inservice_reported = dt.min
        last_outofservice_reported = dt.min
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error('could not find the ipaddress of the instance %s' % self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)

            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result: # passed one check
                healthy_count += 1
                unhealthy_count = 0
                if not self.initially_reported or healthy_count >= health_check_config.healthy_threshold:
                    self.initially_reported = True
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('%s: InService' % self.instance_id)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    self.initially_reported = True
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('%s: OutOfService' % self.instance_id)

            if healthy_count > health_check_config.healthy_threshold:
                healthy_count = 0
            if unhealthy_count > health_check_config.unhealthy_threshold:
                unhealthy_count = 0
            health_check_delay = health_check_config.interval
            while health_check_delay > 0 and self.running:
                time.sleep(1)
                health_check_delay -= 1
예제 #12
0
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None 
        healthy_count = 0
        unhealthy_count = 0
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error('could not find the ipaddress of the instance %s' % self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)
            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:
                healthy_count += 1
                unhealthy_count = 0
                if healthy_count >= health_check_config.healthy_threshold:
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('Reported %s InService' % self.instance_id)
                    try:
                        con = servo.ws.connect_elb(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, security_token=security_token)
                        con.put_instance_health(servo_instance_id, [instance])
                    except Exception, err:
                        servo.log.error('failed to post servo states: %s' % err)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('Reported %s OutOfService' % self.instance_id)
                    try:
                        con = servo.ws.connect_elb(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, security_token=security_token)
                        con.put_instance_health(servo_instance_id, [instance])
                    except Exception, err:
                        servo.log.error('failed to post servo states: %s' % err)