Esempio n. 1
0
def update_port_policy_binding(context, port_id, new_policy_id):
    # detach the old policy (if exists) from the port
    old_policy = obj_reg.load_class('QosPolicy').get_port_policy(
        context, port_id)
    if old_policy:
        if old_policy.id == new_policy_id:
            return
        old_policy.detach_port(port_id)

    # attach the new policy (if exists) to the port
    if new_policy_id is not None:
        new_policy = obj_reg.load_class('QosPolicy').get_object(
            context, id=new_policy_id)
        if new_policy:
            new_policy.attach_port(port_id)
Esempio n. 2
0
def update_port_policy_binding(context, port_id, new_policy_id):
    # detach the old policy (if exists) from the port
    old_policy = obj_reg.load_class('QosPolicy').get_port_policy(
        context, port_id)
    if old_policy:
        if old_policy.id == new_policy_id:
            return
        old_policy.detach_port(port_id)

    # attach the new policy (if exists) to the port
    if new_policy_id is not None:
        new_policy = obj_reg.load_class('QosPolicy').get_object(
            context, id=new_policy_id)
        if new_policy:
            new_policy.attach_port(port_id)
Esempio n. 3
0
def validate_policy_accessable(context, policy_id):
    policy_obj = obj_reg.load_class('QosPolicy').get_object(
        context, id=policy_id)
    if not policy_obj:
        # This means that rbac decided the policy cannot be used with this
        # context
        raise qos_exc.QosPolicyNotFound(policy_id=policy_id)
Esempio n. 4
0
    def process_update_network(self, plugin_context, request_data, db_data):
        new_value = request_data.get(dns.DNSDOMAIN)
        if not validators.is_attr_set(new_value):
            return

        current_dns_domain = db_data.get(dns.DNSDOMAIN)
        if current_dns_domain == new_value:
            return

        net_id = db_data['id']
        if current_dns_domain:
            net_dns_domain = obj_reg.load_class('NetworkDNSDomain').get_object(
                plugin_context, network_id=net_id)
            if new_value:
                net_dns_domain['dns_domain'] = new_value
                db_data[dns.DNSDOMAIN] = new_value
                net_dns_domain.update()
            else:
                net_dns_domain.delete()
                db_data[dns.DNSDOMAIN] = ''
        elif new_value:
            obj_reg.new_instance('NetworkDNSDomain',
                                 plugin_context,
                                 network_id=net_id,
                                 dns_domain=new_value).create()
            db_data[dns.DNSDOMAIN] = new_value
Esempio n. 5
0
    def _update_dns_db(self, dns_name, dns_domain, db_data, plugin_context,
                       has_fixed_ips):
        dns_data_db = obj_reg.load_class('PortDNS').get_object(
            plugin_context, port_id=db_data['id'])
        if dns_data_db:
            is_dns_name_changed = (dns_name is not None and
                                   dns_data_db['current_dns_name'] != dns_name)

            if is_dns_name_changed or (has_fixed_ips
                                       and dns_data_db['current_dns_name']):
                dns_data_db['previous_dns_name'] = (
                    dns_data_db['current_dns_name'])
                dns_data_db['previous_dns_domain'] = (
                    dns_data_db['current_dns_domain'])
                if is_dns_name_changed:
                    dns_data_db[dns.DNSNAME] = dns_name
                    dns_data_db['current_dns_name'] = dns_name
                    if dns_name:
                        dns_data_db['current_dns_domain'] = dns_domain
                    else:
                        dns_data_db['current_dns_domain'] = ''

            dns_data_db.update()
            return dns_data_db
        if dns_name:
            dns_data_db = obj_reg.new_instance('PortDNS',
                                               plugin_context,
                                               port_id=db_data['id'],
                                               current_dns_name=dns_name,
                                               current_dns_domain=dns_domain,
                                               previous_dns_name='',
                                               previous_dns_domain='',
                                               dns_name=dns_name)
            dns_data_db.create()
        return dns_data_db
