def validate_network_config(self, st, si):
        if not si.params.get("interface_list"):
            self._upgrade_config(st, si)

        st_if_list = st.params.get("interface_type", [])
        si_if_list = si.params.get("interface_list", [])
        if not (len(st_if_list) or len(si_if_list)):
            self.logger.log_notice("Interface list empty for ST %s SI %s" % (st.fq_name, si.fq_name))
            return False

        si.vn_info = []
        config_complete = True
        for index in range(0, len(st_if_list)):
            vn_id = None
            try:
                si_if = si_if_list[index]
                st_if = st_if_list[index]
            except IndexError:
                continue

            nic = {}
            user_visible = True
            itf_type = st_if.get("service_interface_type")
            vn_fq_str = si_if.get("virtual_network", None)
            if itf_type == svc_info.get_left_if_str() and (
                st.params.get("service_type") == svc_info.get_snat_service_type()
            ):
                vn_id = self._create_snat_vn(si, vn_fq_str, index)
                user_visible = False
            elif itf_type == svc_info.get_right_if_str() and (
                st.params.get("service_type") == svc_info.get_lb_service_type()
            ):
                iip_id, vn_id = self._get_vip_vmi_iip(si)
                nic["iip-id"] = iip_id
                user_visible = False
            elif not vn_fq_str or vn_fq_str == "":
                vn_id = self._check_create_service_vn(itf_type, si)
            else:
                try:
                    vn_id = self._vnc_lib.fq_name_to_id("virtual-network", vn_fq_str.split(":"))
                except NoIdError:
                    config_complete = False

            nic["type"] = st_if.get("service_interface_type")
            nic["index"] = str(index + 1)
            nic["net-id"] = vn_id
            nic["shared-ip"] = st_if.get("shared_ip")
            nic["static-route-enable"] = st_if.get("static_route_enable")
            nic["static-routes"] = si_if.get("static_routes")
            nic["user-visible"] = user_visible
            si.vn_info.insert(index, nic)

        if config_complete:
            self.logger.log_info("SI %s info is complete" % si.fq_name)
            si.state = "config_complete"
        else:
            self.logger.log_warning("SI %s info is not complete" % si.fq_name)
            si.state = "config_pending"

        return config_complete
    def _get_nic_info(self, si_obj, si_props, st_props):
        si_if_list = si_props.get_interface_list()
        st_if_list = st_props.get_interface_type()

        # for lb relax the check because vip and pool could be in same net
        if (st_props.get_service_type() != svc_info.get_lb_service_type()) \
                and si_if_list and (len(si_if_list) != len(st_if_list)):
            self.logger.log("Error: IF mismatch template %s instance %s" %
                             (len(st_if_list), len(si_if_list)))
            return

        # check and create virtual networks
        nics = []
        proj_fq_name = si_obj.get_parent_fq_name()
        proj_obj = self._vnc_lib.project_read(fq_name=proj_fq_name)
        for idx in range(0, len(st_if_list)):
            nic = {}
            st_if = st_if_list[idx]
            itf_type = st_if.service_interface_type

            # set vn id
            if si_if_list and st_props.get_ordered_interfaces():
                try:
                    si_if = si_if_list[idx]
                except IndexError:
                    continue
                vn_fq_name_str = si_if.get_virtual_network()
                nic['static-routes'] = si_if.get_static_routes()
            else:
                funcname = "get_" + itf_type + "_virtual_network"
                func = getattr(si_props, funcname)
                vn_fq_name_str = func()

            if (itf_type == svc_info.get_left_if_str() and
                    (st_props.get_service_type() ==
                     svc_info.get_snat_service_type())):
                vn_id = self._create_snat_vn(proj_obj, si_obj,
                    si_props, vn_fq_name_str, idx)
            elif (itf_type == svc_info.get_right_if_str() and
                    (st_props.get_service_type() ==
                     svc_info.get_lb_service_type())):
                iip_id, vn_id = self._get_vip_vmi_iip(si_obj)
                nic['iip-id'] = iip_id
            else:
                vn_id = self._get_vn_id(proj_obj, vn_fq_name_str,
                    itf_type, si_obj)
            if vn_id is None:
                continue

            nic['net-id'] = vn_id
            nic['type'] = itf_type
            nic['shared-ip'] = st_if.shared_ip
            nic['static-route-enable'] = st_if.get_static_route_enable()
            nics.append(nic)

        return nics
