def _upgrade_config(self, st, si):
        left_vn = si.params.get('left_virtual_network', None)
        right_vn = si.params.get('right_virtual_network', None)
        mgmt_vn = si.params.get('management_virtual_network', None)

        st_if_list = st.params.get('interface_type', [])
        itf_list = []
        for index in range(0, len(st_if_list)):
            st_if_type = st_if_list[index]['service_interface_type']
            if st_if_type == svc_info.get_left_if_str():
                itf = ServiceInstanceInterfaceType(virtual_network=left_vn)
            elif st_if_type == svc_info.get_right_if_str():
                itf = ServiceInstanceInterfaceType(virtual_network=right_vn)
            elif st_if_type == svc_info.get_management_if_str():
                itf = ServiceInstanceInterfaceType(virtual_network=mgmt_vn)
            itf_list.append(itf)

        si_obj = ServiceInstance()
        si_obj.uuid = si.uuid
        si_obj.fq_name = si.fq_name
        si_props = ServiceInstanceType(**si.params)
        si_props.set_interface_list(itf_list)
        si_obj.set_service_instance_properties(si_props)
        self._vnc_lib.service_instance_update(si_obj)
        self.logger.log_notice("SI %s config upgraded for interfaces" %
                (si_obj.get_fq_name_str()))
예제 #2
0
    def _upgrade_config(self, st, si):
        left_vn = si.params.get('left_virtual_network', None)
        right_vn = si.params.get('right_virtual_network', None)
        mgmt_vn = si.params.get('management_virtual_network', None)
        other0_vn = si.params.get('other0_virtual_network', None)

        st_if_list = st.params.get('interface_type', [])
        itf_list = []
        for index in range(0, len(st_if_list)):
            st_if_type = st_if_list[index]['service_interface_type']
            if st_if_type == svc_info.get_left_if_str():
                itf = ServiceInstanceInterfaceType(virtual_network=left_vn)
            elif st_if_type == svc_info.get_right_if_str():
                itf = ServiceInstanceInterfaceType(virtual_network=right_vn)
            elif st_if_type == svc_info.get_management_if_str():
                itf = ServiceInstanceInterfaceType(virtual_network=mgmt_vn)
            elif st_if_type == svc_info.get_other0_if_str():
                itf = ServiceInstanceInterfaceType(virtual_network=other0_vn)
            itf_list.append(itf)

        si_obj = ServiceInstance()
        si_obj.uuid = si.uuid
        si_obj.fq_name = si.fq_name
        si_props = ServiceInstanceType(**si.params)
        si_props.set_interface_list(itf_list)
        si_obj.set_service_instance_properties(si_props)
        self._vnc_lib.service_instance_update(si_obj)
        self.logger.notice("SI %s config upgraded for interfaces" %
                           (si_obj.get_fq_name_str()))
    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
예제 #4
0
    def _sandesh_populate_vn_info(self, si_info, sandesh_si):
        for if_str in svc_info.get_if_str_list():
            if_set = set()
            if_str_vn = if_str + '-vn'
            if not if_str_vn in si_info.keys():
                continue

            vn_fq_str = str(si_info[if_str_vn])
            vn_uuid = str(si_info[vn_fq_str])
            vn_str = ("VN [%s : %s]" % (vn_fq_str, vn_uuid))
            if_set.add(vn_str)

            iip_uuid_str = if_str + '-iip-uuid'
            if iip_uuid_str in si_info.keys():
                vn_iip_uuid = str(si_info[iip_uuid_str])
                iip_addr_str = if_str + '-iip-addr'
                vn_iip_addr = str(si_info[iip_addr_str])
                iip_str = ("IIP [%s : %s]" % (vn_iip_addr, vn_iip_uuid))
                if_set.add(iip_str)

            if if_str == svc_info.get_left_if_str():
                sandesh_si.left_vn = list(if_set)
            if if_str == svc_info.get_right_if_str():
                sandesh_si.right_vn = list(if_set)
            if if_str == svc_info.get_management_if_str():
                sandesh_si.management_vn = list(if_set)

            si_info['done'] = True
    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
