[SDC] rebase 1710 code
[sdc.git] / catalog-be / src / main / resources / scripts / import / tosca / upgradeHeatTypes1707.py
1 import pycurl
2 import sys, getopt
3 from StringIO import StringIO
4 import json
5 import copy
6 from importCommon import *
7 from importNormativeTypes import *
8 import importCommon
9
10 ################################################################################################################################################
11 #                                                                                                                                                                                                                                                                                      #        
12 # Import all users from a given file                                                                                                                                                                                                               #
13 #                                                                                                                                                                                                                                                                                          #            
14 # activation :                                                                                                                                                                                                                                                             #
15 #       python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ]     #
16 #                                                                                                                                                                                                                                                                                          #                    
17 # shortest activation (be host = localhost, be port = 8080):                                                                                                                                                               #
18 #               python importUsers.py [-f <input file> | --ifile=<input file> ]                                                                                                                                    #
19 #                                                                                                                                                                                                                                                                                      #        
20 ################################################################################################################################################
21
22 def upgradeHeatTypes1707(beHost, bePort, adminUser, fileDir, updateversion):
23         
24         heatTypes = [ "volume",
25                                   "cinderVolume",
26                                   "extVl",
27                                   "extCp",
28                                   "Generic_VFC", 
29                                   "Generic_VF",
30                                   "Generic_PNF",
31                                   "Generic_Service",
32                                   "globalPort",
33                                   "globalNetwork",
34                                   "contrailV2VirtualMachineInterface",
35                                   "contrailV2VLANSubInterface",
36                                   "contrailPort",
37                                   "contrailV2VirtualNetwork",
38                                   "contrailVirtualNetwork",
39                                   "neutronNet",
40                                   "neutronPort",
41                                   "multiFlavorVFC",
42                                   "vnfConfiguration"
43                                   ]
44                 
45         responseCodes = [200, 201]
46                 
47         if(updateversion == 'false'):
48                 responseCodes = [200, 201, 409]
49                 
50         results = []
51         for heatType in heatTypes:
52                 result = createNormativeType(beHost, bePort, adminUser, fileDir, heatType, updateversion)
53                 results.append(result)
54                 if ( result[1] == None or result[1] not in responseCodes) :
55                         print "Failed creating heat type " + heatType + ". " + str(result[1])                           
56         return results  
57
58
59 def main(argv):
60         print 'Number of arguments:', len(sys.argv), 'arguments.'
61
62         beHost = 'localhost' 
63         bePort = '8080'
64         adminUser = 'jh0003'
65         updateversion = 'true'
66         
67         try:
68                 opts, args = getopt.getopt(argv,"i:p:u:v:h:",["ip=","port=","user=","updateversion="])
69         except getopt.GetoptError:
70                 usage()
71                 errorAndExit(2, 'Invalid input')
72                  
73         for opt, arg in opts:
74         #print opt, arg
75                 if opt == '-h':
76                         usage()                        
77                         sys.exit(3)
78                 elif opt in ("-i", "--ip"):
79                         beHost = arg
80                 elif opt in ("-p", "--port"):
81                         bePort = arg
82                 elif opt in ("-u", "--user"):
83                         adminUser = arg
84                 elif opt in ("-v", "--updateversion"):
85                         if (arg.lower() == "false" or arg.lower() == "no"):
86                                 updateversion = 'false'
87
88         print 'be host =',beHost,', be port =', bePort,', user =', adminUser
89         
90         if ( beHost == None ):
91                 usage()
92                 sys.exit(3)
93
94         results = upgradeHeatTypes1707(beHost, bePort, adminUser, "../../../import/tosca/heat-types/", updateversion)
95
96         print "-----------------------------"
97         for result in results:
98                 print "{0:20} | {1:6}".format(result[0], result[1])
99         print "-----------------------------"
100         
101         responseCodes = [200, 201]
102         
103         if(updateversion == 'false'):
104                 responseCodes = [200, 201, 409]
105         
106         failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
107         if (len(failedNormatives) > 0):
108                 errorAndExit(1, None)
109         else:
110                 errorAndExit(0, None)
111
112
113 if __name__ == "__main__":
114         main(sys.argv[1:])
115
116