summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-02-19 10:28:42 +0200
committerMichael Lando <ml636r@att.com>2017-02-19 10:51:01 +0200
commit451a3400b76511393c62a444f588a4ed15f4a549 (patch)
treee4f5873a863d1d3e55618eab48b83262f874719d /catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py
parent5abfe4e1fb5fae4bbd5fbc340519f52075aff3ff (diff)
Initial OpenECOMP SDC commit
Change-Id: I0924d5a6ae9cdc161ae17c68d3689a30d10f407b Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py')
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py
new file mode 100644
index 0000000000..af643da4f4
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py
@@ -0,0 +1,65 @@
+import pycurl
+import sys, getopt
+from StringIO import StringIO
+import json
+import copy
+from importCommon import *
+################################################################################################################################################
+# #
+# Import all users from a given file #
+# #
+# activation : #
+# python importUsers.py [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
+# #
+# shortest activation (be host = localhost, be port = 8080): # #
+# python importUsers.py [-f <input file> | --ifile=<input file> ] #
+# #
+################################################################################################################################################
+
+def createNormativeElement(beHost, bePort, adminUser, fileDir, urlSuffix, ELEMENT_NAME, elementFormName):
+
+ try:
+ log("in create normative element ", ELEMENT_NAME)
+
+ buffer = StringIO()
+ c = pycurl.Curl()
+
+ url = 'http://' + beHost + ':' + bePort + urlSuffix
+ c.setopt(c.URL, url)
+ c.setopt(c.POST, 1)
+
+ adminHeader = 'USER_ID: ' + adminUser
+ #c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])
+ c.setopt(pycurl.HTTPHEADER, [adminHeader])
+
+
+ path = fileDir + "/" + ELEMENT_NAME + ".zip"
+ debug(path)
+
+ send = [(elementFormName, (pycurl.FORM_FILE, path))]
+ debug(send)
+ c.setopt(pycurl.HTTPPOST, send)
+
+ #data = json.dumps(user)
+ #c.setopt(c.POSTFIELDS, data)
+
+ #c.setopt(c.WRITEFUNCTION, lambda x: None)
+ c.setopt(c.WRITEFUNCTION, buffer.write)
+ #print("before perform")
+ res = c.perform()
+
+ #print("Before get response code")
+ httpRes = c.getinfo(c.RESPONSE_CODE)
+ if (httpRes != None):
+ debug("http response=", httpRes)
+ #print('Status: ' + str(responseCode))
+ debug("response buffer", buffer.getvalue())
+ c.close()
+
+ return (ELEMENT_NAME, httpRes, buffer.getvalue())
+
+ except Exception as inst:
+ print("ERROR=" + str(inst))
+ return (ELEMENT_NAME, None, None)
+
+