Some keystone user and image creation cleanups.

This commit is contained in:
Joshua Harlow 2012-02-17 08:53:52 -08:00
parent a49a933735
commit b3f7af5c4d
2 changed files with 35 additions and 19 deletions
devstack
components
image

@ -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,10 +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:
ec2rcfn = self.cfg.getdefaulted("keystone", "ec2_rc_fn", EC2RC_FN)
sh.write_file(ec2rcfn, sysout)
sh.write_file(ec2rcfn, sysout.strip())
LOG.debug("Removing (%s) file since we successfully initialized keystone." % (tgt_fn))
sh.unlink(tgt_fn)
@ -231,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')
@ -257,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

@ -214,42 +214,48 @@ class ImageCreationService:
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")
keystone_url = self.cfg.get('extern', 'os_auth_url')
ip = self.cfg.get('host', 'ip')
port = 5000
if not keystone_url:
keystone_url = 'http://%s:%s/v2.0/tokens' % (ip, port)
else:
keystone_url += 'tokens'
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": keystone.MANAGE_ADMIN_USER,
"password": pwd
"username": key_users['ADMIN_USER_NAME'],
"password": pwd,
},
"tenantName": keystone.MANAGE_ADMIN_USER
"tenantName": key_users['ADMIN_TENANT_NAME'],
}
}, separators=(',', ':'))
})
# prepare the request
request = urllib2.Request(keystone_url)
request = urllib2.Request(keystone_token_url)
# post body
request.add_data(data)
# content type
request.add_header('Content-type', 'application/json')
request.add_header('Content-Type', 'application/json')
# make the request
LOG.info("Getting your token from %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 %s did not match expected json format."
raise IOError(msg)
return token['access']['token']['id']