Adds support for autoscaling based on vnf-metric 56/6956/2
authorBenjamin Diaz <bdiaz@whitestack.com>
Fri, 23 Nov 2018 18:34:24 +0000 (15:34 -0300)
committerBenjamin Diaz <bdiaz@whitestack.com>
Sat, 24 Nov 2018 03:05:41 +0000 (00:05 -0300)
Change-Id: I179395ce1390f9031b15d141ff3b37839943368e
Signed-off-by: Benjamin Diaz <bdiaz@whitestack.com>
14 files changed:
osm_policy_module/core/agent.py
osm_policy_module/core/exceptions.py [new file with mode: 0644]
osm_policy_module/tests/examples/cirros_vdu_scaling_nsd.yaml [deleted file]
osm_policy_module/tests/examples/cirros_vdu_scaling_vnfd.yaml [deleted file]
osm_policy_module/tests/unit/core/__init__.py [new file with mode: 0644]
osm_policy_module/tests/unit/core/test_policy_agent.py [new file with mode: 0644]
osm_policy_module/tests/unit/test_policy_agent.py [deleted file]
osm_policy_module/tests/unit/utils/__init__.py [new file with mode: 0644]
osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_nsd.yaml [new file with mode: 0644]
osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_vnfd_1.yaml [new file with mode: 0644]
osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_vnfd_2.yaml [new file with mode: 0644]
osm_policy_module/tests/unit/utils/test_vnfd_utils.py [new file with mode: 0644]
osm_policy_module/utils/__init__.py [new file with mode: 0644]
osm_policy_module/utils/vnfd.py [new file with mode: 0644]

