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 datetime
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
from .utils import get_current_user
|
||||||
|
|
||||||
|
|
||||||
APP_NAME = "Installer"
|
APP_NAME = "Installer"
|
||||||
|
|
||||||
@@ -26,13 +28,7 @@ except OSError:
|
|||||||
'ownership and try again.' % PACKSTACK_VAR_DIR)
|
'ownership and try again.' % PACKSTACK_VAR_DIR)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
finally:
|
finally:
|
||||||
# in case user switched to root, change ownership back
|
uid, gid = get_current_user()
|
||||||
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()
|
|
||||||
|
|
||||||
if uid != 0 and os.getuid() == 0:
|
if uid != 0 and os.getuid() == 0:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from .datastructures import SortedDict
|
|||||||
from .decorators import retry
|
from .decorators import retry
|
||||||
from .network import get_localhost_ip, host2ip, force_ip, device_from_ip
|
from .network import get_localhost_ip, host2ip, force_ip, device_from_ip
|
||||||
from .shell import ScriptRunner, execute
|
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
|
from .strings import COLORS, color_text, mask_string
|
||||||
|
|
||||||
|
|
||||||
@@ -12,5 +12,5 @@ __all__ = ('SortedDict',
|
|||||||
'retry',
|
'retry',
|
||||||
'get_localhost_ip', 'host2ip', 'force_ip', 'device_from_ip',
|
'get_localhost_ip', 'host2ip', 'force_ip', 'device_from_ip',
|
||||||
'ScriptRunner', 'execute',
|
'ScriptRunner', 'execute',
|
||||||
'host_iter', 'hosts',
|
'host_iter', 'hosts', 'get_current_user', 'get_current_username',
|
||||||
'COLORS', 'color_text', 'mask_string')
|
'COLORS', 'color_text', 'mask_string')
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import grp
|
||||||
|
import os
|
||||||
|
import pwd
|
||||||
|
|
||||||
|
|
||||||
def host_iter(config):
|
def host_iter(config):
|
||||||
for key, value in config.iteritems():
|
for key, value in config.iteritems():
|
||||||
@@ -17,3 +21,20 @@ def hosts(config):
|
|||||||
for key, host in host_iter(config):
|
for key, host in host_iter(config):
|
||||||
result.add(host)
|
result.add(host)
|
||||||
return result
|
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 logging
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
from packstack.installer import validators
|
from packstack.installer import validators
|
||||||
from packstack.installer import basedefs
|
from packstack.installer import basedefs
|
||||||
from packstack.installer import utils
|
from packstack.installer import utils
|
||||||
@@ -112,11 +111,13 @@ def initConfig(controllerObject):
|
|||||||
|
|
||||||
def initSequences(controller):
|
def initSequences(controller):
|
||||||
keystonesteps = [
|
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):
|
def create_manifest(config):
|
||||||
manifestfile = "%s_keystone.pp"%controller.CONF['CONFIG_KEYSTONE_HOST']
|
manifestfile = "%s_keystone.pp" % config['CONFIG_KEYSTONE_HOST']
|
||||||
manifestdata = getManifestTemplate("keystone.pp")
|
manifestdata = getManifestTemplate("keystone.pp")
|
||||||
appendManifestFile(manifestfile, manifestdata)
|
appendManifestFile(manifestfile, manifestdata)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ Installs and configures an OpenStack Client
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
from packstack.installer import validators
|
from packstack.installer import validators
|
||||||
from packstack.installer import basedefs, output_messages
|
from packstack.installer import basedefs, output_messages
|
||||||
@@ -57,16 +58,34 @@ def initSequences(controller):
|
|||||||
]
|
]
|
||||||
controller.addSequence("Installing OpenStack Client", [], [], osclientsteps)
|
controller.addSequence("Installing OpenStack Client", [], [], osclientsteps)
|
||||||
|
|
||||||
|
|
||||||
def createmanifest(config):
|
def createmanifest(config):
|
||||||
client_host = controller.CONF['CONFIG_OSCLIENT_HOST'].strip()
|
client_host = config['CONFIG_OSCLIENT_HOST'].strip()
|
||||||
manifestfile = "%s_osclient.pp" % client_host
|
manifestfile = "%s_osclient.pp" % client_host
|
||||||
manifestdata = getManifestTemplate("openstack_client.pp")
|
|
||||||
appendManifestFile(manifestfile, manifestdata)
|
|
||||||
|
|
||||||
server = utils.ScriptRunner(client_host)
|
server = utils.ScriptRunner(client_host)
|
||||||
server.append('echo $HOME')
|
server.append('echo $HOME')
|
||||||
rc, root_home = server.execute()
|
rc, root_home = server.execute()
|
||||||
|
root_home = root_home.strip()
|
||||||
|
|
||||||
msg = ("To use the command line tools you need to source the file "
|
homedir = os.path.expanduser('~')
|
||||||
"%s/keystonerc_admin created on %s")
|
config['HOME_DIR'] = homedir
|
||||||
controller.MESSAGES.append(msg % (root_home.strip(), client_host))
|
|
||||||
|
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"]
|
name => ["python-novaclient", "python-keystoneclient", "python-glanceclient", "python-swiftclient", "python-cinderclient"]
|
||||||
}
|
}
|
||||||
|
|
||||||
file {"${::home_dir}/keystonerc_admin":
|
$rcadmin_content = "export OS_USERNAME=admin
|
||||||
ensure => "present",
|
|
||||||
mode => '0600',
|
|
||||||
content => "export OS_USERNAME=admin
|
|
||||||
export OS_TENANT_NAME=admin
|
export OS_TENANT_NAME=admin
|
||||||
export OS_PASSWORD=%(CONFIG_KEYSTONE_ADMIN_PW)s
|
export OS_PASSWORD=%(CONFIG_KEYSTONE_ADMIN_PW)s
|
||||||
export OS_AUTH_URL=http://%(CONFIG_KEYSTONE_HOST)s:35357/v2.0/
|
export OS_AUTH_URL=http://%(CONFIG_KEYSTONE_HOST)s:35357/v2.0/
|
||||||
export PS1='[\\u@\\h \\W(keystone_admin)]\\$ '
|
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' {
|
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