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
1=== modified file 'charmhelpers/contrib/openstack/amulet/utils.py'
2--- charmhelpers/contrib/openstack/amulet/utils.py 2014-06-20 13:27:58 +0000
3+++ charmhelpers/contrib/openstack/amulet/utils.py 2014-06-24 13:58:27 +0000
4@@ -1,4 +1,7 @@
5 import logging
6+import os
7+import time
8+import urllib
9
10 import glanceclient.v1.client as glance_client
11 import keystoneclient.v2_0 as keystone_client
12@@ -149,3 +152,58 @@
13 endpoint_type='publicURL')
14 return nova_client.Client(username=user, api_key=password,
15 project_id=tenant, auth_url=ep)
16+
17+ def create_cirros_image(self, glance, image_name):
18+ """Download the latest cirros image and upload it to glance."""
19+ http_proxy = os.getenv('AMULET_HTTP_PROXY')
20+ self.log.debug('AMULET_HTTP_PROXY: {}'.format(http_proxy))
21+ if http_proxy:
22+ proxies = {'http': http_proxy}
23+ opener = urllib.FancyURLopener(proxies)
24+ else:
25+ opener = urllib.FancyURLopener()
26+
27+ f = opener.open("http://download.cirros-cloud.net/version/released")
28+ version = f.read().strip()
29+ cirros_img = "tests/cirros-{}-x86_64-disk.img".format(version)
30+
31+ if not os.path.exists(cirros_img):
32+ cirros_url = "http://{}/{}/{}".format("download.cirros-cloud.net",
33+ version, cirros_img)
34+ opener.retrieve(cirros_url, cirros_img)
35+ f.close()
36+
37+ with open(cirros_img) as f:
38+ image = glance.images.create(name=image_name, is_public=True,
39+ disk_format='qcow2',
40+ container_format='bare', data=f)
41+ return image
42+
43+ def delete_image(self, glance, image):
44+ """Delete the specified image."""
45+ glance.images.delete(image)
46+
47+ def create_instance(self, nova, image_name, instance_name, flavor):
48+ """Create the specified instance."""
49+ image = nova.images.find(name=image_name)
50+ flavor = nova.flavors.find(name=flavor)
51+ instance = nova.servers.create(name=instance_name, image=image,
52+ flavor=flavor)
53+
54+ count = 1
55+ status = instance.status
56+ while status == 'BUILD' and count < 10:
57+ time.sleep(5)
58+ instance = nova.servers.get(instance.id)
59+ status = instance.status
60+ self.log.debug('instance status: {}'.format(status))
61+ count += 1
62+
63+ if status == 'BUILD':
64+ return None
65+
66+ return instance
67+
68+ def delete_instance(self, nova, instance):
69+ """Delete the specified instance."""
70+ nova.servers.delete(instance)

Subscribers

People subscribed via source and target branches