Merge lp:~oubiwann/txaws/415491-instance-object into lp:~txawsteam/txaws/trunk

Proposed by Duncan McGreggor
Status: Merged
Merge reported by: Duncan McGreggor
Merged at revision: not available
Proposed branch: lp:~oubiwann/txaws/415491-instance-object
Merge into: lp:~txawsteam/txaws/trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~oubiwann/txaws/415491-instance-object
Reviewer Review Type Date Requested Status
Original txAWS Team Pending
Review via email: mp+10505@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Duncan McGreggor (oubiwann) wrote :

This is ready for review.

Revision history for this message
Robert Collins (lifeless) wrote :

+1

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'txaws/ec2/client.py'
--- txaws/ec2/client.py 2009-08-19 20:55:04 +0000
+++ txaws/ec2/client.py 2009-08-21 03:26:35 +0000
@@ -32,12 +32,43 @@
32 """An Amazon EC2 Instance.32 """An Amazon EC2 Instance.
3333
34 @attrib instance_id: The instance ID of this instance.34 @attrib instance_id: The instance ID of this instance.
35 @attrib instance_state: The state of this instance.35 @attrib instance_state: The current state of this instance.
36 @attrib instance_type: The instance type.
37 @attrib image_id: Image ID of the AMI used to launch the instance.
38 @attrib private_dns_name: The private DNS name assigned to the instance.
39 This DNS name can only be used inside the Amazon EC2 network. This
40 element remains empty until the instance enters a running state.
41 @attrib dns_name: The public DNS name assigned to the instance. This DNS
42 name is contactable from outside the Amazon EC2 network. This element
43 remains empty until the instance enters a running state.
44 @attrib key_name: If this instance was launched with an associated key
45 pair, this displays the key pair name.
46 @attrib ami_launch_index: The AMI launch index, which can be used to find
47 this instance within the launch group.
48 @attrib product_codes: Product codes attached to this instance.
49 @attrib launch_time: The time the instance launched.
50 @attrib placement: The location where the instance launched.
51 @attrib kernel_id: Optional. Kernel associated with this instance.
52 @attrib ramdisk_id: Optional. RAM disk associated with this instance.
36 """53 """
3754 def __init__(self, instance_id, instance_state, instance_type="",
38 def __init__(self, instance_id, instance_state, reservation=None):55 image_id="", private_dns_name="", dns_name="", key_name="",
56 ami_launch_index="", launch_time="", placement="",
57 product_codes=[], kernel_id=None, ramdisk_id=None,
58 reservation=None):
39 self.instance_id = instance_id59 self.instance_id = instance_id
40 self.instance_state = instance_state60 self.instance_state = instance_state
61 self.instance_type = instance_type
62 self.image_id = image_id
63 self.private_dns_name = private_dns_name
64 self.dns_name = dns_name
65 self.key_name = key_name
66 self.ami_launch_index = ami_launch_index
67 self.launch_time = launch_time
68 self.placement = placement
69 self.product_codes = product_codes
70 self.kernel_id = kernel_id
71 self.ramdisk_id = ramdisk_id
41 self.reservation = reservation72 self.reservation = reservation
4273
4374
@@ -103,8 +134,35 @@
103 instance_state = instance_data.find(134 instance_state = instance_data.find(
104 self.name_space + 'instanceState').findtext(135 self.name_space + 'instanceState').findtext(
105 self.name_space + 'name')136 self.name_space + 'name')
106 instance = Instance(instance_id, instance_state,137 instance_type = instance_data.findtext(
107 reservation=reservation)138 self.name_space + 'instanceType')
139 image_id = instance_data.findtext(self.name_space + 'imageId')
140 private_dns_name = instance_data.findtext(
141 self.name_space + 'privateDnsName')
142 dns_name = instance_data.findtext(self.name_space + 'dnsName')
143 key_name = instance_data.findtext(self.name_space + 'keyName')
144 ami_launch_index = instance_data.findtext(
145 self.name_space + 'amiLaunchIndex')
146 launch_time = instance_data.findtext(
147 self.name_space + 'launchTime')
148 placement = instance_data.find(
149 self.name_space + 'placement').findtext(
150 self.name_space + 'availabilityZone')
151 products = []
152 for product_data in instance_data.find(
153 self.name_space + 'productCodesSet'):
154 product_code = product_data.findtext(
155 self.name_space + 'productCode')
156 products.append(product_code)
157 kernel_id = instance_data.findtext(
158 self.name_space + 'kernelId')
159 ramdisk_id = instance_data.findtext(
160 self.name_space + 'ramdiskId')
161 instance = Instance(
162 instance_id, instance_state, instance_type, image_id,
163 private_dns_name, dns_name, key_name, ami_launch_index,
164 launch_time, placement, products, kernel_id, ramdisk_id,
165 reservation=reservation)
108 instances.append(instance)166 instances.append(instance)
109 results.extend(instances)167 results.extend(instances)
110 return results168 return results
111169
=== modified file 'txaws/ec2/tests/test_client.py'
--- txaws/ec2/tests/test_client.py 2009-08-18 21:56:36 +0000
+++ txaws/ec2/tests/test_client.py 2009-08-21 03:26:35 +0000
@@ -35,7 +35,12 @@
35 <reason/>35 <reason/>
36 <keyName>keyname</keyName>36 <keyName>keyname</keyName>
37 <amiLaunchIndex>0</amiLaunchIndex>37 <amiLaunchIndex>0</amiLaunchIndex>
38 <productCodes/>38 <productCodesSet>
39 <item>
40 <productCode>774F4FF8</productCode>
41 </item>
42 </productCodesSet>
43
39 <instanceType>c1.xlarge</instanceType>44 <instanceType>c1.xlarge</instanceType>
40 <launchTime>2009-04-27T02:23:18.000Z</launchTime>45 <launchTime>2009-04-27T02:23:18.000Z</launchTime>
41 <placement>46 <placement>
@@ -91,6 +96,27 @@
91 self.assertEquals(reservation.groups, ["one", "two"])96 self.assertEquals(reservation.groups, ["one", "two"])
9297
9398
99class InstanceTestCase(TXAWSTestCase):
100
101 def test_instance_creation(self):
102 instance = client.Instance(
103 "id1", "running", "type", "id2", "dns1", "dns2", "key", "ami",
104 "time", "placement", ["prod1", "prod2"], "id3", "id4")
105 self.assertEquals(instance.instance_id, "id1")
106 self.assertEquals(instance.instance_state, "running")
107 self.assertEquals(instance.instance_type, "type")
108 self.assertEquals(instance.image_id, "id2")
109 self.assertEquals(instance.private_dns_name, "dns1")
110 self.assertEquals(instance.dns_name, "dns2")
111 self.assertEquals(instance.key_name, "key")
112 self.assertEquals(instance.ami_launch_index, "ami")
113 self.assertEquals(instance.launch_time, "time")
114 self.assertEquals(instance.placement, "placement")
115 self.assertEquals(instance.product_codes, ["prod1", "prod2"])
116 self.assertEquals(instance.kernel_id, "id3")
117 self.assertEquals(instance.ramdisk_id, "id4")
118
119
94class TestEC2Client(TXAWSTestCase):120class TestEC2Client(TXAWSTestCase):
95 121
96 def test_init_no_creds(self):122 def test_init_no_creds(self):
@@ -116,6 +142,24 @@
116 self.assertEquals(reservation.owner_id, "123456789012")142 self.assertEquals(reservation.owner_id, "123456789012")
117 group = reservation.groups[0]143 group = reservation.groups[0]
118 self.assertEquals(group, "default")144 self.assertEquals(group, "default")
145 self.assertEquals(instance.instance_id, "i-abcdef01")
146 self.assertEquals(instance.instance_state, "running")
147 self.assertEquals(instance.instance_type, "c1.xlarge")
148 self.assertEquals(instance.image_id, "ami-12345678")
149 self.assertEquals(
150 instance.private_dns_name,
151 "domU-12-31-39-03-15-11.compute-1.internal")
152 self.assertEquals(
153 instance.dns_name,
154 "ec2-75-101-245-65.compute-1.amazonaws.com")
155 self.assertEquals(instance.key_name, "keyname")
156 self.assertEquals(instance.ami_launch_index, "0")
157 self.assertEquals(instance.launch_time, "2009-04-27T02:23:18.000Z")
158 self.assertEquals(instance.placement, "us-east-1c")
159 self.assertEquals(instance.product_codes, ["774F4FF8"])
160 self.assertEquals(instance.kernel_id, "aki-b51cf9dc")
161 self.assertEquals(instance.ramdisk_id, "ari-b31cf9da")
162
119163
120 def test_parse_reservation(self):164 def test_parse_reservation(self):
121 ec2 = client.EC2Client(creds='foo')165 ec2 = client.EC2Client(creds='foo')

Subscribers

People subscribed via source and target branches