Pep8 formatting
This commit is contained in:
parent
90888b2477
commit
9fc294e196
@ -22,7 +22,6 @@ from charmhelpers.core.hookenv import (
|
|||||||
from charmhelpers.core.host import (
|
from charmhelpers.core.host import (
|
||||||
mkdir,
|
mkdir,
|
||||||
restart_on_change,
|
restart_on_change,
|
||||||
service_restart,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from charmhelpers.fetch import (
|
from charmhelpers.fetch import (
|
||||||
@ -77,7 +76,7 @@ def config_changed():
|
|||||||
unison.ensure_user(user=SSH_USER, group='keystone')
|
unison.ensure_user(user=SSH_USER, group='keystone')
|
||||||
homedir = unison.get_homedir(SSH_USER)
|
homedir = unison.get_homedir(SSH_USER)
|
||||||
if not os.path.isdir(homedir):
|
if not os.path.isdir(homedir):
|
||||||
mkdir(homedir, SSH_USER, 'keystone', 0775)
|
mkdir(homedir, SSH_USER, 'keystone', 0o775)
|
||||||
|
|
||||||
if openstack_upgrade_available('keystone'):
|
if openstack_upgrade_available('keystone'):
|
||||||
do_openstack_upgrade(configs=CONFIGS)
|
do_openstack_upgrade(configs=CONFIGS)
|
||||||
@ -186,7 +185,7 @@ def ha_changed():
|
|||||||
clustered = relation_get('clustered')
|
clustered = relation_get('clustered')
|
||||||
CONFIGS.write_all()
|
CONFIGS.write_all()
|
||||||
if (clustered is not None and
|
if (clustered is not None and
|
||||||
is_leader(CLUSTER_RES)):
|
is_leader(CLUSTER_RES)):
|
||||||
ensure_initial_admin(config)
|
ensure_initial_admin(config)
|
||||||
log('Cluster configured, notifying other services and updating '
|
log('Cluster configured, notifying other services and updating '
|
||||||
'keystone endpoint configuration')
|
'keystone endpoint configuration')
|
||||||
|
@ -113,7 +113,7 @@ def init_ca(ca_dir, common_name, org_name=ORG_NAME, org_unit_name=ORG_UNIT):
|
|||||||
if not os.path.exists(d):
|
if not os.path.exists(d):
|
||||||
print 'Creating %s.' % d
|
print 'Creating %s.' % d
|
||||||
os.mkdir(d)
|
os.mkdir(d)
|
||||||
os.chmod(os.path.join(ca_dir, 'private'), 0710)
|
os.chmod(os.path.join(ca_dir, 'private'), 0o710)
|
||||||
|
|
||||||
if not os.path.isfile(os.path.join(ca_dir, 'serial')):
|
if not os.path.isfile(os.path.join(ca_dir, 'serial')):
|
||||||
with open(os.path.join(ca_dir, 'serial'), 'wb') as out:
|
with open(os.path.join(ca_dir, 'serial'), 'wb') as out:
|
||||||
@ -161,7 +161,7 @@ def intermediate_ca_csr_key(ca_dir):
|
|||||||
def sign_int_csr(ca_dir, csr, common_name):
|
def sign_int_csr(ca_dir, csr, common_name):
|
||||||
print 'Signing certificate request %s.' % csr
|
print 'Signing certificate request %s.' % csr
|
||||||
crt = os.path.join(ca_dir, 'certs',
|
crt = os.path.join(ca_dir, 'certs',
|
||||||
'%s.crt' % os.path.basename(csr).split('.')[0])
|
'%s.crt' % os.path.basename(csr).split('.')[0])
|
||||||
subj = '/O=%s/OU=%s/CN=%s' % (ORG_NAME, ORG_UNIT, common_name)
|
subj = '/O=%s/OU=%s/CN=%s' % (ORG_NAME, ORG_UNIT, common_name)
|
||||||
cmd = ['openssl', 'ca', '-batch', '-config',
|
cmd = ['openssl', 'ca', '-batch', '-config',
|
||||||
os.path.join(ca_dir, 'ca.cnf'),
|
os.path.join(ca_dir, 'ca.cnf'),
|
||||||
@ -238,6 +238,7 @@ def tar_directory(path):
|
|||||||
|
|
||||||
|
|
||||||
class JujuCA(object):
|
class JujuCA(object):
|
||||||
|
|
||||||
def __init__(self, name, ca_dir, root_ca_dir, user, group):
|
def __init__(self, name, ca_dir, root_ca_dir, user, group):
|
||||||
root_crt, root_key = init_root_ca(root_ca_dir,
|
root_crt, root_key = init_root_ca(root_ca_dir,
|
||||||
'%s Certificate Authority' % name)
|
'%s Certificate Authority' % name)
|
||||||
@ -288,7 +289,7 @@ class JujuCA(object):
|
|||||||
key = open(key, 'r').read()
|
key = open(key, 'r').read()
|
||||||
except:
|
except:
|
||||||
print 'Could not load ssl private key for %s from %s' %\
|
print 'Could not load ssl private key for %s from %s' %\
|
||||||
(common_name, key)
|
(common_name, key)
|
||||||
exit(1)
|
exit(1)
|
||||||
return crt, key
|
return crt, key
|
||||||
crt, key = self._create_certificate(common_name, common_name)
|
crt, key = self._create_certificate(common_name, common_name)
|
||||||
|
@ -13,7 +13,7 @@ from charmhelpers.contrib.hahelpers.cluster import(
|
|||||||
determine_api_port,
|
determine_api_port,
|
||||||
https,
|
https,
|
||||||
is_clustered
|
is_clustered
|
||||||
)
|
)
|
||||||
|
|
||||||
from charmhelpers.contrib.openstack import context, templating
|
from charmhelpers.contrib.openstack import context, templating
|
||||||
|
|
||||||
@ -252,13 +252,13 @@ def migrate_database():
|
|||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
## OLD
|
# OLD
|
||||||
|
|
||||||
def get_local_endpoint():
|
def get_local_endpoint():
|
||||||
""" Returns the URL for the local end-point bypassing haproxy/ssl """
|
""" Returns the URL for the local end-point bypassing haproxy/ssl """
|
||||||
local_endpoint = 'http://localhost:{}/v2.0/'.format(
|
local_endpoint = 'http://localhost:{}/v2.0/'.format(
|
||||||
determine_api_port(api_port('keystone-admin'))
|
determine_api_port(api_port('keystone-admin'))
|
||||||
)
|
)
|
||||||
return local_endpoint
|
return local_endpoint
|
||||||
|
|
||||||
|
|
||||||
@ -317,7 +317,7 @@ def create_service_entry(service_name, service_type, service_desc, owner=None):
|
|||||||
log("Created new service entry '%s'" % service_name)
|
log("Created new service entry '%s'" % service_name)
|
||||||
|
|
||||||
|
|
||||||
def create_endpoint_template(region, service, publicurl, adminurl,
|
def create_endpoint_template(region, service, publicurl, adminurl,
|
||||||
internalurl):
|
internalurl):
|
||||||
""" Create a new endpoint template for service if one does not already
|
""" Create a new endpoint template for service if one does not already
|
||||||
exist matching name *and* region """
|
exist matching name *and* region """
|
||||||
@ -328,7 +328,7 @@ def create_endpoint_template(region, service, publicurl, adminurl,
|
|||||||
for ep in [e._info for e in manager.api.endpoints.list()]:
|
for ep in [e._info for e in manager.api.endpoints.list()]:
|
||||||
if ep['service_id'] == service_id and ep['region'] == region:
|
if ep['service_id'] == service_id and ep['region'] == region:
|
||||||
log("Endpoint template already exists for '%s' in '%s'"
|
log("Endpoint template already exists for '%s' in '%s'"
|
||||||
% (service, region))
|
% (service, region))
|
||||||
|
|
||||||
up_to_date = True
|
up_to_date = True
|
||||||
for k in ['publicurl', 'adminurl', 'internalurl']:
|
for k in ['publicurl', 'adminurl', 'internalurl']:
|
||||||
@ -405,7 +405,7 @@ def create_role(name, user=None, tenant=None):
|
|||||||
|
|
||||||
if None in [user_id, role_id, tenant_id]:
|
if None in [user_id, role_id, tenant_id]:
|
||||||
error_out("Could not resolve [%s, %s, %s]" %
|
error_out("Could not resolve [%s, %s, %s]" %
|
||||||
(user_id, role_id, tenant_id))
|
(user_id, role_id, tenant_id))
|
||||||
|
|
||||||
grant_role(user, name, tenant)
|
grant_role(user, name, tenant)
|
||||||
|
|
||||||
@ -415,7 +415,7 @@ def grant_role(user, role, tenant):
|
|||||||
import manager
|
import manager
|
||||||
manager = manager.KeystoneManager(endpoint=get_local_endpoint(),
|
manager = manager.KeystoneManager(endpoint=get_local_endpoint(),
|
||||||
token=get_admin_token())
|
token=get_admin_token())
|
||||||
log("Granting user '%s' role '%s' on tenant '%s'" % \
|
log("Granting user '%s' role '%s' on tenant '%s'" %
|
||||||
(user, role, tenant))
|
(user, role, tenant))
|
||||||
user_id = manager.resolve_user_id(user)
|
user_id = manager.resolve_user_id(user)
|
||||||
role_id = manager.resolve_role_id(role)
|
role_id = manager.resolve_role_id(role)
|
||||||
@ -426,10 +426,10 @@ def grant_role(user, role, tenant):
|
|||||||
manager.api.roles.add_user_role(user=user_id,
|
manager.api.roles.add_user_role(user=user_id,
|
||||||
role=role_id,
|
role=role_id,
|
||||||
tenant=tenant_id)
|
tenant=tenant_id)
|
||||||
log("Granted user '%s' role '%s' on tenant '%s'" % \
|
log("Granted user '%s' role '%s' on tenant '%s'" %
|
||||||
(user, role, tenant))
|
(user, role, tenant))
|
||||||
else:
|
else:
|
||||||
log("User '%s' already has role '%s' on tenant '%s'" % \
|
log("User '%s' already has role '%s' on tenant '%s'" %
|
||||||
(user, role, tenant))
|
(user, role, tenant))
|
||||||
|
|
||||||
|
|
||||||
@ -453,8 +453,8 @@ def ensure_initial_admin(config):
|
|||||||
log("Loading stored passwd from %s" % STORED_PASSWD)
|
log("Loading stored passwd from %s" % STORED_PASSWD)
|
||||||
passwd = open(STORED_PASSWD, 'r').readline().strip('\n')
|
passwd = open(STORED_PASSWD, 'r').readline().strip('\n')
|
||||||
if passwd == "":
|
if passwd == "":
|
||||||
log("Generating new passwd for user: %s" % \
|
log("Generating new passwd for user: %s" %
|
||||||
config("admin-user"))
|
config("admin-user"))
|
||||||
cmd = ['pwgen', '-c', '16', '1']
|
cmd = ['pwgen', '-c', '16', '1']
|
||||||
passwd = str(subprocess.check_output(cmd)).strip()
|
passwd = str(subprocess.check_output(cmd)).strip()
|
||||||
open(STORED_PASSWD, 'w+').writelines("%s\n" % passwd)
|
open(STORED_PASSWD, 'w+').writelines("%s\n" % passwd)
|
||||||
@ -506,8 +506,8 @@ def update_user_password(username, password):
|
|||||||
error_out("Could not resolve user id for '%s'" % username)
|
error_out("Could not resolve user id for '%s'" % username)
|
||||||
|
|
||||||
manager.api.users.update_password(user=user_id, password=password)
|
manager.api.users.update_password(user=user_id, password=password)
|
||||||
log("Successfully updated password for user '%s'" % \
|
log("Successfully updated password for user '%s'" %
|
||||||
username)
|
username)
|
||||||
|
|
||||||
|
|
||||||
def load_stored_passwords(path=SERVICE_PASSWD_PATH):
|
def load_stored_passwords(path=SERVICE_PASSWD_PATH):
|
||||||
@ -545,7 +545,7 @@ def synchronize_service_credentials():
|
|||||||
broadcasted by peer, depending on hook context.
|
broadcasted by peer, depending on hook context.
|
||||||
'''
|
'''
|
||||||
if (not eligible_leader(CLUSTER_RES) or
|
if (not eligible_leader(CLUSTER_RES) or
|
||||||
not os.path.isfile(SERVICE_PASSWD_PATH)):
|
not os.path.isfile(SERVICE_PASSWD_PATH)):
|
||||||
return
|
return
|
||||||
log('Synchronizing service passwords to all peers.')
|
log('Synchronizing service passwords to all peers.')
|
||||||
if is_clustered():
|
if is_clustered():
|
||||||
@ -569,7 +569,7 @@ def get_ca(user='keystone', group='keystone'):
|
|||||||
ca_dir=os.path.join(SSL_DIR,
|
ca_dir=os.path.join(SSL_DIR,
|
||||||
'%s_intermediate_ca' % d_name),
|
'%s_intermediate_ca' % d_name),
|
||||||
root_ca_dir=os.path.join(SSL_DIR,
|
root_ca_dir=os.path.join(SSL_DIR,
|
||||||
'%s_root_ca' % d_name))
|
'%s_root_ca' % d_name))
|
||||||
# SSL_DIR is synchronized via all peers over unison+ssh, need
|
# SSL_DIR is synchronized via all peers over unison+ssh, need
|
||||||
# to ensure permissions.
|
# to ensure permissions.
|
||||||
subprocess.check_output(['chown', '-R', '%s.%s' % (user, group),
|
subprocess.check_output(['chown', '-R', '%s.%s' % (user, group),
|
||||||
@ -583,7 +583,7 @@ def relation_list(rid):
|
|||||||
cmd = [
|
cmd = [
|
||||||
'relation-list',
|
'relation-list',
|
||||||
'-r', rid,
|
'-r', rid,
|
||||||
]
|
]
|
||||||
result = str(subprocess.check_output(cmd)).split()
|
result = str(subprocess.check_output(cmd)).split()
|
||||||
if result == "":
|
if result == "":
|
||||||
return None
|
return None
|
||||||
@ -773,7 +773,7 @@ def add_endpoint(region, service, publicurl, adminurl, internalurl):
|
|||||||
def get_requested_roles(settings):
|
def get_requested_roles(settings):
|
||||||
''' Retrieve any valid requested_roles from dict settings '''
|
''' Retrieve any valid requested_roles from dict settings '''
|
||||||
if ('requested_roles' in settings and
|
if ('requested_roles' in settings and
|
||||||
settings['requested_roles'] not in ['None', None]):
|
settings['requested_roles'] not in ['None', None]):
|
||||||
return settings['requested_roles'].split(',')
|
return settings['requested_roles'].split(',')
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
@ -3,6 +3,7 @@ from keystoneclient.v2_0 import client
|
|||||||
|
|
||||||
|
|
||||||
class KeystoneManager(object):
|
class KeystoneManager(object):
|
||||||
|
|
||||||
def __init__(self, endpoint, token):
|
def __init__(self, endpoint, token):
|
||||||
self.api = client.Client(endpoint=endpoint, token=token)
|
self.api = client.Client(endpoint=endpoint, token=token)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user