Sync Integ to Master
[sdc.git] / catalog-be / src / main / resources / scripts / import / tosca / importDataTypes.py
1 import pycurl
2 import sys, getopt
3 from StringIO import StringIO
4 import json
5 import copy
6 from importNormativeElements import createNormativeElement
7
8 from importCommon import *
9 #####################################################################################################################################################################################
10 #                                                                                                                                                                                                                                                                                                                                                               #
11 # Import tosca data types                                                                                                                                                                                                                                                                                                                       #
12 #                                                                                                                                                                                                                                                                                                                                                                       #
13 # activation :                                                                                                                                                                                                                                                                                                                                          #
14 #       python importDataTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ]       #
15 #                                                                                                                                                                                                                                                                                                                                                                       #
16 # shortest activation (be host = localhost, be port = 8080):                                                                                                                                                                                                                                            #
17 #               python importDataTypes.py [-f <input file> | --ifile=<input file> ]                                                                                                                                                                                                             #
18 #                                                                                                                                                                                                                                                                                                                                                               #
19 #####################################################################################################################################################################################
20
21 def usage():
22         print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
23
24
25 def importDataTypes(scheme, beHost, bePort, adminUser, exitOnSuccess, fileDir):
26         result = createNormativeElement(scheme, beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/datatypes", "dataTypes", "dataTypesZip")
27
28         printFrameLine()
29         printNameAndReturnCode(result[0], result[1])
30         printFrameLine()
31
32         if ( result[1] == None or result[1] not in [200, 201, 409] ):
33                 errorAndExit(1, None)
34         else:
35                 if (exitOnSuccess == True):
36                         errorAndExit(0, None)
37
38 def main(argv):
39         print 'Number of arguments:', len(sys.argv), 'arguments.'
40
41         beHost = 'localhost' 
42         bePort = '8080'
43         adminUser = 'jh0003'
44         scheme = 'http'
45
46         try:
47                 opts, args = getopt.getopt(argv,"i:p:u:h:s:",["ip=","port=","user=","scheme="])
48         except getopt.GetoptError:
49                 usage()
50                 errorAndExit(2, 'Invalid input')
51                  
52         for opt, arg in opts:
53         #print opt, arg
54                 if opt == '-h':
55                         usage()                        
56                         sys.exit(3)
57                 elif opt in ("-i", "--ip"):
58                         beHost = arg
59                 elif opt in ("-p", "--port"):
60                         bePort = arg
61                 elif opt in ("-u", "--user"):
62                         adminUser = arg
63                 elif opt in ("-s", "--scheme"):
64                         scheme = arg
65
66         print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser
67         
68         if ( beHost == None ):
69                 usage()
70                 sys.exit(3)
71
72         importDataTypes(scheme, beHost, bePort, adminUser, True, "../../../import/tosca/data-types/")
73
74
75 if __name__ == "__main__":
76         main(sys.argv[1:])
77