예제 #6
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 sandesh_si_handle_request(self, req):
        si_resp = sandesh.ServiceInstanceListResp(si_names=[])
        for si in ServiceInstanceSM.values():
            if req.si_name and req.si_name != si.name:
                continue

            st = ServiceTemplateSM.get(si.service_template)
            sandesh_si = sandesh.ServiceInstance(
                name=(':').join(si.fq_name),
                si_type=st.virtualization_type,
                si_state=si.state)

            sandesh_vm_list = []
            for vm_id in si.virtual_machines:
                vm = VirtualMachineSM.get(vm_id)
                if not vm:
                    continue
                vm_str = ("%s: %s" % (vm.name, vm.uuid))

                vr_name = 'None'
                vr = VirtualRouterSM.get(vm.virtual_router)
                if vr:
                    vr_name = vr.name

                ha_str = "active"
                if vm.index < len(si.local_preference):
                    if vm.index >= 0:
                        ha = si.local_preference[vm.index]
                        if ha and int(ha) == svc_info.get_standby_preference():
                            ha_str = "standby"
                        if ha:
                            ha_str = ha_str + ': ' + str(ha)
                    else:
                        ha_str = "unknown"

                vm = sandesh.ServiceInstanceVM(name=vm_str,
                                               vr_name=vr_name,
                                               ha=ha_str)
                sandesh_vm_list.append(vm)
            sandesh_si.vm_list = list(sandesh_vm_list)

            for nic in si.vn_info:
                vn = VirtualNetworkSM.get(nic['net-id'])
                if not vn:
                    continue
                if nic['type'] == svc_info.get_left_if_str():
                    sandesh_si.left_vn = [vn.name, vn.uuid]
                if nic['type'] == svc_info.get_right_if_str():
                    sandesh_si.right_vn = [vn.name, vn.uuid]
                if nic['type'] == svc_info.get_management_if_str():
                    sandesh_si.management_vn = [vn.name, vn.uuid]

            si_resp.si_names.append(sandesh_si)

        si_resp.response(req.context())
예제 #8
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 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
예제 #10
0
    def sandesh_si_handle_request(self, req):
        si_resp = sandesh.ServiceInstanceListResp(si_names=[])
        for si in ServiceInstanceSM.values():
            if req.si_name and req.si_name != si.name:
                continue

            st = ServiceTemplateSM.get(si.service_template)
            sandesh_si = sandesh.ServiceInstance(
                name=(':').join(si.fq_name), si_type=st.virtualization_type,
                si_state=si.state)

            sandesh_vm_list = []
            for vm_id in si.virtual_machines:
                vm = VirtualMachineSM.get(vm_id)
                if not vm:
                    continue
                vm_str = ("%s: %s" % (vm.name, vm.uuid))

                vr_name = 'None'
                vr = VirtualRouterSM.get(vm.virtual_router)
                if vr:
                    vr_name = vr.name

                ha_str = "active"
                if vm.index < len(si.local_preference):
                    if vm.index >= 0:
                        ha = si.local_preference[vm.index]
                        if ha and int(ha) == svc_info.get_standby_preference():
                            ha_str = "standby"
                        if ha:
                            ha_str = ha_str + ': ' + str(ha)
                    else:
                        ha_str = "unknown"

                vm = sandesh.ServiceInstanceVM(
                        name=vm_str, vr_name=vr_name, ha=ha_str)
                sandesh_vm_list.append(vm)
            sandesh_si.vm_list = list(sandesh_vm_list)

            for nic in si.vn_info:
                vn = VirtualNetworkSM.get(nic['net-id'])
                if not vn:
                    continue
                if nic['type'] == svc_info.get_left_if_str():
                    sandesh_si.left_vn = [vn.name, vn.uuid]
                if nic['type'] == svc_info.get_right_if_str():
                    sandesh_si.right_vn = [vn.name, vn.uuid]
                if nic['type'] == svc_info.get_management_if_str():
                    sandesh_si.management_vn = [vn.name, vn.uuid]

            si_resp.si_names.append(sandesh_si)

        si_resp.response(req.context())
예제 #11
0
    def sandesh_si_handle_request(self, req):
        si_resp = sandesh.ServiceInstanceListResp(si_names=[])
        if req.si_name is None:
            si_list = self._db.service_instance_list()

            for si_fq_name_str, si in si_list or []:
                sandesh_si = sandesh.ServiceInstance(
                    name=si_fq_name_str,
                    si_type=si.get('instance_type', ''),
                    si_state=si.get('state', ''))

                sandesh_vm_list = []
                for idx in range(0, int(si.get('max-instances', '0'))):
                    prefix = self._db.get_vm_db_prefix(idx)
                    if not (prefix + 'name') in si.keys():
                        continue
                    vm_name = si.get(prefix + 'name', '')
                    vm_uuid = si.get(prefix + 'uuid', '')
                    vm_str = ("%s: %s" % (vm_name, vm_uuid))
                    vr_name = si.get(prefix + 'vrouter', '')
                    ha = si.get(prefix + 'preference', '')
                    if int(ha) == svc_info.get_standby_preference():
                        ha_str = ("standby: %s" % (ha))
                    else:
                        ha_str = ("active: %s" % (ha))
                    vm = sandesh.ServiceInstanceVM(name=vm_str,
                                                   vr_name=vr_name,
                                                   ha=ha_str)
                    sandesh_vm_list.append(vm)
                sandesh_si.vm_list = list(sandesh_vm_list)

                for itf_type in svc_info.get_if_str_list():
                    key = itf_type + '-vn'
                    if key not in si.keys():
                        continue
                    vn_name = si[key]
                    vn_uuid = si[vn_name]
                    if itf_type == svc_info.get_left_if_str():
                        sandesh_si.left_vn = [vn_name, vn_uuid]
                    if itf_type == svc_info.get_right_if_str():
                        sandesh_si.right_vn = [vn_name, vn_uuid]
                    if itf_type == svc_info.get_management_if_str():
                        sandesh_si.management_vn = [vn_name, vn_uuid]

                si_resp.si_names.append(sandesh_si)

        si_resp.response(req.context())
예제 #12
0
    def sandesh_si_handle_request(self, req):
        si_resp = sandesh.ServiceInstanceListResp(si_names=[])
        if req.si_name is None:
            si_list = self._db.service_instance_list()

            for si_fq_name_str, si in si_list or []:
                sandesh_si = sandesh.ServiceInstance(
                    name=si_fq_name_str, si_type=si.get('instance_type', ''),
                    si_state=si.get('state', ''))

                sandesh_vm_list = []
                for idx in range(0, int(si.get('max-instances', '0'))):
                    prefix = self._db.get_vm_db_prefix(idx)
                    if not (prefix + 'name') in si.keys():
                        continue
                    vm_name = si.get(prefix + 'name', '')
                    vm_uuid = si.get(prefix + 'uuid', '')
                    vm_str = ("%s: %s" % (vm_name, vm_uuid))
                    vr_name = si.get(prefix + 'vrouter', '')
                    ha = si.get(prefix + 'preference', '')
                    if int(ha) == svc_info.get_standby_preference():
                        ha_str = ("standby: %s" % (ha))
                    else:
                        ha_str = ("active: %s" % (ha))
                    vm = sandesh.ServiceInstanceVM(name=vm_str,
                        vr_name=vr_name, ha=ha_str)
                    sandesh_vm_list.append(vm)
                sandesh_si.vm_list = list(sandesh_vm_list)

                for itf_type in svc_info.get_if_str_list():
                    key = itf_type + '-vn'
                    if key not in si.keys():
                        continue
                    vn_name = si[key]
                    vn_uuid = si[vn_name]
                    if itf_type == svc_info.get_left_if_str():
                        sandesh_si.left_vn = [vn_name, vn_uuid]
                    if itf_type == svc_info.get_right_if_str():
                        sandesh_si.right_vn = [vn_name, vn_uuid]
                    if itf_type == svc_info.get_management_if_str():
                        sandesh_si.management_vn = [vn_name, vn_uuid]

                si_resp.si_names.append(sandesh_si)

        si_resp.response(req.context())
예제 #13
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()
        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
예제 #14
0
    def pre_create_service_vm(self, instance_index, si, st, vm):
        for nic in si.vn_info:
            if nic['type'] == svc_info.get_right_if_str():
                vmi = self._get_vip_vmi(si)
                if not vmi:
                    return False
                for iip_id in vmi.instance_ips:
                    nic['iip-id'] = iip_id
                    break
                for fip_id in vmi.floating_ips:
                    nic['fip-id'] = fip_id
                    break
                if len(vmi.security_groups):
                    nic['sg-list'] = vmi.security_groups
                    break
                nic['user-visible'] = False
            elif nic['type'] == svc_info.get_left_if_str():
                nic['user-visible'] = False

        return True
    def pre_create_service_vm(self, instance_index, si, st, vm):
        for nic in si.vn_info:
            if nic['type'] == svc_info.get_right_if_str():
                vmi = self._get_vip_vmi(si)
                if not vmi:
                    return False
                for iip_id in vmi.instance_ips:
                    nic['iip-id'] = iip_id
                    break
                for fip_id in vmi.floating_ips:
                    nic['fip-id'] = fip_id
                    break
                if len(vmi.security_groups):
                    nic['sg-list'] = vmi.security_groups
                    break
                nic['user-visible'] = False
            elif nic['type'] == svc_info.get_left_if_str():
                nic['user-visible'] = False

        return True
