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