@@ -0,0 +1,3241 @@
+#!/usr/bin/env python%0A%0A#AUTHOR: SAVITHRU LOKANATH%0A#CONTACT: SAVITHRU AT JUNIPER.NET%0A%0Aimport sys%0Afrom vnc_api import vnc_api%0A%0A%0Adef create_VirtualNetwork(network_name, network_subnet, network_mask, vnc, project):%0A%0A        %22%22%22 FUNCTION TO CREATE VIRTUAL-NETWORK %22%22%22%0A%0A        vn_obj = vnc_api.VirtualNetwork(name=network_name, parent_obj=project)%0A        vn_obj.add_network_ipam(vnc_api.NetworkIpam(),%0A                        vnc_api.VnSubnetsType(%5Bvnc_api.IpamSubnetType(subnet = vnc_api.SubnetType(network_subnet,network_mask))%5D))%0A%0A        vnc.virtual_network_create(vn_obj)%0A%0A        print 'Network %22%7B%7D%22 created successfully%5Cn'.format(network_name)%0A%0A%0Adef create_ServiceTemplate(vnc):%0A%0A        %22%22%22 FUNCTION TO CREATE SERVICE-TEMPLATE %22%22%22%0A%0A        service_nat_template = 'service_nat_template'%0A%0A        template = vnc_api.ServiceTemplate(name = service_nat_template)%0A%0A        template_properties = vnc_api.ServiceTemplateType(%0A                        service_mode = 'in-network-nat',%0A                        service_type = 'firewall',%0A                        image_name = 'nat-service',%0A                        service_scaling = True,%0A%09%09%09availability_zone = True)%0A%0A        template_properties.add_interface_type(%0A                        vnc_api.ServiceTemplateInterfaceType(service_interface_type = 'management', shared_ip = False))%0A        template_properties.add_interface_type(%0A                        vnc_api.ServiceTemplateInterfaceType(service_interface_type = 'left', shared_ip = False))%0A        template_properties.add_interface_type(%0A                        vnc_api.ServiceTemplateInterfaceType(service_interface_type = 'right', shared_ip = False))%0A%0A        template.set_service_template_properties(template_properties)%0A%0A        vnc.service_template_create(template)%0A%0A        print 'Service template %22%7B%7D%22 created successfully%5Cn'.format(service_nat_template)%0A        return template%0A%0A%0Adef create_ServiceInstance(vnc, project, service_template):%0A%0A        %22%22%22 FUNCTION TO CREATE SERVICE-INSTANCE %22%22%22%0A%0A        instance = vnc_api.ServiceInstance(name = 'service_nat_instance', parent_obj=project)%0A        instance_properties = vnc_api.ServiceInstanceType(%0A                        scale_out = vnc_api.ServiceScaleOutType())%0A%0A        instance.set_service_instance_properties(instance_properties)%0A        instance.set_service_template(service_template)%0A%0A        vnc.service_instance_create(instance)%0A%0A%0Adef main():%0A%0A        %22%22%22 MAIN/AUTHENTICATE %22%22%22%0A%0A        vnc = vnc_api.VncApi(username='admin', password='', api_server_host = '192.168.1.1', tenant_name='admin')%0A        project = vnc.project_read(fq_name = %5B'default-domain', 'admin'%5D)%0A%0A        left_network_name = 'left_VN'%0A        left_network_subnet = '192.168.200.0'%0A        left_network_mask = 24%0A%0A        right_network_name = 'right_VN'%0A        right_network_subnet = '192.168.201.0'%0A        right_network_mask = 24%0A%0A        create_VirtualNetwork(left_network_name, left_network_subnet, left_network_mask, vnc, project)%0A        create_VirtualNetwork(right_network_name, right_network_subnet, right_network_mask, vnc, project)%0A%0A        service_template = create_ServiceTemplate(vnc)%0A%0A        create_ServiceInstance(vnc, project, service_template)%0A%0Aif __name__==%22__main__%22:%0A        main()

Create service instance