summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2014-09-05 13:50:31 (GMT)
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2014-09-05 13:51:12 (GMT)
commitba7d1d1ed3bad002ce36e5d4adf4e3794625091a (patch)
treecb122e0a819e2e9aa593ae0d8110529304479d51
parentaea1029044b7e0d4578f3896bf85898f33791c89 (diff)
downloadmorph-baserock/pedroalvarez/openstack-check-improvements.tar.gz
Check OpenStack credentials in openstack.checkbaserock/pedroalvarez/openstack-check-improvements
If the credentials are wrong, then morph will fail before attempting the OpenStack deployment. To achieve that openstack.check will attempt to run `glance image-list`.
-rwxr-xr-xmorphlib/exts/openstack.check48
-rwxr-xr-xmorphlib/exts/openstack.write14
2 files changed, 49 insertions, 13 deletions
diff --git a/morphlib/exts/openstack.check b/morphlib/exts/openstack.check
index b517301..d9d3ef2 100755
--- a/morphlib/exts/openstack.check
+++ b/morphlib/exts/openstack.check
@@ -17,6 +17,8 @@
'''Preparatory checks for Morph 'openstack' write extension'''
import cliapp
+import os
+import urlparse
import morphlib.writeexts
@@ -34,4 +36,50 @@ class OpenStackCheckExtension(morphlib.writeexts.WriteExtension):
'Use the `ssh-rsync` write extension to deploy upgrades to an '
'existing remote system.')
+ location = args[0]
+ self.check_location(location)
+
+ os_params = self.get_openstack_parameters()
+
+ self.check_openstack_parameters(location, os_params)
+
+ def get_openstack_parameters(self):
+ '''Check the environment variables needed and returns all.
+
+ The environment variables are described in the class documentation.
+ '''
+
+ keys = ('OPENSTACK_USER', 'OPENSTACK_TENANT',
+ 'OPENSTACK_IMAGENAME', 'OPENSTACK_PASSWORD')
+ for key in keys:
+ if key not in os.environ:
+ raise cliapp.AppException(key + ' was not given')
+ return (os.environ[key] for key in keys)
+
+
+ def check_location(self, location):
+ x = urlparse.urlparse(location)
+ if x.scheme not in ['http', 'https']:
+ raise cliapp.AppException('URL schema must be http or https in %s' \
+ % location)
+ if (x.path != '/v2.0' and x.path != '/v2.0/'):
+ raise cliapp.AppException('API version must be v2.0 in %s'\
+ % location)
+
+ def check_openstack_parameters(self, auth_url, os_params):
+ '''Check OpenStack credentials using glance image-list'''
+ self.status(msg='Checking OpenStack credentials...')
+
+ username, tenant_name, image_name, password = os_params
+ cmdline = ['glance',
+ '--os-username', username,
+ '--os-tenant-name', tenant_name,
+ '--os-password', password,
+ '--os-auth-url', auth_url,
+ 'image-list']
+ try:
+ cliapp.runcmd(cmdline)
+ except cliapp.AppException:
+ raise cliapp.AppException('Wrong OpenStack credentals.')
+
OpenStackCheckExtension().run()
diff --git a/morphlib/exts/openstack.write b/morphlib/exts/openstack.write
index 8ee8767..ac2e2c8 100755
--- a/morphlib/exts/openstack.write
+++ b/morphlib/exts/openstack.write
@@ -96,27 +96,15 @@ class OpenStackWriteExtension(morphlib.writeexts.WriteExtension):
self.unmount(mp)
def get_openstack_parameters(self):
- '''Check the environment variables needed and returns all.
+ '''Get the environment variables needed.
The environment variables are described in the class documentation.
'''
keys = ('OPENSTACK_USER', 'OPENSTACK_TENANT',
'OPENSTACK_IMAGENAME', 'OPENSTACK_PASSWORD')
- for key in keys:
- if key not in os.environ:
- raise cliapp.AppException(key + ' was not given')
return (os.environ[key] for key in keys)
- def check_location(self, location):
- x = urlparse.urlparse(location)
- if x.scheme != 'http':
- raise cliapp.AppException('URL schema must be http in %s' \
- % location)
- if (x.path != '/v2.0' and x.path != '/v2.0/'):
- raise cliapp.AppException('API version must be v2.0 in %s'\
- % location)
-
def configure_openstack_image(self, raw_disk, auth_url, os_params):
'''Configure the image in OpenStack using glance-client'''
self.status(msg='Configuring OpenStack image...')