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