Merge lp:~therve/landscape-client/broken-ec2-api-endpoint into lp:~landscape/landscape-client/trunk

Proposed by Thomas Herve
Status: Merged
Approved by: Free Ekanayaka
Approved revision: 234
Merged at revision: not available
Proposed branch: lp:~therve/landscape-client/broken-ec2-api-endpoint
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 134 lines (+41/-27)
1 file modified
landscape/broker/registration.py (+41/-27)
To merge this branch: bzr merge lp:~therve/landscape-client/broken-ec2-api-endpoint
Reviewer Review Type Date Requested Status
Free Ekanayaka (community) Approve
Kevin McDermott (community) Approve
Review via email: mp+23838@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

Looks good, wish that mysterious comment would be explained tho' :-)

+1

review: Approve
Revision history for this message
Kevin McDermott (bigkevmcd) :
review: Approve
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Good fix, +1!

[1]

+ d = self._fetch_async(EC2_API + "/user-data").addErrback(

Please use a full name for this variable, like "result" or "deferred", we normally don't use abbreviations for variable names.

review: Approve
235. By Thomas Herve

Add one comment, remove another, change variable name

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'landscape/broker/registration.py'
--- landscape/broker/registration.py 2009-12-07 10:31:31 +0000
+++ landscape/broker/registration.py 2010-04-22 05:59:21 +0000
@@ -5,7 +5,6 @@
55
6from twisted.internet.defer import Deferred6from twisted.internet.defer import Deferred
77
8from landscape.lib.twisted_util import gather_results
9from landscape.lib.bpickle import loads8from landscape.lib.bpickle import loads
10from landscape.lib.log import log_failure9from landscape.lib.log import log_failure
11from landscape.lib.fetch import fetch, FetchError10from landscape.lib.fetch import fetch, FetchError
@@ -24,16 +23,21 @@
2423
2524
26def persist_property(name):25def persist_property(name):
26
27 def get(self):27 def get(self):
28 return self._persist.get(name)28 return self._persist.get(name)
29
29 def set(self, value):30 def set(self, value):
30 self._persist.set(name, value)31 self._persist.set(name, value)
32
31 return property(get, set)33 return property(get, set)
3234
3335
34def config_property(name):36def config_property(name):
37
35 def get(self):38 def get(self):
36 return getattr(self._config, name)39 return getattr(self._config, name)
40
37 return property(get)41 return property(get)
3842
3943
@@ -118,30 +122,40 @@
118 self._exchange.exchange()122 self._exchange.exchange()
119 return result123 return result
120124
125 def _get_data(self, path, accumulate):
126 """
127 Get data at C{path} on the EC2 API endpoint, and add the result to the
128 C{accumulate} list.
129 """
130 return self._fetch_async(EC2_API + path).addCallback(accumulate.append)
131
121 def _fetch_ec2_data(self):132 def _fetch_ec2_data(self):
133 """Retrieve available EC2 information, if in a EC2 compatible cloud."""
122 id = self._identity134 id = self._identity
123 if self._cloud and not id.secure_id:135 if self._cloud and not id.secure_id:
124 # Fetch data from the EC2 API, to be used later in the registration136 # Fetch data from the EC2 API, to be used later in the registration
125 # process137 # process
126 registration_data = gather_results([138 # We ignore errors from user-data because it's common for the
127 # We ignore errors from user-data because it's common for the139 # URL to return a 404 when the data is unavailable.
128 # URL to return a 404 when the data is unavailable.140 ec2_data = []
129 self._fetch_async(EC2_API + "/user-data")141 deferred = self._fetch_async(EC2_API + "/user-data").addErrback(
130 .addErrback(log_failure),142 log_failure).addCallback(ec2_data.append)
131 # The rest of the fetches don't get protected because we just143 paths = [
132 # fall back to regular registration if any of them don't work.144 "/meta-data/instance-id",
133 self._fetch_async(EC2_API + "/meta-data/instance-id"),145 "/meta-data/reservation-id",
134 self._fetch_async(EC2_API + "/meta-data/reservation-id"),146 "/meta-data/local-hostname",
135 self._fetch_async(EC2_API + "/meta-data/local-hostname"),147 "/meta-data/public-hostname",
136 self._fetch_async(EC2_API + "/meta-data/public-hostname"),148 "/meta-data/ami-launch-index",
137 self._fetch_async(EC2_API + "/meta-data/ami-launch-index"),149 "/meta-data/kernel-id",
138 self._fetch_async(EC2_API + "/meta-data/kernel-id"),150 "/meta-data/ramdisk-id",
139 self._fetch_async(EC2_API + "/meta-data/ramdisk-id"),151 "/meta-data/ami-id"]
140 self._fetch_async(EC2_API + "/meta-data/ami-id"),152 # We're not using a DeferredList here because we want to keep the
141 ],153 # number of connections to the backend minimal. See lp:567515.
142 consume_errors=True)154 for path in paths:
155 deferred.addCallback(
156 lambda ignore, path=path: self._get_data(path, ec2_data))
143157
144 def record_data(ec2_data):158 def record_data(ignore):
145 """Record the instance data returned by the EC2 API."""159 """Record the instance data returned by the EC2 API."""
146 (raw_user_data, instance_key, reservation_key,160 (raw_user_data, instance_key, reservation_key,
147 local_hostname, public_hostname, launch_index,161 local_hostname, public_hostname, launch_index,
@@ -176,9 +190,8 @@
176 log_failure(error, msg="Got error while fetching meta-data: %r"190 log_failure(error, msg="Got error while fetching meta-data: %r"
177 % (error.value,))191 % (error.value,))
178192
179 # It sucks that this deferred is never returned193 deferred.addCallback(record_data)
180 registration_data.addCallback(record_data)194 deferred.addErrback(log_error)
181 registration_data.addErrback(log_error)
182195
183 def _handle_exchange_done(self):196 def _handle_exchange_done(self):
184 """Registered handler for the C{"exchange-done"} event.197 """Registered handler for the C{"exchange-done"} event.
@@ -226,9 +239,9 @@
226 self._exchange.send(message)239 self._exchange.send(message)
227 elif id.account_name:240 elif id.account_name:
228 with_tags = ["", u"and tags %s " % tags][bool(tags)]241 with_tags = ["", u"and tags %s " % tags][bool(tags)]
229 logging.info(u"Queueing message to register with account %r %s"242 logging.info(
230 "as an EC2 instance." % (243 u"Queueing message to register with account %r %s"
231 id.account_name, with_tags,))244 u"as an EC2 instance." % (id.account_name, with_tags))
232 message = {"type": "register-cloud-vm",245 message = {"type": "register-cloud-vm",
233 "otp": None,246 "otp": None,
234 "hostname": socket.getfqdn(),247 "hostname": socket.getfqdn(),
@@ -365,7 +378,7 @@
365 time.sleep(1)378 time.sleep(1)
366 if time.time() - start > timeout:379 if time.time() - start > timeout:
367 break380 break
368 381
369382
370def is_cloud_managed(fetch=fetch):383def is_cloud_managed(fetch=fetch):
371 """384 """
@@ -380,5 +393,6 @@
380 connect_timeout=5)393 connect_timeout=5)
381 except FetchError:394 except FetchError:
382 return False395 return False
383 instance_data = _extract_ec2_instance_data(raw_user_data, int(launch_index))396 instance_data = _extract_ec2_instance_data(
397 raw_user_data, int(launch_index))
384 return instance_data is not None398 return instance_data is not None

Subscribers

People subscribed via source and target branches

to all changes: