txawsteam team mailing list archive
-
txawsteam team
-
Mailing list archive
-
Message #00063
[Merge] lp:~oubiwann/txaws/415491-instance-object into lp:txaws
Duncan McGreggor has proposed merging lp:~oubiwann/txaws/415491-instance-object into lp:txaws.
Requested reviews:
txAWS Team (txawsteam)
This is ready for review.
--
https://code.launchpad.net/~oubiwann/txaws/415491-instance-object/+merge/10505
Your team txAWS Team is subscribed to branch lp:txaws.
=== 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 @@
"""An Amazon EC2 Instance.
@attrib instance_id: The instance ID of this instance.
- @attrib instance_state: The state of this instance.
+ @attrib instance_state: The current state of this instance.
+ @attrib instance_type: The instance type.
+ @attrib image_id: Image ID of the AMI used to launch the instance.
+ @attrib private_dns_name: The private DNS name assigned to the instance.
+ This DNS name can only be used inside the Amazon EC2 network. This
+ element remains empty until the instance enters a running state.
+ @attrib dns_name: The public DNS name assigned to the instance. This DNS
+ name is contactable from outside the Amazon EC2 network. This element
+ remains empty until the instance enters a running state.
+ @attrib key_name: If this instance was launched with an associated key
+ pair, this displays the key pair name.
+ @attrib ami_launch_index: The AMI launch index, which can be used to find
+ this instance within the launch group.
+ @attrib product_codes: Product codes attached to this instance.
+ @attrib launch_time: The time the instance launched.
+ @attrib placement: The location where the instance launched.
+ @attrib kernel_id: Optional. Kernel associated with this instance.
+ @attrib ramdisk_id: Optional. RAM disk associated with this instance.
"""
-
- def __init__(self, instance_id, instance_state, reservation=None):
+ def __init__(self, instance_id, instance_state, instance_type="",
+ image_id="", private_dns_name="", dns_name="", key_name="",
+ ami_launch_index="", launch_time="", placement="",
+ product_codes=[], kernel_id=None, ramdisk_id=None,
+ reservation=None):
self.instance_id = instance_id
self.instance_state = instance_state
+ self.instance_type = instance_type
+ self.image_id = image_id
+ self.private_dns_name = private_dns_name
+ self.dns_name = dns_name
+ self.key_name = key_name
+ self.ami_launch_index = ami_launch_index
+ self.launch_time = launch_time
+ self.placement = placement
+ self.product_codes = product_codes
+ self.kernel_id = kernel_id
+ self.ramdisk_id = ramdisk_id
self.reservation = reservation
@@ -103,8 +134,35 @@
instance_state = instance_data.find(
self.name_space + 'instanceState').findtext(
self.name_space + 'name')
- instance = Instance(instance_id, instance_state,
- reservation=reservation)
+ instance_type = instance_data.findtext(
+ self.name_space + 'instanceType')
+ image_id = instance_data.findtext(self.name_space + 'imageId')
+ private_dns_name = instance_data.findtext(
+ self.name_space + 'privateDnsName')
+ dns_name = instance_data.findtext(self.name_space + 'dnsName')
+ key_name = instance_data.findtext(self.name_space + 'keyName')
+ ami_launch_index = instance_data.findtext(
+ self.name_space + 'amiLaunchIndex')
+ launch_time = instance_data.findtext(
+ self.name_space + 'launchTime')
+ placement = instance_data.find(
+ self.name_space + 'placement').findtext(
+ self.name_space + 'availabilityZone')
+ products = []
+ for product_data in instance_data.find(
+ self.name_space + 'productCodesSet'):
+ product_code = product_data.findtext(
+ self.name_space + 'productCode')
+ products.append(product_code)
+ kernel_id = instance_data.findtext(
+ self.name_space + 'kernelId')
+ ramdisk_id = instance_data.findtext(
+ self.name_space + 'ramdiskId')
+ instance = Instance(
+ instance_id, instance_state, instance_type, image_id,
+ private_dns_name, dns_name, key_name, ami_launch_index,
+ launch_time, placement, products, kernel_id, ramdisk_id,
+ reservation=reservation)
instances.append(instance)
results.extend(instances)
return results
=== 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 @@
<reason/>
<keyName>keyname</keyName>
<amiLaunchIndex>0</amiLaunchIndex>
- <productCodes/>
+ <productCodesSet>
+ <item>
+ <productCode>774F4FF8</productCode>
+ </item>
+ </productCodesSet>
+
<instanceType>c1.xlarge</instanceType>
<launchTime>2009-04-27T02:23:18.000Z</launchTime>
<placement>
@@ -91,6 +96,27 @@
self.assertEquals(reservation.groups, ["one", "two"])
+class InstanceTestCase(TXAWSTestCase):
+
+ def test_instance_creation(self):
+ instance = client.Instance(
+ "id1", "running", "type", "id2", "dns1", "dns2", "key", "ami",
+ "time", "placement", ["prod1", "prod2"], "id3", "id4")
+ self.assertEquals(instance.instance_id, "id1")
+ self.assertEquals(instance.instance_state, "running")
+ self.assertEquals(instance.instance_type, "type")
+ self.assertEquals(instance.image_id, "id2")
+ self.assertEquals(instance.private_dns_name, "dns1")
+ self.assertEquals(instance.dns_name, "dns2")
+ self.assertEquals(instance.key_name, "key")
+ self.assertEquals(instance.ami_launch_index, "ami")
+ self.assertEquals(instance.launch_time, "time")
+ self.assertEquals(instance.placement, "placement")
+ self.assertEquals(instance.product_codes, ["prod1", "prod2"])
+ self.assertEquals(instance.kernel_id, "id3")
+ self.assertEquals(instance.ramdisk_id, "id4")
+
+
class TestEC2Client(TXAWSTestCase):
def test_init_no_creds(self):
@@ -116,6 +142,24 @@
self.assertEquals(reservation.owner_id, "123456789012")
group = reservation.groups[0]
self.assertEquals(group, "default")
+ self.assertEquals(instance.instance_id, "i-abcdef01")
+ self.assertEquals(instance.instance_state, "running")
+ self.assertEquals(instance.instance_type, "c1.xlarge")
+ self.assertEquals(instance.image_id, "ami-12345678")
+ self.assertEquals(
+ instance.private_dns_name,
+ "domU-12-31-39-03-15-11.compute-1.internal")
+ self.assertEquals(
+ instance.dns_name,
+ "ec2-75-101-245-65.compute-1.amazonaws.com")
+ self.assertEquals(instance.key_name, "keyname")
+ self.assertEquals(instance.ami_launch_index, "0")
+ self.assertEquals(instance.launch_time, "2009-04-27T02:23:18.000Z")
+ self.assertEquals(instance.placement, "us-east-1c")
+ self.assertEquals(instance.product_codes, ["774F4FF8"])
+ self.assertEquals(instance.kernel_id, "aki-b51cf9dc")
+ self.assertEquals(instance.ramdisk_id, "ari-b31cf9da")
+
def test_parse_reservation(self):
ec2 = client.EC2Client(creds='foo')
Follow ups