diff options
author | Malarvizhi <malarvizhi.44@wipro.com> | 2021-10-07 10:30:18 +0000 |
---|---|---|
committer | Malarvizhi <malarvizhi.44@wipro.com> | 2021-10-07 10:45:53 +0000 |
commit | 93997d04f30539b8947f3084d2397b34d9d75e27 (patch) | |
tree | 69efbbdb6564e5e9c8ab993bc772085bb8989c86 | |
parent | a578dbb1e5ce1afd1fccbff42048eb320cd69e20 (diff) |
Add sample policies in OSDF repo3.0.6
Issue-ID: OPTFRA-1009
Signed-off-by: Malarvizhi Paramasivam <malarvizhi.44@wipro.com>
Change-Id: I1d1c2edc5bccd2b172087884f2d2f49e2ad58c5a
22 files changed, 1168 insertions, 3 deletions
diff --git a/examples/policies/nsi_policies/optimization_nsi_create_new.json b/examples/policies/nsi_policies/optimization_nsi_create_new.json new file mode 100644 index 0000000..af79be2 --- /dev/null +++ b/examples/policies/nsi_policies/optimization_nsi_create_new.json @@ -0,0 +1,37 @@ +{ + "maximizeCost_{{ service_name }}": { + "metadata": { + "policy-id": "maximizeCost_{{ service_name }}", + "policy-version": 1 + }, + "properties": { + "geography": [], + "identity": "optimization", + "goal": "maximize", + "operation_function": { + "operator": "sum", + "operands": [ + { + "function": "attribute", + "params": { + "attribute": "creation_cost", + "demand": "{{ service_name }}" + } + } + ] + }, + "resources": [ + "{{ service_name }}" + ], + "scope": [ + "shared,create_new" + ], + "services": [ + "{{ service_name }}" + ] + }, + "type": "onap.policies.optimization.resource.OptimizationPolicy", + "type_version": "2.0.0", + "version": "1.0.0" + } +} diff --git a/examples/policies/nsi_policies/optimization_nsi_non_shared.json b/examples/policies/nsi_policies/optimization_nsi_non_shared.json new file mode 100644 index 0000000..12d7d24 --- /dev/null +++ b/examples/policies/nsi_policies/optimization_nsi_non_shared.json @@ -0,0 +1,37 @@ +{ + "minimizeLatency_{{ service_name }}": { + "metadata": { + "policy-id": "minimizeLatency_{{ service_name }}", + "policy-version": 1 + }, + "properties": { + "geography": [], + "identity": "optimization", + "goal": "minimize", + "operation_function": { + "operator": "sum", + "operands": [ + { + "function": "attribute", + "params": { + "attribute": "latency", + "demand": "{{ service_name }}" + } + } + ] + }, + "resources": [ + "{{ service_name }}" + ], + "scope": [ + "non-shared" + ], + "services": [ + "{{ service_name }}" + ] + }, + "type": "onap.policies.optimization.resource.OptimizationPolicy", + "type_version": "2.0.0", + "version": "1.0.0" + } +} diff --git a/examples/policies/nsi_policies/optimization_nsi_reuse.json b/examples/policies/nsi_policies/optimization_nsi_reuse.json new file mode 100644 index 0000000..459cf33 --- /dev/null +++ b/examples/policies/nsi_policies/optimization_nsi_reuse.json @@ -0,0 +1,37 @@ +{ + "minimizeCost_{{ service_name }}": { + "metadata": { + "policy-id": "minimizeCost_{{ service_name }}", + "policy-version": 1 + }, + "properties": { + "geography": [], + "identity": "optimization", + "goal": "minimize", + "operation_function": { + "operator": "sum", + "operands": [ + { + "function": "attribute", + "params": { + "attribute": "creation_cost", + "demand": "{{ service_name }}" + } + } + ] + }, + "resources": [ + "{{ service_name }}" + ], + "scope": [ + "shared,reuse" + ], + "services": [ + "{{ service_name }}" + ] + }, + "type": "onap.policies.optimization.resource.OptimizationPolicy", + "type_version": "2.0.0", + "version": "1.0.0" + } +} diff --git a/examples/policies/nsi_policies/query_nsi.json b/examples/policies/nsi_policies/query_nsi.json new file mode 100644 index 0000000..e888a99 --- /dev/null +++ b/examples/policies/nsi_policies/query_nsi.json @@ -0,0 +1,69 @@ +{ + "queryPolicy_{{ service_name }}":{ + "type":"onap.policies.optimization.service.QueryPolicy", + "version":"1.0.0", + "type_version":"1.0.0", + "metadata":{ + "policy-id":"queryPolicy_{{ service_name }}", + "policy-version":1 + }, + "properties":{ + "scope":[ + "shared,reuse", + "shared,create_new", + "non-shared" + ], + "services":[ + "{{ service_name }}" + ], + "geography":[], + "identity":"queryPolicy_{{ service_name }}", + "queryProperties":[ + { + "attribute":"latency", + "attribute_location":"latency" + }, + { + "attribute":"max_number_of_ues", + "attribute_location":"max_number_of_ues" + }, + { + "attribute":"s_nssai", + "attribute_location":"s_nssai" + }, + { + "attribute":"resource_sharing_level", + "attribute_location":"resource_sharing_level" + }, + { + "attribute":"ue_mobility_level", + "attribute_location":"ue_mobility_level" + }, + { + "attribute":"sst", + "attribute_location":"sst" + }, + { + "attribute":"AN_latency", + "attribute_location":"AN_latency" + }, + { + "attribute":"CN_latency", + "attribute_location":"CN_latency" + }, + { + "attribute":"TN_BH_latency", + "attribute_location":"TN_BH_latency" + }, + { + "attribute":"model_invariant_id", + "attribute_location":"invariantUUID" + }, + { + "attribute":"model_version_id", + "attribute_location":"UUID" + } + ] + } + } +} diff --git a/examples/policies/nsi_policies/threshold_nsi.json b/examples/policies/nsi_policies/threshold_nsi.json new file mode 100644 index 0000000..ef4c362 --- /dev/null +++ b/examples/policies/nsi_policies/threshold_nsi.json @@ -0,0 +1,38 @@ +{ + "Threshold_{{ service_name }}":{ + "metadata":{ + "policy-id":"Threshold_{{ service_name }}", + "policy-version":1 + }, + "properties":{ + "geography":[ + + ], + "identity":"Threshold_{{ service_name }}", + "resources":[ + "{{ service_name }}" + ], + "scope":[ + "shared,reuse", + "shared,create_new", + "non-shared" + ], + "services":[ + "{{ service_name }}" + ], + "thresholdProperties":[ + { + "attribute":"latency", + "operator":"lte", + "threshold":{ + "get_param":"latency" + }, + "unit":"ms" + } + ] + }, + "type":"onap.policies.optimization.resource.ThresholdPolicy", + "type_version":"1.0.0", + "version":"1.0.0" + } +} diff --git a/examples/policies/nsi_policies/vnf_nsi_nonshared.json b/examples/policies/nsi_policies/vnf_nsi_nonshared.json new file mode 100644 index 0000000..49b1c95 --- /dev/null +++ b/examples/policies/nsi_policies/vnf_nsi_nonshared.json @@ -0,0 +1,92 @@ +{ + "vnfPolicy_{{ service_name }}_non_shared":{ + "metadata":{ + "policy-id":"vnfPolicy_{{ service_name }}_non_shared", + "policy-version":1 + }, + "properties":{ + "identity":"vnf_{{ service_name }}", + "resources":["{{ service_name }}"], + "scope":[ + "non-shared" + ], + "services":[ + "{{ service_name }}" + ], + "geography":[], + "vnfProperties":[ + { + "attributes":{ + "service_profile": { + "latency": {"value": {"get_param": "latency"}, "operator": "lte"}, + "s_nssai": {"value": {"get_param": "s_nssai"}, "operator": "eq"}, + "resource_sharing_level": {"value": {"get_param": "resource_sharing_level"}, "operator": "eq"}, + "ue_mobility_level": {"value": {"get_param": "ue_mobility_level"}, "operator": "eq"}, + "sst": {"value": {"get_param": "sst"}, "operator": "eq"}, + "max_number_of_ues": {"value": {"get_param": "max_number_of_ues"}, "operator": "eq"} + }, + "subnets": { + "CN":{ + "latency":{ + "max":{"get_param":"latency"}, + "min":{"get_param":"CN_latency"}, + "steps":5 + }, + "s_nssai":{ + "values":[ + {"get_param": "s_nssai"} + ] + }, + "max_number_of_ues": {"values":[{"get_param": "max_number_of_ues"}]}, + "sst": {"values":[{"get_param": "sst"}]}, + "resource_sharing_level": {"values":[{"get_param": "resource_sharing_level"}]}, + "plmn_id_list": {"values":["39-00"]}, + "survival_time": {"values":["10"]}, + "ue_mobility_level": {"values":[{"get_param": "ue_mobility_level"}]} + }, + "AN":{ + "latency":{ + "max":{"get_param":"latency"}, + "min":{"get_param":"AN_latency"}, + "steps":5 + }, + "s_nssai":{ + "values":[ + {"get_param": "s_nssai"} + ] + }, + "max_number_of_ues": {"values":[{"get_param": "max_number_of_ues"}]}, + "sst": {"values":[{"get_param": "sst"}]}, + "plmn_id_list": {"values":["39-00"]}, + "survival_time": {"values":["10"]}, + "resource_sharing_level": {"values":[{"get_param": "resource_sharing_level"}]}, + "ue_mobility_level": {"values":[{"get_param": "ue_mobility_level"}]} + }, + "TN_BH":{ + "latency":{ + "max":{"get_param":"latency"}, + "min":{"get_param":"TN_BH_latency"}, + "steps":5 + }, + "s_nssai": {"values": [{"get_param": "s_nssai"}]}, + "plmn_id_list": {"values":["39-00"]}, + "max_bandwidth": {"values":[1000]}, + "sst": {"values":[{"get_param": "sst"}]} + } + } + }, + "inventoryProvider":"generator", + "inventoryType":"slice_profiles", + "unique":"true", + "defaultAttributes":{ + "creation_cost" : 0.9 + } + } + ] + }, + "type":"onap.policies.optimization.resource.VnfPolicy", + "type_version":"1.0.0", + "version":"1.0.0" + } +} + diff --git a/examples/policies/nsi_policies/vnf_nsi_notshared.json b/examples/policies/nsi_policies/vnf_nsi_notshared.json new file mode 100644 index 0000000..afdbd50 --- /dev/null +++ b/examples/policies/nsi_policies/vnf_nsi_notshared.json @@ -0,0 +1,121 @@ +{ + "vnfPolicy_{{ service_name }}_not_shared":{ + "metadata":{ + "policy-id":"vnfPolicy_{{ service_name }}_not_shared", + "policy-version":1 + }, + "properties":{ + "identity":"vnf_{{ service_name }}", + "resources":["{{ service_name }}"], + "scope":[ + "non-shared" + ], + "services":[ + "{{ service_name }}" + ], + "geography":[], + "vnfProperties":[ + { + "attributes":{ + "service_profile": { + "latency": {"value": {"get_param": "latency"}, "operator": "lte"}, + "max_throughput": {"value": {"get_param": "max_throughput"}, "operator": "gte"}, + "max_number_of_ues": {"value": {"get_param": "max_number_of_ues"}, "operator": "gte"}, + "terminal_density": {"value": {"get_param": "terminal_density"}, "operator": "gte"}, + "s_nssai_list": {"value": {"get_param": "s_nssai_list"}, "operator": "eq"}, + "plmn_id_list": {"value": {"get_param": "plmn_id_list"}, "operator": "eq"} + }, + "subnets": { + "AN_NF":{ + "latency":{ + "max":{"get_param":"latency"}, + "min":{"get_param":"AN_NF_latency"}, + "steps":1 + }, + "max_throughput":{ + "values":[ + {"get_param": "AN_NF_max_throughput"} + ] + }, + "max_number_of_ues":{ + "values":[ + {"get_param": "AN_NF_max_number_of_ues"} + ] + }, + "terminal_density":{ + "values":[ + {"get_param": "AN_NF_terminal_density"} + ] + }, + "s_nssai_list":{ + "values":[ + {"get_param": "s_nssai_list"} + ] + }, + "plmn_id_list":{ + "values":[ + {"get_param": "plmn_id_list"} + ] + } + }, + "TN_FH":{ + "latency":{ + "max":{"get_param":"latency"}, + "min":{"get_param":"TN_FH_latency"}, + "steps":1 + }, + "max_throughput":{ + "values":[ + {"get_param": "TN_FH_max_throughput"} + ] + }, + "s_nssai_list":{ + "values":[ + {"get_param": "s_nssai_list"} + ] + }, + "plmn_id_list":{ + "values":[ + {"get_param": "plmn_id_list"} + ] + } + }, + "TN_MH":{ + "latency":{ + "max":{"get_param":"latency"}, + "min":{"get_param":"TN_MH_latency"}, + "steps":1 + }, + "max_throughput":{ + "values":[ + {"get_param": "TN_MH_max_throughput"} + ] + }, + "s_nssai_list":{ + "values":[ + {"get_param": "s_nssai_list"} + ] + }, + "plmn_id_list":{ + "values":[ + {"get_param": "plmn_id_list"} + ] + } + } + } + }, + "inventoryProvider":"generator", + "inventoryType":"slice_profiles", + "unique":"true", + "defaultAttributes":{ + "creation_cost" : 0.9 + } + } + ] + }, + "type":"onap.policies.optimization.resource.VnfPolicy", + "type_version":"1.0.0", + "version":"1.0.0" + } +} + diff --git a/examples/policies/nsi_policies/vnf_nsi_shared.json b/examples/policies/nsi_policies/vnf_nsi_shared.json new file mode 100644 index 0000000..cce2f73 --- /dev/null +++ b/examples/policies/nsi_policies/vnf_nsi_shared.json @@ -0,0 +1,105 @@ +{ + "vnfPolicy_{{ service_name }}":{ + "metadata":{ + "policy-id":"vnfPolicy_{{ service_name }}", + "policy-version":1 + }, + "properties":{ + "identity":"vnf_{{ service_name }}", + "resources":["{{ service_name }}"], + "scope":[ + "shared,reuse", + "shared,create_new" + ], + "services":[ + "{{ service_name }}" + ], + "geography":[], + "vnfProperties":[ + { + "attributes":{ + "modelInvariantId":{"get_param": "model_invariant_id"}, + "modelVersionId":{"get_param": "model_version_id"}, + "service-role":"nsi" + }, + "inventoryProvider":"aai", + "inventoryType":"nsi", + "unique":"true", + "defaultAttributes":{ + "creation_cost" : 0.1 + } + }, + { + "attributes":{ + "service_profile": { + "latency": {"value": {"get_param": "latency"}, "operator": "lte"}, + "s_nssai": {"value": {"get_param": "s_nssai"}, "operator": "eq"}, + "resource_sharing_level": {"value": {"get_param": "resource_sharing_level"}, "operator": "eq"}, + "ue_mobility_level": {"value": {"get_param": "ue_mobility_level"}, "operator": "eq"}, + "sst": {"value": {"get_param": "sst"}, "operator": "eq"}, + "max_number_of_ues": {"value": {"get_param": "max_number_of_ues"}, "operator": "eq"} + }, + "subnets": { + "CN":{ + "latency":{ + "max":{"get_param":"latency"}, + "min":{"get_param":"CN_latency"}, + "steps":5 + }, + "s_nssai":{ + "values":[ + {"get_param": "s_nssai"} + ] + }, + "sst": {"values":[{"get_param": "sst"}]}, + "resource_sharing_level": {"values":[{"get_param": "resource_sharing_level"}]}, + "plmn_id_list": {"values":["39-00"]}, + "survival_time": {"values":["10"]}, + "max_number_of_ues": {"values":[{"get_param": "max_number_of_ues"}]}, + "ue_mobility_level": {"values":[{"get_param": "ue_mobility_level"}]} + }, + "AN":{ + "latency":{ + "max":{"get_param":"latency"}, + "min":{"get_param":"AN_latency"}, + "steps":5 + }, + "s_nssai":{ + "values":[ + {"get_param": "s_nssai"} + ] + }, + "sst": {"values":[{"get_param": "sst"}]}, + "plmn_id_list": {"values":["39-00"]}, + "survival_time": {"values":["10"]}, + "max_number_of_ues": {"values":[{"get_param": "max_number_of_ues"}]}, + "resource_sharing_level": {"values":[{"get_param": "resource_sharing_level"}]}, + "ue_mobility_level": {"values":[{"get_param": "ue_mobility_level"}]} + }, + "TN_BH":{ + "latency":{ + "max":{"get_param":"latency"}, + "min":{"get_param":"TN_BH_latency"}, + "steps":5 + }, + "s_nssai": {"values":[{"get_param": "s_nssai"}]}, + "max_bandwidth": {"values":[1000]}, + "plmn_id_list": {"values":["39-00"]}, + "sst": {"values":[{"get_param": "sst"}]} + } + } + }, + "inventoryProvider":"generator", + "inventoryType":"slice_profiles", + "unique":"true", + "defaultAttributes":{ + "creation_cost" : 0.9 + } + } + ] + }, + "type":"onap.policies.optimization.resource.VnfPolicy", + "type_version":"1.0.0", + "version":"1.0.0" + } +} diff --git a/examples/policies/nssi_policies/optimization_nssi.json b/examples/policies/nssi_policies/optimization_nssi.json new file mode 100644 index 0000000..9d744e9 --- /dev/null +++ b/examples/policies/nssi_policies/optimization_nssi.json @@ -0,0 +1,37 @@ +{ + "{{ goal }}_{{ attribute }}_{{ service_name }}": { + "metadata": { + "policy-id": "{{ goal }}_{{ attribute }}_{{ service_name }}", + "policy-version": 1 + }, + "properties": { + "geography": [], + "identity": "optimization", + "goal": "{{ goal }}", + "operation_function": { + "operator": "sum", + "operands": [ + { + "function": "attribute", + "params": { + "attribute": "{{ attribute }}", + "demand": "{{ service_name }}" + } + } + ] + }, + "resources": [ + "{{ service_name }}" + ], + "scope": [ + "OSDF_GUILIN" + ], + "services": [ + "{{ service_name }}" + ] + }, + "type": "onap.policies.optimization.resource.OptimizationPolicy", + "type_version": "2.0.0", + "version": "1.0.0" + } +} diff --git a/examples/policies/nssi_policies/query_nssi.json b/examples/policies/nssi_policies/query_nssi.json new file mode 100644 index 0000000..c5eea26 --- /dev/null +++ b/examples/policies/nssi_policies/query_nssi.json @@ -0,0 +1,39 @@ +{ + "queryPolicy_{{ service_name }}":{ + "type":"onap.policies.optimization.service.QueryPolicy", + "version":"1.0.0", + "type_version":"1.0.0", + "metadata":{ + "policy-id":"queryPolicy_{{ service_name }}", + "policy-version":1 + }, + "properties":{ + "scope":[ + "OSDF_GUILIN" + ], + "services":[ + "{{ service_name }}" + ], + "geography":[], + "identity":"queryPolicy_{{ service_name }}", + "queryProperties":[ + { + "attribute":"latency", + "attribute_location":"latency" + }, + { + "attribute":"reliability", + "attribute_location":"reliability" + }, + { + "attribute":"model_invariant_id", + "attribute_location":"invariantUUID" + }, + { + "attribute":"model_version_id", + "attribute_location":"UUID" + } + ] + } + } +}
\ No newline at end of file diff --git a/examples/policies/nssi_policies/threshold_nssi.json b/examples/policies/nssi_policies/threshold_nssi.json new file mode 100644 index 0000000..f7b7ff6 --- /dev/null +++ b/examples/policies/nssi_policies/threshold_nssi.json @@ -0,0 +1,44 @@ +{ + "Threshold_{{ service_name }}":{ + "metadata":{ + "policy-id":"Threshold_{{ service_name }}", + "policy-version":1 + }, + "properties":{ + "geography":[ + + ], + "identity":"Threshold_{{ service_name }}", + "resources":[ + "{{ service_name }}" + ], + "scope":[ + "OSDF_GUILIN" + ], + "services":[ + "{{ service_name }}" + ], + "thresholdProperties":[ + { + "attribute":"latency", + "operator":"lte", + "threshold":{ + "get_param":"latency" + }, + "unit":"ms" + }, + { + "attribute":"reliability", + "operator":"gte", + "threshold":{ + "get_param":"reliability" + }, + "unit":"" + } + ] + }, + "type":"onap.policies.optimization.resource.ThresholdPolicy", + "type_version":"1.0.0", + "version":"1.0.0" + } +}
\ No newline at end of file diff --git a/examples/policies/nssi_policies/vnf_nssi.json b/examples/policies/nssi_policies/vnf_nssi.json new file mode 100644 index 0000000..fd54b7b --- /dev/null +++ b/examples/policies/nssi_policies/vnf_nssi.json @@ -0,0 +1,37 @@ +{ + "vnfPolicy_{{ service_name }}":{ + "metadata":{ + "policy-id":"vnfPolicy_{{ service_name }}", + "policy-version":1 + }, + "properties":{ + "identity":"vnf_{{ service_name }}", + "resources":[ + "{{ service_name }}" + ], + "scope":[ + "OSDF_GUILIN" + ], + "services":[ + "{{ service_name }}" + ], + "geography":[], + "vnfProperties":[ + { + "attributes":{ + "modelInvariantId":{"get_param": "model_invariant_id"}, + "modelVersionId":{"get_param": "model_version_id"}, + "service-function":"shared", + "service-role":"nssi" + }, + "inventoryProvider":"aai", + "inventoryType":"nssi", + "unique":"true" + } + ] + }, + "type":"onap.policies.optimization.resource.VnfPolicy", + "type_version":"1.0.0", + "version":"1.0.0" + } +}
\ No newline at end of file diff --git a/examples/policies/nst_policies/attribute_policy_nst.json b/examples/policies/nst_policies/attribute_policy_nst.json new file mode 100644 index 0000000..da2e5fe --- /dev/null +++ b/examples/policies/nst_policies/attribute_policy_nst.json @@ -0,0 +1,41 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", + "topology_template": { + "policies": [ +{ + "Threshold_nst": { + "metadata": { + "policy-id": "Threshold_nst", + "policy-version": 1 + }, + "properties": { + "geography": [], + "identity": "nst_Threshold", + "resources": [ + "nst" + ], + "scope": [ + "OSDF_GUILIN" + ], + "services": [ + "nst" + ], + "thresholdProperties": [ + { + "attribute": "latency", + "operator": "lte", + "threshold": { + "get_param": "latency" + }, + "unit": "ms" + } + ] + }, + "type": "onap.policies.optimization.resource.ThresholdPolicy", + "type_version": "1.0.0", + "version": "1.0.0" + } +} + ] + } +} diff --git a/examples/policies/nst_policies/optimization_policy_nst.json b/examples/policies/nst_policies/optimization_policy_nst.json new file mode 100644 index 0000000..09737ad --- /dev/null +++ b/examples/policies/nst_policies/optimization_policy_nst.json @@ -0,0 +1,44 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", + "topology_template": { + "policies": [ +{ + "nst_minimize_latency": { + "metadata": { + "policy-id": "nst_minimize_latency", + "policy-version": 1 + }, + "properties": { + "geography": [], + "identity": "optimization", + "goal": "minimize", + "operation_function": { + "operator": "sum", + "operands": [ + { + "function": "attribute", + "params": { + "attribute": "latency", + "demand": "nst" + } + } + ] + }, + "resources": [ + "nst" + ], + "scope": [ + "OSDF_GUILIN" + ], + "services": [ + "nst" + ] + }, + "type": "onap.policies.optimization.resource.OptimizationPolicy", + "type_version": "2.0.0", + "version": "1.0.0" + } +} + ] + } +} diff --git a/examples/policies/nst_policies/query_policy_nst.json b/examples/policies/nst_policies/query_policy_nst.json new file mode 100644 index 0000000..2ce441b --- /dev/null +++ b/examples/policies/nst_policies/query_policy_nst.json @@ -0,0 +1,38 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", + "topology_template": { + "policies": [ +{ + "queryPolicy_nst": { + "type": "onap.policies.optimization.service.QueryPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "queryPolicy_nst", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_GUILIN" + ], + "services": [ + "nst" + ], + "geography": [], + "identity": "queryPolicy_nst", + "queryProperties": [ + { + "attribute": "latency", + "attribute_location": "latency" + }, + { + "attribute": "areaTrafficCapDL", + "attribute_location": "areaTrafficCapDL" + } + ] + } + } +} + ] + } +} diff --git a/examples/policies/nst_policies/vnf_policy_nst.json b/examples/policies/nst_policies/vnf_policy_nst.json new file mode 100644 index 0000000..422030c --- /dev/null +++ b/examples/policies/nst_policies/vnf_policy_nst.json @@ -0,0 +1,41 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", + "topology_template": { + "policies": [ +{ + "vnfPolicy_nst": { + "type": "onap.policies.optimization.resource.VnfPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "vnfPolicy_nst", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_GUILIN" + ], + "resources": [ + "nst" + ], + "services": [ + "nst" + ], + "identity": "vnf_nst", + "applicableResources": "any", + "vnfProperties": [ + { + "inventoryProvider": "aai", + "inventoryType": "nst", + "unique": "true", + "attributes": { + "model-role": "NST" + } + } + ] + } + } +} + ] + } +} diff --git a/examples/policies/policy_types/optimization_v2.json b/examples/policies/policy_types/optimization_v2.json new file mode 100644 index 0000000..ea5ca6f --- /dev/null +++ b/examples/policies/policy_types/optimization_v2.json @@ -0,0 +1,61 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", + "policy_types": { + "onap.policies.optimization.resource.OptimizationPolicy": { + "derived_from": "onap.policies.optimization.Resource", + "version": "2.0.0", + "name": "onap.policies.optimization.resource.OptimizationPolicy", + "properties": { + "goal": { + "type": "list", + "required": true, + "entry_schema": { + "type": "string", + "constraints": [ + { + "valid_values": [ + "minimize", + "maximize" + ] + } + ] + } + }, + "operation_function": { + "type": "policy.data.operation_function_properties", + "required": true + } + } + } + }, + "data_types": { + "policy.data.operation_function_properties": { + "derived_from": "tosca.nodes.Root", + "properties": { + "operands": { + "type": "list", + "required": true, + "entry_schema": { + "type": "map" + } + }, + "operator": { + "type": "string", + "required": true, + "entry_schema": { + "type": "string", + "constraints": [ + { + "valid_values": [ + "sum", + "min", + "max" + ] + } + ] + } + } + } + } + } +}
\ No newline at end of file diff --git a/examples/policies/policy_types/threshold.json b/examples/policies/policy_types/threshold.json new file mode 100644 index 0000000..60c73fa --- /dev/null +++ b/examples/policies/policy_types/threshold.json @@ -0,0 +1,56 @@ +{ + "tosca_definitions_version": "tosca_simple_yaml_1_1_0", + "policy_types": { + "onap.policies.optimization.resource.ThresholdPolicy": { + "derived_from": "onap.policies.optimization.Resource", + "version": "1.0.0", + "properties": { + "applicableResources": { + "type": "list", + "required": true, + "entry_schema": { + "type": "string", + "constraints": [ + { + "valid_values": [ + "any", + "all" + ] + } + ] + } + }, + "thresholdProperties": { + "type": "list", + "required": true, + "entry_schema": { + "type": "policy.data.thresholdProperties_properties" + } + } + } + } + }, + "data_types": { + "policy.data.thresholdProperties_properties": { + "derived_from": "tosca.nodes.Root", + "properties": { + "attribute": { + "type": "string", + "required": true + }, + "operator": { + "type": "string", + "required": true + }, + "threshold": { + "type": "float", + "required": true + }, + "unit": { + "type": "string", + "required": false + } + } + } + } +}
\ No newline at end of file diff --git a/examples/policies/policy_utils.py b/examples/policies/policy_utils.py new file mode 100644 index 0000000..0c1b595 --- /dev/null +++ b/examples/policies/policy_utils.py @@ -0,0 +1,192 @@ +from jinja2 import Template +import json +import os +import requests +import sys + +BASE_DIR = os.path.dirname(os.path.dirname(__file__)) + +HEADERS = {'Content-Type': 'application/json'} +AUTH = requests.auth.HTTPBasicAuth('healthcheck', 'zb!XztG34') + + +def get_tosca_policy(policy): + pol = json.loads(policy) + tosca_policy = { + 'tosca_definitions_version': 'tosca_simple_yaml_1_1_0', + 'topology_template': { + 'policies': [pol] + } + } + return json.dumps(tosca_policy) + +def gen_policy(template_dir, gen_dir, filename, jinja_args): + with open(os.path.join(template_dir, filename), 'r') as file: + contents = file.read() + tm = Template(contents) + gen = tm.render(jinja_args) + tosca_policy = get_tosca_policy(gen) + with open(os.path.join(gen_dir, filename), 'w') as file: + file.write(tosca_policy) + +def create_and_push_policies(policy_dir): + for filename in os.listdir(policy_dir): + if filename.endswith('.json'): + with open(os.path.join(policy_dir, filename), 'r') as file: + data = json.loads(file.read()) + metadata = create_policy(data) + if metadata: + push_policy(metadata) + +def delete_policies(policy_dir): + for filename in os.listdir(policy_dir): + if filename.endswith('.json'): + with open(os.path.join(policy_dir, filename), 'r') as file: + data = json.loads(file.read()) + policy_id = list(data['topology_template']['policies'][0].keys())[0] + undeploy_policy(policy_id) + metadata = delete_policy(data) + +def create_policy(data): + policy = data['topology_template']['policies'][0] + content = policy[list(policy.keys())[0]] + policy_type = content['type'] + type_version = content['type_version'] + policy_url = "https://policy-api:6969" + path = '/policy/api/v1/policytypes/{}/versions/{}/policies'.format(policy_type, type_version) + url = policy_url + path + try: + response = requests.post(url, headers=HEADERS, auth=AUTH, data=json.dumps(data), verify=False) + except Exception as e: + print(str(e)) + return None + if response.status_code == 200: + print('Policy {} created'.format(content['metadata']['policy-id'])) + return content['metadata'] + else: + print(response.content) + return None + +def push_policy(metadata): + data = {'policies': [metadata]} + policy_url = "https://policy-pap:6969" + path = '/policy/pap/v1/pdps/policies' + url = policy_url + path + try: + response = requests.post(url, headers=HEADERS, auth=AUTH, data=json.dumps(data), verify=False) + except Exception as e: + print(str(e)) + print("Cannot push policy {}".format(metadata['policy-id'])) + if response.status_code == 200: + print("Policy {} pushed".format(metadata['policy-id'])) + else: + print(response.content) + +def undeploy_policy(policy_id): + policy_url = "https://policy-pap:6969" + path = '/policy/pap/v1/pdps/policies/{}'.format(policy_id) + url = policy_url + path + try: + response = requests.delete(url, headers=HEADERS, auth=AUTH, verify=False) + except Exception as e: + print(str(e)) + print("Cannot undeploy policy {}".format(policy_id)) + if response.status_code == 200: + print("Policy {} undeployed".format(policy_id)) + else: + print(response.content) + +def delete_policy(data): + policy = data['topology_template']['policies'][0] + content = policy[list(policy.keys())[0]] + policy_type = content['type'] + type_version = content['type_version'] + policy_id = content['metadata']['policy-id'] + version = content['version'] + policy_url = "https://policy-api:6969" + path = '/policy/api/v1/policytypes/{}/versions/{}/policies/{}/versions/{}'.format(policy_type, type_version, policy_id, version) + url = policy_url + path + try: + response = requests.delete(url, headers=HEADERS, auth=AUTH, data=json.dumps(data), verify=False) + except Exception as e: + print(str(e)) + return None + if response.status_code == 200: + print('Policy {} deleted'.format(content['metadata']['policy-id'])) + return content['metadata'] + else: + print(response.content) + return None + +def generate_nssi_policies(jinja_args): + template_dir = BASE_DIR + 'nssi_policies' + gen_dir = BASE_DIR + 'gen_nssi_policies' + + if not os.path.exists(gen_dir): + os.mkdir(gen_dir) + + for filename in os.listdir(template_dir): + if filename.endswith('.json'): + gen_policy(template_dir, gen_dir, filename, jinja_args) + +def generate_nsi_policies(jinja_args): + template_dir = BASE_DIR + 'nsi_policies' + gen_dir = BASE_DIR + 'gen_nsi_policies' + + if not os.path.exists(gen_dir): + os.mkdir(gen_dir) + + for filename in os.listdir(template_dir): + if filename.endswith('.json'): + gen_policy(template_dir, gen_dir, filename, jinja_args) + +def create_policy_types(policy_dir): + for filename in os.listdir(policy_dir): + if filename.endswith('.json'): + with open(os.path.join(policy_dir, filename), 'r') as file: + data = json.loads(file.read()) + create_policy_type(data) + +def create_policy_type(data): + policy_url = "https://policy-api:6969" + path = '/policy/api/v1/policytypes' + url = policy_url + path + try: + response = requests.post(url, headers=HEADERS, auth=AUTH, data=json.dumps(data), verify=False) + except Exception as e: + print(str(e)) + return None + if response.status_code == 200: + print('Policy type created') + else: + print(response.content) + return None + + +action = sys.argv[1] + +if action == "generate_nssi_policies": + jinja_args = { + 'service_name': sys.argv[2], + 'goal': sys.argv[3], + 'attribute': sys.argv[4] + } + generate_nssi_policies(jinja_args) + +elif action == "create_and_push_policies": + policy_dir = sys.argv[2] + create_and_push_policies(policy_dir) + +elif action == "delete_policies": + policy_dir = sys.argv[2] + delete_policies(policy_dir) + +elif action == "generate_nsi_policies": + jinja_args = { + 'service_name': sys.argv[2] + } + generate_nsi_policies(jinja_args) + +elif action == "create_policy_types": + policy_dir = sys.argv[2] + create_policy_types(policy_dir)
\ No newline at end of file diff --git a/examples/policies/requirements.txt b/examples/policies/requirements.txt new file mode 100644 index 0000000..1c579e7 --- /dev/null +++ b/examples/policies/requirements.txt @@ -0,0 +1 @@ +jinja2
\ No newline at end of file diff --git a/requirements.txt b/requirements.txt index fb2217f..b17a915 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,5 +16,3 @@ pathtools>=0.1.2 pycryptodome>=3.9.6 python-consul>=1.1.0 tornado>=6.1 - - diff --git a/version.properties b/version.properties index 7eff519..bb98692 100644 --- a/version.properties +++ b/version.properties @@ -19,7 +19,7 @@ major=3 minor=0 -patch=5 +patch=6 base_version=${major}.${minor}.${patch} |