Merge branch 'master' of github.com:yahoo/Openstack-DevstackPy

Conflicts:
	devstack/components/keystone.py
This commit is contained in:
Joshua Harlow 2012-02-17 10:04:03 -08:00
commit 74a4a1ce19
3 changed files with 67 additions and 7 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash
# From devstack commit bd13b708f2 with some modifications
set +e
set -o errexit
# These are used by keystone commands below
export SERVICE_TOKEN=%SERVICE_TOKEN%

View File

@ -185,9 +185,7 @@ class KeystoneInstaller(comp.PythonInstallComponent):
mp.update(get_shared_params(self.cfg))
elif config_fn == MANAGE_DATA_CONF:
mp['ADMIN_PASSWORD'] = self.cfg.get('passwords', 'horizon_keystone_admin')
mp['ADMIN_USER_NAME'] = self.cfg.getdefaulted("keystone", "admin_user", MANAGE_ADMIN_USER)
mp['DEMO_USER_NAME'] = self.cfg.getdefaulted("keystone", "demo_user", MANAGE_DEMO_USER)
mp['INVIS_USER_NAME'] = self.cfg.getdefaulted("keystone", "invisible_user", MANAGE_INVIS_USER)
mp.update(get_shared_users(self.cfg))
mp.update(get_shared_params(self.cfg))
return mp
@ -211,9 +209,10 @@ class KeystoneRuntime(comp.PythonRuntime):
env['BIN_DIR'] = self.bindir
setup_cmd = MANAGE_CMD_ROOT + [tgt_fn]
LOG.info("Running (%s) command to initialize keystone." % (" ".join(setup_cmd)))
(sysout, stderr) = sh.execute(*setup_cmd, env_overrides=env, run_as_root=False)
(sysout, _) = sh.execute(*setup_cmd, env_overrides=env, run_as_root=False)
if sysout:
sh.write_file(settings.EC2RC_FN, sysout)
ec2rcfn = self.cfg.getdefaulted("keystone", "ec2_rc_fn", settings.EC2RC_FN)
sh.write_file(ec2rcfn, sysout.strip())
LOG.debug("Removing (%s) file since we successfully initialized keystone." % (tgt_fn))
sh.unlink(tgt_fn)
@ -230,6 +229,17 @@ class KeystoneRuntime(comp.PythonRuntime):
return APP_OPTIONS.get(app)
def get_shared_users(config):
mp = dict()
mp['ADMIN_USER_NAME'] = config.getdefaulted("keystone", "admin_user", MANAGE_ADMIN_USER)
mp['ADMIN_TENANT_NAME'] = mp['ADMIN_USER_NAME']
mp['DEMO_USER_NAME'] = config.getdefaulted("keystone", "demo_user", MANAGE_DEMO_USER)
mp['DEMO_TENANT_NAME'] = mp['DEMO_USER_NAME']
mp['INVIS_USER_NAME'] = config.getdefaulted("keystone", "invisible_user", MANAGE_INVIS_USER)
mp['INVIS_TENANT_NAME'] = mp['INVIS_USER_NAME']
return mp
def get_shared_params(config):
mp = dict()
host_ip = config.get('host', 'ip')
@ -256,5 +266,6 @@ def get_shared_params(config):
mp['SERVICE_ENDPOINT'] = urlunparse((keystone_service_proto,
"%s:%s" % (keystone_service_host, keystone_service_port),
"v2.0", "", "", ""))
mp['SERVICE_TOKEN'] = config.get("passwords", "service_token")
return mp

View File

@ -14,15 +14,18 @@
# License for the specific language governing permissions and limitations
# under the License.
import json
import os
import tarfile
import tempfile
import urllib
import urllib2
import ConfigParser
from devstack import log
from devstack import shell
from devstack import utils
from devstack.components import keystone
LOG = log.getLogger("devstack.image.creator")
@ -210,6 +213,52 @@ class ImageCreationService:
def __init__(self, cfg):
self.cfg = cfg
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))
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)
return token['access']['token']['id']
def install(self):
urls = list()
token = None
@ -230,7 +279,7 @@ class ImageCreationService:
am_installed = 0
if urls:
LOG.info("Attempting to download & extract and upload (%s) images." % (", ".join(urls)))
token = self.cfg.get("passwords", "service_token")
token = self._get_token()
for url in urls:
try:
Image(url, token).install()