Creates keystonerc_admin for user
- creates keystonerc_admin for user running Packstack in case OpenStack client host is the host where packstack is running (eg. all-in-one installation) Change-Id: I37be40de46f54c78c934a27bc3f5e3c9381e7f19 Fixes: rhbz#964005, rhbz#976394
This commit is contained in:
@@ -10,6 +10,8 @@ import sys
|
||||
import datetime
|
||||
import tempfile
|
||||
|
||||
from .utils import get_current_user
|
||||
|
||||
|
||||
APP_NAME = "Installer"
|
||||
|
||||
@@ -26,13 +28,7 @@ except OSError:
|
||||
'ownership and try again.' % PACKSTACK_VAR_DIR)
|
||||
sys.exit(1)
|
||||
finally:
|
||||
# in case user switched to root, change ownership back
|
||||
try:
|
||||
user = pwd.getpwnam(os.getlogin())
|
||||
uid, gid = user.pw_uid, user.pw_gid
|
||||
except OSError:
|
||||
# in case Packstack is run by a script
|
||||
uid, gid = os.getuid(), os.getgid()
|
||||
uid, gid = get_current_user()
|
||||
|
||||
if uid != 0 and os.getuid() == 0:
|
||||
try:
|
||||
|
||||
@@ -4,7 +4,7 @@ from .datastructures import SortedDict
|
||||
from .decorators import retry
|
||||
from .network import get_localhost_ip, host2ip, force_ip, device_from_ip
|
||||
from .shell import ScriptRunner, execute
|
||||
from .shortcuts import host_iter, hosts
|
||||
from .shortcuts import host_iter, hosts, get_current_user, get_current_username
|
||||
from .strings import COLORS, color_text, mask_string
|
||||
|
||||
|
||||
@@ -12,5 +12,5 @@ __all__ = ('SortedDict',
|
||||
'retry',
|
||||
'get_localhost_ip', 'host2ip', 'force_ip', 'device_from_ip',
|
||||
'ScriptRunner', 'execute',
|
||||
'host_iter', 'hosts',
|
||||
'host_iter', 'hosts', 'get_current_user', 'get_current_username',
|
||||
'COLORS', 'color_text', 'mask_string')
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import grp
|
||||
import os
|
||||
import pwd
|
||||
|
||||
|
||||
def host_iter(config):
|
||||
for key, value in config.iteritems():
|
||||
@@ -17,3 +21,20 @@ def hosts(config):
|
||||
for key, host in host_iter(config):
|
||||
result.add(host)
|
||||
return result
|
||||
|
||||
|
||||
def get_current_user():
|
||||
try:
|
||||
user = pwd.getpwnam(os.getlogin())
|
||||
uid, gid = user.pw_uid, user.pw_gid
|
||||
except OSError:
|
||||
# in case program is run by a script
|
||||
uid, gid = os.getuid(), os.getgid()
|
||||
return uid, gid
|
||||
|
||||
|
||||
def get_current_username():
|
||||
uid, gid = get_current_user()
|
||||
user = pwd.getpwuid(uid).pw_name
|
||||
group = grp.getgrgid(gid).gr_name
|
||||
return user, group
|
||||
|
||||
@@ -5,7 +5,6 @@ Installs and configures Keystone
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
|
||||
from packstack.installer import validators
|
||||
from packstack.installer import basedefs
|
||||
from packstack.installer import utils
|
||||
@@ -112,11 +111,13 @@ def initConfig(controllerObject):
|
||||
|
||||
def initSequences(controller):
|
||||
keystonesteps = [
|
||||
{'title': 'Adding Keystone manifest entries', 'functions':[createmanifest]}
|
||||
{'title': 'Adding Keystone manifest entries',
|
||||
'functions': [create_manifest]},
|
||||
]
|
||||
controller.addSequence("Installing OpenStack Keystone", [], [], keystonesteps)
|
||||
controller.addSequence("Installing OpenStack Keystone", [], [],
|
||||
keystonesteps)
|
||||
|
||||
def createmanifest(config):
|
||||
manifestfile = "%s_keystone.pp"%controller.CONF['CONFIG_KEYSTONE_HOST']
|
||||
def create_manifest(config):
|
||||
manifestfile = "%s_keystone.pp" % config['CONFIG_KEYSTONE_HOST']
|
||||
manifestdata = getManifestTemplate("keystone.pp")
|
||||
appendManifestFile(manifestfile, manifestdata)
|
||||
|
||||
@@ -3,6 +3,7 @@ Installs and configures an OpenStack Client
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from packstack.installer import validators
|
||||
from packstack.installer import basedefs, output_messages
|
||||
@@ -57,16 +58,34 @@ def initSequences(controller):
|
||||
]
|
||||
controller.addSequence("Installing OpenStack Client", [], [], osclientsteps)
|
||||
|
||||
|
||||
def createmanifest(config):
|
||||
client_host = controller.CONF['CONFIG_OSCLIENT_HOST'].strip()
|
||||
client_host = config['CONFIG_OSCLIENT_HOST'].strip()
|
||||
manifestfile = "%s_osclient.pp" % client_host
|
||||
manifestdata = getManifestTemplate("openstack_client.pp")
|
||||
appendManifestFile(manifestfile, manifestdata)
|
||||
|
||||
server = utils.ScriptRunner(client_host)
|
||||
server.append('echo $HOME')
|
||||
rc, root_home = server.execute()
|
||||
root_home = root_home.strip()
|
||||
|
||||
msg = ("To use the command line tools you need to source the file "
|
||||
"%s/keystonerc_admin created on %s")
|
||||
controller.MESSAGES.append(msg % (root_home.strip(), client_host))
|
||||
homedir = os.path.expanduser('~')
|
||||
config['HOME_DIR'] = homedir
|
||||
|
||||
uname, gname = utils.get_current_username()
|
||||
config['NO_ROOT_USER'], config['NO_ROOT_GROUP'] = uname, gname
|
||||
|
||||
no_root_allinone = (client_host == utils.get_localhost_ip() and
|
||||
root_home != homedir)
|
||||
config['NO_ROOT_USER_ALLINONE'] = no_root_allinone and 'true' or 'false'
|
||||
|
||||
manifestdata = getManifestTemplate("openstack_client.pp")
|
||||
appendManifestFile(manifestfile, manifestdata)
|
||||
|
||||
msg = ("File %s/keystonerc_admin has been created on OpenStack client host"
|
||||
" %s. To use the command line tools you need to source the file.")
|
||||
controller.MESSAGES.append(msg % (root_home, client_host))
|
||||
|
||||
if no_root_allinone:
|
||||
msg = ("Copy of keystonerc_admin file has been created for non-root "
|
||||
"user in %s.")
|
||||
controller.MESSAGES.append(msg % homedir)
|
||||
|
||||
@@ -7,15 +7,17 @@ package {"clientlibs":
|
||||
name => ["python-novaclient", "python-keystoneclient", "python-glanceclient", "python-swiftclient", "python-cinderclient"]
|
||||
}
|
||||
|
||||
file {"${::home_dir}/keystonerc_admin":
|
||||
ensure => "present",
|
||||
mode => '0600',
|
||||
content => "export OS_USERNAME=admin
|
||||
$rcadmin_content = "export OS_USERNAME=admin
|
||||
export OS_TENANT_NAME=admin
|
||||
export OS_PASSWORD=%(CONFIG_KEYSTONE_ADMIN_PW)s
|
||||
export OS_AUTH_URL=http://%(CONFIG_KEYSTONE_HOST)s:35357/v2.0/
|
||||
export PS1='[\\u@\\h \\W(keystone_admin)]\\$ '
|
||||
",
|
||||
"
|
||||
|
||||
file {"${::home_dir}/keystonerc_admin":
|
||||
ensure => "present",
|
||||
mode => '0600',
|
||||
content => $rcadmin_content,
|
||||
}
|
||||
|
||||
if '%(CONFIG_PROVISION_DEMO)s' == 'y' {
|
||||
@@ -30,3 +32,13 @@ export PS1='[\\u@\\h \\W(keystone_demo)]\\$ '
|
||||
",
|
||||
}
|
||||
}
|
||||
|
||||
if %(NO_ROOT_USER_ALLINONE)s {
|
||||
file {"%(HOME_DIR)s/keystonerc_admin":
|
||||
ensure => present,
|
||||
owner => '%(NO_ROOT_USER)s',
|
||||
group => '%(NO_ROOT_GROUP)s',
|
||||
mode => '0600',
|
||||
content => $rcadmin_content,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user