Esempio n. 6
0
def _update_port_in_external_dns_service(resource, event, trigger, **kwargs):
    dns_driver = _get_dns_driver()
    if not dns_driver:
        return
    context = kwargs['context']
    updated_port = kwargs['port']
    original_port = kwargs.get('original_port')
    if not original_port:
        return
    original_ips = [ip['ip_address'] for ip in original_port['fixed_ips']]
    updated_ips = [ip['ip_address'] for ip in updated_port['fixed_ips']]
    is_dns_name_changed = (updated_port[dns.DNSNAME] !=
                           original_port[dns.DNSNAME])
    is_dns_domain_changed = (
        dns.DNSDOMAIN in updated_port
        and updated_port[dns.DNSDOMAIN] != original_port[dns.DNSDOMAIN])
    ips_changed = set(original_ips) != set(updated_ips)
    if not any((is_dns_name_changed, is_dns_domain_changed, ips_changed)):
        return
    dns_data_db = obj_reg.load_class('PortDNS').get_object(
        context, port_id=updated_port['id'])
    if not (dns_data_db and (dns_data_db['previous_dns_name']
                             or dns_data_db['current_dns_name'])):
        return
    if dns_data_db['previous_dns_name']:
        _remove_data_from_external_dns_service(
            context, dns_driver, dns_data_db['previous_dns_domain'],
            dns_data_db['previous_dns_name'], original_ips)
    if dns_data_db['current_dns_name']:
        _send_data_to_external_dns_service(context, dns_driver,
                                           dns_data_db['current_dns_domain'],
                                           dns_data_db['current_dns_name'],
                                           updated_ips)
Esempio n. 7
0
    def process_update_network(self, plugin_context, request_data, db_data):
        new_value = request_data.get(dns.DNSDOMAIN)
        if not validators.is_attr_set(new_value):
            return

        current_dns_domain = db_data.get(dns.DNSDOMAIN)
        if current_dns_domain == new_value:
            return

        net_id = db_data['id']
        if current_dns_domain:
            net_dns_domain = obj_reg.load_class('NetworkDNSDomain').get_object(
                plugin_context,
                network_id=net_id)
            if new_value:
                net_dns_domain['dns_domain'] = new_value
                db_data[dns.DNSDOMAIN] = new_value
                net_dns_domain.update()
            else:
                net_dns_domain.delete()
                db_data[dns.DNSDOMAIN] = ''
        elif new_value:
            obj_reg.new_instance('NetworkDNSDomain', plugin_context,
                                 network_id=net_id,
                                 dns_domain=new_value).create()
            db_data[dns.DNSDOMAIN] = new_value
Esempio n. 8
0
def _update_port_in_external_dns_service(resource, event, trigger, **kwargs):
    dns_driver = _get_dns_driver()
    if not dns_driver:
        return
    context = kwargs['context']
    updated_port = kwargs['port']
    original_port = kwargs.get('original_port')
    if not original_port:
        return
    original_ips = [ip['ip_address'] for ip in original_port['fixed_ips']]
    updated_ips = [ip['ip_address'] for ip in updated_port['fixed_ips']]
    is_dns_name_changed = (updated_port[dns.DNSNAME] !=
                           original_port[dns.DNSNAME])
    is_dns_domain_changed = (dns.DNSDOMAIN in updated_port and
                             updated_port[dns.DNSDOMAIN] !=
                             original_port[dns.DNSDOMAIN])
    ips_changed = set(original_ips) != set(updated_ips)
    if not any((is_dns_name_changed, is_dns_domain_changed, ips_changed)):
        return
    dns_data_db = obj_reg.load_class('PortDNS').get_object(
        context, port_id=updated_port['id'])
    if not (dns_data_db and
            (dns_data_db['previous_dns_name'] or
             dns_data_db['current_dns_name'])):
        return
    if dns_data_db['previous_dns_name']:
        _remove_data_from_external_dns_service(
            context, dns_driver, dns_data_db['previous_dns_domain'],
            dns_data_db['previous_dns_name'], original_ips)
    if dns_data_db['current_dns_name']:
        _send_data_to_external_dns_service(context, dns_driver,
                                           dns_data_db['current_dns_domain'],
                                           dns_data_db['current_dns_name'],
                                           updated_ips)
