def find_hostname_references(fslist, wmlist, hostname, portalObject, users_to_process):
    portal = portalObject
    hostname_references = []

    #find url-based items and check for hostname specified
    url_items = portal.search(['id','type','url'], portalpy.URL_ITEM_FILTER + " AND " + build_user_query(users_to_process),num=10000)
    if url_items:
        print "{} URL-based items found matching user list".format(len(url_items))
        for item in url_items:
            if parse_hostname(item['url'], include_port=True) == hostname:
                fslist.append((item['id'], item['type'], item['url']))
        print "{} total URL-based items found with hostname references".format(len(hostname_references))

    #find webmap items and check for hostname specified within the layers of the webmap
    print "searching webmaps, this may take some time"
    webmaps = portal.webmaps(build_user_query(users_to_process))
    if webmaps:
        print "{} webmaps found matching user list".format(len(webmaps))
        for webmap in webmaps:
            urls = webmap.urls(normalize=True)
            contains_update_layer = False
            for url in urls:
                if parse_hostname(url, include_port=True) == hostname:
                    contains_update_layer = True
            if contains_update_layer:
                wmlist.append((webmap.id, 'Web Map', url))
            print "{} total web maps found with hostname references".format(len(wmlist))
Beispiel #2
0
def find_hostname_references():
    hostname = 'wh94.fltplan.com'
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    hostname_references = []
    url_items = portal.search(['id', 'type', 'url'], portalpy.URL_ITEM_FILTER)
    for item in url_items:
        if parse_hostname(item['url']) == hostname:
            hostname_references.append((item['id'], item['type'], item['url']))
    webmaps = portal.webmaps()
    for webmap in webmaps:
        urls = webmap.urls(normalize=True)
        for url in urls:
            if parse_hostname(url) == hostname:
                hostname_references.append((webmap.id, 'Web Map', url))
    pprint(hostname_references, indent=2)
Beispiel #3
0
def find_hostname_references():
    hostname = 'wh94.fltplan.com'
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    hostname_references = []
    url_items = portal.search(['id','type','url'], portalpy.URL_ITEM_FILTER)
    for item in url_items:
        if parse_hostname(item['url']) == hostname:
            hostname_references.append((item['id'], item['type'], item['url']))
    webmaps = portal.webmaps()
    for webmap in webmaps:
        urls = webmap.urls(normalize=True)
        for url in urls:
            if parse_hostname(url) == hostname:
                hostname_references.append((webmap.id, 'Web Map', url))
    pprint(hostname_references, indent=2)
Beispiel #4
0
def update_hostname_references():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    hostname_map = {'wh94.fltplan.com:8080': 'wh94.fltplan.com'}
    url_items = portal.search(['id', 'type', 'url'], portalpy.URL_ITEM_FILTER)
    for item in url_items:
        url = item.get('url')
        if url:
            url = normalize_url(url)
            host = parse_hostname(url, include_port=True)
            if host in hostname_map:
                url = url.replace(host, hostname_map[host])
                portal.update_item(item['id'], {'url': url})
    webmaps = portal.webmaps()
    for webmap in webmaps:
        is_update = False
        for url in webmap.urls():
            normalized_url = normalize_url(url)
            host = parse_hostname(normalized_url, include_port=True)
            if host in hostname_map:
                new_url = normalized_url.replace(host, hostname_map[host])
                webmap.data = webmap.data.replace(url, new_url)
                is_update = True
        if is_update:
            portal.update_webmap(webmap)
Beispiel #5
0
def update_hostname_references():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    hostname_map = {'wh94.fltplan.com:8080': 'wh94.fltplan.com'}
    url_items = portal.search(['id','type','url'], portalpy.URL_ITEM_FILTER)
    for item in url_items:
        url = item.get('url')
        if url:
            url = normalize_url(url)
            host = parse_hostname(url, include_port=True)
            if host in hostname_map:
                url = url.replace(host, hostname_map[host])
                portal.update_item(item['id'], {'url': url})
    webmaps = portal.webmaps()
    for webmap in webmaps:
        is_update = False
        for url in webmap.urls():
            normalized_url = normalize_url(url)
            host = parse_hostname(normalized_url, include_port=True)
            if host in hostname_map:
                new_url = normalized_url.replace(host, hostname_map[host])
                webmap.data = webmap.data.replace(url, new_url)
                is_update = True
        if is_update:
            portal.update_webmap(webmap)
def update_hostname_references_wm(old_hostname, new_hostname, portalObject, users_to_process):
    portal = portalObject
    hostname_map = {old_hostname:new_hostname}
    webmaps = portal.webmaps(build_user_query(users_to_process))
    if webmaps:
        print "checking {} webmaps for users".format(len(webmaps))
        for webmap in webmaps:
            is_update = False
            for url in webmap.urls():
                normalized_url = normalize_url(url)
                host = parse_hostname(normalized_url, include_port=True)
                if host in hostname_map:
                    new_url = normalized_url.replace(host, hostname_map[host])
                    webmap.data = webmap.data.replace(url, new_url)
                    if http_to_https:
                        webmap.data = webmap.data.replace("http:","https:")
                    is_update = True
            if is_update:
                print "updating web map: " + str(webmap.info()['id'])
                wmlist.append(webmap.info()['id'])
                portal.update_webmap(webmap)
def update_hostname_references_fs(old_name, new_name, portalObject, users_to_process):
    portal = portalObject
    hostname_map = {old_name:new_name}
    url_items = portal.search(['id','type','url'], portalpy.URL_ITEM_FILTER + " AND " + build_user_query(users_to_process))
    if url_items:
        # find and update feature services and map services
        print "checking {} URL-based items".format(len(url_items))
        count = 0
        for item in url_items:
            count += 1
            if count%10 == 0:print "processed {} items".format(count)
            url = item.get('url')
            id = item.get('id')
            #if portal.user_item(id)[0]['owner'] not in users_to_process:
            #    break
            if url:
                url = normalize_url(url)
                host = parse_hostname(url, include_port=True)
                if host in hostname_map:
                    fslist.append(id)
                    print "updating item: " + id
                    url = url.replace(host, hostname_map[host])
                    portal.update_item(item['id'], {'url': url})
        print "done updating URL-based items"
