Merge lp:~corey.bryant/charm-helpers/image-instance into lp:charm-helpers

Proposed by Corey Bryant
Status: Merged
Merged at revision: 172
Proposed branch: lp:~corey.bryant/charm-helpers/image-instance
Merge into: lp:charm-helpers
Diff against target: 70 lines (+58/-0)
1 file modified
charmhelpers/contrib/openstack/amulet/utils.py (+58/-0)
To merge this branch: bzr merge lp:~corey.bryant/charm-helpers/image-instance
Reviewer Review Type Date Requested Status
James Page Needs Fixing
Review via email: mp+224170@code.launchpad.net

Description of the change

Add openstack Amulet utility methods for using images/instances

To post a comment you must log in.
Revision history for this message
James Page (james-page) :
review: Needs Fixing
Revision history for this message
Corey Bryant (corey.bryant) wrote :

James,

Thanks for reviewing. I've pushed a new version that uses AMULET_HTTP_PROXY to set the proxy server.

Thanks,
Corey

Revision history for this message
James Troup (elmo) wrote :

Is there any reason not to use $http_proxy (sic) rather than a custom/Amulet specific variable name? $http_proxy is the de facto standard environment variable name.

Revision history for this message
Corey Bryant (corey.bryant) wrote :

I think we can probably use http_proxy instead. I'll give that a shot.
 Thanks for the comment!

On Mon, Jun 23, 2014 at 5:32 PM, James Troup <email address hidden>
wrote:

> Is there any reason not to use $http_proxy (sic) rather than a
> custom/Amulet specific variable name? $http_proxy is the de facto standard
> environment variable name.
> --
>
> https://code.launchpad.net/~corey.bryant/charm-helpers/image-instance/+merge/224170
> You are the owner of lp:~corey.bryant/charm-helpers/image-instance.
>

--
Regards,
Corey

Revision history for this message
Corey Bryant (corey.bryant) wrote :

> Is there any reason not to use $http_proxy (sic) rather than a custom/Amulet
> specific variable name? $http_proxy is the de facto standard environment
> variable name.

I don't know what the deal is but juju does not like http_proxy. juju deployment/status commands hang when it is set.

165. By Corey Bryant

Add openstack Amulet utility methods for using images/instances.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/contrib/openstack/amulet/utils.py'
--- charmhelpers/contrib/openstack/amulet/utils.py 2014-06-20 13:27:58 +0000
+++ charmhelpers/contrib/openstack/amulet/utils.py 2014-06-24 13:58:27 +0000
@@ -1,4 +1,7 @@
1import logging1import logging
2import os
3import time
4import urllib
25
3import glanceclient.v1.client as glance_client6import glanceclient.v1.client as glance_client
4import keystoneclient.v2_0 as keystone_client7import keystoneclient.v2_0 as keystone_client
@@ -149,3 +152,58 @@
149 endpoint_type='publicURL')152 endpoint_type='publicURL')
150 return nova_client.Client(username=user, api_key=password,153 return nova_client.Client(username=user, api_key=password,
151 project_id=tenant, auth_url=ep)154 project_id=tenant, auth_url=ep)
155
156 def create_cirros_image(self, glance, image_name):
157 """Download the latest cirros image and upload it to glance."""
158 http_proxy = os.getenv('AMULET_HTTP_PROXY')
159 self.log.debug('AMULET_HTTP_PROXY: {}'.format(http_proxy))
160 if http_proxy:
161 proxies = {'http': http_proxy}
162 opener = urllib.FancyURLopener(proxies)
163 else:
164 opener = urllib.FancyURLopener()
165
166 f = opener.open("http://download.cirros-cloud.net/version/released")
167 version = f.read().strip()
168 cirros_img = "tests/cirros-{}-x86_64-disk.img".format(version)
169
170 if not os.path.exists(cirros_img):
171 cirros_url = "http://{}/{}/{}".format("download.cirros-cloud.net",
172 version, cirros_img)
173 opener.retrieve(cirros_url, cirros_img)
174 f.close()
175
176 with open(cirros_img) as f:
177 image = glance.images.create(name=image_name, is_public=True,
178 disk_format='qcow2',
179 container_format='bare', data=f)
180 return image
181
182 def delete_image(self, glance, image):
183 """Delete the specified image."""
184 glance.images.delete(image)
185
186 def create_instance(self, nova, image_name, instance_name, flavor):
187 """Create the specified instance."""
188 image = nova.images.find(name=image_name)
189 flavor = nova.flavors.find(name=flavor)
190 instance = nova.servers.create(name=instance_name, image=image,
191 flavor=flavor)
192
193 count = 1
194 status = instance.status
195 while status == 'BUILD' and count < 10:
196 time.sleep(5)
197 instance = nova.servers.get(instance.id)
198 status = instance.status
199 self.log.debug('instance status: {}'.format(status))
200 count += 1
201
202 if status == 'BUILD':
203 return None
204
205 return instance
206
207 def delete_instance(self, nova, instance):
208 """Delete the specified instance."""
209 nova.servers.delete(instance)

Subscribers

People subscribed via source and target branches