From 93f1b1305cef4f52581c80dbbe2ed6ccef1bbeab Mon Sep 17 00:00:00 2001 From: Benjamin Diaz Date: Fri, 23 Nov 2018 15:34:24 -0300 Subject: [PATCH] Adds support for autoscaling based on vnf-metric Change-Id: I179395ce1390f9031b15d141ff3b37839943368e Signed-off-by: Benjamin Diaz --- osm_policy_module/core/agent.py | 10 ++- osm_policy_module/core/exceptions.py | 27 +++++++ osm_policy_module/tests/unit/core/__init__.py | 23 ++++++ .../unit/{ => core}/test_policy_agent.py | 0 .../tests/unit/utils/__init__.py | 23 ++++++ .../examples/cirros_vdu_scaling_nsd.yaml | 0 .../examples/cirros_vdu_scaling_vnfd_1.yaml} | 19 ++--- .../examples/cirros_vdu_scaling_vnfd_2.yaml | 75 +++++++++++++++++++ .../tests/unit/utils/test_vnfd_utils.py | 45 +++++++++++ osm_policy_module/utils/__init__.py | 23 ++++++ osm_policy_module/utils/vnfd.py | 41 ++++++++++ 11 files changed, 275 insertions(+), 11 deletions(-) create mode 100644 osm_policy_module/core/exceptions.py create mode 100644 osm_policy_module/tests/unit/core/__init__.py rename osm_policy_module/tests/unit/{ => core}/test_policy_agent.py (100%) create mode 100644 osm_policy_module/tests/unit/utils/__init__.py rename osm_policy_module/tests/{ => unit/utils}/examples/cirros_vdu_scaling_nsd.yaml (100%) rename osm_policy_module/tests/{examples/cirros_vdu_scaling_vnfd.yaml => unit/utils/examples/cirros_vdu_scaling_vnfd_1.yaml} (81%) create mode 100644 osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_vnfd_2.yaml create mode 100644 osm_policy_module/tests/unit/utils/test_vnfd_utils.py create mode 100644 osm_policy_module/utils/__init__.py create mode 100644 osm_policy_module/utils/vnfd.py diff --git a/osm_policy_module/core/agent.py b/osm_policy_module/core/agent.py index ab8f857..3e64652 100644 --- a/osm_policy_module/core/agent.py +++ b/osm_policy_module/core/agent.py @@ -36,6 +36,7 @@ from osm_policy_module.common.mon_client import MonClient from osm_policy_module.core import database from osm_policy_module.core.config import Config from osm_policy_module.core.database import ScalingGroup, ScalingAlarm, ScalingPolicy, ScalingCriteria, DatabaseManager +from osm_policy_module.utils.vnfd import VnfdUtils log = logging.getLogger(__name__) @@ -262,8 +263,13 @@ class PolicyModuleAgent: ) ) elif 'vnf-metric' in vnf_monitoring_param: - log.warning("vnf-metric is not currently supported.") - continue + vdu = VnfdUtils.get_mgmt_vdu(vnfd) + vdurs = list( + filter( + lambda vdur: vdur['vdu-id-ref'] == vdu['id'], + vnfr['vdur'] + ) + ) else: log.warning( "Scaling criteria is referring to a vnf-monitoring-param that does not " diff --git a/osm_policy_module/core/exceptions.py b/osm_policy_module/core/exceptions.py new file mode 100644 index 0000000..906bb03 --- /dev/null +++ b/osm_policy_module/core/exceptions.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Whitestack, LLC +# ************************************************************* + +# This file is part of OSM Monitoring module +# All Rights Reserved to Whitestack, LLC + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# For those usages not covered by the Apache License, Version 2.0 please +# contact: bdiaz@whitestack.com or glavado@whitestack.com +## + + +class ManagementVduNotFound(Exception): + pass diff --git a/osm_policy_module/tests/unit/core/__init__.py b/osm_policy_module/tests/unit/core/__init__.py new file mode 100644 index 0000000..d81308a --- /dev/null +++ b/osm_policy_module/tests/unit/core/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Whitestack, LLC +# ************************************************************* + +# This file is part of OSM Monitoring module +# All Rights Reserved to Whitestack, LLC + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# For those usages not covered by the Apache License, Version 2.0 please +# contact: bdiaz@whitestack.com or glavado@whitestack.com +## diff --git a/osm_policy_module/tests/unit/test_policy_agent.py b/osm_policy_module/tests/unit/core/test_policy_agent.py similarity index 100% rename from osm_policy_module/tests/unit/test_policy_agent.py rename to osm_policy_module/tests/unit/core/test_policy_agent.py diff --git a/osm_policy_module/tests/unit/utils/__init__.py b/osm_policy_module/tests/unit/utils/__init__.py new file mode 100644 index 0000000..d81308a --- /dev/null +++ b/osm_policy_module/tests/unit/utils/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Whitestack, LLC +# ************************************************************* + +# This file is part of OSM Monitoring module +# All Rights Reserved to Whitestack, LLC + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# For those usages not covered by the Apache License, Version 2.0 please +# contact: bdiaz@whitestack.com or glavado@whitestack.com +## diff --git a/osm_policy_module/tests/examples/cirros_vdu_scaling_nsd.yaml b/osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_nsd.yaml similarity index 100% rename from osm_policy_module/tests/examples/cirros_vdu_scaling_nsd.yaml rename to osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_nsd.yaml diff --git a/osm_policy_module/tests/examples/cirros_vdu_scaling_vnfd.yaml b/osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_vnfd_1.yaml similarity index 81% rename from osm_policy_module/tests/examples/cirros_vdu_scaling_vnfd.yaml rename to osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_vnfd_1.yaml index dc599f5..a626674 100644 --- a/osm_policy_module/tests/examples/cirros_vdu_scaling_vnfd.yaml +++ b/osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_vnfd_1.yaml @@ -38,8 +38,8 @@ vnfd:vnfd-catalog: vpci: 0000:00:0a.0 external-connection-point-ref: eth0 monitoring-param: - - id: "cirros_vnfd-VM_memory_util" - nfvi-metric: "average_memory_utilization" # The associated NFVI metric to be monitored. Id of the metric + - id: "cirros_vnfd-VM_cpu_util" + nfvi-metric: "cpu_utilization" # The associated NFVI metric to be monitored. Id of the metric #interface-name-ref: reference to interface name, required for some metrics connection-point: - name: eth0 @@ -49,17 +49,17 @@ vnfd:vnfd-catalog: min-instance-count: 1 max-instance-count: 10 scaling-policy: - - name: "auto_memory_util_above_threshold" + - name: "auto_cpu_util_above_threshold" scaling-type: "automatic" threshold-time: 10 cooldown-time: 60 scaling-criteria: - - name: "group1_memory_util_above_threshold" + - name: "group1_cpu_util_above_threshold" scale-in-threshold: 20 scale-in-relational-operation: "LT" scale-out-threshold: 80 scale-out-relational-operation: "GT" - vnf-monitoring-param-ref: "cirros_vnf_memory_util" + vnf-monitoring-param-ref: "cirros_vnf_cpu_util" vdu: - vdu-id-ref: cirros_vnfd-VM count: 1 @@ -67,8 +67,9 @@ vnfd:vnfd-catalog: # - trigger: post-scale-out # vnf-config-primitive-name-ref: monitoring-param: - - id: "cirros_vnf_memory_util" - name: "cirros_vnf_memory_util" + - id: "cirros_vnf_cpu_util" + name: "cirros_vnf_cpu_util" aggregation-type: AVERAGE - vdu-ref: "cirros_vnfd-VM" - vdu-monitoring-param-ref: "cirros_vnfd-VM_memory_util" \ No newline at end of file + vdu-monitoring-param: + vdu-ref: "cirros_vnfd-VM" + vdu-monitoring-param-ref: "cirros_vnfd-VM_cpu_util" \ No newline at end of file diff --git a/osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_vnfd_2.yaml b/osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_vnfd_2.yaml new file mode 100644 index 0000000..8e0c603 --- /dev/null +++ b/osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_vnfd_2.yaml @@ -0,0 +1,75 @@ +vnfd:vnfd-catalog: + vnfd: + - id: cirros_vdu_scaling_vnf + name: cirros_vdu_scaling_vnf + short-name: cirros_vdu_scaling_vnf + description: Simple VNF example with a cirros and a scaling group descriptor + vendor: OSM + version: '1.0' + # Place the logo as png in icons directory and provide the name here + logo: cirros-64.png + # Management vdu id + mgmt-interface: + vdu-id: cirros_vnfd-VM + # Atleast one VDU need to be specified + vdu: + - id: cirros_vnfd-VM + name: cirros_vnfd-VM + description: cirros_vnfd-VM + count: 1 + + # Flavour of the VM to be instantiated for the VDU + # flavor below can fit into m1.micro + vm-flavor: + vcpu-count: 1 + memory-mb: 256 + storage-gb: 2 + # Image/checksum or image including the full path + image: 'cirros034' + #checksum: + interface: + # Specify the external interfaces + # There can be multiple interfaces defined + - name: eth0 + type: EXTERNAL + virtual-interface: + type: VIRTIO + bandwidth: '0' + vpci: 0000:00:0a.0 + external-connection-point-ref: eth0 + monitoring-param: + - id: "cirros_vnfd-VM_cpu_util" + nfvi-metric: "cpu_utilization" # The associated NFVI metric to be monitored. Id of the metric + #interface-name-ref: reference to interface name, required for some metrics + connection-point: + - name: eth0 + type: VPORT + scaling-group-descriptor: + - name: "scale_cirros_vnfd-VM" + min-instance-count: 1 + max-instance-count: 10 + scaling-policy: + - name: "auto_cpu_util_above_threshold" + scaling-type: "automatic" + threshold-time: 10 + cooldown-time: 60 + scaling-criteria: + - name: "group1_cpu_util_above_threshold" + scale-in-threshold: 20 + scale-in-relational-operation: "LT" + scale-out-threshold: 80 + scale-out-relational-operation: "GT" + vnf-monitoring-param-ref: "cirros_vnf_cpu_util" + vdu: + - vdu-id-ref: cirros_vnfd-VM + count: 1 + # scaling-config-action: # Para utilizar charms + # - trigger: post-scale-out + # vnf-config-primitive-name-ref: + monitoring-param: + - id: "cirros_vnf_cpu_util" + name: "cirros_vnf_cpu_util" + aggregation-type: AVERAGE + vdu-monitoring-param: + vdu-ref: "cirros_vnfd-VM" + vdu-monitoring-param-ref: "cirros_vnfd-VM_cpu_util" \ No newline at end of file diff --git a/osm_policy_module/tests/unit/utils/test_vnfd_utils.py b/osm_policy_module/tests/unit/utils/test_vnfd_utils.py new file mode 100644 index 0000000..5b770dd --- /dev/null +++ b/osm_policy_module/tests/unit/utils/test_vnfd_utils.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Whitestack, LLC +# ************************************************************* + +# This file is part of OSM Monitoring module +# All Rights Reserved to Whitestack, LLC + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# For those usages not covered by the Apache License, Version 2.0 please +# contact: bdiaz@whitestack.com or glavado@whitestack.com +## +import os +import unittest + +import yaml + +from osm_policy_module.utils.vnfd import VnfdUtils + + +class VnfdUtilsTest(unittest.TestCase): + def test_get_mgmt_vdu_by_cp(self): + with open( + os.path.join(os.path.dirname(__file__), 'examples/cirros_vdu_scaling_vnfd_1.yaml'), 'r') as file: + vnfd = yaml.safe_load(file)['vnfd:vnfd-catalog']['vnfd'][0] + vdu = VnfdUtils.get_mgmt_vdu(vnfd) + self.assertEqual(vdu['id'], 'cirros_vnfd-VM') + + def test_get_mgmt_vdu_by_id(self): + with open( + os.path.join(os.path.dirname(__file__), 'examples/cirros_vdu_scaling_vnfd_2.yaml'), 'r') as file: + vnfd = yaml.safe_load(file)['vnfd:vnfd-catalog']['vnfd'][0] + vdu = VnfdUtils.get_mgmt_vdu(vnfd) + self.assertEqual(vdu['id'], 'cirros_vnfd-VM') diff --git a/osm_policy_module/utils/__init__.py b/osm_policy_module/utils/__init__.py new file mode 100644 index 0000000..d81308a --- /dev/null +++ b/osm_policy_module/utils/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Whitestack, LLC +# ************************************************************* + +# This file is part of OSM Monitoring module +# All Rights Reserved to Whitestack, LLC + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# For those usages not covered by the Apache License, Version 2.0 please +# contact: bdiaz@whitestack.com or glavado@whitestack.com +## diff --git a/osm_policy_module/utils/vnfd.py b/osm_policy_module/utils/vnfd.py new file mode 100644 index 0000000..234d864 --- /dev/null +++ b/osm_policy_module/utils/vnfd.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Whitestack, LLC +# ************************************************************* + +# This file is part of OSM Monitoring module +# All Rights Reserved to Whitestack, LLC + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# For those usages not covered by the Apache License, Version 2.0 please +# contact: bdiaz@whitestack.com or glavado@whitestack.com +## +from osm_policy_module.core.exceptions import ManagementVduNotFound + + +class VnfdUtils: + + @staticmethod + def get_mgmt_vdu(vnfd: dict): + if 'cp' in vnfd['mgmt-interface']: + for vdu in vnfd['vdu']: + for interface in vdu['interface']: + if 'external-connection-point-ref' in interface: + if interface['external-connection-point-ref'] == vnfd['mgmt-interface']['cp']: + return vdu + elif 'vdu-id' in vnfd['mgmt-interface']: + for vdu in vnfd['vdu']: + if vdu['id'] == vnfd['mgmt-interface']['vdu-id']: + return vdu + raise ManagementVduNotFound("Management vdu not founr in vnfd %s", vnfd['id']) -- 2.25.1