3 from StringIO import StringIO
6 from importCommon import *
7 from importNormativeTypes import *
10 ################################################################################################################################################
12 # Import all users from a given file #
15 # python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
17 # shortest activation (be host = localhost, be port = 8080): #
18 # python importUsers.py [-f <input file> | --ifile=<input file> ] #
20 ################################################################################################################################################
22 def importHeatTypes(beHost, bePort, adminUser, fileDir, updateversion):
24 heatTypes = [ "globalNetwork",
29 "contrailVirtualNetwork",
43 "contrailNetworkRules",
45 "contrailV2NetworkRules",
46 "contrailV2VirtualNetwork",
48 "contrailAbstractSubstitute",
50 "contrailV2VirtualMachineInterface",
52 "contrailV2VLANSubInterface",
57 responseCodes = [200, 201]
59 if(updateversion == 'false'):
60 responseCodes = [200, 201, 409]
63 for heatType in heatTypes:
64 result = createNormativeType(beHost, bePort, adminUser, fileDir, heatType, updateversion)
65 results.append(result)
66 if ( result[1] == None or result[1] not in responseCodes) :
67 print "Failed creating heat type " + heatType + ". " + str(result[1])
72 print 'Number of arguments:', len(sys.argv), 'arguments.'
77 updateversion = 'true'
80 opts, args = getopt.getopt(argv,"i:p:u:v:h:",["ip=","port=","user=","updateversion="])
81 except getopt.GetoptError:
83 errorAndExit(2, 'Invalid input')
90 elif opt in ("-i", "--ip"):
92 elif opt in ("-p", "--port"):
94 elif opt in ("-u", "--user"):
96 elif opt in ("-v", "--updateversion"):
97 if (arg.lower() == "false" or arg.lower() == "no"):
98 updateversion = 'false'
100 print 'be host =',beHost,', be port =', bePort,', user =', adminUser
102 if ( beHost == None ):
106 results = importHeatTypes(beHost, bePort, adminUser, "../../../import/tosca/heat-types/", updateversion)
108 print "-----------------------------"
109 for result in results:
110 print "{0:20} | {1:6}".format(result[0], result[1])
111 print "-----------------------------"
113 responseCodes = [200, 201]
115 if(updateversion == 'false'):
116 responseCodes = [200, 201, 409]
118 failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
119 if (len(failedNormatives) > 0):
120 errorAndExit(1, None)
122 errorAndExit(0, None)
125 if __name__ == "__main__":