summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xconfig/osdf_config.yaml2
-rw-r--r--osdf/adapters/policy/interface.py30
-rwxr-xr-xosdfapp.py4
3 files changed, 36 insertions, 0 deletions
diff --git a/config/osdf_config.yaml b/config/osdf_config.yaml
index 8c6d9f1..eac9883 100755
--- a/config/osdf_config.yaml
+++ b/config/osdf_config.yaml
@@ -20,6 +20,8 @@ conductorMinorVersion: 0
# Policy Platform -- requires ClientAuth, Authorization, and Environment
policyPlatformUrl: http://policy.api.simpledemo.onap.org:8081/pdp/api/getConfig # Policy Dev platform URL
policyPlatformEnv: TEST # Environment for policy platform
+# URL for policy model uploading
+policyPlatformUrlForModelUploading: http://policy.api.simpledemo.onap.org:8081/policy/api/v1/policytypes
# Config for DMaaP
messageReaderHosts: NA
diff --git a/osdf/adapters/policy/interface.py b/osdf/adapters/policy/interface.py
index 95bfacc..7de5858 100644
--- a/osdf/adapters/policy/interface.py
+++ b/osdf/adapters/policy/interface.py
@@ -19,6 +19,9 @@
import base64
import itertools
import json
+import yaml
+import os
+import uuid
from requests import RequestException
@@ -186,3 +189,30 @@ def get_policies(request_json, service_type):
policies = remote_api(request_json, osdf_config, service_type)
return policies
+
+def upload_policy_models():
+ """Upload all the policy models reside in the folder"""
+ model_path = "../../models/policy/placement/tosca"
+ requestId = uuid.uuid4()
+ config = osdf_config.deployment
+ uid, passwd = config['policyPlatformUsername'], config['policyPlatformPassword']
+ pcuid, pcpasswd = config['policyClientUsername'], config['policyClientPassword']
+ headers = {"ClientAuth": base64.b64encode(bytes("{}:{}".format(pcuid, pcpasswd), "ascii"))}
+ headers.update({'Environment': config['policyPlatformEnv']})
+ headers.update({'X-ONAP-RequestID': requestId})
+ url = config['policyPlatformUrlForModelUploading']
+ rc = RestClient(userid=uid, passwd=passwd, headers=headers, url=url, log_func=debug_log.debug)
+
+ for file in os.listdir(model_path):
+ if not file.endswith(".yml"):
+ continue
+ with open(file) as f:
+ file_converted = json.dumps(yaml.load(f))
+ response = rc.request(json=file_converted, ok_codes=(200))
+ if not response:
+ success = False
+ audit_log.warn("Policy model %s uploading failed!" % file)
+ if not success:
+ return "Policy model uploading success!"
+ else:
+ return "Policy model uploading not success!"
diff --git a/osdfapp.py b/osdfapp.py
index a83adb7..ed518b2 100755
--- a/osdfapp.py
+++ b/osdfapp.py
@@ -34,6 +34,7 @@ from schematics.exceptions import DataError
import osdf.adapters.aaf.sms as sms
import osdf.operation.responses
from osdf.adapters.policy.interface import get_policies
+from osdf.adapters.policy.interface import upload_policy_models
from osdf.config.base import osdf_config
from osdf.logging.osdf_logging import MH, audit_log, error_log, debug_log
from osdf.models.api.pciOptimizationRequest import PCIOptimizationAPI
@@ -98,6 +99,9 @@ def handle_data_error(e):
def do_osdf_health_check():
"""Simple health check"""
audit_log.info("A health check request is processed!")
+ """Upload policy models"""
+ response = upload_policy_models()
+ audit_log.info(response)
return "OK"