Пример #3
0
    def _get_nic_info(self, si_obj, si_props, st_props):
        si_if_list = si_props.get_interface_list()
        st_if_list = st_props.get_interface_type()

        # for lb relax the check because vip and pool could be in same net
        if (st_props.get_service_type() != svc_info.get_lb_service_type()) \
                and si_if_list and (len(si_if_list) != len(st_if_list)):
            self.logger.log("Error: IF mismatch template %s instance %s" %
                            (len(st_if_list), len(si_if_list)))
            return []

        # check and create virtual networks
        nics = []
        proj_fq_name = si_obj.get_parent_fq_name()
        proj_obj = self._vnc_lib.project_read(fq_name=proj_fq_name)
        for idx in range(0, len(st_if_list)):
            nic = {}
            st_if = st_if_list[idx]
            itf_type = st_if.service_interface_type

            # set vn id
            if si_if_list and st_props.get_ordered_interfaces():
                try:
                    si_if = si_if_list[idx]
                except IndexError:
                    continue
                vn_fq_name_str = si_if.get_virtual_network()
                nic['static-routes'] = si_if.get_static_routes()
            else:
                funcname = "get_" + itf_type + "_virtual_network"
                func = getattr(si_props, funcname)
                vn_fq_name_str = func()

            if (itf_type == svc_info.get_left_if_str()
                    and (st_props.get_service_type()
                         == svc_info.get_snat_service_type())):
                vn_id = self._create_snat_vn(proj_obj, si_obj, si_props,
                                             vn_fq_name_str, idx)
            elif (itf_type == svc_info.get_right_if_str()
                  and (st_props.get_service_type()
                       == svc_info.get_lb_service_type())):
                iip_id, vn_id = self._get_vip_vmi_iip(si_obj)
                nic['iip-id'] = iip_id
            else:
                vn_id = self._get_vn_id(proj_obj, vn_fq_name_str, itf_type,
                                        si_obj)
            if vn_id is None:
                continue

            nic['net-id'] = vn_id
            nic['type'] = itf_type
            nic['shared-ip'] = st_if.shared_ip
            nic['static-route-enable'] = st_if.get_static_route_enable()
            nics.append(nic)

        return nics
    def validate_network_config(self, st, si):
        config_complete = True
        st_if_list = st.params.get('interface_type')
        si_if_list = si.params.get('interface_list')
        si.vn_info = []
        for index in range(0, len(st_if_list)):
            vn_id = None
            try:
                si_if = si_if_list[index]
                st_if = st_if_list[index]
            except IndexError:
                continue

            nic = {}
            user_visible = True
            itf_type = st_if.get('service_interface_type')
            vn_fq_str = si_if.get('virtual_network', None)
            if (itf_type == svc_info.get_left_if_str() and
                    (st.params.get('service_type') ==
                     svc_info.get_snat_service_type())):
                vn_id = self._create_snat_vn(si, vn_fq_str, index)
                user_visible = False
            elif (itf_type == svc_info.get_right_if_str() and
                    (st.params.get('service_type') ==
                     svc_info.get_lb_service_type())):
                iip_id, vn_id = self._get_vip_vmi_iip(si)
                nic['iip-id'] = iip_id
                user_visible = False
            elif not vn_fq_str or vn_fq_str == '':
                vn_id = self._check_create_service_vn(itf_type, si)
            else:
                try:
                    vn_id = self._vnc_lib.fq_name_to_id(
                        'virtual-network', vn_fq_str.split(':'))
                except NoIdError:
                    config_complete = False

            nic['type'] = st_if.get('service_interface_type')
            nic['index'] = str(index + 1)
            nic['net-id'] = vn_id
            nic['shared-ip'] = st_if.get('shared_ip')
            nic['static-route-enable'] = st_if.get('static_route_enable')
            nic['static-routes'] = si_if.get('static_routes')
            nic['user-visible'] = user_visible
            si.vn_info.insert(index, nic)

        if config_complete:
            self.logger.log_info("SI %s info is complete" % si.fq_name)
            si.state = 'config_complete'
        else:
            self.logger.log_warn("SI %s info is not complete" % si.fq_name)
            si.state = 'config_pending'

        return config_complete