예제 #16
0
    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
        '''TODO: add check for lb and snat. Need a new class to drive this
        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)

        # set max instances
        local_prefs = None
        max_instances = 1
        if si_props.get_ha_mode() == 'active-standby':
            max_instances = 2
            local_prefs = self._get_local_prefs(si_obj, max_instances)
        elif si_props.get_scale_out():
            max_instances = si_props.get_scale_out().get_max_instances()

        # Create virtual machines, associate them to the service instance and
        # schedule them to different virtual routers
        for inst_count in range(0, max_instances):
            # Create a virtual machine
            instance_name = self._get_instance_name(si_obj, inst_count)
            try:
                vm_obj = self._vnc_lib.virtual_machine_read(
                    fq_name=[instance_name])
                self.logger.log("Info: VM %s already exists" % (instance_name))
            except NoIdError:
                vm_obj = VirtualMachine(instance_name)
                self._vnc_lib.virtual_machine_create(vm_obj)
                self.logger.log("Info: VM %s created" % (instance_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
            row_entry = {}
            local_preference = None
            if local_prefs:
                local_preference = local_prefs[inst_count]
                row_entry['local_preference'] = local_preference

            for nic in nics:
                user_visible = True
                if nic['type'] == svc_info.get_left_if_str():
                    user_visible = False
                vmi_obj = self._create_svc_vm_port(nic, instance_name, st_obj,
                                                   si_obj, local_preference,
                                                   user_visible)
                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['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
            if chosen_vr_fq_name:
                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(),
                    vr_name=':'.join(chosen_vr_fq_name))
            else:
                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())
예제 #17
0
 def pre_create_service_vm(self, instance_index, si, st, vm):
     for nic in si.vn_info:
         if nic['type'] == svc_info.get_left_if_str():
             nic['user-visible'] = False
     return True
예제 #18
0
 def pre_create_service_vm(self, instance_index, si, st, vm):
     for nic in si.vn_info:
         if nic['type'] == svc_info.get_left_if_str():
             nic['user-visible'] = False
    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

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

        # set max instances
        local_prefs = None
        max_instances = 1
        if si_props.get_ha_mode() == 'active-standby':
            max_instances = 2
            local_prefs = self._get_local_prefs(si_obj, max_instances)
        elif si_props.get_scale_out():
            max_instances = si_props.get_scale_out().get_max_instances()

        # Create virtual machines, associate them to the service instance and
        # schedule them to different virtual routers
        for inst_count in range(0, max_instances):
            # Create a virtual machine
            instance_name = self._get_instance_name(si_obj, inst_count)
            try:
                vm_obj = self._vnc_lib.virtual_machine_read(fq_name=[instance_name])
                self.logger.log("Info: VM %s already exists" % (instance_name))
            except NoIdError:
                vm_obj = VirtualMachine(instance_name)
                self._vnc_lib.virtual_machine_create(vm_obj)
                self.logger.log("Info: VM %s created" % (instance_name))

            si_refs = vm_obj.get_service_instance_refs()
            if (si_refs is None) or (si_refs[0]['to'][0] == 'ERROR'):
                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
            row_entry = {}
            local_preference = None
            row_entry['local_preference'] = str(0)
            if local_prefs:
                local_preference = local_prefs[inst_count]
                row_entry['local_preference'] = str(local_preference)

            for nic in nics:
                user_visible = True
                if nic['type'] == svc_info.get_left_if_str():
                    user_visible = False
                if vmi_obj.get_virtual_machine_refs() is None:
                    vmi_obj = self._create_svc_vm_port(nic, instance_name, st_obj,
                        si_obj, int(local_preference), user_visible)
                    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['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 = None
            row_entry['vrouter_name'] = 'None'
            if vm_obj.get_virtual_router_back_refs() is None:
                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
            if chosen_vr_fq_name:
                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(),
                    vr_name=':'.join(chosen_vr_fq_name))
            else:
                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())