Sync Integ to Master
[sdc.git] / catalog-be / src / main / resources / scripts / import / tosca / importNormativeCapabilities.py
1 import pycurl
2 import sys, getopt
3 from StringIO import StringIO
4 import json
5 import copy
6 from importNormativeElements import createNormativeElement
7 from importCommon import *
8 import importCommon 
9
10 #################################################################################################################################################################################################
11 #                                                                                                                                                                                                                                                                                                                                                                                       #
12 # Import normative capabilities                                                                                                                                                                                                                                                                                                                                 #
13 #                                                                                                                                                                                                                                                                                                                                                                                               #
14 # activation :                                                                                                                                                                                                                                                                                                                                                                  #
15 #       python importNormativeCapabilities.py [-s <scheme> | --scheme=<scheme> ] [-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 importNormativeCapabilities.py [-f <input file> | --ifile=<input file> ]                                                                                                                                                                                                         #
19 #                                                                                                                                                                                                                                                                                                                                                                                       #
20 #################################################################################################################################################################################################
21
22         
23 def usage():
24         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> ]'
25
26
27 def importNormativeCapabilities(scheme, beHost, bePort, adminUser, exitOnSuccess, fileDir):
28         result = createNormativeElement(scheme, beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/capability", "capabilityTypes", "capabilityTypeZip")
29         
30         printFrameLine()
31         printNameAndReturnCode(result[0], result[1])
32         printFrameLine()
33
34         if ( result[1] == None or result[1] not in [200, 201, 409] ):
35                 importCommon.errorAndExit(1, None)
36         else:
37                 if (exitOnSuccess == True):
38                         importCommon.errorAndExit(0, None)
39
40
41 def main(argv):
42         print 'Number of arguments:', len(sys.argv), 'arguments.'
43
44         beHost = 'localhost' 
45         bePort = '8080'
46         adminUser = 'jh0003'
47         scheme = 'http'
48
49         try:
50                 opts, args = getopt.getopt(argv,"i:p:u:h:s:",["ip=","port=","user=","scheme="])
51         except getopt.GetoptError:
52                 usage()
53                 importCommon.errorAndExit(2, 'Invalid input')
54                  
55         for opt, arg in opts:
56         #print opt, arg
57                 if opt == '-h':
58                         usage()                        
59                         sys.exit(3)
60                 elif opt in ("-i", "--ip"):
61                         beHost = arg
62                 elif opt in ("-p", "--port"):
63                         bePort = arg
64                 elif opt in ("-u", "--user"):
65                         adminUser = arg
66                 elif opt in ("-s", "--scheme"):
67                         scheme = arg
68
69         print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser
70         
71         if ( beHost == None ):
72                 usage()
73                 sys.exit(3)
74
75         importNormativeCapabilities(scheme, beHost, bePort, adminUser, True, "../../../import/tosca/capability-types/")
76
77
78 if __name__ == "__main__":
79         main(sys.argv[1:])
80