Exemplo n.º 1
0
 def test_build_put_params_invalid(self):
     c = CloudWatchConnection()
     params = {}
     try:
         c.build_put_params(params, name=["N", "M"], value=[1, 2, 3])
     except:
         pass
     else:
         self.fail("Should not accept lists of different lengths.")
Exemplo n.º 2
0
 def test_build_put_params_invalid(self):
     c = CloudWatchConnection()
     params = {}
     try:
         c.build_put_params(params, name=["N", "M"], value=[1, 2, 3])
     except:
         pass
     else:
         self.fail("Should not accept lists of different lengths.")
Exemplo n.º 3
0
 def test_build_put_params_one(self):
     c = CloudWatchConnection()
     params = {}
     c.build_put_params(params, name="N", value=1, dimensions={"D": "V"})
     expected_params = {
         'MetricData.member.1.MetricName': 'N',
         'MetricData.member.1.Value': 1,
         'MetricData.member.1.Dimensions.member.1.Name': 'D',
         'MetricData.member.1.Dimensions.member.1.Value': 'V',
         }
     self.assertEqual(params, expected_params)
Exemplo n.º 4
0
 def test_build_put_params_one(self):
     c = CloudWatchConnection()
     params = {}
     c.build_put_params(params, name="N", value=1, dimensions={"D": "V"})
     expected_params = {
         'MetricData.member.1.MetricName': 'N',
         'MetricData.member.1.Value': 1,
         'MetricData.member.1.Dimensions.member.1.Name': 'D',
         'MetricData.member.1.Dimensions.member.1.Value': 'V',
     }
     self.assertEqual(params, expected_params)
Exemplo n.º 5
0
 def test_build_put_params_multiple_dimensions(self):
     c = CloudWatchConnection()
     params = {}
     c.build_put_params(params, name="N", value=[1, 2], dimensions=[{"D": "V"}, {"D": "W"}])
     expected_params = {
         'MetricData.member.1.MetricName': 'N',
         'MetricData.member.1.Value': 1,
         'MetricData.member.1.Dimensions.member.1.Name': 'D',
         'MetricData.member.1.Dimensions.member.1.Value': 'V',
         'MetricData.member.2.MetricName': 'N',
         'MetricData.member.2.Value': 2,
         'MetricData.member.2.Dimensions.member.1.Name': 'D',
         'MetricData.member.2.Dimensions.member.1.Value': 'W',
         }
     self.assertEqual(params, expected_params)
Exemplo n.º 6
0
 def test_build_put_params_multiple_parameter_dimension(self):
     self.maxDiff = None
     c = CloudWatchConnection()
     params = {}
     dimensions = [OrderedDict((("D1", "V"), ("D2", "W")))]
     c.build_put_params(params, name="N", value=[1], dimensions=dimensions)
     expected_params = {
         'MetricData.member.1.MetricName': 'N',
         'MetricData.member.1.Value': 1,
         'MetricData.member.1.Dimensions.member.1.Name': 'D1',
         'MetricData.member.1.Dimensions.member.1.Value': 'V',
         'MetricData.member.1.Dimensions.member.2.Name': 'D2',
         'MetricData.member.1.Dimensions.member.2.Value': 'W',
     }
     self.assertEqual(params, expected_params)
Exemplo n.º 7
0
 def test_build_put_params_multiple_dimensions(self):
     c = CloudWatchConnection()
     params = {}
     c.build_put_params(params, name="N", value=[1, 2], dimensions=[{"D": "V"}, {"D": "W"}])
     expected_params = {
         'MetricData.member.1.MetricName': 'N',
         'MetricData.member.1.Value': 1,
         'MetricData.member.1.Dimensions.member.1.Name': 'D',
         'MetricData.member.1.Dimensions.member.1.Value': 'V',
         'MetricData.member.2.MetricName': 'N',
         'MetricData.member.2.Value': 2,
         'MetricData.member.2.Dimensions.member.1.Name': 'D',
         'MetricData.member.2.Dimensions.member.1.Value': 'W',
         }
     self.assertEqual(params, expected_params)
Exemplo n.º 8
0
 def test_build_put_params_multiple_metrics(self):
     c = CloudWatchConnection()
     params = {}
     c.build_put_params(params, name=["N", "M"], value=[1, 2], dimensions={"D": "V"})
     expected_params = {
         "MetricData.member.1.MetricName": "N",
         "MetricData.member.1.Value": 1,
         "MetricData.member.1.Dimensions.member.1.Name": "D",
         "MetricData.member.1.Dimensions.member.1.Value": "V",
         "MetricData.member.2.MetricName": "M",
         "MetricData.member.2.Value": 2,
         "MetricData.member.2.Dimensions.member.1.Name": "D",
         "MetricData.member.2.Dimensions.member.1.Value": "V",
     }
     self.assertEqual(params, expected_params)
Exemplo n.º 9
0
 def test_build_put_params_multiple_parameter_dimension(self):
     self.maxDiff = None
     c = CloudWatchConnection()
     params = {}
     dimensions = [OrderedDict((("D1", "V"), ("D2", "W")))]
     c.build_put_params(params,
                        name="N",
                        value=[1],
                        dimensions=dimensions)
     expected_params = {
         'MetricData.member.1.MetricName': 'N',
         'MetricData.member.1.Value': 1,
         'MetricData.member.1.Dimensions.member.1.Name': 'D1',
         'MetricData.member.1.Dimensions.member.1.Value': 'V',
         'MetricData.member.1.Dimensions.member.2.Name': 'D2',
         'MetricData.member.1.Dimensions.member.2.Value': 'W',
     }
     self.assertEqual(params, expected_params)
Exemplo n.º 10
0
class EucaELBConnection(ELBConnection):
    def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
                 is_secure=False, port=None, proxy=None, proxy_port=None,
                 proxy_user=None, proxy_pass=None, debug=0,
                 https_connection_factory=None, region=None, path='/',
                 security_token=None, validate_certs=True):
        """
        Init method to create a new connection to EC2 Load Balancing Service.

        note:: The region argument is overridden by the region specified in
            the boto configuration file.
        """
        if not region:
            region = RegionInfo(self, self.DefaultRegionName,
                                self.DefaultRegionEndpoint)
        self.region = region
        self.cw_con = CloudWatchConnection(aws_access_key_id,
                                    aws_secret_access_key,
                                    is_secure, port, proxy, proxy_port,
                                    proxy_user, proxy_pass, debug,
                                    https_connection_factory, region, path,
                                    security_token,
                                    validate_certs=validate_certs)
        ELBConnection.__init__(self, aws_access_key_id,
                                    aws_secret_access_key,
                                    is_secure, port, proxy, proxy_port,
                                    proxy_user, proxy_pass, debug,
                                    https_connection_factory, region, path,
                                    security_token,
                                    validate_certs=validate_certs)

    def put_cw_metric(self, servo_instance_id, metric):
        params = {'InstanceId':servo_instance_id}
        namespace = 'Servo'
        name = ['Latency','RequestCount','HTTPCode_ELB_4XX','HTTPCode_ELB_5XX','HTTPCode_Backend_2XX','HTTPCode_Backend_3XX','HTTPCode_Backend_4XX','HTTPCode_Backend_5XX']
        value = [metric.Latency, metric.RequestCount, metric.HTTPCode_ELB_4XX, metric.HTTPCode_ELB_5XX, metric.HTTPCode_Backend_2XX, metric.HTTPCode_Backend_3XX, metric.HTTPCode_Backend_4XX, metric.HTTPCode_Backend_5XX]
        unit = ['Milliseconds','Count','Count','Count','Count','Count','Count','Count']
        self.cw_con.build_put_params(params, name, value=value,timestamp=None, unit=unit, dimensions=None, statistics=None)

        return self.get_status('PutServoStates', params)

    def put_instance_health(self, servo_instance_id, instances):
        """
        Test the internal loadbalancer vms
        """
        params = {'InstanceId':servo_instance_id}
        if instances:
            self.build_list_params(params, instances, 'Instances.member.%d.InstanceId')
        return self.get_status('PutServoStates', params)

    def get_servo_load_balancers(self, servo_instance_id):
        #marker = "servo:%s" % servo_instance_id
        params = {"InstanceId": servo_instance_id}
        lbs = self.get_list('DescribeLoadBalancersByServo', params,
                             [('member', LoadBalancer)])

        for lb in lbs:
            instances = []
            if lb.instances is not None and isinstance(lb.instances, Iterable):
                for inst in lb.instances:
                    inst_id=str(inst.id) 
                    if inst_id.find(':')>=0:
                        token = inst_id.split(':')
                        inst_id=token[0]
                        ipaddr=token[1]
                        hostname_cache.register(inst_id, ipaddr)
                        inst.id = inst_id
 
        return lbs