def main():

    scriptName = sys.argv[0]

    specified_users = None
    #specified_ops_types = None
    specified_groups = None
    id_mapping_file = None
    
    # ---------------------------------------------------------------------
    # Check arguments
    # ---------------------------------------------------------------------   
    if len(sys.argv) < 5:
        print '\n' + scriptName + ' <PortalURL> <AdminUser> <AdminPassword> ' + \
                    '<ContentFolderPath> {UsersToPost} {GroupsToPost} {IdMappingFile}'
        print '\nWhere:'
        print '\n\t<PortalURL> (required): URL of Portal to post content (i.e. https://fully_qualified_domain_name/arcgis)'
        
        print '\n\t<AdminUser> (required): Portal user that has administrator role.'
        
        print '\n\t<AdminPassword> (required): Password for AdminUser.'
        
        print '\n\t<ContentFolderPath> (required): Folder path containing portal content to post.'
        
        print '\n\t{UsersToPost} (optional):'
        print '\t\t-By default, content for all users is posted'
        print '\t\t-Specify # placeholder character if you want to post content for all users and you are'
        print '\t\t   specifying {GroupsToPost} values'
        print '\t\t-To post content for only specific users specify comma delimited list of users, i.e. user1,user2,...'
        print '\t\t-To post content for ALL users except specific users, specify comma delimited '
        print '\t\t   list of users to exclude with "-" prefix, i.e. -user1,user2,...'
        print '\t\t-NOTE: Users names must match the "SourceUserName" values in the <ContentFolderPath>\userfile.txt file.'
 
        print '\n\t{GroupsToPost} (optional):'
        print '\t\t-To post content shared with specific portal groups specify a pipe "|" delimited list of groups using the syntax "GroupOwner:GroupTitle|GroupOwner:GroupTitle|...".'
        print '\t\t-Specify # placeholder character if you do not want to use this parameter and need to specify the {IdMappingFile} parameter value.'
        print '\t\t-NOTE: GroupOwner and GroupTitle values are case sensitive.'
        print '\t\t-NOTE: Parameter value MUST be surrounded by double-quotes.'
        
        print '\n\t{IdMappingFile} (optional): JSON file containing mapping between source and target portal item ids.'
        print '\t\t-Provides "overwrite" capability. If IdMappingFile is specified, the script will'
        print '\t\t   update any item that already exists; items that do not exist will be added.'
        
        print '\n\tNOTES:'
        print '\t\t(1) To include spaces in any of the parameter lists, surround the list with double-quotes,'
        print '\t\t i.e., "value1, value2, ..."'
        
        print '\n\t\t(2) Replacement of portal item URLs:'
        print '\t\t\t-This script will replace the host names in URLs in service, webmap and operation view items; '
        print '\t\t\t the script is hardcoded to replace the source hostname "' + source_hostname + '" with the '
        print '\t\t\t hostname of the target portal server <PortalURL>; i.e., this script assumes that the target'
        print '\t\t\t ArcGIS Server is installed on the target portal machine.'
        sys.exit(1)
    
    
    # Set variables from script parameters
    target_portal_address = sys.argv[1]
    adminuser = sys.argv[2]
    adminpassword = sys.argv[3]
    contentpath = sys.argv[4]
    if len(sys.argv) > 5:
        specified_users = sys.argv[5]
    if len(sys.argv) > 6:
        specified_groups = sys.argv[6]
        specified_groups = [group.strip() for group in specified_groups.split('|')]
    if len(sys.argv) > 7:
        id_mapping_file = sys.argv[7]
    if len(sys.argv) > 8:
        print "You entered too many script parameters."
        sys.exit(1)
        
    if DEBUG:
        print "target_portal_address: " + str(target_portal_address)
        print "adminuser: "******"adminpassword: "******"contentpath: " + str(contentpath)
        if specified_users:
            print "specifiedUsers: " + str(specified_users)
        if specified_groups:
            print "specifiedOpsTypes: " + str(specified_groups)
        if id_mapping_file:
            print "id_mapping_file: " + str(id_mapping_file)
    
    
    # Check if specified content folder exists.
    if not val_arg_content_path(contentpath):
        print "Parameter <ContentFolderPath>: folder '" + contentpath + "' does not exist."
        sys.exit(1)
    
    # Check if specified users are valid
    users = val_arg_users(specified_users, contentpath)
    
    if DEBUG:
        print "Users to publish: " + str(users.keys())
    
    # Check if specified id mapping file exists
    if id_mapping_file:
        if not os.path.exists(id_mapping_file):
            print "Parameter {IdMappingFile}: folder '" + id_mapping_file + "' does not exist."
    
    # Extract target ArcGIS Server hostname from target portal URL;
    # NOTE: this script assumes that the ArcGIS Server is installed
    # on the same machine as Portal for ArcGIS
    new_hostname =  parse_hostname(target_portal_address)
    hostname_map = {source_hostname: new_hostname}
        
    # Publish content to target portal
    publish_portal(target_portal_address, contentpath, adminuser, adminpassword, users, hostname_map, specified_groups, id_mapping_file)
    
    os.chdir(contentpath)
