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) 
        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:
                servo.log.error('failed to get credentials from floppy: %s' % err)
                return
 
            try:
                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 = 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:
                servo.log.error('failed to download the server certificate: %s' % err)
                return
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()
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()
Exemple #4
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)
    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)
Exemple #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
        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
    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
    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)