ArcGIS Server Administrator API 编写python脚本(二)-----创建站点
2013-03-22 13:48
411 查看
本示例介绍了如何根据用户提供的值(主站点管理员帐户、配置存储位置和服务器目录的根位置)创建 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:]))
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:]))
相关文章推荐
- ArcGIS Server Administrator API 编写python脚本(一)
- 使用Python创建.sd服务定义文件,实现脚本自动发布ArcGIS服务
- 通过Python脚本创建ArcGIS地图服务缓存
- 使用Python创建.sd服务定义文件,实现脚本自动发布ArcGIS服务
- ArcGIS for Server 创建站点失败The server was unable to access the URL: 'https://ip:6443/arcgis/services'
- 编写第一个python 脚本(重要文件创建备份)
- Arcgis for Server 10.1 linux 创建站点失败
- 通过Python脚本创建ArcGIS地图服务缓存
- 使用python编写批量ping主机脚本
- 用Python编写生成树状结构的文件目录的脚本的教程
- 如何编写一个创建FTP站点的函数?
- ArcGIS.Server.9.3和ArcGIS API for JavaScript实现语句查询QueryTask(八)
- GeoServer/ArcGIS Server的ol/jsApi跨域访问配置笔记
- ArcGIS Python API可视化及分析系列教程(一):入门与简介(2)安装与配置
- Arcgis Server for JavaScript API之自定义InfoWindow
- ArcGIS.Server.9.3和ArcGIS API for JavaScript实现语句查询QueryTask(八)
- ArcGIS.Server.9.3和ArcGIS API for JavaScript实现Identify功能(六)
- 使用python编写脚本获取手机当前应用apk的信息
- 老李推荐:第3章3节《MonkeyRunner源码剖析》脚本编写示例: MonkeyImage API使用示例 2
- Sublime2编辑器编写Python脚本的快捷操作