Merge lp:~fwierzbicki/txaws/break-out-parse-instance into lp:txaws

Proposed by Frank Wierzbicki
Status: Merged
Approved by: Jamu Kakar
Approved revision: 82
Merged at revision: 83
Proposed branch: lp:~fwierzbicki/txaws/break-out-parse-instance
Merge into: lp:txaws
Diff against target: 110 lines (+48/-27)
2 files modified
txaws/ec2/client.py (+42/-25)
txaws/testing/ec2.py (+6/-2)
To merge this branch: bzr merge lp:~fwierzbicki/txaws/break-out-parse-instance
Reviewer Review Type Date Requested Status
Jamu Kakar Approve
Duncan McGreggor Approve
Review via email: mp+58340@code.launchpad.net

Description of the change

This branch breaks out the parsing of an instance from the parsing of an instance set for use in Landscape where we need to extend Instance with our own field.

It also adds a query_factory parameter to FakeEC2Client to match the real EC2Client.

To post a comment you must log in.
Revision history for this message
Duncan McGreggor (oubiwann) wrote :

This is something I wanted to do ages ago, so +1 in general.

One comment for possible change: in the fake client constructor, it might be better to put the new parameter at the end. Esthetically, that's a little odd, but this way it wouldn't interfere with anyone that has been passing unnamed parameters.

That being said, there probably aren't a lot of users of the fake client...

I'll set to approve, pending one more approval.

review: Approve
82. By Frank Wierzbicki

Put query_factory at the end in case someone somewhere is passing parameters by
position. Also fix bug in query_factory assignment.

Revision history for this message
Frank Wierzbicki (fwierzbicki) wrote :

> This is something I wanted to do ages ago, so +1 in general.
>
> One comment for possible change: in the fake client constructor, it might be
> better to put the new parameter at the end. Esthetically, that's a little odd,
> but this way it wouldn't interfere with anyone that has been passing unnamed
> parameters.
That's reasonable, I moved query_factory to the end.

> That being said, there probably aren't a lot of users of the fake client...
>
> I'll set to approve, pending one more approval.

Revision history for this message
Jamu Kakar (jkakar) wrote :

[1]

+ def _parse_instance(self, instance_data, reservation):

Please add a docstring to this method with @param and @return
components.

Also, it sounds like you'll be calling this method from Landscape
code... do we want it to be private, in that case? It could change
under you if someone else refactors it without knowing its used in
Landscape.

review: Needs Information
Revision history for this message
Jamu Kakar (jkakar) wrote :

I guess the perfect fix would be to completely decouple the parsing
logic from the client, but that's probably more work than you want to
do. Anyway, if you're find with calling a private method I'm fine
with this branch, assuming it _parse_instance gets a docstring.

Nice one, +1! :)

review: Approve
Revision history for this message
Frank Wierzbicki (fwierzbicki) wrote :

Hey Jamu! We're working together again already :)

> [1]
>
> + def _parse_instance(self, instance_data, reservation):
>
> Please add a docstring to this method with @param and @return
> components.
Oops, right - I added these to all of the methods I touched.

>
> Also, it sounds like you'll be calling this method from Landscape
> code... do we want it to be private, in that case? It could change
> under you if someone else refactors it without knowing its used in
> Landscape.
That sounds reasonable - I made all of the potentially overridden methods for this pass public.

BTW I will probably be changing many of the other methods in the same way in one or more future branches.

83. By Frank Wierzbicki

Add proper docstrings and make methods that we may override public.

Revision history for this message
Frank Wierzbicki (fwierzbicki) wrote :

> I guess the perfect fix would be to completely decouple the parsing
> logic from the client, but that's probably more work than you want to
> do. Anyway, if you're find with calling a private method I'm fine
> with this branch, assuming it _parse_instance gets a docstring.
Oops got to work before reading the follow on comment - do you think I should go back to private methods? Going public does mean that the public API for this class is going to probably get to be too big for some...

> Nice one, +1! :)

84. By Frank Wierzbicki

Revert back to private methods for parsing -- later we may want to pull the
parsing out of client.py and then public methods would be reasonable.

Revision history for this message
Frank Wierzbicki (fwierzbicki) wrote :

> I guess the perfect fix would be to completely decouple the parsing
> logic from the client, but that's probably more work than you want to
> do. Anyway, if you're find with calling a private method I'm fine
> with this branch, assuming it _parse_instance gets a docstring.
I went ahead and moved those methods back to being private pending the need to move the parsing out.

Revision history for this message
Jamu Kakar (jkakar) wrote :

