Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arcgismanager
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈高星
arcgismanager
Commits
682725a1
Commit
682725a1
authored
May 15, 2019
by
chengaoxing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update : a new project
parents
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
292 additions
and
0 deletions
+292
-0
src/portalmng.py
src/portalmng.py
+165
-0
src/servermng.py
src/servermng.py
+127
-0
No files found.
src/portalmng.py
0 → 100644
View file @
682725a1
#
# 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
)
src/servermng.py
0 → 100644
View file @
682725a1
#
# 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
# 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
,
arcgis_home
,
user
,
passwd
):
self
.
arcgis_home
=
arcgis_home
self
.
user
=
user
self
.
passwd
=
passwd
self
.
hostname
=
""
self
.
java_home
=
""
def
validateEnv
(
self
):
'''
Validate the needed environment variables
'''
self
.
hostname
=
os
.
environ
.
get
(
"ARCGIS_HOSTNAME"
,
""
)
if
self
.
hostname
==
""
:
print
(
"The Environment variable ARCGIS_HOSTNAME MUST be set, for example: gisportal.xxxxx.com"
)
return
False
self
.
java_home
=
os
.
environ
.
get
(
"JAVA_HOME"
,
""
)
if
self
.
java_home
==
""
:
print
(
"Warning : JAVA_HOME not be set, set to $ARCGIS_HOIME/portal/framwork/runtime/jre"
)
os
.
environ
[
'JAVA_HOME'
]
=
"$ARCGIS_HOME/portal/framework/runtime/jre"
return
True
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
.
arcgis_home
content_store_path
=
os
.
path
.
join
(
defaultdir
,
"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"
:
"APAAS CUSTOMER"
,
"email"
:
"user@bd-apaas.com"
,
"description"
:
"Administrator account created for APAAS"
,
"securityQuestionIdx"
:
1
,
"securityQuestionAns"
:
"Nothing"
,
"contentStore"
:
content_storeJSON
,
"f"
:
"json"
}
uri
=
"https://
%
s:7443/arcgis/portaladmin/createNewSite"
%
self
.
hostname
response
=
None
timeout
=
False
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__"
:
home
=
os
.
environ
.
get
(
"ARCGIS_HOME"
,
"/arcgis"
)
user
=
os
.
environ
.
get
(
"PORTAL_USER"
,
"portaladmin"
)
passwd
=
os
.
environ
.
get
(
"PORTAL_PASSWORD"
,
"Aa123456"
)
ag
=
arcgis
(
home
,
user
,
passwd
)
if
ag
.
validateEnv
():
if
user
==
"portaladmin"
or
passwd
==
"Aa123456"
:
print
(
"Warning: default Parameter will be used when create new site user:
%
s and password:
%
s"
%
(
user
,
passwd
))
if
ag
.
create_site
():
print
(
"Create the new site Successfully"
)
sys
.
exit
(
0
)
print
(
"Failed to Create a new site"
)
sys
.
exit
(
1
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment