Merge "edit activity workflow plan for NS INIT"
[vfc/nfvo/lcm.git] / lcm / pub / utils / toscaparser / nsdmodel.py
index b58462c..9792dd9 100644 (file)
@@ -1,3 +1,17 @@
+# Copyright 2017 ZTE Corporation.
+#
+# 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.
+
 import functools
 
 from lcm.pub.utils.toscaparser.basemodel import BaseInfoModel
@@ -26,7 +40,9 @@ class EtsiNsdInfoModel(BaseInfoModel):
         self.vnffgs = self._get_all_vnffg(tosca.topology_template.groups)
         self.server_groups = self.get_all_server_group(tosca.topology_template.groups)
         self.ns_exposed = self.get_all_endpoint_exposed(tosca.topology_template)
-
+        self.policies = self._get_policies_scaling(tosca.topology_template.policies)
+        self.ns_flavours = self.get_all_flavour(tosca.topology_template.groups)
+        self.nested_ns = self.get_all_nested_ns(nodeTemplates)
 
     def buildInputs(self, top_inputs):
         ret = {}
@@ -40,7 +56,7 @@ class EtsiNsdInfoModel(BaseInfoModel):
         return ret
 
     def buildNode(self, nodeTemplate, inputs, parsed_params):
-        ret ={}
+        ret = {}
         ret['name'] = nodeTemplate.name
         ret['nodeType'] = nodeTemplate.type
         if 'description' in nodeTemplate.entity_tpl:
@@ -53,7 +69,8 @@ class EtsiNsdInfoModel(BaseInfoModel):
         self.buildCapabilities(nodeTemplate, inputs, ret)
         self.buildArtifacts(nodeTemplate, inputs, ret)
         interfaces = self.build_interfaces(nodeTemplate)
-        if interfaces: ret['interfaces'] = interfaces
+        if interfaces:
+            ret['interfaces'] = interfaces
         return ret
 
     def _get_all_vnf(self, nodeTemplates):
@@ -94,7 +111,7 @@ class EtsiNsdInfoModel(BaseInfoModel):
                     for key, value in item.items():
                         if key.upper().startswith('VIRTUALBINDING'):
                             req_node_name = self.get_requirement_node_name(value)
-                            if req_node_name != None and req_node_name == node['name']:
+                            if req_node_name is not None and req_node_name == node['name']:
                                 cps.append(tmpnode)
         return cps
 
@@ -154,9 +171,9 @@ class EtsiNsdInfoModel(BaseInfoModel):
         cp_vl = {}
         cp_vl['vl_id'] = self.get_prop_from_obj(req, 'node')
         relationship = self.get_prop_from_obj(req, 'relationship')
-        if relationship != None:
+        if relationship is not None:
             properties = self.get_prop_from_obj(relationship, 'properties')
-            if properties != None and isinstance(properties, dict):
+            if properties is not None and isinstance(properties, dict):
                 for key, value in properties.items():
                     cp_vl[key] = value
         return cp_vl
@@ -300,4 +317,45 @@ class EtsiNsdInfoModel(BaseInfoModel):
                     forward_cps.append({"key_name": key, "cpd_id": value[0]})
                 else:
                     forward_cps.append({"key_name": key, "cpd_id": value})
-        return forward_cps
\ No newline at end of file
+        return forward_cps
+
+    def _get_policies_scaling(self, top_policies):
+        policies_scaling = []
+        scaling_policies = self.get_scaling_policies(top_policies)
+        if len(scaling_policies) > 0:
+            policies_scaling.append({"scaling": scaling_policies})
+        return policies_scaling
+
+    def get_policies_by_keyword(self, top_policies, keyword):
+        ret = []
+        for policy in top_policies:
+            if policy.type.upper().find(keyword) >= 0:
+                tmp = {}
+                tmp['policy_id'] = policy.name
+                tmp['description'] = policy.description
+                if 'properties' in policy.entity_tpl:
+                    tmp['properties'] = policy.entity_tpl['properties']
+                tmp['targets'] = policy.targets
+                ret.append(tmp)
+
+        return ret
+
+    def get_scaling_policies(self, top_policies):
+        return self.get_policies_by_keyword(top_policies, '.SCALING')
+
+    def get_all_flavour(self, groups):
+        rets = []
+        for group in groups:
+            if self._isFlavour(group):
+                ret = {}
+                ret['flavour_id'] = group.name
+                ret['description'] = group.description
+                if 'properties' in group.tpl:
+                    ret['properties'] = group.tpl['properties']
+                ret['members'] = group.members
+
+                rets.append(ret)
+        return rets
+
+    def _isFlavour(self, group):
+        return group.type.upper().find('FLAVOUR') >= 0