コード例 #1
0
ファイル: nfks.py プロジェクト: devkev/ncicloudusers
def add_project(project):
    keystone = client.Client(username=username,
                             password=password,
                             tenant_name=tenant_name,
                             auth_url=auth_url)
    db = DataBase.acctDB()
    users = researchers.findprojlogins(db, project)

    # sanity check
    if len(users) == 0:
        print "That project has no users."
        return

    title = session.query(Projects,
                          Projects.title).filter_by(project=project)[0].title

    # get tenant by name is bugged at the moment
    # https://bugs.launchpad.net/keystone/+bug/1055763
    tenants = keystone.tenants.list()
    t = [t for t in tenants if t.name == project]
    if len(t) == 0:
        print "making project " + project + " with description '" + title + "'"
        keystone.tenants.create(project, description=title, enabled=True)
        tenants = keystone.tenants.list()

    tenant = [t for t in tenants if t.name == project][0]
    existingusers = [k for k in keystone.users.list()]
    existingusernames = [k.name for k in existingusers]

    for user in users:
        existinguser = [u for u in existingusers if u.name == user]
        if len(existinguser) == 1:
            existinguser = existinguser[0]
            print "adding member roles to " + user
            keystone.roles.add_user_role(existinguser.id,
                                         role=memberRole,
                                         tenant=tenant.id)
        else:
            print "adding " + user
            userpw = str(base64.encodestring(sha.new(
                randpasswd()).digest())).replace('=', '-')[:-1]
            pid = researchers.get_personid(db, user)

            # some users don't have email addresses
            ppl = session.query(People.email).filter_by(personid=pid)
            for p in ppl:
                email = p.email
                break
            keystone.users.create(name=user,
                                  password=userpw,
                                  email=email,
                                  tenant_id=tenant.id,
                                  enabled=True)
            create_cred_file(user, userpw, tenant.name)
コード例 #2
0
ファイル: nfks.py プロジェクト: devkev/ncicloudusers
def add_project(project):
    keystone = client.Client(username=username, password=password, tenant_name=tenant_name, auth_url=auth_url)
    db = DataBase.acctDB()
    users = researchers.findprojlogins(db, project)

    # sanity check
    if len(users) == 0:
        print "That project has no users."
        return

    title =  session.query(Projects, Projects.title).filter_by(project=project)[0].title

    # get tenant by name is bugged at the moment
    # https://bugs.launchpad.net/keystone/+bug/1055763
    tenants = keystone.tenants.list()
    t = [t for t in tenants if t.name==project]
    if len(t) == 0:
        print "making project " + project + " with description '" + title + "'"
        keystone.tenants.create(project, description=title, enabled=True)
        tenants = keystone.tenants.list()

    tenant = [t for t in tenants if t.name==project][0]
    existingusers = [k for k in keystone.users.list()]
    existingusernames = [k.name for k in existingusers]

    for user in users:
        existinguser = [u for u in existingusers if u.name == user]
        if len(existinguser) == 1:
            existinguser = existinguser[0]
            print "adding member roles to " + user
            keystone.roles.add_user_role(existinguser.id, role=memberRole, tenant=tenant.id)
        else:
            print "adding " + user
            userpw = str(base64.encodestring(sha.new(randpasswd()).digest())).replace('=','-')[:-1]
            pid = researchers.get_personid(db, user)

            # some users don't have email addresses
            ppl = session.query(People.email).filter_by(personid=pid)
            for p in ppl:
                email = p.email
                break
            keystone.users.create(name=user, password=userpw, email=email, tenant_id=tenant.id, enabled=True)
            create_cred_file(user, userpw, tenant.name)
コード例 #3
0
ファイル: nfks.py プロジェクト: devkev/ncicloudusers
def add_user_to_tenant(user, tenant):
    keystone = client.Client(username=username, password=password, tenant_name=tenant_name, auth_url=auth_url)
    db = DataBase.acctDB()
コード例 #4
0
ファイル: nfks.py プロジェクト: devkev/ncicloudusers
def add_user_to_tenant(user, tenant):
    keystone = client.Client(username=username,
                             password=password,
                             tenant_name=tenant_name,
                             auth_url=auth_url)
    db = DataBase.acctDB()