当前位置: 首页>>代码示例>>Python>>正文


Python elb.ELBConnection类代码示例

本文整理汇总了Python中boto.ec2.elb.ELBConnection的典型用法代码示例。如果您正苦于以下问题:Python ELBConnection类的具体用法?Python ELBConnection怎么用?Python ELBConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ELBConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    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)
开发者ID:hnousiainen,项目名称:load-balancer-servo,代码行数:29,代码来源:__init__.py

示例2: handle

    def handle(self, *args, **options):
        ec2_connection = EC2Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
        regions = boto.ec2.elb.regions()
        my_priv_ip = get_my_private_ip()

        for region in regions:
            region_lb_connection = ELBConnection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, region=region)
            # regions is a list of RegionInfo with connection_cls ELBConnection
            # so for our EC2Connection we want to get an EC2Connection RegionInfo with the corresponding region descriptor
            region_connection = EC2Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, region=boto.ec2.get_region(region.name))

            load_balancers = region_lb_connection.get_all_load_balancers()
            instances = [r.instances[0] for r in region_connection.get_all_instances()]
            try:
                # FIXME: TEST This in dev, stage, prod environments
                me = [i for i in instances if i.private_ip_address == my_priv_ip][0]
                my_main_group = me.groups[0].name
            except IndexError:
                me = None
                my_main_group = 'dev'
            instances = [i for i in instances if i.state != u'stopped' and i.groups[0].name == my_main_group]
            load_balancers = [lb for lb in load_balancers if lb.name == my_main_group]

            if load_balancers:
                print region, load_balancers[0]
                for instance in instances:
                    print instance.tags['Name'], instance.public_dns_name, instance.tags['Name'] + '.c2gops.com' # FIXME assumes basename
开发者ID:AlfredArouna,项目名称:class2go,代码行数:27,代码来源:aws_getinfo.py

示例3: test_next_token

 def test_next_token(self):
     elb = ELBConnection(aws_access_key_id="aws_access_key_id", aws_secret_access_key="aws_secret_access_key")
     mock_response = mock.Mock()
     mock_response.read.return_value = DISABLE_RESPONSE
     mock_response.status = 200
     elb.make_request = mock.Mock(return_value=mock_response)
     disabled = elb.disable_availability_zones("mine", ["sample-zone"])
     self.assertEqual(disabled, ["sample-zone"])
开发者ID:bigale,项目名称:boto,代码行数:8,代码来源:test_loadbalancer.py

示例4: test_detach_subnets

    def test_detach_subnets(self):
        elb = ELBConnection(aws_access_key_id="aws_access_key_id", aws_secret_access_key="aws_secret_access_key")
        lb = LoadBalancer(elb, "mylb")

        mock_response = mock.Mock()
        mock_response.read.return_value = DETACH_RESPONSE
        mock_response.status = 200
        elb.make_request = mock.Mock(return_value=mock_response)
        lb.detach_subnets("s-xxx")
开发者ID:bigale,项目名称:boto,代码行数:9,代码来源:test_loadbalancer.py

示例5: test_request_with_marker

 def test_request_with_marker(self):
     elb = ELBConnection(aws_access_key_id="aws_access_key_id", aws_secret_access_key="aws_secret_access_key")
     mock_response = mock.Mock()
     mock_response.read.return_value = DESCRIBE_RESPONSE
     mock_response.status = 200
     elb.make_request = mock.Mock(return_value=mock_response)
     load_balancers1 = elb.get_all_load_balancers()
     self.assertEqual("1234", load_balancers1.marker)
     load_balancers2 = elb.get_all_load_balancers(marker=load_balancers1.marker)
     self.assertEqual(len(load_balancers2), 1)
开发者ID:bigale,项目名称:boto,代码行数:10,代码来源:test_loadbalancer.py

示例6: _setup_mock

 def _setup_mock(self):
     """Sets up a mock elb request.
     Returns: response, elb connection and LoadBalancer
     """
     mock_response = mock.Mock()
     mock_response.status = 200
     elb = ELBConnection(aws_access_key_id='aws_access_key_id',
                         aws_secret_access_key='aws_secret_access_key')
     elb.make_request = mock.Mock(return_value=mock_response)
     return mock_response, elb, LoadBalancer(elb, 'test_elb')
开发者ID:10sr,项目名称:hue,代码行数:10,代码来源:test_attribute.py

示例7: BotoBalanceInterface