Esempio n. 9
0
def validate_policy_accessable(context, policy_id):
    policy_obj = obj_reg.load_class('QosPolicy').get_object(context,
                                                            id=policy_id)
    if not policy_obj:
        # This means that rbac decided the policy cannot be used with this
        # context
        raise qos_exc.QosPolicyNotFound(policy_id=policy_id)
    def schedule_unscheduled_bgp_speakers(self, context, host):
        """Schedule unscheduled BgpSpeaker to a BgpDrAgent.
        """

        LOG.debug('Started auto-scheduling on host %s', host)
        with context.session.begin(subtransactions=True):
            bgp_dragent = obj_reg.load_class('Agent').get_object(
                context,
                agent_type=bgp_consts.AGENT_TYPE_BGP_ROUTING,
                host=host,
                admin_state_up=True)
            if not bgp_dragent:
                LOG.debug('No enabled BgpDrAgent on host %s', host)
                return False

            if utils.is_agent_down(bgp_dragent.heartbeat_timestamp):
                LOG.warning(_LW('BgpDrAgent %s is down'), bgp_dragent.id)
                return False

            if self._is_bgp_speaker_hosted(context, bgp_dragent['id']):
                # One BgpDrAgent can only host one BGP speaker
                LOG.debug(
                    'BgpDrAgent already hosting a speaker on host %s. '
                    'Cannot schedule an another one', host)
                return False

            unscheduled_speakers = self._get_unscheduled_bgp_speakers(context)
            if not unscheduled_speakers:
                LOG.debug('Nothing to auto-schedule on host %s', host)
                return False

            self.bind(context, [bgp_dragent], unscheduled_speakers[0])
        return True
Esempio n. 11
0
    def _update_dns_db(self, dns_name, dns_domain, db_data,
                      plugin_context, has_fixed_ips):
        dns_data_db = obj_reg.load_class('PortDNS').get_object(
            plugin_context,
            port_id=db_data['id'])
        if dns_data_db:
            is_dns_name_changed = (dns_name is not None and
                    dns_data_db['current_dns_name'] != dns_name)

            if is_dns_name_changed or (has_fixed_ips and
                                       dns_data_db['current_dns_name']):
                dns_data_db['previous_dns_name'] = (
                    dns_data_db['current_dns_name'])
                dns_data_db['previous_dns_domain'] = (
                    dns_data_db['current_dns_domain'])
                if is_dns_name_changed:
                    dns_data_db[dns.DNSNAME] = dns_name
                    dns_data_db['current_dns_name'] = dns_name
                    if dns_name:
                        dns_data_db['current_dns_domain'] = dns_domain
                    else:
                        dns_data_db['current_dns_domain'] = ''

            dns_data_db.update()
            return dns_data_db
        if dns_name:
            dns_data_db = obj_reg.new_instance(
                'PortDNS', plugin_context, port_id=db_data['id'],
                current_dns_name=dns_name, current_dns_domain=dns_domain,
                previous_dns_name='', previous_dns_domain='',
                dns_name=dns_name)
            dns_data_db.create()
        return dns_data_db
    def schedule_unscheduled_bgp_speakers(self, context, host):
        """Schedule unscheduled BgpSpeaker to a BgpDrAgent.
        """

        LOG.debug('Started auto-scheduling on host %s', host)
        with context.session.begin(subtransactions=True):
            bgp_dragent = obj_reg.load_class('Agent').get_object(
                context,
                agent_type=bgp_consts.AGENT_TYPE_BGP_ROUTING,
                host=host,
                admin_state_up=True)
            if not bgp_dragent:
                LOG.debug('No enabled BgpDrAgent on host %s', host)
                return False

            if utils.is_agent_down(
                    bgp_dragent.heartbeat_timestamp):
                LOG.warning(_LW('BgpDrAgent %s is down'), bgp_dragent.id)
                return False

            if self._is_bgp_speaker_hosted(context, bgp_dragent['id']):
                # One BgpDrAgent can only host one BGP speaker
                LOG.debug('BgpDrAgent already hosting a speaker on host %s. '
                          'Cannot schedule an another one', host)
                return False

            unscheduled_speakers = self._get_unscheduled_bgp_speakers(context)
            if not unscheduled_speakers:
                LOG.debug('Nothing to auto-schedule on host %s', host)
                return False

            self.bind(context, [bgp_dragent], unscheduled_speakers[0])
        return True
Esempio n. 13
0
def _delete_port_in_external_dns_service(resource, event, trigger, **kwargs):
    dns_driver = _get_dns_driver()
    if not dns_driver:
        return
    context = kwargs['context']
    port_id = kwargs['port_id']
    dns_data_db = obj_reg.load_class('PortDNS').get_object(context,
                                                           port_id=port_id)
    if not dns_data_db:
        return
    if dns_data_db['current_dns_name']:
        ip_allocations = obj_reg.load_class('IPAllocation').get_objects(
            context, port_id=port_id)
        records = [str(alloc['ip_address']) for alloc in ip_allocations]
        _remove_data_from_external_dns_service(
            context, dns_driver, dns_data_db['current_dns_domain'],
            dns_data_db['current_dns_name'], records)
Esempio n. 14
0
    def _get_ports_with_policy(self, context, policy):
        networks_ids = policy.get_bound_networks()

        ports_with_net_policy = obj_reg.load_class('Port').get_objects(
            context, network_id=networks_ids)

        # Filter only these ports which don't have overwritten policy
        ports_with_net_policy = [
            port for port in ports_with_net_policy if
            port.qos_policy_id is None
        ]

        ports_ids = policy.get_bound_ports()
        ports_with_policy = obj_reg.load_class('Port').get_objects(
            context, id=ports_ids)
        t_ports = list(set(ports_with_policy + ports_with_net_policy))

        t_ctx = t_context.get_context_from_neutron_context(context)
        for t_port in t_ports:
            mappings = db_api.get_bottom_mappings_by_top_id(
                t_ctx, t_port.id, t_constants.RT_PORT)
            if mappings:
                b_pod, b_port_id = mappings[0]
                b_region_name = b_pod['region_name']
                b_client = self._get_client(region_name=b_region_name)
                b_port = b_client.get_ports(t_ctx, b_port_id)
                new_binding = obj_reg.new_instance(
                    'PortBinding',
                    port_id=t_port.id,
                    vif_type=b_port.get('binding:vif_type',
                                        portbindings.VIF_TYPE_UNBOUND),
                    vnic_type=b_port.get('binding:vnic_type',
                                         portbindings.VNIC_NORMAL)
                )
                t_port.binding = new_binding
            else:
                new_binding = obj_reg.new_instance(
                    'PortBinding',
                    port_id=t_port.id,
                    vif_type=portbindings.VIF_TYPE_UNBOUND,
                    vnic_type=portbindings.VNIC_NORMAL
                )
                t_port.binding = new_binding

        return t_ports
Esempio n. 15
0
def _delete_port_in_external_dns_service(resource, event,
                                         trigger, payload=None):
    dns_driver = _get_dns_driver()
    if not dns_driver:
        return
    context = payload.context
    port_id = payload.resource_id
    dns_data_db = obj_reg.load_class('PortDNS').get_object(
        context, port_id=port_id)
    if not dns_data_db:
        return
    if dns_data_db['current_dns_name']:
        ip_allocations = obj_reg.load_class('IPAllocation').get_objects(
            context, port_id=port_id)
        records = [str(alloc['ip_address']) for alloc in ip_allocations]
        _remove_data_from_external_dns_service(
            context, dns_driver, dns_data_db['current_dns_domain'],
            dns_data_db['current_dns_name'], records)
