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
1=== modified file 'landscape/broker/registration.py'
2--- landscape/broker/registration.py 2009-12-07 10:31:31 +0000
3+++ landscape/broker/registration.py 2010-04-22 05:59:21 +0000
4@@ -5,7 +5,6 @@
5
6 from twisted.internet.defer import Deferred
7
8-from landscape.lib.twisted_util import gather_results
9 from landscape.lib.bpickle import loads
10 from landscape.lib.log import log_failure
11 from landscape.lib.fetch import fetch, FetchError
12@@ -24,16 +23,21 @@
13
14
15 def persist_property(name):
16+
17 def get(self):
18 return self._persist.get(name)
19+
20 def set(self, value):
21 self._persist.set(name, value)
22+
23 return property(get, set)
24
25
26 def config_property(name):
27+
28 def get(self):
29 return getattr(self._config, name)
30+
31 return property(get)
32
33
34@@ -118,30 +122,40 @@
35 self._exchange.exchange()
36 return result
37
38+ def _get_data(self, path, accumulate):
39+ """
40+ Get data at C{path} on the EC2 API endpoint, and add the result to the
41+ C{accumulate} list.
42+ """
43+ return self._fetch_async(EC2_API + path).addCallback(accumulate.append)
44+
45 def _fetch_ec2_data(self):
46+ """Retrieve available EC2 information, if in a EC2 compatible cloud."""
47 id = self._identity
48 if self._cloud and not id.secure_id:
49 # Fetch data from the EC2 API, to be used later in the registration
50 # process
51- registration_data = gather_results([
52- # We ignore errors from user-data because it's common for the
53- # URL to return a 404 when the data is unavailable.
54- self._fetch_async(EC2_API + "/user-data")
55- .addErrback(log_failure),
56- # The rest of the fetches don't get protected because we just
57- # fall back to regular registration if any of them don't work.
58- self._fetch_async(EC2_API + "/meta-data/instance-id"),
59- self._fetch_async(EC2_API + "/meta-data/reservation-id"),
60- self._fetch_async(EC2_API + "/meta-data/local-hostname"),
61- self._fetch_async(EC2_API + "/meta-data/public-hostname"),
62- self._fetch_async(EC2_API + "/meta-data/ami-launch-index"),
63- self._fetch_async(EC2_API + "/meta-data/kernel-id"),
64- self._fetch_async(EC2_API + "/meta-data/ramdisk-id"),
65- self._fetch_async(EC2_API + "/meta-data/ami-id"),
66- ],
67- consume_errors=True)
68+ # We ignore errors from user-data because it's common for the
69+ # URL to return a 404 when the data is unavailable.
70+ ec2_data = []
71+ deferred = self._fetch_async(EC2_API + "/user-data").addErrback(
72+ log_failure).addCallback(ec2_data.append)
73+ paths = [
74+ "/meta-data/instance-id",
75+ "/meta-data/reservation-id",
76+ "/meta-data/local-hostname",
77+ "/meta-data/public-hostname",
78+ "/meta-data/ami-launch-index",
79+ "/meta-data/kernel-id",
80+ "/meta-data/ramdisk-id",
81+ "/meta-data/ami-id"]
82+ # We're not using a DeferredList here because we want to keep the
83+ # number of connections to the backend minimal. See lp:567515.
84+ for path in paths:
85+ deferred.addCallback(
86+ lambda ignore, path=path: self._get_data(path, ec2_data))
87
88- def record_data(ec2_data):
89+ def record_data(ignore):
90 """Record the instance data returned by the EC2 API."""
91 (raw_user_data, instance_key, reservation_key,
92 local_hostname, public_hostname, launch_index,
93@@ -176,9 +190,8 @@
94 log_failure(error, msg="Got error while fetching meta-data: %r"
95 % (error.value,))
96
97- # It sucks that this deferred is never returned
98- registration_data.addCallback(record_data)
99- registration_data.addErrback(log_error)
100+ deferred.addCallback(record_data)
101+ deferred.addErrback(log_error)
102
103 def _handle_exchange_done(self):
104 """Registered handler for the C{"exchange-done"} event.
105@@ -226,9 +239,9 @@
106 self._exchange.send(message)
107 elif id.account_name:
108 with_tags = ["", u"and tags %s " % tags][bool(tags)]
109- logging.info(u"Queueing message to register with account %r %s"
110- "as an EC2 instance." % (
111- id.account_name, with_tags,))
112+ logging.info(
113+ u"Queueing message to register with account %r %s"
114+ u"as an EC2 instance." % (id.account_name, with_tags))
115 message = {"type": "register-cloud-vm",
116 "otp": None,
117 "hostname": socket.getfqdn(),
118@@ -365,7 +378,7 @@
119 time.sleep(1)
120 if time.time() - start > timeout:
121 break
122-
123+
124
125 def is_cloud_managed(fetch=fetch):
126 """
127@@ -380,5 +393,6 @@
128 connect_timeout=5)
129 except FetchError:
130 return False
131- instance_data = _extract_ec2_instance_data(raw_user_data, int(launch_index))
132+ instance_data = _extract_ec2_instance_data(
133+ raw_user_data, int(launch_index))
134 return instance_data is not None

Subscribers

People subscribed via source and target branches

to all changes: