コード例 #1
0
    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))
コード例 #2
0
def create_ServiceTemplate(vnc):
    """ FUNCTION TO CREATE SERVICE-TEMPLATE """

    service_nat_template = 'service_nat_template'

    template = vnc_api.ServiceTemplate(name=service_nat_template)

    template_properties = vnc_api.ServiceTemplateType(
        service_mode='in-network-nat',
        service_type='firewall',
        image_name='nat-service',
        service_scaling=True,
        availability_zone=True)

    template_properties.add_interface_type(
        vnc_api.ServiceTemplateInterfaceType(
            service_interface_type='management', shared_ip=False))
    template_properties.add_interface_type(
        vnc_api.ServiceTemplateInterfaceType(service_interface_type='left',
                                             shared_ip=False))
    template_properties.add_interface_type(
        vnc_api.ServiceTemplateInterfaceType(service_interface_type='right',
                                             shared_ip=False))

    template.set_service_template_properties(template_properties)

    vnc.service_template_create(template)

    print 'Service template "{}" created successfully\n'.format(
        service_nat_template)
    return template
コード例 #3
0
 def handle_create(self):
     domain = self.vnc_lib().domain_read(
         fq_name=[self.properties[self.DOMAIN]])
     st_obj = vnc_api.ServiceTemplate(name=self.properties[self.NAME],
                                      parent_obj=domain)
     svc_properties = vnc_api.ServiceTemplateType()
     svc_properties.set_image_name(self.properties[self.IMAGE_NAME])
     svc_properties.set_flavor(self.properties[self.FLAVOR])
     if self.properties[self.SERVICE_SCALING] == 'True':
         svc_properties.set_service_scaling(True)
     else:
         svc_properties.set_service_scaling(False)
     if self.properties[self.AVAILABILITY_ZONE_ENABLE] == 'True':
         svc_properties.set_availability_zone_enable(True)
     else:
         svc_properties.set_availability_zone_enable(False)
     svc_properties.set_service_mode(self.properties[self.SERVICE_MODE])
     svc_properties.set_service_type(self.properties[self.SERVICE_TYPE])
     svc_properties.set_service_virtualization_type(
         self.properties[self.SERVICE_VIRT_TYPE])
     if self.properties[self.ORDERED_INTERFACES] == 'True':
         svc_properties.set_ordered_interfaces(True)
     else:
         svc_properties.set_ordered_interfaces(False)
     svc_properties.set_version(int(self.properties[self.SERVICE_VERSION]))
     # set interface list
     itf_list = self.properties[self.SERVICE_INTERFACE_TYPE_LIST]
     for itf in itf_list:
         index = itf_list.index(itf)
         try:
             shared_ip = self.properties[self.SHARED_IP_LIST][index]
             if shared_ip == 'True':
                 shared_ip_val = True
             else:
                 shared_ip_val = False
         except (IndexError, TypeError):
             shared_ip_val = False
         try:
             static_route = self.properties[self.STATIC_ROUTES_LIST][index]
             if static_route == 'True':
                 static_route_val = True
             else:
                 static_route_val = False
         except (IndexError, TypeError):
             static_route_val = False
         if_type = vnc_api.ServiceTemplateInterfaceType(
             shared_ip=shared_ip_val)
         if_type.set_service_interface_type(itf)
         if_type.set_static_route_enable(static_route_val)
         svc_properties.add_interface_type(if_type)
     st_obj.set_service_template_properties(svc_properties)
     st_uuid = self.vnc_lib().service_template_create(st_obj)
     self.resource_id_set(st_uuid)
コード例 #4
0
    def handle_update(self, json_snippet, tmpl_diff, prop_diff):
        try:
            obj_0 = self.vnc_lib().service_template_read(
                id=self.resource_id
            )
        except:
            raise Exception(_('service-template %s not found.') % self.name)

        if prop_diff.get(self.DISPLAY_NAME) is not None:
            obj_0.set_display_name(prop_diff.get(self.DISPLAY_NAME))
        if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES) is not None:
            obj_1 = vnc_api.ServiceTemplateType()
            if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_VERSION) is not None:
                obj_1.set_version(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_VERSION))
            if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_MODE) is not None:
                obj_1.set_service_mode(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_MODE))
            if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_TYPE) is not None:
                obj_1.set_service_type(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_TYPE))
            if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_IMAGE_NAME) is not None:
                obj_1.set_image_name(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_IMAGE_NAME))
            if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_SCALING) is not None:
                obj_1.set_service_scaling(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_SCALING))
            if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE) is not None:
                for index_1 in range(len(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE))):
                    obj_2 = vnc_api.ServiceTemplateInterfaceType()
                    if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE, {})[index_1].get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE_SERVICE_INTERFACE_TYPE) is not None:
                        obj_2.set_service_interface_type(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE, {})[index_1].get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE_SERVICE_INTERFACE_TYPE))
                    if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE, {})[index_1].get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE_SHARED_IP) is not None:
                        obj_2.set_shared_ip(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE, {})[index_1].get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE_SHARED_IP))
                    if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE, {})[index_1].get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE_STATIC_ROUTE_ENABLE) is not None:
                        obj_2.set_static_route_enable(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE, {})[index_1].get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE_STATIC_ROUTE_ENABLE))
                    obj_1.add_interface_type(obj_2)
            if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_FLAVOR) is not None:
                obj_1.set_flavor(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_FLAVOR))
            if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_ORDERED_INTERFACES) is not None:
                obj_1.set_ordered_interfaces(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_ORDERED_INTERFACES))
            if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_VIRTUALIZATION_TYPE) is not None:
                obj_1.set_service_virtualization_type(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_VIRTUALIZATION_TYPE))
            if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_AVAILABILITY_ZONE_ENABLE) is not None:
                obj_1.set_availability_zone_enable(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_AVAILABILITY_ZONE_ENABLE))
            if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_VROUTER_INSTANCE_TYPE) is not None:
                obj_1.set_vrouter_instance_type(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_VROUTER_INSTANCE_TYPE))
            if prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INSTANCE_DATA) is not None:
                obj_1.set_instance_data(prop_diff.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INSTANCE_DATA))
            obj_0.set_service_template_properties(obj_1)

        # reference to service_appliance_set_refs
        ref_obj_list = []
        ref_data_list = []
        if self.SERVICE_APPLIANCE_SET_REFS in prop_diff:
            for index_0 in range(len(prop_diff.get(self.SERVICE_APPLIANCE_SET_REFS) or [])):
                try:
                    ref_obj = self.vnc_lib().service_appliance_set_read(
                        id=prop_diff.get(self.SERVICE_APPLIANCE_SET_REFS)[index_0]
                    )
                except:
                    ref_obj = self.vnc_lib().service_appliance_set_read(
                        fq_name_str=prop_diff.get(self.SERVICE_APPLIANCE_SET_REFS)[index_0]
                    )
                ref_obj_list.append(ref_obj.fq_name)

            obj_0.set_service_appliance_set_list(ref_obj_list)
            # End: reference to service_appliance_set_refs

        try:
            self.vnc_lib().service_template_update(obj_0)
        except:
            raise Exception(_('service-template %s could not be updated.') % self.name)
