def test_create(self):
        st_obj = vnc_api.ServiceTemplate(name="test-template")
        svc_properties = vnc_api.ServiceTemplateType()
        svc_properties.set_service_virtualization_type('vrouter-instance')
        svc_properties.set_image_name('test')
        svc_properties.set_ordered_interfaces(True)
        if_list = [['management', False], ['left', False], ['right', False]]
        for itf in if_list:
            if_type = vnc_api.ServiceTemplateInterfaceType(shared_ip=itf[1])
            if_type.set_service_interface_type(itf[0])
            svc_properties.add_interface_type(if_type)
        svc_properties.set_vrouter_instance_type("docker")
        st_obj.set_service_template_properties(svc_properties)
        si_obj = vnc_api.ServiceInstance("test2")
        si_prop = vnc_api.ServiceInstanceType(
            left_virtual_network="left",
            right_virtual_network="right",
            management_virtual_network="management")
        si_prop.set_interface_list([
            vnc_api.ServiceInstanceInterfaceType(virtual_network="left"),
            vnc_api.ServiceInstanceInterfaceType(virtual_network="right"),
            vnc_api.ServiceInstanceInterfaceType(virtual_network="management")
        ])
        si_prop.set_virtual_router_id(uuid.uuid4())
        si_obj.set_service_instance_properties(si_prop)
        si_obj.set_service_template(st_obj)
        si_obj.uuid = str(uuid.uuid4())
        st_obj.uuid = str(uuid.uuid4())

        self.vrouter_manager.create_service(st_obj, si_obj)
        self.vrouter_manager.db.service_instance_insert.assert_called_with(
            si_obj.get_fq_name_str(), DBObjMatcher(self.DB_PREFIX))
    def _svc_instance_neutron_to_vnc(self, si_q):
        from neutron_plugin_contrail.plugins.opencontrail.vnc_client.vn_res_handler import VNetworkHandler

        project_id = self._project_id_neutron_to_vnc(si_q['tenant_id'])
        try:
            project_obj = self._project_read(proj_id=project_id)
        except vnc_exc.NoIdError:
            raise self._raise_contrail_exception('ProjectNotFound',
                                                 project_id=project_id,
                                                 resource='svc_instance')
        net_id = si_q['external_net']
        ext_vn = VNetworkHandler(self._vnc_lib).get_vn_obj(id=net_id)
        scale_out = vnc_api.ServiceScaleOutType(max_instances=1,
                                                auto_scale=False)
        si_prop = vnc_api.ServiceInstanceType(
            auto_policy=True,
            left_virtual_network="",
            right_virtual_network=ext_vn.get_fq_name_str(),
            scale_out=scale_out)
        si_prop.set_scale_out(scale_out)
        si_vnc = vnc_api.ServiceInstance(name=si_q['name'],
                                         parent_obj=project_obj,
                                         service_instance_properties=si_prop)

        return si_vnc
Ejemplo n.º 3
0
def create_ServiceInstance(vnc, project, service_template):
    """ FUNCTION TO CREATE SERVICE-INSTANCE """

    instance = vnc_api.ServiceInstance(name='service_nat_instance',
                                       parent_obj=project)
    instance_properties = vnc_api.ServiceInstanceType(
        scale_out=vnc_api.ServiceScaleOutType())

    instance.set_service_instance_properties(instance_properties)
    instance.set_service_template(service_template)

    vnc.service_instance_create(instance)
Ejemplo n.º 4
0
    def handle_create(self):
        try:
            st_obj = self.vnc_lib().service_template_read(
                id=self.properties[self.SERVICE_TEMPLATE])
        except vnc_api.NoIdError:
            st_obj = self.vnc_lib().service_template_read(
                fq_name_str=self.properties[self.SERVICE_TEMPLATE])

        tenant_id = self.stack.context.tenant_id
        project_obj = self.vnc_lib().project_read(id=str(uuid.UUID(tenant_id)))
        si_obj = vnc_api.ServiceInstance(
            name=self.properties[self.NAME], parent_obj=project_obj)

        svc_tmpl_if_list = st_obj.get_service_template_properties().interface_type
        svc_inst_if_list = self.properties[self.INTERFACE_LIST]
        if len(svc_tmpl_if_list) != len(svc_inst_if_list):
            raise vnc_api.BadRequest

        if_index = 0
        si_prop = vnc_api.ServiceInstanceType()
        for intf in self.properties[self.INTERFACE_LIST]:
            virt_net = intf[self.VIRTUAL_NETWORK]
            if virt_net == "auto":
                vn_name = ""
            elif not ":" in virt_net:
                fq_name = self.vnc_lib().id_to_fq_name(virt_net)
                vn_name = ":".join(fq_name)
            else:
                vn_name = virt_net

            # now check for static routes on this interface
            routes_list = {}
            if svc_tmpl_if_list[if_index].get_static_route_enable(
                ) and self.STATIC_ROUTES in intf:
                routes_list['route'] = intf[self.STATIC_ROUTES]

            if_type = vnc_api.ServiceInstanceInterfaceType(
                virtual_network=vn_name,static_routes=routes_list or None)
            si_prop.add_interface_list(if_type)
            if_index = if_index + 1

        if self.properties[self.SCALE_OUT] is None:
            max_instances = 1
            auto_scale = False
        else:
            max_instances = self.properties[self.SCALE_OUT][self.MAX_INSTANCES]
            auto_scale = self.properties[self.SCALE_OUT][self.AUTO_SCALE]
        scale_out = vnc_api.ServiceScaleOutType(max_instances=max_instances,
                                                auto_scale=auto_scale)
        si_prop.set_scale_out(scale_out)

        si_prop.set_availability_zone(self.properties[self.AVAILABILITY_ZONE])

        si_prop.set_ha_mode(self.properties[self.HA_MODE])
        si_obj.set_service_instance_properties(si_prop)

        st_obj = self.vnc_lib().service_template_read(id=st_obj.uuid)
        si_obj.set_service_template(st_obj)

        si_uuid = self.vnc_lib().service_instance_create(si_obj)
        self.resource_id_set(si_uuid)