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