I think keeping them private pending moving the parsing out is best
for now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'txaws/ec2/client.py'
2--- txaws/ec2/client.py 2011-03-21 08:55:48 +0000
3+++ txaws/ec2/client.py 2011-04-19 17:35:56 +0000
4@@ -43,35 +43,52 @@
5 return d.addCallback(self._parse_describe_instances)
6
7 def _parse_instances_set(self, root, reservation):
8+ """Parse the instances data out of an XML payload.
9+
10+ @param root: the root node of the XML payload.
11+ @param reservation: the L{Reservation} associtated with the
12+ instances from the response.
13+ @return a C{list} of L{Instance}.
14+ """
15 instances = []
16 for instance_data in root.find("instancesSet"):
17- instance_id = instance_data.findtext("instanceId")
18- instance_state = instance_data.find(
19- "instanceState").findtext("name")
20- instance_type = instance_data.findtext("instanceType")
21- image_id = instance_data.findtext("imageId")
22- private_dns_name = instance_data.findtext("privateDnsName")
23- dns_name = instance_data.findtext("dnsName")
24- key_name = instance_data.findtext("keyName")
25- ami_launch_index = instance_data.findtext("amiLaunchIndex")
26- launch_time = instance_data.findtext("launchTime")
27- placement = instance_data.find("placement").findtext(
28- "availabilityZone")
29- products = []
30- product_codes = instance_data.find("productCodes")
31- if product_codes:
32- for product_data in instance_data.find("productCodes"):
33- products.append(product_data.text)
34- kernel_id = instance_data.findtext("kernelId")
35- ramdisk_id = instance_data.findtext("ramdiskId")
36- instance = model.Instance(
37- instance_id, instance_state, instance_type, image_id,
38- private_dns_name, dns_name, key_name, ami_launch_index,
39- launch_time, placement, products, kernel_id, ramdisk_id,
40- reservation=reservation)
41- instances.append(instance)
42+ instances.append(self._parse_instance(instance_data, reservation))
43 return instances
44
45+ def _parse_instance(self, instance_data, reservation):
46+ """Parse the instance data out of an XML payload.
47+
48+ @param instance_data: an XML node containing instance data.
49+ @param reservation: the L{Reservation} associatated with the
50+ instance.
51+ @return an L{Instance}.
52+ """
53+ instance_id = instance_data.findtext("instanceId")
54+ instance_state = instance_data.find(
55+ "instanceState").findtext("name")
56+ instance_type = instance_data.findtext("instanceType")
57+ image_id = instance_data.findtext("imageId")
58+ private_dns_name = instance_data.findtext("privateDnsName")
59+ dns_name = instance_data.findtext("dnsName")
60+ key_name = instance_data.findtext("keyName")
61+ ami_launch_index = instance_data.findtext("amiLaunchIndex")
62+ launch_time = instance_data.findtext("launchTime")
63+ placement = instance_data.find("placement").findtext(
64+ "availabilityZone")
65+ products = []
66+ product_codes = instance_data.find("productCodes")
67+ if product_codes:
68+ for product_data in instance_data.find("productCodes"):
69+ products.append(product_data.text)
70+ kernel_id = instance_data.findtext("kernelId")
71+ ramdisk_id = instance_data.findtext("ramdiskId")
72+ instance = model.Instance(
73+ instance_id, instance_state, instance_type, image_id,
74+ private_dns_name, dns_name, key_name, ami_launch_index,
75+ launch_time, placement, products, kernel_id, ramdisk_id,
76+ reservation=reservation)
77+ return instance
78+
79 def _parse_describe_instances(self, xml_bytes):
80 """
81 Parse the reservations XML payload that is returned from an AWS
82
83=== modified file 'txaws/testing/ec2.py'
84--- txaws/testing/ec2.py 2009-10-14 14:41:28 +0000
85+++ txaws/testing/ec2.py 2011-04-19 17:35:56 +0000
86@@ -10,13 +10,18 @@
87
88 from txaws.ec2.model import Keypair, SecurityGroup
89
90+
91 class FakeEC2Client(object):
92
93 def __init__(self, creds, endpoint, instances=None, keypairs=None,
94 volumes=None, key_material="", security_groups=None,
95- snapshots=None, addresses=None, availability_zones=None):
96+ snapshots=None, addresses=None, availability_zones=None,
97+ query_factory=None):
98+
99 self.creds = creds
100 self.endpoint = endpoint
101+ self.query_factory = query_factory
102+
103 self.instances = instances or []
104 self.keypairs = keypairs or []
105 self.keypairs_deleted = []
106@@ -141,4 +146,3 @@
107 except:
108 failure = Failure()
109 return fail(failure)
110-

Subscribers

People subscribed via source and target branches