Esempio n. 16
0
    def _get_ports_with_policy(self, context, policy):
        networks_ids = policy.get_bound_networks()

        ports_with_net_policy = obj_reg.load_class('Port').get_objects(
            context, network_id=networks_ids)

        # Filter only these ports which don't have overwritten policy
        ports_with_net_policy = [
            port for port in ports_with_net_policy
            if port.qos_policy_id is None
        ]

        ports_ids = policy.get_bound_ports()
        ports_with_policy = obj_reg.load_class('Port').get_objects(
            context, id=ports_ids)
        t_ports = list(set(ports_with_policy + ports_with_net_policy))

        t_ctx = t_context.get_context_from_neutron_context(context)
        for t_port in t_ports:
            mappings = db_api.get_bottom_mappings_by_top_id(
                t_ctx, t_port.id, t_constants.RT_PORT)
            if mappings:
                b_pod, b_port_id = mappings[0]
                b_region_name = b_pod['region_name']
                b_client = self._get_client(region_name=b_region_name)
                b_port = b_client.get_ports(t_ctx, b_port_id)
                new_binding = obj_reg.new_instance(
                    'PortBinding',
                    port_id=t_port.id,
                    vif_type=b_port.get('binding:vif_type',
                                        portbindings.VIF_TYPE_UNBOUND),
                    vnic_type=b_port.get('binding:vnic_type',
                                         portbindings.VNIC_NORMAL))
                t_port.binding = new_binding
            else:
                new_binding = obj_reg.new_instance(
                    'PortBinding',
                    port_id=t_port.id,
                    vif_type=portbindings.VIF_TYPE_UNBOUND,
                    vnic_type=portbindings.VNIC_NORMAL)
                t_port.binding = new_binding

        return t_ports
Esempio n. 17
0
def _create_port_in_external_dns_service(resource, event, trigger, **kwargs):
    dns_driver = _get_dns_driver()
    if not dns_driver:
        return
    context = kwargs['context']
    port = kwargs['port']
    dns_data_db = obj_reg.load_class('PortDNS').get_object(context,
                                                           port_id=port['id'])
    if not (dns_data_db and dns_data_db['current_dns_name']):
        return
    records = [ip['ip_address'] for ip in port['fixed_ips']]
    _send_data_to_external_dns_service(context, dns_driver,
                                       dns_data_db['current_dns_domain'],
                                       dns_data_db['current_dns_name'],
                                       records)
Esempio n. 18
0
def _create_port_in_external_dns_service(resource, event, trigger, **kwargs):
    dns_driver = _get_dns_driver()
    if not dns_driver:
        return
    context = kwargs['context']
    port = kwargs['port']
    dns_data_db = obj_reg.load_class('PortDNS').get_object(
        context, port_id=port['id'])
    if not (dns_data_db and dns_data_db['current_dns_name']):
        return
    records = [ip['ip_address'] for ip in port['fixed_ips']]
    _send_data_to_external_dns_service(context, dns_driver,
                                       dns_data_db['current_dns_domain'],
                                       dns_data_db['current_dns_name'],
                                       records)
Esempio n. 19
0
 def _process_only_dns_name_update(self, plugin_context, db_data, dns_name):
     dns_data_db = obj_reg.load_class('PortDNS').get_object(
         plugin_context,
         port_id=db_data['id'])
     if dns_data_db:
         dns_data_db['dns_name'] = dns_name
         dns_data_db.update()
         return dns_data_db
     if dns_name:
         dns_data_db = obj_reg.new_instance(
             'PortDNS', plugin_context, port_id=db_data['id'],
             current_dns_name='', current_dns_domain='',
             previous_dns_name='', previous_dns_domain='',
             dns_name=dns_name)
         dns_data_db.create()
     return dns_data_db
Esempio n. 20
0
 def _process_only_dns_name_update(self, plugin_context, db_data, dns_name):
     dns_data_db = obj_reg.load_class('PortDNS').get_object(
         plugin_context,
         port_id=db_data['id'])
     if dns_data_db:
         dns_data_db['dns_name'] = dns_name
         dns_data_db.update()
         return dns_data_db
     if dns_name:
         dns_data_db = obj_reg.new_instance(
             'PortDNS', plugin_context, port_id=db_data['id'],
             current_dns_name='', current_dns_domain='',
             previous_dns_name='', previous_dns_domain='',
             dns_name=dns_name)
         dns_data_db.create()
     return dns_data_db
Esempio n. 21
0
def set_qos_policy_on_new_net(context, net_data, created_net):
    """Update the network with the assigned or default QoS policy

    Update the network-qos binding table, and the new network structure
    """
    qos_policy_id = net_data.get(qos_consts.QOS_POLICY_ID)
    if not qos_policy_id:
        # try and get the default one
        qos_obj = obj_reg.load_class('QosPolicyDefault').get_object(
            context, project_id=created_net['project_id'])
        if qos_obj:
            qos_policy_id = qos_obj.qos_policy_id

    if qos_policy_id:
        # attach the policy to the network in the neutron DB
        update_network_policy_binding(context, created_net['id'],
                                      qos_policy_id)
    created_net[qos_consts.QOS_POLICY_ID] = qos_policy_id
    return qos_policy_id
Esempio n. 22
0
    def _verify_trunk_info(self, trunk, has_items):
        ovn_subports_info = self._get_ovn_trunk_info()
        neutron_subports_info = []
        for subport in trunk.get('sub_ports', []):
            neutron_subports_info.append({
                'port_id': subport['port_id'],
                'parent_port_id': [trunk['port_id']],
                'tag': [subport['segmentation_id']]
            })
            # Check that the subport has the binding is active.
            binding = obj_reg.load_class('PortBinding').get_object(
                self.context, port_id=subport['port_id'], host='')
            self.assertEqual(n_consts.PORT_STATUS_ACTIVE, binding['status'])

        self.assertItemsEqual(ovn_subports_info, neutron_subports_info)
        self.assertEqual(has_items, len(neutron_subports_info) != 0)

        if trunk.get('status'):
            self.assertEqual(trunk_consts.TRUNK_ACTIVE_STATUS, trunk['status'])
Esempio n. 23
0
def set_qos_policy_on_new_net(context, net_data, created_net):
    """Update the network with the assigned or default QoS policy

    Update the network-qos binding table, and the new network structure
    """
    qos_policy_id = net_data.get(qos_consts.QOS_POLICY_ID)
    if not qos_policy_id:
        # try and get the default one
        qos_obj = obj_reg.load_class('QosPolicyDefault').get_object(
            context, project_id=created_net['project_id'])
        if qos_obj:
            qos_policy_id = qos_obj.qos_policy_id

    if qos_policy_id:
        # attach the policy to the network in the neutron DB
        update_network_policy_binding(
            context,
            created_net['id'],
            qos_policy_id)
    created_net[qos_consts.QOS_POLICY_ID] = qos_policy_id
    return qos_policy_id
Esempio n. 24
0
    def _create_floatingip(self,
                           context,
                           floatingip,
                           initial_status=n_const.FLOATINGIP_STATUS_ACTIVE):
        fip = floatingip['floatingip']
        fip_id = uuidutils.generate_uuid()

        f_net_id = fip['floating_network_id']
        if not self._core_plugin._network_is_external(context, f_net_id):
            msg = _("Network %s is not a valid external network") % f_net_id
            raise n_exc.BadRequest(resource='floatingip', msg=msg)

        self._validate_network_for_floatingip(context, f_net_id)

        # This external port is never exposed to the tenant.
        # it is used purely for internal system and admin use when
        # managing floating IPs.

        port = {
            'tenant_id': '',  # tenant intentionally not set
            'network_id': f_net_id,
            'admin_state_up': True,
            'device_id': 'PENDING',
            'device_owner': DEVICE_OWNER_FLOATINGIP,
            'status': n_const.PORT_STATUS_NOTAPPLICABLE,
            'name': ''
        }
        # Both subnet_id and floating_ip_address are accepted, if
        # floating_ip_address is not in the subnet,
        # InvalidIpForSubnet exception will be raised.
        fixed_ip = {}
        if fip['subnet_id']:
            fixed_ip['subnet_id'] = fip['subnet_id']
        if fip['floating_ip_address']:
            fixed_ip['ip_address'] = fip['floating_ip_address']
        if fixed_ip:
            port['fixed_ips'] = [fixed_ip]

        # 'status' in port dict could not be updated by default, use
        # check_allow_post to stop the verification of system
        # TODO(boden): rehome create_port into neutron-lib
        external_port = plugin_utils.create_port(self._core_plugin,
                                                 context.elevated(),
                                                 {'port': port},
                                                 check_allow_post=False)

        with plugin_utils.delete_port_on_error(
                self._core_plugin, context.elevated(),
                external_port['id']),\
                context.session.begin(subtransactions=True):
            external_ips = self._port_fixed_ips_for_floatingip(external_port)
            if not external_ips:
                raise n_exc.ExternalIpAddressExhausted(net_id=f_net_id)

            floating_fixed_ip = external_ips[0]
            floating_ip_address = floating_fixed_ip['ip_address']
            floatingip_obj = obj_reg.new_instance(
                'FloatingIP',
                context,
                id=fip_id,
                project_id=fip['tenant_id'],
                status=initial_status,
                floating_network_id=fip['floating_network_id'],
                floating_ip_address=floating_ip_address,
                floating_port_id=external_port['id'],
                description=fip.get('description'))
            # Update association with internal port
            # and define external IP address
            assoc_result = self._update_fip_assoc(context, fip, floatingip_obj)
            floatingip_obj.create()
            floatingip_dict = self._make_floatingip_dict(
                floatingip_obj, process_extensions=False)
            if self._is_dns_integration_supported:
                dns_data = self._process_dns_floatingip_create_precommit(
                    context, floatingip_dict, fip)
            # NOTE(yamamoto): MidoNet doesn't have Floating IP QoS
            # if self._is_fip_qos_supported:
            #     self._process_extra_fip_qos_create(context, fip_id, fip)
            floatingip_obj = obj_reg.load_class('FloatingIP').get_object(
                context, id=floatingip_obj.id)
            floatingip_db = floatingip_obj.db_obj

            registry.notify(resources.FLOATING_IP,
                            events.PRECOMMIT_CREATE,
                            self,
                            context=context,
                            floatingip=fip,
                            floatingip_id=fip_id,
                            floatingip_db=floatingip_db)

        self._core_plugin.update_port(context.elevated(), external_port['id'],
                                      {'port': {
                                          'device_id': fip_id
                                      }})
        registry.notify(resources.FLOATING_IP, events.AFTER_UPDATE,
                        self._update_fip_assoc, **assoc_result)

        if self._is_dns_integration_supported:
            self._process_dns_floatingip_create_postcommit(
                context, floatingip_dict, dns_data)
        # TODO(lujinluo): Change floatingip_db to floatingip_obj once all
        # codes are migrated to use Floating IP OVO object.
        resource_extend.apply_funcs(l3_apidef.FLOATINGIPS, floatingip_dict,
                                    floatingip_db)
        return floatingip_dict
Esempio n. 25
0
def get_network_policy_id(context, net_id):
    policy = obj_reg.load_class('QosPolicy').get_network_policy(
        context, net_id)
    if policy:
        return policy.id
from neutron_lib.objects import registry as obj_reg
from neutron_lib.objects import utils as obj_utils
from oslo_config import cfg
from oslo_utils import uuidutils

from neutron.services.qos import qos_plugin
from neutron.tests.unit.services.qos import base

from vmware_nsx.db import db as nsx_db
from vmware_nsx.plugins.nsx_v3 import utils as v3_utils
from vmware_nsx.services.qos.nsx_v3 import driver as qos_driver
from vmware_nsx.services.qos.nsx_v3 import utils as qos_utils
from vmware_nsx.tests.unit.nsx_v3 import test_plugin

PLUGIN_NAME = 'vmware_nsx.plugins.nsx_v3.plugin.NsxV3Plugin'
QoSPolicy = obj_reg.load_class('QosPolicy')
QosBandwidthLimitRule = obj_reg.load_class('QosBandwidthLimitRule')
QosDscpMarkingRule = obj_reg.load_class('QosDscpMarkingRule')
QosMinimumBandwidthRule = obj_reg.load_class('QosMinimumBandwidthRule')


class TestQosNsxV3Notification(base.BaseQosTestCase,
                               test_plugin.NsxV3PluginTestCaseMixin):

    def setUp(self):
        # Reset the drive to re-create it
        qos_driver.DRIVER = None
        super(TestQosNsxV3Notification, self).setUp()
        self.setup_coreplugin(PLUGIN_NAME)

        self.qos_plugin = qos_plugin.QoSPlugin()
Esempio n. 27
0
from neutron_lib.objects import registry as obj_reg
from oslo_config import cfg
from oslo_utils import uuidutils

from neutron.services.qos import qos_plugin
from neutron.tests.unit.services.qos import base

from vmware_nsx.common import utils
from vmware_nsx.plugins.nsx_v3 import utils as v3_utils
from vmware_nsx.services.qos.nsx_v3 import driver as qos_driver
from vmware_nsx.services.qos.nsx_v3 import pol_utils as qos_utils
from vmware_nsx.tests.unit.nsx_p import test_plugin
from vmware_nsxlib.v3.policy import core_defs as policy_defs

PLUGIN_NAME = 'vmware_nsx.plugins.nsx_p.plugin.NsxPolicyPlugin'
QoSPolicy = obj_reg.load_class('QosPolicy')
QosBandwidthLimitRule = obj_reg.load_class('QosBandwidthLimitRule')
QosDscpMarkingRule = obj_reg.load_class('QosDscpMarkingRule')
QosMinimumBandwidthRule = obj_reg.load_class('QosMinimumBandwidthRule')


class TestQosNsxPNotification(base.BaseQosTestCase,
                              test_plugin.NsxPPluginTestCaseMixin):
    def setUp(self):
        # Reset the drive to re-create it
        qos_driver.DRIVER = None
        super(TestQosNsxPNotification, self).setUp()
        self.setup_coreplugin(PLUGIN_NAME)

        self.qos_plugin = qos_plugin.QoSPlugin()
        self.ctxt = context.Context('fake_user', 'fake_tenant')
Esempio n. 28
0
def get_network_policy_id(context, net_id):
    policy = obj_reg.load_class('QosPolicy').get_network_policy(
        context, net_id)
    if policy:
        return policy.id
Esempio n. 29
0
from neutron_lib import context
from neutron_lib.objects import registry as obj_reg
from neutron_lib.plugins import directory
from neutron_lib.services.qos import constants as qos_consts
from oslo_config import cfg
from oslo_utils import uuidutils

from vmware_nsx.dvs import dvs
from vmware_nsx.dvs import dvs_utils
from vmware_nsx.services.qos.common import utils as qos_com_utils
from vmware_nsx.services.qos.nsx_v import driver as qos_driver
from vmware_nsx.services.qos.nsx_v import utils as qos_utils
from vmware_nsx.tests.unit.nsx_v import test_plugin

CORE_PLUGIN = "vmware_nsx.plugins.nsx_v.plugin.NsxVPluginV2"
QosPolicy = obj_reg.load_class('QosPolicy')
QosPolicyDefault = obj_reg.load_class('QosPolicyDefault')
QosBandwidthLimitRule = obj_reg.load_class('QosBandwidthLimitRule')
QosDscpMarkingRule = obj_reg.load_class('QosDscpMarkingRule')


class TestQosNsxVNotification(test_plugin.NsxVPluginV2TestCase,
                              base.BaseQosTestCase):

    @mock.patch.object(dvs_utils, 'dvs_create_session')
    def setUp(self, *mocks):
        # init the nsx-v plugin for testing with DVS
        self._init_dvs_config()
        # Reset the drive to re-create it
        qos_driver.DRIVER = None
        # Skip Octavia init because of RPC conflicts
from oslo_config import cfg
from oslo_utils import uuidutils

from neutron.common import exceptions
from neutron.objects import base as base_object
from neutron.services.qos import qos_plugin
from neutron.tests.unit.services.qos import base

from vmware_nsx.db import db as nsx_db
from vmware_nsx.plugins.nsx_v3 import utils as v3_utils
from vmware_nsx.services.qos.nsx_v3 import driver as qos_driver
from vmware_nsx.services.qos.nsx_v3 import utils as qos_utils
from vmware_nsx.tests.unit.nsx_v3 import test_plugin

PLUGIN_NAME = 'vmware_nsx.plugins.nsx_v3.plugin.NsxV3Plugin'
QoSPolicyObject = obj_reg.load_class('QosPolicy')


class TestQosNsxV3Notification(base.BaseQosTestCase,
                               test_plugin.NsxV3PluginTestCaseMixin):
    def setUp(self):
        # Reset the drive to re-create it
        qos_driver.DRIVER = None
        super(TestQosNsxV3Notification, self).setUp()
        self.setup_coreplugin(PLUGIN_NAME)

        self.qos_plugin = qos_plugin.QoSPlugin()
        self.ctxt = context.Context('fake_user', 'fake_tenant')
        mock.patch.object(self.ctxt.session, 'refresh').start()
        mock.patch.object(self.ctxt.session, 'expunge').start()
        self.policy_data = {