Exemplo n.º 11
0
class EucaELBConnection(ELBConnection):
    def __init__(self,
                 aws_access_key_id=None,
                 aws_secret_access_key=None,
                 is_secure=False,
                 port=None,
                 proxy=None,
                 proxy_port=None,
                 proxy_user=None,
                 proxy_pass=None,
                 debug=0,
                 https_connection_factory=None,
                 region=None,
                 path='/',
                 security_token=None,
                 validate_certs=True):
        """
        Init method to create a new connection to EC2 Load Balancing Service.

        note:: The region argument is overridden by the region specified in
            the boto configuration file.
        """
        if not region:
            region = RegionInfo(self, self.DefaultRegionName,
                                self.DefaultRegionEndpoint)
        self.region = region
        self.cw_con = CloudWatchConnection(aws_access_key_id,
                                           aws_secret_access_key,
                                           is_secure,
                                           port,
                                           proxy,
                                           proxy_port,
                                           proxy_user,
                                           proxy_pass,
                                           debug,
                                           https_connection_factory,
                                           region,
                                           path,
                                           security_token,
                                           validate_certs=validate_certs)
        ELBConnection.__init__(self,
                               aws_access_key_id,
                               aws_secret_access_key,
                               is_secure,
                               port,
                               proxy,
                               proxy_port,
                               proxy_user,
                               proxy_pass,
                               debug,
                               https_connection_factory,
                               region,
                               path,
                               security_token,
                               validate_certs=validate_certs)

    def put_cw_metric(self, servo_instance_id, metric):
        params = {'InstanceId': servo_instance_id}
        namespace = 'Servo'
        name = [
            'Latency', 'RequestCount', 'HTTPCode_ELB_4XX', 'HTTPCode_ELB_5XX',
            'HTTPCode_Backend_2XX', 'HTTPCode_Backend_3XX',
            'HTTPCode_Backend_4XX', 'HTTPCode_Backend_5XX'
        ]
        value = [
            metric.Latency, metric.RequestCount, metric.HTTPCode_ELB_4XX,
            metric.HTTPCode_ELB_5XX, metric.HTTPCode_Backend_2XX,
            metric.HTTPCode_Backend_3XX, metric.HTTPCode_Backend_4XX,
            metric.HTTPCode_Backend_5XX
        ]
        unit = [
            'Milliseconds', 'Count', 'Count', 'Count', 'Count', 'Count',
            'Count', 'Count'
        ]
        self.cw_con.build_put_params(params,
                                     name,
                                     value=value,
                                     timestamp=None,
                                     unit=unit,
                                     dimensions=None,
                                     statistics=None)
        response = self.get_object('PutServoStates', params,
                                   PutServoStatesResponseType)
        try:
            config.set_query_period(
                response.servo_response_metadata.get_lb_interval)
            config.set_cwatch_report_period(
                response.servo_response_metadata.put_metric_interval)
            config.set_backend_instance_health_period(
                response.servo_response_metadata.put_instance_health_interval)
        except Exception, err:
            pass
