def _generate_os_env(self): lines = list() lines.append('# Openstack stuff') lines.extend(self._make_export_cfg('OS_PASSWORD', ('passwords', 'horizon_keystone_admin'))) key_users = keystone.get_shared_users(self.cfg) key_ends = keystone.get_shared_params(self.cfg) lines.extend(self._make_export('OS_TENANT_NAME', key_users['DEMO_TENANT_NAME'])) lines.extend(self._make_export('OS_USERNAME', key_users['DEMO_USER_NAME'])) lines.extend(self._make_export('OS_AUTH_URL', key_ends['SERVICE_ENDPOINT'])) lines.append("") return lines
def _get_token(self): LOG.info("Fetching your keystone admin token so that we can perform image uploads.") pwd = self.cfg.get("passwords", "horizon_keystone_admin") key_users = keystone.get_shared_users(self.cfg) key_params = keystone.get_shared_params(self.cfg) keystone_service_url = key_params['SERVICE_ENDPOINT'] keystone_token_url = "%s/tokens" % (keystone_service_url) #form the post json data data = json.dumps( { "auth": { "passwordCredentials": { "username": key_users['ADMIN_USER_NAME'], "password": pwd, }, "tenantName": key_users['ADMIN_TENANT_NAME'], } }) # prepare the request request = urllib2.Request(keystone_token_url) # post body request.add_data(data) # content type request.add_header('Content-Type', 'application/json') # make the request LOG.info("Getting your token from url [%s], please wait..." % (keystone_token_url)) LOG.debug("With post json data %s" % (data)) response = urllib2.urlopen(request) token = json.loads(response.read()) if (not token or not type(token) is dict or not token.get('access') or not type(token.get('access')) is dict or not token.get('access').get('token') or not type(token.get('access').get('token')) is dict or not token.get('access').get('token').get('id')): msg = "Response from url [%s] did not match expected json format." % (keystone_token_url) raise IOError(msg) #basic checks passed, extract it! tok = token['access']['token']['id'] LOG.debug("Got token %s" % (tok)) return tok
def _generate_nova_env(self): lines = list() lines.append('# Nova stuff') lines.extend(self._make_export_cfg('NOVA_PASSWORD', ('passwords', 'horizon_keystone_admin'))) key_users = keystone.get_shared_users(self.cfg) key_ends = keystone.get_shared_params(self.cfg) lines.extend(self._make_export('NOVA_URL', key_ends['SERVICE_ENDPOINT'])) lines.extend(self._make_export('NOVA_PROJECT_ID', key_users['DEMO_TENANT_NAME'])) lines.extend(self._make_export('NOVA_USERNAME', key_users['DEMO_USER_NAME'])) lines.extend(self._make_export_cfg('NOVA_VERSION', ('nova', 'nova_version'))) lines.extend(self._make_export_cfg('NOVA_CERT', ('extern', 'nova_cert_fn'))) lines.append("") return lines