# # example: http://server.arcgis.com/en/server/latest/administer/linux/example-create-a-site.htm # Note the example is for ArcGIS Server not Portal but the concepts are the same. # from __future__ import print_function import sys import os, time import requests import json import argparse # HTTPS calls will generate warnings about the self-signed certificate if you delete this. from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning) class arcgis(object): def __init__(self,**kwargs): self.arcgishome = kwargs.get('arcgishome') self.user = kwargs.get('user') self.passwd = kwargs.get('passwd') self.hostname = kwargs.get('hostname') self.fullname = kwargs.get('fullname') self.email = kwargs.get('email') self.content = kwargs.get('content') self.java_home = kwargs.get('java_home') os.environ['JAVA_HOME']=self.java_home def status_check(self): uri = "https://%s:7443/arcgis/portaladmin/Status" % self.hostname parameters = { "f" : "json" } try: response = requests.post( uri, data=parameters, timeout=10, verify=False ) rj = json.loads(response.text) status = rj["status"] print("portal is in servering with status %s"%(status)) except Exception as e: print("Failed to request the server %s with reason %s"%(uri,e)) return False return True def create_site(self): defaultdir = "%s/portal/usr" % self.arcgishome content_store_path = self.content content_store = { "type" : "FileSystem", "provider" : "FileSystem", "connectionString" : content_store_path } content_storeJSON = json.dumps(content_store) parameters = { "username" : self.user, "password" : self.passwd, "fullname" : self.fullname, "email" : self.email, "description" : "Administrator account created for APAAS", "securityQuestionIdx" : 1, "securityQuestionAns" : "Nothing", "contentStore" : content_storeJSON, "f" : "json" } uri = "https://%s:7443/arcgis/portaladmin/createNewSite" % self.hostname try: response = requests.post( uri, data=parameters, timeout=500, verify=False ) if response and response.status_code != 200: print("Server not available; code ", response.status_code) err = json.loads(response.text).get('error',None) if err is not None: print("Some error happended when create the new site: \n %s \n"%(err)) return False except Exception as e: print("Error when post the requrest with reason :%s"%e) timeout = True return True # ------------------------------------------------------------------------ if __name__ == "__main__": # parser = argparse.ArgumentParser(description=""" # usage: python portalmanager.py arcgis_hme hostname, user,password [options] # """ # ) parser = argparse.ArgumentParser(add_help=True) parser.add_argument("-a","--arcgishome", default="/arcgis", help="The home path where arcgis portal installed, default is /arcgis") parser.add_argument("-n","--hostname", default="arcgisportal", help="The hostname where the server in ") parser.add_argument("-u","--user", default="portaladmin", help="the username to register amdin account, default is arcgis") parser.add_argument("-p","--password", default="Aa123456", help="the password to register amdin account, default is ABCD1234") parser.add_argument("-c","--content", default=None, help="the path to content store, defautl is $ARCGISHOME/portal/usr/arcgisportal") parser.add_argument("-f","--fullname", default="PORTAL ADMIN", help="the full name for admin user,default as APAAS CUSTOMER") parser.add_argument("-e","--email", default="portaladmin@bd-apaas.com", help="the email for admin user, defautl is user@bd-apaas.com") parser.add_argument("-j","--javahome", default=None, help="the email for admin user, defautl is user@bd-apaas.com") args = parser.parse_args() if args.content is None: args.content = "{}/portal/usr/arcgisportal".format(args.arcgishome) if args.javahome is None: args.javahome = "{}/portal/framework/runtime/jre".format(args.arcgishome) print(""" attempting to register a new user with information : {user}:{password}@{hostname}; the home path of arcgis was in {arcgishome}; and data was stored in default path {content}; user's ({user}) full name is {fullname} and email is {email} """.format(user=args.user,password=args.password,arcgishome=args.arcgishome, hostname=args.hostname,email=args.email,fullname=args.fullname, content=args.content) ) home = '/'+args.arcgishome.split('/')[-1], user = args.user, passwd = args.password, hostname = args.hostname, content = args.content, fullname = args.fullname, email = args.email ag = arcgis(arcgishome = '/'+args.arcgishome.split('/')[-1], user = args.user, passwd = args.password, hostname = args.hostname, content = args.content, fullname = args.fullname, email = args.email, java_home = args.javahome ) if ag.create_site(): print("Success ...") sys.exit(0) else: print("Failed to Create a new site") sys.exit(1)