Merge lp:~tpatil/nova/bug737240 into lp:~hudson-openstack/nova/trunk

Proposed by Tushar Patil
Status: Merged
Approved by: Jay Pipes
Approved revision: 828
Merged at revision: 834
Proposed branch: lp:~tpatil/nova/bug737240
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 169 lines (+106/-7)
2 files modified
contrib/boto_v6/ec2/connection.py (+100/-0)
smoketests/sysadmin_smoketests.py (+6/-7)
To merge this branch: bzr merge lp:~tpatil/nova/bug737240
Reviewer Review Type Date Requested Status
Jay Pipes (community) Approve
Todd Willey (community) Approve
Devin Carlen (community) Approve
Review via email: mp+54046@code.launchpad.net

Description of the change

Added run_instances method to the connection.py of the contrib/boto_v6/ec2 which would return ReservationV6 object instead of Reservation in order to access attribute dns_name_v6 of an instance.

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve
Revision history for this message
Tushar Patil (tpatil) wrote :

After adding run_instances method to the contrib/boto_v6/ec2/connection.py, netadmin_smoketests are failing for ipv6. There is no issue for ipv4.

I am setting it back to work in progress. fix will come soon.

Revision history for this message
Todd Willey (xtoddx) :
review: Approve
Revision history for this message
Jay Pipes (jaypipes) wrote :

lgtm3. nice job, Tushar.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'contrib/boto_v6/ec2/connection.py'
2--- contrib/boto_v6/ec2/connection.py 2011-01-12 03:05:27 +0000
3+++ contrib/boto_v6/ec2/connection.py 2011-03-18 21:36:33 +0000
4@@ -4,8 +4,10 @@
5 @author: Nachi Ueno <ueno.nachi@lab.ntt.co.jp>
6 '''
7 import boto
8+import base64
9 import boto.ec2
10 from boto_v6.ec2.instance import ReservationV6
11+from boto.ec2.securitygroup import SecurityGroup
12
13
14 class EC2ConnectionV6(boto.ec2.EC2Connection):
15@@ -39,3 +41,101 @@
16 self.build_filter_params(params, filters)
17 return self.get_list('DescribeInstancesV6', params,
18 [('item', ReservationV6)])
19+
20+ def run_instances(self, image_id, min_count=1, max_count=1,
21+ key_name=None, security_groups=None,
22+ user_data=None, addressing_type=None,
23+ instance_type='m1.small', placement=None,
24+ kernel_id=None, ramdisk_id=None,
25+ monitoring_enabled=False, subnet_id=None,
26+ block_device_map=None):
27+ """
28+ Runs an image on EC2.
29+
30+ :type image_id: string
31+ :param image_id: The ID of the image to run
32+
33+ :type min_count: int
34+ :param min_count: The minimum number of instances to launch
35+
36+ :type max_count: int
37+ :param max_count: The maximum number of instances to launch
38+
39+ :type key_name: string
40+ :param key_name: The name of the key pair with which to
41+ launch instances
42+
43+ :type security_groups: list of strings
44+ :param security_groups: The names of the security groups with
45+ which to associate instances
46+
47+ :type user_data: string
48+ :param user_data: The user data passed to the launched instances
49+
50+ :type instance_type: string
51+ :param instance_type: The type of instance to run
52+ (m1.small, m1.large, m1.xlarge)
53+
54+ :type placement: string
55+ :param placement: The availability zone in which to launch
56+ the instances
57+
58+ :type kernel_id: string
59+ :param kernel_id: The ID of the kernel with which to
60+ launch the instances
61+
62+ :type ramdisk_id: string
63+ :param ramdisk_id: The ID of the RAM disk with which to
64+ launch the instances
65+
66+ :type monitoring_enabled: bool
67+ :param monitoring_enabled: Enable CloudWatch monitoring
68+ on the instance.
69+
70+ :type subnet_id: string
71+ :param subnet_id: The subnet ID within which to launch
72+ the instances for VPC.
73+
74+ :type block_device_map:
75+ :class:`boto.ec2.blockdevicemapping.BlockDeviceMapping`
76+ :param block_device_map: A BlockDeviceMapping data structure
77+ describing the EBS volumes associated
78+ with the Image.
79+
80+ :rtype: Reservation
81+ :return: The :class:`boto.ec2.instance.ReservationV6`
82+ associated with the request for machines
83+ """
84+ params = {'ImageId': image_id,
85+ 'MinCount': min_count,
86+ 'MaxCount': max_count}
87+ if key_name:
88+ params['KeyName'] = key_name
89+ if security_groups:
90+ l = []
91+ for group in security_groups:
92+ if isinstance(group, SecurityGroup):
93+ l.append(group.name)
94+ else:
95+ l.append(group)
96+ self.build_list_params(params, l, 'SecurityGroup')
97+ if user_data:
98+ params['UserData'] = base64.b64encode(user_data)
99+ if addressing_type:
100+ params['AddressingType'] = addressing_type
101+ if instance_type:
102+ params['InstanceType'] = instance_type
103+ if placement:
104+ params['Placement.AvailabilityZone'] = placement
105+ if kernel_id:
106+ params['KernelId'] = kernel_id
107+ if ramdisk_id:
108+ params['RamdiskId'] = ramdisk_id
109+ if monitoring_enabled:
110+ params['Monitoring.Enabled'] = 'true'
111+ if subnet_id:
112+ params['SubnetId'] = subnet_id
113+ if block_device_map:
114+ block_device_map.build_list_params(params)
115+ return self.get_object('RunInstances', params,
116+ ReservationV6, verb='POST')
117
118=== modified file 'smoketests/sysadmin_smoketests.py'
119--- smoketests/sysadmin_smoketests.py 2011-02-23 02:04:08 +0000
120+++ smoketests/sysadmin_smoketests.py 2011-03-18 21:36:33 +0000
121@@ -34,8 +34,6 @@
122 from smoketests import flags
123 from smoketests import base
124
125-
126-
127 FLAGS = flags.FLAGS
128 flags.DEFINE_string('bundle_kernel', 'openwrt-x86-vmlinuz',
129 'Local kernel file to use for bundling tests')
130@@ -46,6 +44,8 @@
131 TEST_BUCKET = '%s_bucket' % TEST_PREFIX
132 TEST_KEY = '%s_key' % TEST_PREFIX
133 TEST_GROUP = '%s_group' % TEST_PREFIX
134+
135+
136 class ImageTests(base.UserSmokeTestCase):
137 def test_001_can_bundle_image(self):
138 self.assertTrue(self.bundle_image(FLAGS.bundle_image))
139@@ -148,7 +148,8 @@
140 self.fail('could not ping instance')
141
142 if FLAGS.use_ipv6:
143- if not self.wait_for_ping(self.data['instance'].ip_v6, "ping6"):
144+ if not self.wait_for_ping(self.data['instance'].dns_name_v6,
145+ "ping6"):
146 self.fail('could not ping instance v6')
147
148 def test_005_can_ssh_to_private_ip(self):
149@@ -157,7 +158,7 @@
150 self.fail('could not ssh to instance')
151
152 if FLAGS.use_ipv6:
153- if not self.wait_for_ssh(self.data['instance'].ip_v6,
154+ if not self.wait_for_ssh(self.data['instance'].dns_name_v6,
155 TEST_KEY):
156 self.fail('could not ssh to instance v6')
157
158@@ -284,10 +285,8 @@
159 self.conn.terminate_instances([self.data['instance'].id])
160 self.conn.delete_key_pair(TEST_KEY)
161
162-
163 if __name__ == "__main__":
164 suites = {'image': unittest.makeSuite(ImageTests),
165 'instance': unittest.makeSuite(InstanceTests),
166- 'volume': unittest.makeSuite(VolumeTests)
167- }
168+ 'volume': unittest.makeSuite(VolumeTests)}
169 sys.exit(base.run_tests(suites))