Sync Integ to Master
[sdc.git] / catalog-be / src / main / resources / scripts / import / tosca / importNormativeNoHeatAndNormativeTypes.py
1 import pycurl
2 import sys, getopt, os
3 from StringIO import StringIO
4 import json
5 import copy
6 import time
7 #from importNormativeElements import createNormativeElement
8 from importNormativeElements import * 
9 from importNormativeTypes import importNormativeTypes
10 from importHeatTypes import importHeatTypes
11 from importNormativeCapabilities import importNormativeCapabilities
12 from importCategoryTypes import importCategories
13 from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType
14 from importDataTypes import importDataTypes
15 from importGroupTypes import importGroupTypes
16 from importPolicyTypes import importPolicyTypes
17 from importCommon import *
18 import importCommon
19
20 #####################################################################################################################################################################################################################################################
21 #                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               #
22 # Import all users from a given file                                                                                                                                                                                                                                                                                                                                                                                                                            #
23 #                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       #
24 # activation :                                                                                                                                                                                                                                                                                                                                                                                                                                                                          #
25 #       python importNormativeNoHeatAndNormativeTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>]      #
26 #                                                                        [-v <true|false> | --updateversion=<true|false>]                                                                                                                                                                                                                                                                                                                               #
27 #                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       #
28 # shortest activation (be host = localhost, be port = 8080, user = jh0003):                                                                                                                                                                                                                                                                                                                                             #
29 #               python importNormativeNoHeatAndNormativeTypes.py                                                                                                                                                                                                                                                                                                                                                                                #
30 #                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               #
31 #####################################################################################################################################################################################################################################################
32
33 def usage():
34         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> ] [-d <true|false> | --debug=<true|false>] [-v <true|false> | --updateversion=<true|false>]'
35
36 def handleResults(results, updateversion):
37         printFrameLine()
38         for result in results:
39                 printNameAndReturnCode(result[0], result[1])
40         printFrameLine()
41         
42         responseCodes = [200, 201]
43         
44         if(updateversion == 'false'):
45                 responseCodes = [200, 201, 409]
46         
47         failedResults = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
48         if (len(failedResults) > 0):
49                 errorAndExit(1, None)
50
51 def main(argv):
52         print 'Number of arguments:', len(sys.argv), 'arguments.'
53
54         beHost = 'localhost' 
55         bePort = '8080'
56         adminUser = 'jh0003'
57         debugf = None
58         updateversion = 'true'
59         importCommon.debugFlag = False 
60         scheme = 'http'
61
62         try:
63                 opts, args = getopt.getopt(argv,"i:p:u:d:v:h:s:",["ip=","port=","user=","debug=","updateversion=", "scheme="])
64         except getopt.GetoptError:
65                 usage()
66                 errorAndExit(2, 'Invalid input')
67         
68         for opt, arg in opts:
69         #print opt, arg
70                 if opt == '-h':
71                         usage()                        
72                         sys.exit(3)
73                 elif opt in ("-i", "--ip"):
74                         beHost = arg
75                 elif opt in ("-p", "--port"):
76                         bePort = arg
77                 elif opt in ("-u", "--user"):
78                         adminUser = arg
79                 elif opt in ("-s", "--scheme"):
80                         scheme = arg
81                 elif opt in ("-d", "--debug"):
82                         print arg
83                         debugf = bool(arg.lower() == "true" or arg.lower() == "yes")
84                 elif opt in ("-v", "--updateversion"):
85                         print arg
86                         if (arg.lower() == "false" or arg.lower() == "no"):
87                                 updateversion = 'false'                 
88
89         print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf, ', updateversion =', updateversion
90
91         if (debugf != None):
92                 print 'set debug mode to ' + str(debugf)
93                 importCommon.debugFlag = debugf
94         
95         if ( beHost == None ):
96                 usage()
97                 sys.exit(3)
98
99         print sys.argv[0]
100         pathdir = os.path.dirname(os.path.realpath(sys.argv[0]))      
101         debug("path dir =" + pathdir)
102
103         baseFileLocation = pathdir + "/../../../import/tosca/"
104
105         fileLocation = baseFileLocation + "data-types/"
106         importDataTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
107
108         print 'sleep until data type cache is updated'
109         time.sleep( 70 )
110         
111         fileLocation = baseFileLocation + "capability-types/"
112         importNormativeCapabilities(scheme, beHost, bePort, adminUser, False, fileLocation)
113
114         fileLocation = baseFileLocation + "interface-lifecycle-types/"
115         importNormativeInterfaceLifecycleType(scheme, beHost, bePort, adminUser, False, fileLocation)   
116
117         #fileLocation = baseFileLocation + "categories/"
118         #importCategories(beHost, bePort, adminUser, False, fileLocation)
119         
120         #fileLocation = baseFileLocation + "normative-types/"
121         #results = importNormativeTypes(beHost, bePort, adminUser, fileLocation, updateversion)
122         #handleResults(results, updateversion)
123
124         #fileLocation = baseFileLocation + "heat-types/"
125         #resultsHeat = importHeatTypes(beHost, bePort, adminUser, fileLocation, updateversion)
126         #handleResults(resultsHeat, updateversion)
127   
128         fileLocation = baseFileLocation + "group-types/"
129         importGroupTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
130         
131         fileLocation = baseFileLocation + "policy-types/"
132         importPolicyTypes(scheme, beHost, bePort, adminUser, False, fileLocation)
133
134         errorAndExit(0, None)   
135
136 if __name__ == "__main__":
137         main(sys.argv[1:])
138