diff options
author | Vikas Varma <vv8305@att.com> | 2019-04-09 13:51:04 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-09 13:51:04 +0000 |
commit | 134a18e619772b6cb21000c97291d7966d5598eb (patch) | |
tree | f8bb8721373f998333fb995ebc085b0aecd1beb1 /osdf/adapters | |
parent | 2d59800cf61a90e2a80902186bdce3b28e5ae14d (diff) | |
parent | 0e957e6ff4bae412ba909f9677d485d4abc0362b (diff) |
Merge "Automate the process of policy model uploading"
Diffstat (limited to 'osdf/adapters')
-rw-r--r-- | osdf/adapters/policy/interface.py | 30 |
1 files changed, 30 insertions, 0 deletions
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!" |