class BotoBalanceInterface(BalanceInterface):
    conn = None
    saveclcdata = False

    def __init__(self, clc_host, access_id, secret_key, token):
        #boto.set_stream_logger('foo')
        path='/services/elb'
        port=8773
        if clc_host[len(clc_host)-13:] == 'amazonaws.com':
            clc_host = clc_host.replace('ec2', 'elasticloadbalancing', 1)
            path = '/'
            reg = None
            port=443
        reg = RegionInfo(name='eucalyptus', endpoint=clc_host)
        self.conn = ELBConnection(access_id, secret_key, region=reg,
                                  port=port, path=path,
                                  is_secure=True, security_token=token, debug=0)
        self.conn.https_validate_certificates = False
        self.conn.http_connection_kwargs['timeout'] = 30

    def __save_json__(self, obj, name):
        f = open(name, 'w')
        json.dump(obj, f, cls=BotoJsonBalanceEncoder, indent=2)
        f.close()

    def create_load_balancer(self, name, zones, listeners, subnets=None,
                             security_groups=None, scheme='internet-facing'):
        return self.conn.create_load_balancer(name, zones, listeners, subnets, security_groups, scheme)
    
    def delete_load_balancer(self, name):
        return self.conn.delete_load_balancer(name)

    def get_all_load_balancers(self, load_balancer_names=None):
        return []
        obj = self.conn.get_all_load_balancers(load_balancer_names)
        if self.saveclcdata:
            self.__save_json__(obj, "mockdata/ELB_Balancers.json")
        return obj

    def deregister_instances(self, load_balancer_name, instances):
        return self.conn.deregister_instances(load_balancer_name, instances)

    def register_instances(self, load_balancer_name, instances):
        return self.conn.register_instances(load_balancer_name, instances)

    def create_load_balancer_listeners(self, name, listeners):
        return self.conn.create_load_balancer_listeners(name, listeners)

    def delete_load_balancer_listeners(self, name, ports):
        return self.conn.delete_load_balancer_listeners(name, ports)

    def configure_health_check(self, name, health_check):
        return self.conn.configure_health_check(name, health_check)

    def describe_instance_health(self, load_balancer_name, instances=None):
        obj = self.conn.describe_instance_health(load_balancer_name, instances)
        if self.saveclcdata:
            self.__save_json__(obj, "mockdata/ELB_Instances.json")
        return obj
开发者ID:aldeka,项目名称:eucalyptus,代码行数:59,代码来源:botobalanceinterface.py

示例8: get_all_load_balancers

    def get_all_load_balancers():
        connection = ELBConnection()
        all_load_balancers = []
        load_balancers = connection.get_all_load_balancers()
        all_load_balancers.extend(load_balancers)

        while load_balancers.is_truncated:
            load_balancers = connection.get_all_load_balancers()
            all_load_balancers.extend(load_balancers)

        return all_load_balancers
开发者ID:esanchezm,项目名称:forseti,代码行数:11,代码来源:base.py

示例9: test_build_list_params

 def test_build_list_params(self):
     c = ELBConnection()
     params = {}
     c.build_list_params(
         params, ['thing1', 'thing2', 'thing3'], 'ThingName%d')
     expected_params = {
         'ThingName1': 'thing1',
         'ThingName2': 'thing2',
         'ThingName3': 'thing3'
         }
     self.assertEqual(params, expected_params)
开发者ID:BenCorneau,项目名称:boto,代码行数:11,代码来源:test_connection.py

示例10: test_create_load_balancer

    def test_create_load_balancer(self):
        c = ELBConnection()
        name = 'elb-boto-unit-test'
        availability_zones = ['us-east-1a']
        listeners = [(80, 8000, 'HTTP')]
        balancer = c.create_load_balancer(name, availability_zones, listeners)
        self.assertEqual(balancer.name, name)
        self.assertEqual(balancer.availability_zones, availability_zones)
        self.assertEqual(balancer.listeners, listeners)

        balancers = c.get_all_load_balancers()
        self.assertEqual([lb.name for lb in balancers], [name])
开发者ID:BenCorneau,项目名称:boto,代码行数:12,代码来源:test_connection.py

示例11: _remove_instance_from_load_balancer

def _remove_instance_from_load_balancer(conn, instance, instance_info) :
    if 'load_balancer' in instance_info : 
        load_balancer_name = instance_info['load_balancer']
                
        elb_conn = ELBConnection()
        
        if _instance_in_load_balancer(elb_conn, load_balancer_name, instance.id) :
            print("Removing Instance(s) " + str([instance.id]) + " from load balancer " + load_balancer_name)
            elb_conn.deregister_instances(load_balancer_name, [instance.id])
        else :
            print("Instance(s) " + str([instance.id]) + " not associated with load balancer " + load_balancer_name + ", Nothing left to do")
        
    else :
        print("Skipping disassociation with Load Balancer ")
