aboutsummaryrefslogtreecommitdiffstats
path: root/asdctool/src/main/resources/scripts/python
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2018-03-04 14:53:33 +0200
committerMichael Lando <ml636r@att.com>2018-03-07 13:19:05 +0000
commita5445100050e49e83f73424198d73cd72d672a4d (patch)
treecacf4df817df31be23e4e790d1dda857bdae061e /asdctool/src/main/resources/scripts/python
parent51157f92c21976cba4914c378aaa3cba49826931 (diff)
Sync Integ to Master
Change-Id: I71e3acc26fa612127756ac04073a522b9cc6cd74 Issue-ID: SDC-977 Signed-off-by: Gitelman, Tal (tg851x) <tg851x@intl.att.com>
Diffstat (limited to 'asdctool/src/main/resources/scripts/python')
-rw-r--r--asdctool/src/main/resources/scripts/python/user/exportUsers.py41
-rw-r--r--asdctool/src/main/resources/scripts/python/user/importUsers.py60
2 files changed, 59 insertions, 42 deletions
diff --git a/asdctool/src/main/resources/scripts/python/user/exportUsers.py b/asdctool/src/main/resources/scripts/python/user/exportUsers.py
index e32a3b0a21..9e695ad8fd 100644
--- a/asdctool/src/main/resources/scripts/python/user/exportUsers.py
+++ b/asdctool/src/main/resources/scripts/python/user/exportUsers.py
@@ -4,17 +4,17 @@ from StringIO import StringIO
import json
-################################################################################################################################################
-# #
-# Export all active users to file - for 1602+ #
-# #
-# activation : #
-# python exportUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <output file> | --ofile=<output file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): # #
-# python exportUsers.py [-f <output file> | --ofile=<output file> ] #
-# #
-################################################################################################################################################
+####################################################################################################################################################################################
+# #
+# Export all active users to file - for 1602+ #
+# #
+# activation : #
+# python exportUsers.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <output file> | --ofile=<output file> ] #
+# #
+# shortest activation (be host = localhost, be port = 8080): #
+# python exportUsers.py [-f <output file> | --ofile=<output file> ] #
+# #
+####################################################################################################################################################################################
ALL_USERS_SUFFIX = '/sdc2/rest/v1/user/users'
@@ -25,19 +25,23 @@ def errorAndExit(errorCode, errorDesc):
print("status=" + str(errorCode))
sys.exit(errorCode)
-def getUsers(beHost, bePort, adminUser):
+def getUsers(scheme, beHost, bePort, adminUser):
try:
buffer = StringIO()
c = pycurl.Curl()
- url = 'http://' + beHost + ':' + bePort + ALL_USERS_SUFFIX
+ url = scheme + '://' + beHost + ':' + bePort + ALL_USERS_SUFFIX
print(url)
c.setopt(c.URL, url)
c.setopt(c.WRITEFUNCTION, buffer.write)
#c.setopt(c.WRITEFUNCTION, lambda x: None)
adminHeader = 'USER_ID: ' + adminUser
c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])
+
+ if scheme == 'https':
+ c.setopt(c.SSL_VERIFYPEER, 0)
+
res = c.perform()
#print(res)
@@ -63,7 +67,7 @@ def getUsers(beHost, bePort, adminUser):
def usage():
- print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <output file> | --ofile=<output file> ]'
+ print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <output file> | --ofile=<output file> ]'
def main(argv):
print 'Number of arguments:', len(sys.argv), 'arguments.'
@@ -72,9 +76,10 @@ def main(argv):
beHost = 'localhost'
bePort = '8080'
outputfile = None
+ scheme = 'http'
try:
- opts, args = getopt.getopt(argv,"i:p:f:h:",["ip=","port=","ofile="])
+ opts, args = getopt.getopt(argv,"i:p:f:h:s:",["ip=","port=","ofile=","scheme="])
except getopt.GetoptError:
usage()
errorAndExit(2, 'Invalid input')
@@ -90,14 +95,16 @@ def main(argv):
bePort = arg
elif opt in ("-f", "--ofile"):
outputfile = arg
+ elif opt in ("-s", "--scheme"):
+ scheme = arg
- print 'be host =',beHost,', be port =', bePort,', output file =',outputfile
+ print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', output file =',outputfile
if ( outputfile == None ):
usage()
sys.exit(3)
- users = getUsers(beHost, bePort, adminHeader)
+ users = getUsers(scheme, beHost, bePort, adminHeader)
error = users[1]
body = users[0]
diff --git a/asdctool/src/main/resources/scripts/python/user/importUsers.py b/asdctool/src/main/resources/scripts/python/user/importUsers.py
index 669cbbe6f2..984b75bd4c 100644
--- a/asdctool/src/main/resources/scripts/python/user/importUsers.py
+++ b/asdctool/src/main/resources/scripts/python/user/importUsers.py
@@ -4,20 +4,20 @@ from StringIO import StringIO
import json
import copy
-################################################################################################################################################
-# #
-# Import all users from a given file #
-# #
-# activation : #
-# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
-# #
-# shortest activation (be host = localhost, be port = 8080): # #
-# python importUsers.py [-f <input file> | --ifile=<input file> ] #
-# #
-################################################################################################################################################
-
-
-def importUsers(beHost, bePort, users, adminUser):
+#####################################################################################################################################################################################
+# #
+# Import all users from a given file #
+# #
+# activation : #
+# python importUsers.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
+# #
+# shortest activation (be host = localhost, be port = 8080): #
+# python importUsers.py [-f <input file> | --ifile=<input file> ] #
+# #
+#####################################################################################################################################################################################
+
+
+def importUsers(scheme, beHost, bePort, users, adminUser):
result = []
@@ -25,12 +25,12 @@ def importUsers(beHost, bePort, users, adminUser):
#print("Going to add user " + user['userId'])
- getRes = getUser(beHost, bePort, user)
+ getRes = getUser(scheme, beHost, bePort, user)
userId = getRes[0]
error = getRes[1]
#print error
if ( error != None and error == 404 ):
- res = createUser(beHost, bePort, user ,adminUser)
+ res = createUser(scheme, beHost, bePort, user ,adminUser)
result.append(res)
else:
if ( error == 200 ):
@@ -54,7 +54,7 @@ def convertUsersToCreationObject(users):
return cloneUsers
-def getUser(beHost, bePort, user):
+def getUser(scheme, beHost, bePort, user):
userId = user['userId']
try:
@@ -62,12 +62,16 @@ def getUser(beHost, bePort, user):
c = pycurl.Curl()
#print type(userId)
- url = 'http://' + beHost + ':' + bePort + '/sdc2/rest/v1/user/' + str(userId)
+ url = scheme + '://' + beHost + ':' + bePort + '/sdc2/rest/v1/user/' + str(userId)
c.setopt(c.URL, url)
#adminHeader = 'USER_ID: ' + adminUser
c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json'])
c.setopt(c.WRITEFUNCTION, lambda x: None)
+
+ if scheme == 'https':
+ c.setopt(c.SSL_VERIFYPEER, 0)
+
res = c.perform()
#print("Before get response code")
@@ -87,14 +91,14 @@ def getUser(beHost, bePort, user):
-def createUser(beHost, bePort, user, adminUser):
+def createUser(scheme, beHost, bePort, user, adminUser):
userId = user['userId']
try:
buffer = StringIO()
c = pycurl.Curl()
- url = 'http://' + beHost + ':' + bePort + '/sdc2/rest/v1/user'
+ url = scheme + '://' + beHost + ':' + bePort + '/sdc2/rest/v1/user'
c.setopt(c.URL, url)
c.setopt(c.POST, 1)
@@ -105,6 +109,10 @@ def createUser(beHost, bePort, user, adminUser):
c.setopt(c.POSTFIELDS, data)
c.setopt(c.WRITEFUNCTION, lambda x: None)
+
+ if scheme == 'https':
+ c.setopt(c.SSL_VERIFYPEER, 0)
+
#print("before perform")
res = c.perform()
#print(res)
@@ -133,7 +141,7 @@ def errorAndExit(errorCode, errorDesc):
sys.exit(errorCode)
def usage():
- print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ]'
+ print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ]'
def main(argv):
print 'Number of arguments:', len(sys.argv), 'arguments.'
@@ -141,11 +149,11 @@ def main(argv):
beHost = 'localhost'
bePort = '8080'
inputfile = None
-
+ scheme = 'http'
adminUser = 'jh0003'
try:
- opts, args = getopt.getopt(argv,"i:p:f:h:",["ip=","port=","ifile="])
+ opts, args = getopt.getopt(argv,"i:p:f:h:s:",["ip=","port=","ifile=","scheme="])
except getopt.GetoptError:
usage()
errorAndExit(2, 'Invalid input')
@@ -161,8 +169,10 @@ def main(argv):
bePort = arg
elif opt in ("-f", "--ifile"):
inputfile = arg
+ elif opt in ("-s", "--scheme"):
+ scheme = arg
- print 'be host =',beHost,', be port =', bePort,', users file =',inputfile
+ print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', users file =',inputfile
if ( inputfile == None ):
usage()
@@ -182,7 +192,7 @@ def main(argv):
#print activeUsers
- resultTable = importUsers(beHost, bePort, activeUsers, adminUser)
+ resultTable = importUsers(scheme, beHost, bePort, activeUsers, adminUser)
g = lambda x: x[1] != 201 and x[1] != 409