def main():

    scriptName = sys.argv[0]

    specified_users = None
    #specified_ops_types = None
    specified_groups = None
    id_mapping_file = None

    # ---------------------------------------------------------------------
    # Check arguments
    # ---------------------------------------------------------------------
    if len(sys.argv) < 5:
        print '\n' + scriptName + ' <PortalURL> <AdminUser> <AdminPassword> ' + \
                    '<ContentFolderPath> {UsersToPost} {GroupsToPost} {IdMappingFile}'
        print '\nWhere:'
        print '\n\t<PortalURL> (required): URL of Portal to post content (i.e. https://fully_qualified_domain_name/arcgis)'

        print '\n\t<AdminUser> (required): Portal user that has administrator role.'

        print '\n\t<AdminPassword> (required): Password for AdminUser.'

        print '\n\t<ContentFolderPath> (required): Folder path containing portal content to post.'

        print '\n\t{UsersToPost} (optional):'
        print '\t\t-By default, content for all users is posted'
        print '\t\t-Specify # placeholder character if you want to post content for all users and you are'
        print '\t\t   specifying {OpsServerTypesToPost} values'
        print '\t\t-To post content for only specific users specify comma delimited list of users, i.e. user1,user2,...'
        print '\t\t-To post content for ALL users except specific users, specify comma delimited '
        print '\t\t   list of users to exclude with "-" prefix, i.e. -user1,user2,...'

        print '\n\t{GroupsToPost} (optional):'
        print '\t\t-To post content shared with specific portal groups specify a pipe "|" delimited list of groups using the syntax "GroupOwner:GroupTitle|GroupOwner:GroupTitle|...".'
        print '\t\t-Specify # placeholder character if you do not want to use this parameter and need to specify the {IdMappingFile} parameter value.'
        print '\t\t-NOTE: GroupOwner and GroupTitle values are case sensitive.'
        print '\t\t-NOTE: Parameter value MUST be surrounded by double-quotes.'

        print '\n\t{IdMappingFile} (optional): JSON file containing mapping between source and target portal item ids.'
        print '\t\t-Provides "overwrite" capability. If IdMappingFile is specified, the script will'
        print '\t\t   update any item that already exists; items that do not exist will be added.'

        print '\n\tNOTES:'
        print '\t\t(1) To include spaces in any of the parameter lists, surround the list with double-quotes,'
        print '\t\t i.e., "value1, value2, ..."'

        print '\n\t\t(2) Replacement of portal item URLs:'
        print '\t\t\t-This script will replace the host names in URLs in service, webmap and operation view items; '
        print '\t\t\t the script is hardcoded to replace the source hostname "' + source_hostname + '" with the '
        print '\t\t\t hostname of the target portal server <PortalURL>; i.e., this script assumes that the target'
        print '\t\t\t ArcGIS Server is installed on the target portal machine.'
        sys.exit(1)

    # Set variables from script parameters
    target_portal_address = sys.argv[1]
    adminuser = sys.argv[2]
    adminpassword = sys.argv[3]
    contentpath = sys.argv[4]
    if len(sys.argv) > 5:
        specified_users = sys.argv[5]
    if len(sys.argv) > 6:
        specified_groups = sys.argv[6]
        specified_groups = [
            group.strip() for group in specified_groups.split('|')
        ]
    if len(sys.argv) > 7:
        id_mapping_file = sys.argv[7]
    if len(sys.argv) > 8:
        print "You entered too many script parameters."
        sys.exit(1)

    if DEBUG:
        print "target_portal_address: " + str(target_portal_address)
        print "adminuser: "******"adminpassword: "******"contentpath: " + str(contentpath)
        if specified_users:
            print "specifiedUsers: " + str(specified_users)
        if specified_groups:
            print "specifiedOpsTypes: " + str(specified_groups)
        if id_mapping_file:
            print "id_mapping_file: " + str(id_mapping_file)

    # Check if specified content folder exists.
    if not val_arg_content_path(contentpath):
        print "Parameter <ContentFolderPath>: folder '" + contentpath + "' does not exist."
        sys.exit(1)

    # Check if specified users are valid
    users = val_arg_users(specified_users, contentpath)

    if DEBUG:
        print "Users to publish: " + str(users.keys())

    # Check if specified id mapping file exists
    if id_mapping_file:
        if not os.path.exists(id_mapping_file):
            print "Parameter {IdMappingFile}: folder '" + id_mapping_file + "' does not exist."

    # Extract target ArcGIS Server hostname from target portal URL;
    # NOTE: this script assumes that the ArcGIS Server is installed
    # on the same machine as Portal for ArcGIS
    new_hostname = parse_hostname(target_portal_address)
    hostname_map = {source_hostname: new_hostname}

    # Publish content to target portal
    publish_portal(target_portal_address, contentpath, adminuser,
                   adminpassword, users, hostname_map, specified_groups,
                   id_mapping_file)

    os.chdir(contentpath)