开发者ID:hashedin,项目名称:awslib,代码行数:14,代码来源:utils.py

示例12: _add_instance_to_load_balancer

def _add_instance_to_load_balancer(conn, instance, instance_info) :
    if 'load_balancer' in instance_info : 
        load_balancer_name = instance_info['load_balancer']
                
        elb_conn = ELBConnection()
        
        if _instance_in_load_balancer(elb_conn, load_balancer_name, instance.id) :
            print("Removing Instance(s) " + str([instance.id]) + " from load balancer " + load_balancer_name)
            elb_conn.deregister_instances(load_balancer_name, [instance.id])

        print("Adding Instance(s) " + str([instance.id]) + " to load balancer " + load_balancer_name)
        elb_conn.register_instances(load_balancer_name, [instance.id])
        
    else :
        print("Skipping association with Load Balancer ")
开发者ID:hashedin,项目名称:awslib,代码行数:15,代码来源:utils.py

示例13: test_create_load_balancer_listeners

    def test_create_load_balancer_listeners(self):
        c = ELBConnection()
        name = 'elb-boto-unit-test'
        availability_zones = ['us-east-1a']
        listeners = [(80, 8000, 'HTTP')]
        balancer = c.create_load_balancer(name, availability_zones, listeners)

        more_listeners = [(443, 8001, 'HTTP')]
        c.create_load_balancer_listeners(name, more_listeners)
        balancers = c.get_all_load_balancers()
        self.assertEqual([lb.name for lb in balancers], [name])
        self.assertEqual(
            sorted(l.get_tuple() for l in balancers[0].listeners),
            sorted(listeners + more_listeners)
            )
开发者ID:BenCorneau,项目名称:boto,代码行数:15,代码来源:test_connection.py

示例14: __init__

 def __init__(self,PREFIX='tfound-',ENV='dev',AMI='',TYPE='',SIZE='',
              DOMAIN='tfound',SSHKEY='myprivatekey',AWSKEY='',AWSSECRET='',AVAIL_ZONES=["us-east-1a","us-east-1b","us-east-1c","us-east-1d"]):
     '''
     Shows examples
     Create load balancer group 'tfound-dev-web-lb' for web servers, in dev group for tfound:
         python control-lb-and-groups.py --createlb --env dev --aws SC --type web
     Add an instance to the load balancer group:
         python control-lb-and-groups.py --addtolb=true --env dev --aws SC --type web --instance=i-999999
     Create launch config using ami ami-fa6b8393 (default), medium sized instance, and Autoscale Group 'tfound-dev-web-group' with a min of 2 instances, max 5, with health check on port 80:
         python control-lb-and-groups.py  --createlc --ami ami-fa6b8393 --size c1.medium --env dev --aws SC --type web --createag --min 2 --max 5
     Triggers/Health checks are hard coded to spawn new instances when total cpu reaches 60 percent or health check fails.
     '''
     self.PREFIX=PREFIX+DOMAIN+'-'+ENV+'-'+TYPE
     self.ENV=ENV
     self.AMI=AMI
     self.TYPE=TYPE
     self.DOMAIN=DOMAIN
     self.SIZE=SIZE
     self.MIN=MIN
     self.MAX=MAX
     self.SSHKEY=SSHKEY
     self.AWSKEY=AWSKEY
     self.AWSSECRET=AWSSECRET
     self.AVAIL_ZONES=AVAIL_ZONES
     self.LBNAME=self.PREFIX+'-lb'
     self.AGNAME=self.PREFIX+'-group'
     self.TRNAME=self.PREFIX+'-trigger'
     self.LCNAME=self.PREFIX+'-launch_config'
     self.asconn=AutoScaleConnection(self.AWSKEY, self.AWSSECRET)
     self.elbconn = ELBConnection(aws_access_key_id=AWSKEY,aws_secret_access_key=AWSSECRET)
     self.lc = self._buildLaunchConfig()
     self.ag = self._buildAutoscaleGroup()
开发者ID:syspimp,项目名称:zenMaster,代码行数:32,代码来源:aws.py

示例15: setUp

 def setUp(self):
     """Creates a named load balancer that can be safely
     deleted at the end of each test"""
     self.conn = ELBConnection()
     self.name = 'elb-boto-unit-test'
     self.availability_zones = ['us-east-1a']
     self.listeners = [(80, 8000, 'HTTP')]
     self.balancer = self.conn.create_load_balancer(self.name, self.availability_zones, self.listeners)
开发者ID:2mind,项目名称:boto,代码行数:8,代码来源:test_connection.py


注:本文中的boto.ec2.elb.ELBConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。