-============LICENSE_START=======================================================
-org.onap.dcae
================================================================================
Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
================================================================================
# dcae-policy plugin and node-type
+
- python-package dcaepolicyplugin to be used in cloudify plugins to retrieve the policy from policy-handler
---
## dcaepolicy node type [dcaepolicy-node-type.yaml](./dcaepolicy-node-type.yaml)
+
- node type for dcae.nodes.policy
---
```yaml
imports:
- - https://YOUR_NEXUS_RAW_SERVER/type_files/dcaepolicy/1.0.0/node-type.yaml
+ - https://YOUR_NEXUS_RAW_SERVER/type_files/dcaepolicy/2.1.0/node-type.yaml
```
provide the value for policy_id property
-# ============LICENSE_START=======================================================
-# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
dcaepolicy:
executor: 'central_deployment_agent'
package_name: dcaepolicyplugin
- package_version: 2.0.0
+ package_version: 2.1.0
data_types:
# the properties inside dcae.data.policy_filter are identical to /getConfig API of policy-engine except the requestID field.
# policy-engine /getConfig wiki: The filter works as a combined "AND" operation.
# To retrieve all policies using "sample" as configName,
# the request needs to have policyName = ".*" and configName as = "sample"
- # configAttributes is a key-value dictionary
+ # configAttributes is a key-value dictionary or a stringified json of the dictionary
dcae.data.policy_filter:
properties:
policyName:
-# ============LICENSE_START=======================================================
-# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
-# ============LICENSE_START=======================================================
-# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
-# ============LICENSE_START=======================================================
-# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
DCAE_POLICY_TYPE = 'dcae.nodes.policy'
DCAE_POLICIES_TYPE = 'dcae.nodes.policies'
DCAE_POLICY_TYPES = [DCAE_POLICY_TYPE, DCAE_POLICIES_TYPE]
+CONFIG_ATTRIBUTES = "configAttributes"
class PolicyHandler(object):
"""talk to policy-handler"""
ctx.instance.runtime_properties[POLICY_BODY] = policy[POLICY_BODY]
return True
+def _fix_policy_filter(policy_filter):
+ if CONFIG_ATTRIBUTES in policy_filter:
+ config_attributes = policy_filter.get(CONFIG_ATTRIBUTES)
+ if isinstance(config_attributes, dict):
+ return
+ try:
+ config_attributes = json.loads(config_attributes)
+ if config_attributes and isinstance(config_attributes, dict):
+ policy_filter[CONFIG_ATTRIBUTES] = config_attributes
+ return
+ except (ValueError, TypeError):
+ pass
+ if config_attributes:
+ ctx.logger.warn("unexpected %s: %s", CONFIG_ATTRIBUTES, config_attributes)
+ del policy_filter[CONFIG_ATTRIBUTES]
+
def _policies_find():
"""
dcae.nodes.policies -
(k, v) for (k, v) in dict(ctx.node.properties.get(POLICY_FILTER, {})).iteritems()
if v or isinstance(v, (int, float))
))
+ _fix_policy_filter(policy_filter)
+
if REQUEST_ID not in policy_filter:
policy_filter[REQUEST_ID] = str(uuid.uuid4())
<groupId>org.onap.dcaegen2.platform.plugins</groupId>
<artifactId>dcae-policy</artifactId>
<name>dcae-policy-plugin</name>
- <version>2.0.0-SNAPSHOT</version>
+ <version>2.1.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-# ============LICENSE_START=======================================================
-# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
setup(
name='dcaepolicyplugin',
description='Cloudify plugin for dcae.nodes.policy node to retrieve the policy config',
- version="2.0.0",
+ version="2.1.0",
author='Alex Shatov',
packages=['dcaepolicyplugin'],
install_requires=[
-# org.onap.dcae
# ================================================================================
# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
-# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
-# ============LICENSE_START=======================================================
-# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
-# ============LICENSE_START=======================================================
-# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
POLICY_BODY = 'policy_body'
POLICY_CONFIG = 'config'
LATEST_POLICIES = "latest_policies"
+CONFIG_NAME = "ConfigName"
MONKEYED_POLICY_ID = 'monkeyed.Config_peach'
LOG_FILE = 'logs/test_dcaepolicyplugin.log'
POLICY_CONFIG: config,
"matchingConditions": {
"ONAPName": "DCAE",
- "ConfigName": "alex_config_name"
+ CONFIG_NAME: "alex_config_name"
},
"responseAttributes": {},
"property": None
{LATEST_POLICIES: {
MONKEYED_POLICY_ID: MonkeyedPolicyBody.create_policy(MONKEYED_POLICY_ID)}})
-def test_policy_find(monkeypatch):
+def test_policies_find(monkeypatch):
"""test policy_get operation on dcae.nodes.policies node"""
monkeypatch.setattr('requests.post', monkeyed_policy_handler_find)
'test_dcae_policies_node_id',
'test_dcae_policies_node_name',
tasks.DCAE_POLICIES_TYPE,
- {tasks.POLICY_FILTER: {POLICY_NAME: MONKEYED_POLICY_ID}}
+ {
+ tasks.POLICY_FILTER: {
+ POLICY_NAME: MONKEYED_POLICY_ID,
+ tasks.CONFIG_ATTRIBUTES: json.dumps({
+ CONFIG_NAME: "alex_config_name"
+ })
+ }
+ }
)
try: