New feature: Support static IP in VNF connection points
[osm/SO.git] / examples / ping_pong_ns / rift / mano / examples / ping_pong_nsd.py
index 5348e00..db066f8 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-# 
+#
 #   Copyright 2016 RIFT.IO Inc
 #
 #   Licensed under the Apache License, Version 2.0 (the "License");
@@ -127,7 +127,7 @@ class VirtualNetworkFunction(ManoDescriptor):
 
     def compose(self, image_name, cloud_init="", cloud_init_file="", endpoint=None, mon_params=[],
                 mon_port=8888, mgmt_port=8888, num_vlr_count=1, num_ivlr_count=1,
-                num_vms=1, image_md5sum=None, mano_ut=False):
+                num_vms=1, image_md5sum=None, mano_ut=False, use_static_ip=False):
         self.descriptor = RwVnfdYang.YangData_Vnfd_VnfdCatalog()
         self.id = str(uuid.uuid1())
         vnfd = self.descriptor.vnfd.add()
@@ -156,6 +156,11 @@ class VirtualNetworkFunction(ManoDescriptor):
             cp = vnfd.connection_point.add()
             cp.type_yang = 'VPORT'
             cp.name = '%s/cp%d' % (self.name, i)
+            if use_static_ip:
+                if 'pong_' in self.name:
+                    cp.static_ip_address = '31.31.31.31'
+                else:
+                    cp.static_ip_address = '31.31.31.32'
 
         if endpoint is not None:
             endp = VnfdYang.YangData_Vnfd_VnfdCatalog_Vnfd_HttpEndpoint(
@@ -214,12 +219,18 @@ class VirtualNetworkFunction(ManoDescriptor):
                 node = vdu.guest_epa.numa_node_policy.node.add()
                 node.id = 0
                 node.memory_mb = 512
-                node.vcpu = [0, 1]
+                vcpu = node.vcpu.add()
+                vcpu.id = 0
+                vcpu = node.vcpu.add()
+                vcpu.id = 1
 
                 node = vdu.guest_epa.numa_node_policy.node.add()
                 node.id = 1
                 node.memory_mb = 512
-                node.vcpu = [2, 3]
+                vcpu = node.vcpu.add()
+                vcpu.id = 2
+                vcpu = node.vcpu.add()
+                vcpu.id = 3
 
                 # specify the vswitch EPA
                 vdu.vswitch_epa.ovs_acceleration = 'DISABLED'
@@ -254,7 +265,8 @@ class VirtualNetworkFunction(ManoDescriptor):
                     internal_cp.name = cp_name + "/icp{}".format(i)
                     internal_cp.id = cp_name + "/icp{}".format(i)
                     internal_cp.type_yang = 'VPORT'
-                    internal_vlds[i].internal_connection_point_ref.append(internal_cp.id)
+                    ivld_cp = internal_vlds[i].internal_connection_point_ref.add()
+                    ivld_cp.id_ref = internal_cp.id
 
                     internal_interface = vdu.internal_interface.add()
                     internal_interface.name = 'fab%d' % i
@@ -637,7 +649,7 @@ exit 0
         ip_profile.ip_profile_params.ip_version = "ipv4"
         ip_profile.ip_profile_params.subnet_address = "31.31.31.0/24"
         ip_profile.ip_profile_params.gateway_address = "31.31.31.210"
-        
+
         vld_id = 1
         for cpgroup in cpgroup_list:
             vld = nsd.vld.add()
@@ -885,6 +897,7 @@ def generate_ping_pong_descriptors(fmt="json",
                                    ex_pong_userdata=None,
                                    use_placement_group=True,
                                    use_ns_init_conf=True,
+                                   use_static_ip=False,
                                    ):
     # List of connection point groups
     # Each connection point group refers to a virtual link
@@ -929,6 +942,7 @@ def generate_ping_pong_descriptors(fmt="json",
             num_vms=num_vnf_vms,
             image_md5sum=ping_md5sum,
             mano_ut=mano_ut,
+            use_static_ip=use_static_ip,
             )
 
     pong = VirtualNetworkFunction("pong_vnfd%s" % (suffix))
@@ -969,6 +983,7 @@ def generate_ping_pong_descriptors(fmt="json",
             num_vms=num_vnf_vms,
             image_md5sum=pong_md5sum,
             mano_ut=mano_ut,
+            use_static_ip=use_static_ip,
             )
 
     # Initialize the member VNF index