Пример #5
0
    def validate_network_config(self, st, si):
        config_complete = True
        st_if_list = st.params.get('interface_type')
        si_if_list = si.params.get('interface_list')
        si.vn_info = []
        for index in range(0, len(st_if_list)):
            vn_id = None
            try:
                si_if = si_if_list[index]
                st_if = st_if_list[index]
            except IndexError:
                continue

            nic = {}
            user_visible = True
            itf_type = st_if.get('service_interface_type')
            vn_fq_str = si_if.get('virtual_network', None)
            if (itf_type == svc_info.get_left_if_str()
                    and (st.params.get('service_type')
                         == svc_info.get_snat_service_type())):
                vn_id = self._create_snat_vn(si, vn_fq_str, index)
                user_visible = False
            elif (itf_type == svc_info.get_right_if_str()
                  and (st.params.get('service_type')
                       == svc_info.get_lb_service_type())):
                iip_id, vn_id = self._get_vip_vmi_iip(si)
                nic['iip-id'] = iip_id
                user_visible = False
            elif not vn_fq_str or vn_fq_str == '':
                vn_id = self._check_create_service_vn(itf_type, si)
            else:
                try:
                    vn_id = self._vnc_lib.fq_name_to_id(
                        'virtual-network', vn_fq_str.split(':'))
                except NoIdError:
                    config_complete = False

            nic['type'] = st_if.get('service_interface_type')
            nic['index'] = str(index + 1)
            nic['net-id'] = vn_id
            nic['shared-ip'] = st_if.get('shared_ip')
            nic['static-route-enable'] = st_if.get('static_route_enable')
            nic['static-routes'] = si_if.get('static_routes')
            nic['user-visible'] = user_visible
            si.vn_info.insert(index, nic)

        if config_complete:
            self.logger.log_info("SI %s info is complete" % si.fq_name)
            si.state = 'config_complete'
        else:
            self.logger.log_warn("SI %s info is not complete" % si.fq_name)
            si.state = 'config_pending'

        return config_complete
    def _get_nic_info(self, si_obj, si_props, st_props):
        si_if_list = si_props.get_interface_list()
        st_if_list = st_props.get_interface_type()
        if si_if_list and (len(si_if_list) != len(st_if_list)):
            self.logger.log("Error: IF mismatch template %s instance %s" % (len(st_if_list), len(si_if_list)))
            return

        # check and create virtual networks
        nics = []
        proj_fq_name = si_obj.get_parent_fq_name()
        proj_obj = self._vnc_lib.project_read(fq_name=proj_fq_name)
        for idx in range(0, len(st_if_list)):
            nic = {}
            st_if = st_if_list[idx]
            itf_type = st_if.service_interface_type

            # set vn id
            if si_if_list and st_props.get_ordered_interfaces():
                si_if = si_if_list[idx]
                vn_fq_name_str = si_if.get_virtual_network()
                nic["static-routes"] = si_if.get_static_routes()
            else:
                funcname = "get_" + itf_type + "_virtual_network"
                func = getattr(si_props, funcname)
                vn_fq_name_str = func()

            if itf_type == svc_info.get_left_if_str() and (
                st_props.get_service_type() == svc_info.get_snat_service_type()
            ):
                vn_id = self._create_snat_vn(proj_obj, si_obj, si_props, vn_fq_name_str)
            else:
                vn_id = self._get_vn_id(proj_obj, vn_fq_name_str, itf_type)
            if vn_id is None:
                continue

            nic["net-id"] = vn_id
            nic["type"] = itf_type
            nic["shared-ip"] = st_if.shared_ip
            nic["static-route-enable"] = st_if.get_static_route_enable()
            nics.append(nic)

        return nics
 def handle_service_type(self):
     return svc_info.get_snat_service_type()