Exemplo n.º 12
0
class EucaELBConnection(ELBConnection):
    def __init__(self,
                 aws_access_key_id=None,
                 aws_secret_access_key=None,
                 is_secure=False,
                 port=None,
                 proxy=None,
                 proxy_port=None,
                 proxy_user=None,
                 proxy_pass=None,
                 debug=0,
                 https_connection_factory=None,
                 region=None,
                 path='/',
                 security_token=None,
                 validate_certs=True):
        """
        Init method to create a new connection to EC2 Load Balancing Service.

        note:: The region argument is overridden by the region specified in
            the boto configuration file.
        """
        if not region:
            region = RegionInfo(self, self.DefaultRegionName,
                                self.DefaultRegionEndpoint)
        self.region = region
        self.cw_con = CloudWatchConnection(aws_access_key_id,
                                           aws_secret_access_key,
                                           is_secure,
                                           port,
                                           proxy,
                                           proxy_port,
                                           proxy_user,
                                           proxy_pass,
                                           debug,
                                           https_connection_factory,
                                           region,
                                           path,
                                           security_token,
                                           validate_certs=validate_certs)
        ELBConnection.__init__(self,
                               aws_access_key_id,
                               aws_secret_access_key,
                               is_secure,
                               port,
                               proxy,
                               proxy_port,
                               proxy_user,
                               proxy_pass,
                               debug,
                               https_connection_factory,
                               region,
                               path,
                               security_token,
                               validate_certs=validate_certs)

    def put_cw_metric(self, servo_instance_id, metric):
        params = {'InstanceId': servo_instance_id}
        namespace = 'Servo'
        name = [
            'Latency', 'RequestCount', 'HTTPCode_ELB_4XX', 'HTTPCode_ELB_5XX',
            'HTTPCode_Backend_2XX', 'HTTPCode_Backend_3XX',
            'HTTPCode_Backend_4XX', 'HTTPCode_Backend_5XX'
        ]
        value = [
            metric.Latency, metric.RequestCount, metric.HTTPCode_ELB_4XX,
            metric.HTTPCode_ELB_5XX, metric.HTTPCode_Backend_2XX,
            metric.HTTPCode_Backend_3XX, metric.HTTPCode_Backend_4XX,
            metric.HTTPCode_Backend_5XX
        ]
        unit = [
            'Milliseconds', 'Count', 'Count', 'Count', 'Count', 'Count',
            'Count', 'Count'
        ]
        self.cw_con.build_put_params(params,
                                     name,
                                     value=value,
                                     timestamp=None,
                                     unit=unit,
                                     dimensions=None,
                                     statistics=None)

        return self.get_status('PutServoStates', params)

    def put_instance_health(self, servo_instance_id, instances):
        """
        Test the internal loadbalancer vms
        """
        params = {'InstanceId': servo_instance_id}
        if instances:
            self.build_list_params(params, instances,
                                   'Instances.member.%d.InstanceId')
        return self.get_status('PutServoStates', params)

    def get_servo_load_balancers(self, servo_instance_id):
        #marker = "servo:%s" % servo_instance_id
        params = {"InstanceId": servo_instance_id}
        lbs = self.get_list('DescribeLoadBalancersByServo', params,
                            [('member', LoadBalancer)])

        for lb in lbs:
            instances = []
            if lb.instances is not None and isinstance(lb.instances, Iterable):
                for inst in lb.instances:
                    inst_id = str(inst.id)
                    if inst_id.find(':') >= 0:
                        token = inst_id.split(':')
                        inst_id = token[0]
                        ipaddr = token[1]
                        hostname_cache.register(inst_id, ipaddr)
                        inst.id = inst_id

        return lbs