def createDBUser(database, connection, dbuser_pwd, role):
    # if dbuser_pwd != '':
    #    dbuser_pwd = database.lower() + '_' + role.upper() + '_' + str(datetime.datetime.now().year)
    #   arcpy.AddWarning('No password specified. Setting the password to: ' + dbuser_pwd)
    try:
        dbuser = (database + '_' + role).upper()
        role = 'R_SDE_' + role.upper()
        arcpy.AddMessage('Creating database user ' + dbuser)
        arcpy.CreateDatabaseUser_management(
            input_database=connection,
            user_authentication_type='DATABASE_USER',
            user_name=dbuser,
            user_password=dbuser_pwd,
            role=role,
            tablespace_name='')
        for i in range(arcpy.GetMessageCount()):
            arcpy.AddReturnMessage(i)
        arcpy.AddMessage("++++++++++++++++++")
    except:
        for i in range(arcpy.GetMessageCount()):
            arcpy.AddReturnMessage(i)
Ejemplo n.º 2
0
    adminConn = arcpy.CreateDatabaseConnection_management(r'<path_to_save_file>', '<file_name>.sde', platform, instance, authentication, \
                                                          databaseAdmin, databaseAdminPass,'', database, schema)

    # First create a few roles for data viewers and data editors.
    print("\tCreating the viewer and editor roles")
    arcpy.CreateRole_management(adminConn, 'viewers')
    arcpy.CreateRole_management(adminConn, 'editors')

    # Next create users and assign them to their proper roles.
    # Generate a list of users to be added as editors and a list to be added as viewers.
    print("\t\tCreating users")
    editors = ['jack', 'jill', 'larry', 'loretta']
    viewers = ['darryl', 'carol', 'rick', 'maggie']
    for user in editors:
        arcpy.CreateDatabaseUser_management(adminConn, 'DATABASE_USER', user,
                                            '<your_choice_of_password>',
                                            'editors')
    for user1 in viewers:
        arcpy.CreateDatabaseUser_management(adminConn, 'DATABASE_USER', user1,
                                            '<your_choice_of_password>',
                                            'viewers')

    # Create a data owner user named 'gdb'
    print("Creating the data owner (gdb)")
    arcpy.CreateDatabaseUser_management(adminConn, 'DATABASE_USER',
                                        '<your_gdb_username>',
                                        '<your_gdb_password>')
    print("****Finished tasks as the DBA user**** \n\n")

    # Now connect as the gdb admin to import a custom configuration keyword
    print(
                                                          databaseAdmin, databaseAdminPass,'SAVE_USERNAME', database)


    # First create a few roles for data viewers and data editors.
    print("Creating the viewer and editor roles")
    arcpy.CreateRole_management(adminConn, 'viewers')
    arcpy.CreateRole_management(adminConn, 'editors')

    # Next create users and assign them to their proper roles.
    # Generate a list of users to be added as editors and a list to be added as viewers.
    print("Creating users")
    onemap_editors = ['onemap_editor1', 'onemap_editor2', 'onemap_editor3', 'onemap_editor4', 'onemap_editor5', 'onemap_editor6', 'onemap_editor7', 'onemap_editor8', 'onemap_editor9', 'onemap_editor10', 'onemap_editor11', 'onemap_editor12', 'onemap_editor13', 'onemap_editor14', 'onemap_editor15', 'onemap_editor16', 'onemap_editor17', 'onemap_editor18', 'onemap_editor19', 'onemap_editor20']
    onemap_viewers = ['onemap_viewer1', 'onemap_viewer2', 'onemap_viewer3', 'onemap_viewer4', 'onemap_viewer5','onemap_viewer6', 'onemap_viewer7', 'onemap_viewer8', 'onemap_viewer9', 'onemap_viewer10', 'onemap_viewer11', 'onemap_viewer12', 'onemap_viewer13', 'onemap_viewer14','onemap_viewer15', 'onemap_viewer16', 'onemap_viewer17', 'onemap_viewer18', 'onemap_viewer19', 'onemap_viewer20']

    for user in editors:
        arcpy.CreateDatabaseUser_management(adminConn, 'DATABASE_USER',
                                            user, user, 'editors')
    for user1 in viewers:
        arcpy.CreateDatabaseUser_management(adminConn, 'DATABASE_USER',
                                            user1, user1, 'viewers')

    # Create a data owner user named 'gdb'
    print("Creating the data owner (onemapgdb_owner)")
    arcpy.CreateDatabaseUser_management(adminConn, 'DATABASE_USER', 'onemapgdb_owner', 'onemapgdb_owner')
    print("Finished tasks as the DBA user \n")
    
    # Now connect as the gdb admin to import a custom configuration keyword
    print("Creating a connection to the geodatabase as the gdb admin user (sde)")
    gdbAdminConn = arcpy.CreateDatabaseConnection_management('D:/versioning_training',
                                                          'sde@versioning_training.sde', platform, instance,
                                                          'DATABASE_AUTH', gdbAdmin, adminPass,
                                                          'SAVE_USERNAME', database)
Ejemplo n.º 4
0
# Create the geodatabase
# Full tool documentation: Data Management Toolbox < Geodatabase Administration Toolset
# https://pro.arcgis.com/en/pro-app/tool-reference/data-management/create-enterprise-geodatabase.htm
# different database platforms have different requirements so refer to documentation for 
# particulars to connect
arcpy.CreateEnterpriseGeodatabase_management('<your_platform>', 
                                             '<your_instance_name>', 
                                             '<database_name>', # see doc
                                             '<authentication_type>', # see doc
                                             '<your_dba_user_name>', 
                                             '<your_dba_password>', 
                                             '<sde_schema>', # see doc, only relevant to SQL Server 
                                             '<geodatabase_administrator_name>',
                                             '<geodatabase_administrator_password>', 
                                             '', r'<path_to_your_license_file>')

# Create database connection
arcpy.CreateDatabaseConnection_management(r'<full_path_to_connection_file>', '<file_name>.sde', '<platform>', '<your_instance_name>', '<authentication_type>', '<your_dba_user_name>', '<dba_password>', '<save_user_pass>', '<database>', 'schema')

# Create an editor role
arcpy.CreateRole_management(r'<full_path_to_connection_file>\<file_name>.sde', 'editor')

# Create list of users
userList = ['matt', 'tom', 'colin']

# Create users and assign to editor role
for user in userList:
    arcpy.CreateDatabaseUser_management(r'<full_path_to_connection_file>\<file_name>.sde', '<authentication_type>', user, '<your_choice_password>', 'editor')
        
roleName = None
dbInstance = "ESRIBX0373\SQLEXPRESS"

arcpy.env.overwriteOutput = True
print("Creating database")
#create database
arcpy.CreateEnterpriseGeodatabase_management("SQL_Server", dbInstance, databasename, "OPERATING_SYSTEM_AUTH",
                                             "", "", "SDE_SCHEMA",
                                             "sde", "sde","",r"D:\EGT16\Part 1 - Administration\keycodes")

# Create Connection
print("Creating connection")
arcpy.CreateDatabaseConnection_management(connectionFolderPath,databasename,"SQL_SERVER",
                                          dbInstance,"OPERATING_SYSTEM_AUTH","","","SAVE_USERNAME",databasename)

## Create list of users
print("Creating users")
userList = ['jack', 'linda', 'bill']

## Create users and assign to editor role
for user in userList:
    print("Creating user: {}".format(user))
    arcpy.CreateDatabaseUser_management(connectionFilepath, "DATABASE_USER", user, "SomePassword01") #, roleName)

#import xml workspace document
print("Importing XML Workspace")
arcpy.ImportXMLWorkspaceDocument_management(connectionFilepath,
                                                'D:\EGT16\Part 1 - Administration\WINDMILLS.XML',
                                                'DATA')

print("Script complete")
Ejemplo n.º 6
0
'''
Created on Feb 28, 2013

@author: kyleg
'''
import arcpy
SDEUsername = "******"
DevRole = "GIS_VIEWER"  #Options are GIS_ADMIN, GIS_DEVELOPER, GIS_EDITOR, GIS_VIEWER, GIS_AVIATION
ProdRole = "GIS_VIEWER"  #Options are GIS_ADMIN, GIS_DEVELOPER, GIS_EDITOR, GIS_VIEWER, GIS_AVIATION
SYSProd = "Database Connections/SDEPROD-SYS.sde"
SYSDev = "Database Connections/SDEDEV-SYS.sde"

arcpy.CreateDatabaseUser_management(SYSDev,"DATABASE_USER",SDEUsername,SDEUsername,DevRole,"GISDATA")
arcpy.CreateDatabaseUser_management(SYSProd,"DATABASE_USER",SDEUsername,SDEUsername,ProdRole,"GISDATA")