1 from importNormativeTypes import *
4 #####################################################################################################################################################################################
9 # python importHeatTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
11 # shortest activation (be host = localhost, be port = 8080): #
12 # python importHeatTypes.py [-f <input file> | --ifile=<input file> ] #
14 #####################################################################################################################################################################################
16 def importHeatTypes(scheme, be_host, be_port, admin_user, file_dir, update_version):
17 heat_types = ["globalNetwork",
22 "contrailVirtualNetwork",
37 "contrailNetworkRules",
41 "contrailV2NetworkRules",
42 "contrailV2VirtualNetwork",
44 "contrailAbstractSubstitute",
46 "contrailV2VirtualMachineInterface",
48 "contrailV2VLANSubInterface",
54 "portMirroringByPolicy",
58 "extVirtualMachineInterfaceCP",
59 "VLANNetworkReceptor",
62 "contrailV2VLANSubInterfaceV2",
63 "fabricConfiguration"]
65 response_codes = [200, 201]
67 if update_version == 'false':
68 response_codes = [200, 201, 409]
71 for heat_type in heat_types:
72 result = createNormativeType(scheme, be_host, be_port, admin_user, file_dir, heat_type, update_version)
73 results.append(result)
74 if result[1] is None or result[1] not in response_codes:
75 print "Failed creating heat type " + heat_type + ". " + str(result[1])
80 print 'Number of arguments:', len(sys.argv), 'arguments.'
85 update_version = 'true'
89 opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="])
90 except getopt.GetoptError:
92 error_and_exit(2, 'Invalid input')
99 elif opt in ("-i", "--ip"):
101 elif opt in ("-p", "--port"):
103 elif opt in ("-u", "--user"):
105 elif opt in ("-s", "--scheme"):
107 elif opt in ("-v", "--updateversion"):
108 if arg.lower() == "false" or arg.lower() == "no":
109 update_version = 'false'
111 print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user
117 results = importHeatTypes(scheme, be_host, be_port, admin_user, "../../../import/tosca/heat-types/", update_version)
119 print "-----------------------------"
120 for result in results:
121 print "{0:20} | {1:6}".format(result[0], result[1])
122 print "-----------------------------"
124 response_codes = [200, 201]
126 if update_version == 'false':
127 response_codes = [200, 201, 409]
129 failed_normatives = filter(lambda x: x[1] is None or x[1] not in response_codes, results)
130 if len(list(failed_normatives)) > 0:
131 error_and_exit(1, None)
133 error_and_exit(0, None)
136 if __name__ == "__main__":