index ab8f857..3e64652 100644 (file)
@@ -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 (file)
index 0000000..906bb03
--- /dev/null
@@ -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/examples/cirros_vdu_scaling_nsd.yaml b/osm_policy_module/tests/examples/cirros_vdu_scaling_nsd.yaml
deleted file mode 100644 (file)
index a9e0abd..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-nsd:nsd-catalog:
-    nsd:
-    -   id: cirros_vdu_scaling_ns
-        name: cirros_vdu_scaling_ns
-        short-name: cirros_vdu_scaling_ns
-        description: Simple NS example with a cirros_vdu_scaling_vnf
-        vendor: OSM
-        version: '1.0'
-
-        # Place the logo as png in icons directory and provide the name here
-        logo: osm.png
-
-        # Specify the VNFDs that are part of this NSD
-        constituent-vnfd:
-            # The member-vnf-index needs to be unique, starting from 1
-            # vnfd-id-ref is the id of the VNFD
-            # Multiple constituent VNFDs can be specified
-        -   member-vnf-index: '1'
-            vnfd-id-ref: cirros_vdu_scaling_vnf
-        -   member-vnf-index: '2'
-            vnfd-id-ref: cirros_vdu_scaling_vnf
-        vld:
-        # Networks for the VNFs
-            -   id: cirros_nsd_vld1
-                name: cirros_nsd_vld1
-                type: ELAN
-                mgmt-network: 'true'
-                # vim-network-name: <update>
-                # provider-network:
-                #     segmentation_id: <update>
-                vnfd-connection-point-ref:
-                # Specify the constituent VNFs
-                # member-vnf-index-ref - entry from constituent vnf
-                # vnfd-id-ref - VNFD id
-                # vnfd-connection-point-ref - connection point name in the VNFD
-                -   member-vnf-index-ref: 1
-                    vnfd-id-ref: cirros_vdu_scaling_vnf
-                    # NOTE: Validate the entry below
-                    vnfd-connection-point-ref: eth0
-                -   member-vnf-index-ref: 2
-                    vnfd-id-ref: cirros_vdu_scaling_vnf
-                    vnfd-connection-point-ref: eth0
\ No newline at end of file
diff --git a/osm_policy_module/tests/examples/cirros_vdu_scaling_vnfd.yaml b/osm_policy_module/tests/examples/cirros_vdu_scaling_vnfd.yaml
deleted file mode 100644 (file)
index dc599f5..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-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 interface
-        mgmt-interface:
-            cp: eth0
-        # 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_memory_util"
-                nfvi-metric: "average_memory_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_memory_util_above_threshold"
-                scaling-type: "automatic"
-                threshold-time: 10
-                cooldown-time: 60
-                scaling-criteria:
-                -   name: "group1_memory_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"
-            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_memory_util"
-            name: "cirros_vnf_memory_util"
-            aggregation-type: AVERAGE
-            vdu-ref: "cirros_vnfd-VM"
-            vdu-monitoring-param-ref: "cirros_vnfd-VM_memory_util"
\ No newline at end of file
diff --git a/osm_policy_module/tests/unit/core/__init__.py b/osm_policy_module/tests/unit/core/__init__.py
new file mode 100644 (file)
index 0000000..d81308a
--- /dev/null
@@ -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/core/test_policy_agent.py b/osm_policy_module/tests/unit/core/test_policy_agent.py
new file mode 100644 (file)
index 0000000..932adf4
--- /dev/null
@@ -0,0 +1,123 @@
+# -*- 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 asyncio
+import datetime
+import unittest
+from unittest import mock
+from unittest.mock import Mock
+
+from osm_policy_module.core.agent import PolicyModuleAgent
+from osm_policy_module.core.database import DatabaseManager
+
+
+class PolicyAgentTest(unittest.TestCase):
+    def setUp(self):
+        self.loop = asyncio.new_event_loop()
+        asyncio.set_event_loop(None)
+
+    @mock.patch('osm_policy_module.core.agent.CommonDbClient')
+    @mock.patch('osm_policy_module.core.agent.MonClient')
+    @mock.patch('osm_policy_module.core.agent.LcmClient')
+    @mock.patch.object(PolicyModuleAgent, '_configure_scaling_groups')
+    def test_handle_instantiated_or_scaled(self, configure_scaling_groups, lcm_client, mon_client, db_client):
+        async def mock_configure_scaling_groups(nsr_id):
+            pass
+
+        agent = PolicyModuleAgent(self.loop)
+        assert lcm_client.called
+        assert mon_client.called
+        assert db_client.called
+        content = {
+            'nslcmop_id': 'test_id',
+        }
+        nslcmop_completed = {
+            'operationState': 'COMPLETED',
+            'nsInstanceId': 'test_nsr_id'
+        }
+        nslcmop_failed = {
+            'operationState': 'FAILED',
+            'nsInstanceId': 'test_nsr_id'
+        }
+        configure_scaling_groups.side_effect = mock_configure_scaling_groups
+
+        db_client.return_value.get_nslcmop.return_value = nslcmop_completed
+        self.loop.run_until_complete(agent._handle_instantiated_or_scaled(content))
+        configure_scaling_groups.assert_called_with('test_nsr_id')
+        configure_scaling_groups.reset_mock()
+
+        db_client.return_value.get_nslcmop.return_value = nslcmop_failed
+        self.loop.run_until_complete(agent._handle_instantiated_or_scaled(content))
+        configure_scaling_groups.assert_not_called()
+
+    @mock.patch('osm_policy_module.core.agent.CommonDbClient')
+    @mock.patch('osm_policy_module.core.agent.MonClient')
+    @mock.patch('osm_policy_module.core.agent.LcmClient')
+    @mock.patch.object(DatabaseManager, 'get_alarm')
+    def test_handle_alarm_notification(self, get_alarm, lcm_client, mon_client, db_client):
+        async def mock_scale(nsr_id, scaling_group_name, vnf_member_index, action):
+            pass
+
+        agent = PolicyModuleAgent(self.loop)
+        assert lcm_client.called
+        assert mon_client.called
+        assert db_client.called
+        content = {
+            'notify_details': {
+                'alarm_uuid': 'test_alarm_uuid',
+                'metric_name': 'test_metric_name',
+                'operation': 'test_operation',
+                'threshold_value': 'test_threshold_value',
+                'vdu_name': 'test_vdu_name',
+                'vnf_member_index': 'test_vnf_member_index',
+                'ns_id': 'test_nsr_id'
+            }
+        }
+        mock_alarm = Mock()
+        mock_alarm.vnf_member_index = 1
+        mock_alarm.action = 'scale_out'
+        mock_scaling_criteria = Mock()
+        mock_scaling_policy = Mock()
+        mock_scaling_group = Mock()
+        mock_scaling_group.nsr_id = 'test_nsr_id'
+        mock_scaling_group.name = 'test_name'
+        mock_scaling_policy.cooldown_time = 60
+        mock_scaling_policy.scaling_group = mock_scaling_group
+        mock_scaling_criteria.scaling_policy = mock_scaling_policy
+        mock_alarm.scaling_criteria = mock_scaling_criteria
+        get_alarm.return_value = mock_alarm
+        lcm_client.return_value.scale.side_effect = mock_scale
+
+        mock_scaling_policy.last_scale = datetime.datetime.now() - datetime.timedelta(minutes=90)
+
+        self.loop.run_until_complete(agent._handle_alarm_notification(content))
+        lcm_client.return_value.scale.assert_called_with('test_nsr_id', 'test_name', 1, 'scale_out')
+        lcm_client.return_value.scale.reset_mock()
+
+        mock_scaling_policy.last_scale = datetime.datetime.now()
+        self.loop.run_until_complete(agent._handle_alarm_notification(content))
+        lcm_client.return_value.scale.assert_not_called()
+
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/osm_policy_module/tests/unit/test_policy_agent.py b/osm_policy_module/tests/unit/test_policy_agent.py
deleted file mode 100644 (file)
index 932adf4..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-# -*- 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 asyncio
-import datetime
-import unittest
-from unittest import mock
-from unittest.mock import Mock
-
-from osm_policy_module.core.agent import PolicyModuleAgent
-from osm_policy_module.core.database import DatabaseManager
-
-
-class PolicyAgentTest(unittest.TestCase):
-    def setUp(self):
-        self.loop = asyncio.new_event_loop()
-        asyncio.set_event_loop(None)
-
-    @mock.patch('osm_policy_module.core.agent.CommonDbClient')
-    @mock.patch('osm_policy_module.core.agent.MonClient')
-    @mock.patch('osm_policy_module.core.agent.LcmClient')
-    @mock.patch.object(PolicyModuleAgent, '_configure_scaling_groups')
-    def test_handle_instantiated_or_scaled(self, configure_scaling_groups, lcm_client, mon_client, db_client):
-        async def mock_configure_scaling_groups(nsr_id):
-            pass
-
-        agent = PolicyModuleAgent(self.loop)
-        assert lcm_client.called
-        assert mon_client.called
-        assert db_client.called
-        content = {
-            'nslcmop_id': 'test_id',
-        }
-        nslcmop_completed = {
-            'operationState': 'COMPLETED',
-            'nsInstanceId': 'test_nsr_id'
-        }
-        nslcmop_failed = {
-            'operationState': 'FAILED',
-            'nsInstanceId': 'test_nsr_id'
-        }
-        configure_scaling_groups.side_effect = mock_configure_scaling_groups
-
-        db_client.return_value.get_nslcmop.return_value = nslcmop_completed
-        self.loop.run_until_complete(agent._handle_instantiated_or_scaled(content))
-        configure_scaling_groups.assert_called_with('test_nsr_id')
-        configure_scaling_groups.reset_mock()
-
-        db_client.return_value.get_nslcmop.return_value = nslcmop_failed
-        self.loop.run_until_complete(agent._handle_instantiated_or_scaled(content))
-        configure_scaling_groups.assert_not_called()
-
-    @mock.patch('osm_policy_module.core.agent.CommonDbClient')
-    @mock.patch('osm_policy_module.core.agent.MonClient')
-    @mock.patch('osm_policy_module.core.agent.LcmClient')
-    @mock.patch.object(DatabaseManager, 'get_alarm')
-    def test_handle_alarm_notification(self, get_alarm, lcm_client, mon_client, db_client):
-        async def mock_scale(nsr_id, scaling_group_name, vnf_member_index, action):
-            pass
-
-        agent = PolicyModuleAgent(self.loop)
-        assert lcm_client.called
-        assert mon_client.called
-        assert db_client.called
-        content = {
-            'notify_details': {
-                'alarm_uuid': 'test_alarm_uuid',
-                'metric_name': 'test_metric_name',
-                'operation': 'test_operation',
-                'threshold_value': 'test_threshold_value',
-                'vdu_name': 'test_vdu_name',
-                'vnf_member_index': 'test_vnf_member_index',
-                'ns_id': 'test_nsr_id'
-            }
-        }
-        mock_alarm = Mock()
-        mock_alarm.vnf_member_index = 1
-        mock_alarm.action = 'scale_out'
-        mock_scaling_criteria = Mock()
-        mock_scaling_policy = Mock()
-        mock_scaling_group = Mock()
-        mock_scaling_group.nsr_id = 'test_nsr_id'
-        mock_scaling_group.name = 'test_name'
-        mock_scaling_policy.cooldown_time = 60
-        mock_scaling_policy.scaling_group = mock_scaling_group
-        mock_scaling_criteria.scaling_policy = mock_scaling_policy
-        mock_alarm.scaling_criteria = mock_scaling_criteria
-        get_alarm.return_value = mock_alarm
-        lcm_client.return_value.scale.side_effect = mock_scale
-
-        mock_scaling_policy.last_scale = datetime.datetime.now() - datetime.timedelta(minutes=90)
-
-        self.loop.run_until_complete(agent._handle_alarm_notification(content))
-        lcm_client.return_value.scale.assert_called_with('test_nsr_id', 'test_name', 1, 'scale_out')
-        lcm_client.return_value.scale.reset_mock()
-
-        mock_scaling_policy.last_scale = datetime.datetime.now()
-        self.loop.run_until_complete(agent._handle_alarm_notification(content))
-        lcm_client.return_value.scale.assert_not_called()
-
-
-if __name__ == '__main__':
-    unittest.main()
diff --git a/osm_policy_module/tests/unit/utils/__init__.py b/osm_policy_module/tests/unit/utils/__init__.py
new file mode 100644 (file)
index 0000000..d81308a
--- /dev/null
@@ -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/utils/examples/cirros_vdu_scaling_nsd.yaml b/osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_nsd.yaml
new file mode 100644 (file)
index 0000000..a9e0abd
--- /dev/null
@@ -0,0 +1,42 @@
+nsd:nsd-catalog:
+    nsd:
+    -   id: cirros_vdu_scaling_ns
+        name: cirros_vdu_scaling_ns
+        short-name: cirros_vdu_scaling_ns
+        description: Simple NS example with a cirros_vdu_scaling_vnf
+        vendor: OSM
+        version: '1.0'
+
+        # Place the logo as png in icons directory and provide the name here
+        logo: osm.png
+
+        # Specify the VNFDs that are part of this NSD
+        constituent-vnfd:
+            # The member-vnf-index needs to be unique, starting from 1
+            # vnfd-id-ref is the id of the VNFD
+            # Multiple constituent VNFDs can be specified
+        -   member-vnf-index: '1'
+            vnfd-id-ref: cirros_vdu_scaling_vnf
+        -   member-vnf-index: '2'
+            vnfd-id-ref: cirros_vdu_scaling_vnf
+        vld:
+        # Networks for the VNFs
+            -   id: cirros_nsd_vld1
+                name: cirros_nsd_vld1
+                type: ELAN
+                mgmt-network: 'true'
+                # vim-network-name: <update>
+                # provider-network:
+                #     segmentation_id: <update>
+                vnfd-connection-point-ref:
+                # Specify the constituent VNFs
+                # member-vnf-index-ref - entry from constituent vnf
+                # vnfd-id-ref - VNFD id
+                # vnfd-connection-point-ref - connection point name in the VNFD
+                -   member-vnf-index-ref: 1
+                    vnfd-id-ref: cirros_vdu_scaling_vnf
+                    # NOTE: Validate the entry below
+                    vnfd-connection-point-ref: eth0
+                -   member-vnf-index-ref: 2
+                    vnfd-id-ref: cirros_vdu_scaling_vnf
+                    vnfd-connection-point-ref: eth0
\ No newline at end of file
diff --git a/osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_vnfd_1.yaml b/osm_policy_module/tests/unit/utils/examples/cirros_vdu_scaling_vnfd_1.yaml
new file mode 100644 (file)
index 0000000..a626674
--- /dev/null
@@ -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 interface
+        mgmt-interface:
+            cp: eth0
+        # 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/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 (file)
index 0000000..8e0c603
--- /dev/null
@@ -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 (file)
index 0000000..5b770dd
--- /dev/null
@@ -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 (file)
index 0000000..d81308a
--- /dev/null
@@ -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 (file)
index 0000000..234d864
--- /dev/null
@@ -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'])