ArcGIS Server Administrator API 编写python脚本(二)-----创建站点

本示例介绍了如何根据用户提供的值(主站点管理员帐户、配置存储位置和服务器目录的根位置)创建 ArcGIS Server 站点。这些值与在 ArcGIS Server 管理器中手动创建站点时要求用户输入的值完全相同。代码示例如下:

import httplib, urllib, json
import sys, os
import getpass

def main(argv=None):

#输入用户名和密码信息
username = raw_input("Enter desired primary site administrator name: ")
password = getpass.getpass("Enter desired primary site administrator password: ")

#输入服务器名称
serverName = raw_input("Enter server name: ")
serverPort = 6080

# 输入配置文件路径和服务器目录信息arcgiscache等
configStorePath = raw_input("Enter config store path: ")
rootDirPath = raw_input("Enter root server directory path: ")

# Set up required properties for config store
configStoreConnection={"connectionString": configStorePath, "type": "FILESYSTEM"}

# Set up paths for server directories
cacheDirPath = os.path.join(rootDirPath, "arcgiscache")
jobsDirPath = os.path.join(rootDirPath, "arcgisjobs")
outputDirPath = os.path.join(rootDirPath, "arcgisoutput")
systemDirPath = os.path.join(rootDirPath, "arcgissystem")

# Create Python dictionaries representing server directories
cacheDir = dict(name = "arcgiscache",physicalPath = cacheDirPath,directoryType = "CACHE",cleanupMode = "NONE",maxFileAge = 0,description = "Stores tile caches used by map, globe, and image services for rapid performance.", virtualPath = "")
jobsDir = dict(name = "arcgisjobs",physicalPath = jobsDirPath, directoryType = "JOBS",cleanupMode = "TIME_ELAPSED_SINCE_LAST_MODIFIED",maxFileAge = 360,description = "Stores results and other information from geoprocessing services.", virtualPath = "")
outputDir = dict(name = "arcgisoutput",physicalPath = outputDirPath,directoryType = "OUTPUT",cleanupMode = "TIME_ELAPSED_SINCE_LAST_MODIFIED",maxFileAge = 10,description = "Stores various information generated by services, such as map images.", virtualPath = "")
systemDir = dict(name = "arcgissystem",physicalPath = systemDirPath,directoryType = "SYSTEM",cleanupMode = "NONE",maxFileAge = 0,description = "Stores files that are used internally by the GIS server.", virtualPath = "")

# Serialize directory information to JSON
directoriesJSON = json.dumps(dict(directories = [cacheDir, jobsDir, outputDir, systemDir]))

# Construct URL to create a new site
createNewSiteURL = "/arcgis/admin/createNewSite"

# Set up parameters for the request
params = urllib.urlencode({'username': username, 'password': password, 'configStoreConnection':

configStoreConnection, 'directories':directoriesJSON, 'f': 'json'})

headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}

# Connect to URL and post parameters
httpConn = httplib.HTTPConnection(serverName, serverPort)
httpConn.request("POST", createNewSiteURL, params, headers)

# Read response
response = httpConn.getresponse()
if (response.status != 200):
httpConn.close()
print "Error while creating the site."
return
else:
data = response.read()
httpConn.close()

# Check that data returned is not an error object
if not assertJsonSuccess(data):
print "Error returned by operation. " + str(data)
else:
print "Site created successfully"

return

# A function that checks that the input JSON object
# is not an error object.
def assertJsonSuccess(data):
obj = json.loads(data)
if 'status' in obj and obj['status'] == "error":
print "Error: JSON object returns an error. " + str(obj)
return False
else:
return True


# Script start
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值