Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: third_party/gsutil/boto/boto/ec2/elb/loadbalancer.py

Issue 10199002: Upgrade gsutil to 3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/ 1 # Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/
2 # 2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a 3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the 4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including 5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis- 6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit 7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol- 8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions: 9 # lowing conditions:
10 # 10 #
(...skipping 11 matching lines...) Expand all
22 from boto.ec2.elb.healthcheck import HealthCheck 22 from boto.ec2.elb.healthcheck import HealthCheck
23 from boto.ec2.elb.listener import Listener 23 from boto.ec2.elb.listener import Listener
24 from boto.ec2.elb.listelement import ListElement 24 from boto.ec2.elb.listelement import ListElement
25 from boto.ec2.elb.policies import Policies 25 from boto.ec2.elb.policies import Policies
26 from boto.ec2.elb.securitygroup import SecurityGroup 26 from boto.ec2.elb.securitygroup import SecurityGroup
27 from boto.ec2.instanceinfo import InstanceInfo 27 from boto.ec2.instanceinfo import InstanceInfo
28 from boto.resultset import ResultSet 28 from boto.resultset import ResultSet
29 29
30 class LoadBalancer(object): 30 class LoadBalancer(object):
31 """ 31 """
32 Represents an EC2 Load Balancer 32 Represents an EC2 Load Balancer.
33 """ 33 """
34 34
35 def __init__(self, connection=None, name=None, endpoints=None): 35 def __init__(self, connection=None, name=None, endpoints=None):
36 """
37 :ivar boto.ec2.elb.ELBConnection connection: The connection this load
38 balancer was instance was instantiated from.
39 :ivar list listeners: A list of tuples in the form of
40 ``(<Inbound port>, <Outbound port>, <Protocol>)``
41 :ivar boto.ec2.elb.healthcheck.HealthCheck health_check: The health
42 check policy for this load balancer.
43 :ivar boto.ec2.elb.policies.Policies policies: Cookie stickiness and
44 other policies.
45 :ivar str dns_name: The external DNS name for the balancer.
46 :ivar str created_time: A date+time string showing when the
47 load balancer was created.
48 :ivar list instances: A list of :py:class:`boto.ec2.instanceinfo.Instanc eInfo`
49 instances, representing the EC2 instances this load balancer is
50 distributing requests to.
51 :ivar list availability_zones: The availability zones this balancer
52 covers.
53 :ivar str canonical_hosted_zone_name: Current CNAME for the balancer.
54 :ivar str canonical_hosted_zone_name_id: The Route 53 hosted zone
55 ID of this balancer. Needed when creating an Alias record in a
56 Route 53 hosted zone.
57 :ivar boto.ec2.elb.securitygroup.SecurityGroup source_security_group:
58 The security group that you can use as part of your inbound rules
59 for your load balancer back-end instances to disallow traffic
60 from sources other than your load balancer.
61 :ivar list subnets: A list of subnets this balancer is on.
62 :ivar list security_groups: A list of additional security groups that
63 have been applied.
64 :ivar str vpc_id: The ID of the VPC that this ELB resides within.
65 """
36 self.connection = connection 66 self.connection = connection
37 self.name = name 67 self.name = name
38 self.listeners = None 68 self.listeners = None
39 self.health_check = None 69 self.health_check = None
40 self.policies = None 70 self.policies = None
41 self.dns_name = None 71 self.dns_name = None
42 self.created_time = None 72 self.created_time = None
43 self.instances = None 73 self.instances = None
44 self.availability_zones = ListElement() 74 self.availability_zones = ListElement()
45 self.canonical_hosted_zone_name = None 75 self.canonical_hosted_zone_name = None
46 self.canonical_hosted_zone_name_id = None 76 self.canonical_hosted_zone_name_id = None
47 self.source_security_group = None 77 self.source_security_group = None
78 self.subnets = ListElement()
79 self.security_groups = ListElement()
80 self.vpc_id = None
81
48 82
49 def __repr__(self): 83 def __repr__(self):
50 return 'LoadBalancer:%s' % self.name 84 return 'LoadBalancer:%s' % self.name
51 85
52 def startElement(self, name, attrs, connection): 86 def startElement(self, name, attrs, connection):
53 if name == 'HealthCheck': 87 if name == 'HealthCheck':
54 self.health_check = HealthCheck(self) 88 self.health_check = HealthCheck(self)
55 return self.health_check 89 return self.health_check
56 elif name == 'ListenerDescriptions': 90 elif name == 'ListenerDescriptions':
57 self.listeners = ResultSet([('member', Listener)]) 91 self.listeners = ResultSet([('member', Listener)])
58 return self.listeners 92 return self.listeners
59 elif name == 'AvailabilityZones': 93 elif name == 'AvailabilityZones':
60 return self.availability_zones 94 return self.availability_zones
61 elif name == 'Instances': 95 elif name == 'Instances':
62 self.instances = ResultSet([('member', InstanceInfo)]) 96 self.instances = ResultSet([('member', InstanceInfo)])
63 return self.instances 97 return self.instances
64 elif name == 'Policies': 98 elif name == 'Policies':
65 self.policies = Policies(self) 99 self.policies = Policies(self)
66 return self.policies 100 return self.policies
67 elif name == 'SourceSecurityGroup': 101 elif name == 'SourceSecurityGroup':
68 self.source_security_group = SecurityGroup() 102 self.source_security_group = SecurityGroup()
69 return self.source_security_group 103 return self.source_security_group
104 elif name == 'Subnets':
105 return self.subnets
106 elif name == 'SecurityGroups':
107 return self.security_groups
108 elif name == 'VPCId':
109 pass
70 else: 110 else:
71 return None 111 return None
72 112
73 def endElement(self, name, value, connection): 113 def endElement(self, name, value, connection):
74 if name == 'LoadBalancerName': 114 if name == 'LoadBalancerName':
75 self.name = value 115 self.name = value
76 elif name == 'DNSName': 116 elif name == 'DNSName':
77 self.dns_name = value 117 self.dns_name = value
78 elif name == 'CreatedTime': 118 elif name == 'CreatedTime':
79 self.created_time = value 119 self.created_time = value
80 elif name == 'InstanceId': 120 elif name == 'InstanceId':
81 self.instances.append(value) 121 self.instances.append(value)
82 elif name == 'CanonicalHostedZoneName': 122 elif name == 'CanonicalHostedZoneName':
83 self.canonical_hosted_zone_name = value 123 self.canonical_hosted_zone_name = value
84 elif name == 'CanonicalHostedZoneNameID': 124 elif name == 'CanonicalHostedZoneNameID':
85 self.canonical_hosted_zone_name_id = value 125 self.canonical_hosted_zone_name_id = value
126 elif name == 'VPCId':
127 self.vpc_id = value
86 else: 128 else:
87 setattr(self, name, value) 129 setattr(self, name, value)
88 130
89 def enable_zones(self, zones): 131 def enable_zones(self, zones):
90 """ 132 """
91 Enable availability zones to this Access Point. 133 Enable availability zones to this Access Point.
92 All zones must be in the same region as the Access Point. 134 All zones must be in the same region as the Access Point.
93 135
94 :type zones: string or List of strings 136 :type zones: string or List of strings
95 :param zones: The name of the zone(s) to add. 137 :param zones: The name of the zone(s) to add.
(...skipping 12 matching lines...) Expand all
108 :param zones: The name of the zone(s) to add. 150 :param zones: The name of the zone(s) to add.
109 151
110 """ 152 """
111 if isinstance(zones, str) or isinstance(zones, unicode): 153 if isinstance(zones, str) or isinstance(zones, unicode):
112 zones = [zones] 154 zones = [zones]
113 new_zones = self.connection.disable_availability_zones(self.name, zones) 155 new_zones = self.connection.disable_availability_zones(self.name, zones)
114 self.availability_zones = new_zones 156 self.availability_zones = new_zones
115 157
116 def register_instances(self, instances): 158 def register_instances(self, instances):
117 """ 159 """
118 Add instances to this Load Balancer 160 Adds instances to this load balancer. All instances must be in the same
119 All instances must be in the same region as the Load Balancer. 161 region as the load balancer. Adding endpoints that are already
120 Adding endpoints that are already registered with the Load Balancer 162 registered with the load balancer has no effect.
121 has no effect.
122 163
123 :type zones: string or List of instance id's 164 :param list instances: List of instance IDs (strings) that you'd like
124 :param zones: The name of the endpoint(s) to add. 165 to add to this load balancer.
125 166
126 """ 167 """
127 if isinstance(instances, str) or isinstance(instances, unicode): 168 if isinstance(instances, str) or isinstance(instances, unicode):
128 instances = [instances] 169 instances = [instances]
129 new_instances = self.connection.register_instances(self.name, instances) 170 new_instances = self.connection.register_instances(self.name, instances)
130 self.instances = new_instances 171 self.instances = new_instances
131 172
132 def deregister_instances(self, instances): 173 def deregister_instances(self, instances):
133 """ 174 """
134 Remove instances from this Load Balancer. 175 Remove instances from this load balancer. Removing instances that are
135 Removing instances that are not registered with the Load Balancer 176 not registered with the load balancer has no effect.
136 has no effect.
137 177
138 :type zones: string or List of instance id's 178 :param list instances: List of instance IDs (strings) that you'd like
139 :param zones: The name of the endpoint(s) to add. 179 to remove from this load balancer.
140 180
141 """ 181 """
142 if isinstance(instances, str) or isinstance(instances, unicode): 182 if isinstance(instances, str) or isinstance(instances, unicode):
143 instances = [instances] 183 instances = [instances]
144 new_instances = self.connection.deregister_instances(self.name, instance s) 184 new_instances = self.connection.deregister_instances(self.name, instance s)
145 self.instances = new_instances 185 self.instances = new_instances
146 186
147 def delete(self): 187 def delete(self):
148 """ 188 """
149 Delete this load balancer 189 Delete this load balancer.
150 """ 190 """
151 return self.connection.delete_load_balancer(self.name) 191 return self.connection.delete_load_balancer(self.name)
152 192
153 def configure_health_check(self, health_check): 193 def configure_health_check(self, health_check):
194 """
195 Configures the health check behavior for the instances behind this
196 load balancer. See :ref:`elb-configuring-a-health-check` for a
197 walkthrough.
198
199 :param boto.ec2.elb.healthcheck.HealthCheck health_check: A
200 HealthCheck instance that tells the load balancer how to check
201 its instances for health.
202 """
154 return self.connection.configure_health_check(self.name, health_check) 203 return self.connection.configure_health_check(self.name, health_check)
155 204
156 def get_instance_health(self, instances=None): 205 def get_instance_health(self, instances=None):
206 """
207 Returns a list of :py:class:`boto.ec2.elb.instancestate.InstanceState`
208 objects, which show the health of the instances attached to this
209 load balancer.
210
211 :rtype: list
212 :returns: A list of
213 :py:class:`InstanceState <boto.ec2.elb.instancestate.InstanceState>`
214 instances, representing the instances
215 attached to this load balancer.
216 """
157 return self.connection.describe_instance_health(self.name, instances) 217 return self.connection.describe_instance_health(self.name, instances)
158 218
159 def create_listeners(self, listeners): 219 def create_listeners(self, listeners):
160 return self.connection.create_load_balancer_listeners(self.name, listene rs) 220 return self.connection.create_load_balancer_listeners(self.name, listene rs)
161 221
162 def create_listener(self, inPort, outPort=None, proto="tcp"): 222 def create_listener(self, inPort, outPort=None, proto="tcp"):
163 if outPort == None: 223 if outPort == None:
164 outPort = inPort 224 outPort = inPort
165 return self.create_listeners([(inPort, outPort, proto)]) 225 return self.create_listeners([(inPort, outPort, proto)])
166 226
167 def delete_listeners(self, listeners): 227 def delete_listeners(self, listeners):
168 return self.connection.delete_load_balancer_listeners(self.name, listene rs) 228 return self.connection.delete_load_balancer_listeners(self.name, listene rs)
169 229
170 def delete_listener(self, inPort, outPort=None, proto="tcp"): 230 def delete_listener(self, inPort):
171 if outPort == None: 231 return self.delete_listeners([inPort])
172 outPort = inPort
173 return self.delete_listeners([(inPort, outPort, proto)])
174 232
175 def delete_policy(self, policy_name): 233 def delete_policy(self, policy_name):
176 """ 234 """
177 Deletes a policy from the LoadBalancer. The specified policy must not 235 Deletes a policy from the LoadBalancer. The specified policy must not
178 be enabled for any listeners. 236 be enabled for any listeners.
179 """ 237 """
180 return self.connection.delete_lb_policy(self.name, policy_name) 238 return self.connection.delete_lb_policy(self.name, policy_name)
181 239
182 def set_policies_of_listener(self, lb_port, policies): 240 def set_policies_of_listener(self, lb_port, policies):
183 return self.connection.set_lb_policies_of_listener(self.name, lb_port, p olicies) 241 return self.connection.set_lb_policies_of_listener(self.name, lb_port, p olicies)
184 242
185 def create_cookie_stickiness_policy(self, cookie_expiration_period, policy_n ame): 243 def create_cookie_stickiness_policy(self, cookie_expiration_period, policy_n ame):
186 return self.connection.create_lb_cookie_stickiness_policy(cookie_expirat ion_period, self.name, policy_name) 244 return self.connection.create_lb_cookie_stickiness_policy(cookie_expirat ion_period, self.name, policy_name)
187 245
188 def create_app_cookie_stickiness_policy(self, name, policy_name): 246 def create_app_cookie_stickiness_policy(self, name, policy_name):
189 return self.connection.create_app_cookie_stickiness_policy(name, self.na me, policy_name) 247 return self.connection.create_app_cookie_stickiness_policy(name, self.na me, policy_name)
190 248
191 def set_listener_SSL_certificate(self, lb_port, ssl_certificate_id): 249 def set_listener_SSL_certificate(self, lb_port, ssl_certificate_id):
192 return self.connection.set_lb_listener_SSL_certificate(self.name, lb_por t, ssl_certificate_id) 250 return self.connection.set_lb_listener_SSL_certificate(self.name, lb_por t, ssl_certificate_id)
193 251
252 def attach_subnets(self, subnets):
253 """
254 Attaches load balancer to one or more subnets.
255 Attaching subnets that are already registered with the
256 Load Balancer has no effect.
257
258 :type subnets: string or List of strings
259 :param subnets: The name of the subnet(s) to add.
260
261 """
262 if isinstance(subnets, str) or isinstance(subnets, unicode):
263 subnets = [subnets]
264 new_subnets = self.connection.attach_lb_to_subnets(self.name, subnets)
265 self.subnets = new_subnets
266
267 def detach_subnets(self, subnets):
268 """
269 Detaches load balancer from one or more subnets.
270
271 :type subnets: string or List of strings
272 :param subnets: The name of the subnet(s) to detach.
273
274 """
275 if isinstance(subnets, str) or isinstance(subnets, unicode):
276 subnets = [subnets]
277 new_subnets = self.connection.detach_lb_to_subnets(self.name, subnets)
278 self.subnets = new_subnets
279
280 def apply_security_groups(self, security_groups):
281 """
282 Applies security groups to the load balancer.
283 Applying security groups that are already registered with the
284 Load Balancer has no effect.
285
286 :type security_groups: string or List of strings
287 :param security_groups: The name of the security group(s) to add.
288
289 """
290 if isinstance(security_groups, str) or \
291 isinstance(security_groups, unicode):
292 security_groups = [security_groups]
293 new_sgs = self.connection.apply_security_groups_to_lb(
294 self.name, security_groups)
295 self.security_groups = new_sgs
296
297
OLDNEW
« no previous file with comments | « third_party/gsutil/boto/boto/ec2/elb/listener.py ('k') | third_party/gsutil/boto/boto/ec2/elb/policies.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698