Пример #8
0
 def handle_service_type(self):
     return svc_info.get_snat_service_type()
    def create_service(self, st_obj, si_obj):
        si_props = si_obj.get_service_instance_properties()
        st_props = st_obj.get_service_template_properties()
        if st_props is None:
            self.logger.log("Cannot find service template associated to "
                             "service instance %s" % si_obj.get_fq_name_str())
            return
        if (st_props.get_service_type() != svc_info.get_snat_service_type()):
            self.logger.log("Only service type 'source-nat' is supported "
                             "with 'network-namespace' service "
                             "virtualization type")
            return

        # populate nic information
        nics = self._get_nic_info(si_obj, si_props, st_props)

        # Create virtual machines, associate them to the service instance and
        # schedule them to different virtual routers
        max_instances = si_props.get_scale_out().get_max_instances()
        for inst_count in range(0, max_instances):
            # Create a virtual machine
            instance_name = si_obj.name + '_' + str(inst_count + 1)
            proj_fq_name = si_obj.get_parent_fq_name()
            vm_name = "__".join(proj_fq_name + [instance_name])
            try:
                vm_obj = self._vnc_lib.virtual_machine_read(fq_name=[vm_name])
                self.logger.log("Info: VM %s already exists" % (vm_name))
            except NoIdError:
                vm_obj = VirtualMachine(vm_name)
                self._vnc_lib.virtual_machine_create(vm_obj)
                self.logger.log("Info: VM %s created" % (vm_name))

            vm_obj.set_service_instance(si_obj)
            self._vnc_lib.virtual_machine_update(vm_obj)
            self.logger.log("Info: VM %s updated with SI %s" %
                             (instance_name, si_obj.get_fq_name_str()))

            # Create virtual machine interfaces with an IP on networks
            for nic in nics:
                vmi_obj = self._create_svc_vm_port(nic, instance_name, st_obj,
                                                   si_obj)
                vmi_obj.set_virtual_machine(vm_obj)
                self._vnc_lib.virtual_machine_interface_update(vmi_obj)
                self.logger.log("Info: VMI %s updated with VM %s" %
                                 (vmi_obj.get_fq_name_str(), instance_name))

            # store NetNS instance in db use for linking when NetNS
            # is up. If the 'vrouter_name' key does not exist that means the
            # NetNS was not scheduled to a vrouter
            row_entry = {}
            row_entry['si_fq_str'] = si_obj.get_fq_name_str()
            row_entry['instance_name'] = instance_name
            row_entry['instance_type'] = svc_info.get_netns_instance_type()

            # Associate instance on the scheduled vrouter
            chosen_vr_fq_name = self.vrouter_scheduler.schedule(si_obj.uuid,
                                                                vm_obj.uuid)
            if chosen_vr_fq_name:
                row_entry['vrouter_name'] = chosen_vr_fq_name[-1]
                self.logger.log("Info: VRouter %s updated with VM %s" %
                                 (':'.join(chosen_vr_fq_name), instance_name))

            self.db.virtual_machine_insert(vm_obj.uuid, row_entry)

            # uve trace
            self.logger.uve_svc_instance(si_obj.get_fq_name_str(),
                status='CREATE', vm_uuid=vm_obj.uuid,
                st_name=st_obj.get_fq_name_str())