コード例 #5
0
    def handle_create(self):
        parent_obj = None
        if parent_obj is None and self.properties.get(self.DOMAIN):
            try:
                parent_obj = self.vnc_lib().domain_read(id=self.properties.get(self.DOMAIN))
            except vnc_api.NoIdError:
                parent_obj = self.vnc_lib().domain_read(fq_name_str=self.properties.get(self.DOMAIN))
            except:
                parent_obj = None

        if parent_obj is None:
            raise Exception('Error: parent is not specified in template!')

        obj_0 = vnc_api.ServiceTemplate(name=self.properties[self.NAME],
            parent_obj=parent_obj)

        if self.properties.get(self.DISPLAY_NAME) is not None:
            obj_0.set_display_name(self.properties.get(self.DISPLAY_NAME))
        if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES) is not None:
            obj_1 = vnc_api.ServiceTemplateType()
            if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_VERSION) is not None:
                obj_1.set_version(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_VERSION))
            if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_MODE) is not None:
                obj_1.set_service_mode(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_MODE))
            if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_TYPE) is not None:
                obj_1.set_service_type(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_TYPE))
            if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_IMAGE_NAME) is not None:
                obj_1.set_image_name(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_IMAGE_NAME))
            if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_SCALING) is not None:
                obj_1.set_service_scaling(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_SCALING))
            if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE) is not None:
                for index_1 in range(len(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE))):
                    obj_2 = vnc_api.ServiceTemplateInterfaceType()
                    if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE, {})[index_1].get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE_SERVICE_INTERFACE_TYPE) is not None:
                        obj_2.set_service_interface_type(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE, {})[index_1].get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE_SERVICE_INTERFACE_TYPE))
                    if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE, {})[index_1].get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE_SHARED_IP) is not None:
                        obj_2.set_shared_ip(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE, {})[index_1].get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE_SHARED_IP))
                    if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE, {})[index_1].get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE_STATIC_ROUTE_ENABLE) is not None:
                        obj_2.set_static_route_enable(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE, {})[index_1].get(self.SERVICE_TEMPLATE_PROPERTIES_INTERFACE_TYPE_STATIC_ROUTE_ENABLE))
                    obj_1.add_interface_type(obj_2)
            if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_FLAVOR) is not None:
                obj_1.set_flavor(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_FLAVOR))
            if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_ORDERED_INTERFACES) is not None:
                obj_1.set_ordered_interfaces(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_ORDERED_INTERFACES))
            if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_VIRTUALIZATION_TYPE) is not None:
                obj_1.set_service_virtualization_type(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_SERVICE_VIRTUALIZATION_TYPE))
            if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_AVAILABILITY_ZONE_ENABLE) is not None:
                obj_1.set_availability_zone_enable(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_AVAILABILITY_ZONE_ENABLE))
            if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_VROUTER_INSTANCE_TYPE) is not None:
                obj_1.set_vrouter_instance_type(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_VROUTER_INSTANCE_TYPE))
            if self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INSTANCE_DATA) is not None:
                obj_1.set_instance_data(self.properties.get(self.SERVICE_TEMPLATE_PROPERTIES, {}).get(self.SERVICE_TEMPLATE_PROPERTIES_INSTANCE_DATA))
            obj_0.set_service_template_properties(obj_1)

        # reference to service_appliance_set_refs
        if self.properties.get(self.SERVICE_APPLIANCE_SET_REFS):
            for index_0 in range(len(self.properties.get(self.SERVICE_APPLIANCE_SET_REFS))):
                try:
                    ref_obj = self.vnc_lib().service_appliance_set_read(
                        id=self.properties.get(self.SERVICE_APPLIANCE_SET_REFS)[index_0]
                    )
                except vnc_api.NoIdError:
                    ref_obj = self.vnc_lib().service_appliance_set_read(
                        fq_name_str=self.properties.get(self.SERVICE_APPLIANCE_SET_REFS)[index_0]
                    )
                obj_0.add_service_appliance_set(ref_obj)

        try:
            obj_uuid = super(ContrailServiceTemplate, self).resource_create(obj_0)
        except:
            raise Exception(_('service-template %s could not be updated.') % self.name)

        self.resource_id_set(obj_uuid)