Exemplo n.º 1
0
    def _validate_update_network_callback(self,
                                          resource,
                                          event,
                                          trigger,
                                          payload=None):
        context = payload.context
        original_network = payload.states[0]
        updated_network = payload.desired_state

        original_policy_id = original_network.get(qos_consts.QOS_POLICY_ID)
        policy_id = updated_network.get(qos_consts.QOS_POLICY_ID)

        if policy_id is None or policy_id == original_policy_id:
            return

        policy = policy_object.QosPolicy.get_object(context.elevated(),
                                                    id=policy_id)
        self.validate_policy_for_network(context,
                                         policy,
                                         network_id=updated_network['id'])

        ports = ports_object.Port.get_objects(context,
                                              network_id=updated_network['id'])
        # Filter only this ports which don't have overwritten policy
        ports = [port for port in ports if port.qos_policy_id is None]
        self.validate_policy_for_ports(context, policy, ports)
Exemplo n.º 2
0
    def create_l2_gateway_connection_precommit(self, context, gw_connection):
        """Validate the L2 gateway connection
        Do not allow another connection with the same bride cluster and seg_id
        """
        admin_ctx = context.elevated()
        nsxlib = self._core_plugin.nsxlib
        l2gw_id = gw_connection.get(l2gw_const.L2GATEWAY_ID)
        devices = self._get_l2_gateway_devices(context, l2gw_id)
        bep_id = devices[0].get('device_name')
        # Check for bridge endpoint profile existence
        # if bridge endpoint profile is not found, this is likely an old
        # connection, fail with error.
        try:
            nsxlib.bridge_endpoint_profile.get_id_by_name_or_id(bep_id)
        except nsxlib_exc.ManagerError as e:
            msg = (_("Error while retrieving bridge endpoint profile "
                     "%(bep_id)s from NSX backend. Check that the profile "
                     "exits and there are not multiple profiles with "
                     "the given name. Exception: %(exc)s") %
                   {'bep_id': bep_id, 'exc': e})
            raise n_exc.InvalidInput(error_message=msg)

        interface_name, seg_id = self._get_conn_parameters(
            admin_ctx, gw_connection)
        try:
            # Use search API for listing bridge endpoints on NSX for provided
            # VLAN id, transport zone id, and Bridge endpoint profile
            endpoints = nsxlib.search_all_resource_by_attributes(
                nsxlib.bridge_endpoint.resource_type,
                bridge_endpoint_profile_id=bep_id,
                vlan_transport_zone_id=interface_name,
                vlan=seg_id)
            endpoint_map = dict((endpoint['id'],
                                 endpoint['bridge_endpoint_profile_id'])
                            for endpoint in endpoints)
        except nsxlib_exc.ManagerError as e:
            msg = (_("Error while retrieving endpoints for bridge endpoint "
                     "profile %(bep_id)s s from NSX backend. "
                     "Exception: %(exc)s") % {'bep_id': bep_id, 'exc': e})
            raise n_exc.InvalidInput(error_message=msg)

        # get all bridge endpoint ports
        with db_api.CONTEXT_WRITER.using(admin_ctx):
            port_filters = {'device_owner': [nsx_constants.BRIDGE_ENDPOINT]}
            ports = self._core_plugin.get_ports(
                admin_ctx, filters=port_filters)
            for port in ports:
                device_id = port.get('device_id')
                if endpoint_map.get(device_id) == bep_id:
                    # This device is using the same vlan id and bridge endpoint
                    # profile as the one requested. Not ok.
                    msg = (_("Cannot create multiple connections with the "
                             "same segmentation id %(seg_id)s for bridge "
                             "endpoint profile %(bep_id)s") %
                           {'seg_id': seg_id,
                            'bep_id': bep_id})
                    raise n_exc.InvalidInput(error_message=msg)
Exemplo n.º 3
0
    def _check_port_for_placement_allocation_change(self, resource, event,
                                                    trigger, **kwargs):
        context = kwargs['context']
        orig_port = kwargs['original_port']
        original_policy_id = orig_port.get(qos_consts.QOS_POLICY_ID)
        policy_id = kwargs['port'].get(qos_consts.QOS_POLICY_ID)

        if policy_id == original_policy_id:
            return

        # Do this only for compute bound ports
        if (nl_constants.DEVICE_OWNER_COMPUTE_PREFIX in
                orig_port['device_owner']):
            original_policy = policy_object.QosPolicy.get_object(
                context.elevated(), id=original_policy_id)
            policy = policy_object.QosPolicy.get_object(
                context.elevated(), id=policy_id)
            self._change_placement_allocation(original_policy, policy,
                                              orig_port)
Exemplo n.º 4
0
    def _validate_create_port_callback(self, resource, event, trigger,
                                       **kwargs):
        context = kwargs['context']
        port_id = kwargs['port']['id']
        port = ports_object.Port.get_object(context, id=port_id)

        policy_id = port.qos_policy_id or port.qos_network_policy_id
        if policy_id is None:
            return

        policy = policy_object.QosPolicy.get_object(
            context.elevated(), id=policy_id)
        self.validate_policy_for_port(context, policy, port)
Exemplo n.º 5
0
    def _validate_create_network_callback(self, resource, event, trigger,
                                          **kwargs):
        context = kwargs['context']
        network_id = kwargs['network']['id']
        network = network_object.Network.get_object(context, id=network_id)

        policy_id = network.qos_policy_id
        if policy_id is None:
            return

        policy = policy_object.QosPolicy.get_object(context.elevated(),
                                                    id=policy_id)
        self.validate_policy_for_network(context, policy, network_id)
Exemplo n.º 6
0
    def _validate_create_network_callback(self, resource, event, trigger,
                                          payload=None):
        context = payload.context
        network_id = payload.resource_id
        network = network_object.Network.get_object(context, id=network_id)

        policy_id = network.qos_policy_id
        if policy_id is None:
            return

        policy = policy_object.QosPolicy.get_object(
            context.elevated(), id=policy_id)
        self.validate_policy_for_network(context, policy, network_id)
Exemplo n.º 7
0
    def _check_port_for_placement_allocation_change(self, resource, event,
                                                    trigger, payload):
        context = payload.context
        orig_port = payload.states[0]
        port = payload.latest_state
        original_policy_id = orig_port.get(qos_consts.QOS_POLICY_ID)
        if qos_consts.QOS_POLICY_ID not in port:
            return
        policy_id = port.get(qos_consts.QOS_POLICY_ID)

        if policy_id == original_policy_id:
            return

        # Do this only for compute bound ports
        if (nl_constants.DEVICE_OWNER_COMPUTE_PREFIX in
                orig_port['device_owner']):
            original_policy = policy_object.QosPolicy.get_object(
                context.elevated(), id=original_policy_id)
            policy = policy_object.QosPolicy.get_object(
                context.elevated(), id=policy_id)
            self._change_placement_allocation(original_policy, policy,
                                              orig_port)
Exemplo n.º 8
0
    def _validate_create_port_callback(self, resource, event, trigger,
                                       payload=None):
        context = payload.context
        port_id = payload.resource_id
        port = ports_object.Port.get_object(context, id=port_id)

        policy_id = port.qos_policy_id or port.qos_network_policy_id
        if policy_id is None:
            return

        policy = policy_object.QosPolicy.get_object(
            context.elevated(), id=policy_id)
        self.validate_policy_for_port(context, policy, port)
Exemplo n.º 9
0
    def _validate_create_port_callback(self, resource, event, trigger,
                                       **kwargs):
        context = kwargs['context']
        port_id = kwargs['port']['id']
        port = ports_object.Port.get_object(context, id=port_id)
        network = network_object.Network.get_object(context,
                                                    id=port.network_id)

        policy_id = port.qos_policy_id or network.qos_policy_id
        if policy_id is None:
            return

        policy = policy_object.QosPolicy.get_object(
            context.elevated(), id=policy_id)
        self.validate_policy_for_port(policy, port)
Exemplo n.º 10
0
    def _validate_update_port_callback(self, resource, event, trigger,
                                       payload=None):
        context = payload.context
        original_policy_id = payload.states[0].get(
            qos_consts.QOS_POLICY_ID)
        policy_id = payload.desired_state.get(qos_consts.QOS_POLICY_ID)

        if policy_id is None or policy_id == original_policy_id:
            return

        updated_port = ports_object.Port.get_object(
            context, id=payload.desired_state['id'])
        policy = policy_object.QosPolicy.get_object(
            context.elevated(), id=policy_id)

        self.validate_policy_for_port(context, policy, updated_port)
Exemplo n.º 11
0
    def _validate_update_port_callback(self, resource, event, trigger,
                                       payload=None):
        context = payload.context
        original_policy_id = payload.states[0].get(
            qos_consts.QOS_POLICY_ID)
        policy_id = payload.desired_state.get(qos_consts.QOS_POLICY_ID)

        if policy_id is None or policy_id == original_policy_id:
            return

        updated_port = ports_object.Port.get_object(
            context, id=payload.desired_state['id'])
        policy = policy_object.QosPolicy.get_object(
            context.elevated(), id=policy_id)

        self.validate_policy_for_port(policy, updated_port)
Exemplo n.º 12
0
    def _validate_update_network_callback(self, resource, event, trigger,
                                          payload=None):
        context = payload.context
        original_network = payload.states[0]
        updated_network = payload.desired_state

        original_policy_id = original_network.get(qos_consts.QOS_POLICY_ID)
        policy_id = updated_network.get(qos_consts.QOS_POLICY_ID)

        if policy_id is None or policy_id == original_policy_id:
            return

        policy = policy_object.QosPolicy.get_object(
            context.elevated(), id=policy_id)
        ports = ports_object.Port.get_objects(
                context, network_id=updated_network['id'])
        # Filter only this ports which don't have overwritten policy
        ports = [
            port for port in ports if port.qos_policy_id is None
        ]
        self.validate_policy_for_ports(policy, ports)
Exemplo n.º 13
0
    def create_l2_gateway_connection_precommit(self, context, gw_connection):
        """Validate the L2 gateway connection
        Do not allow another connection with the same bride cluster and seg_id
        """
        admin_ctx = context.elevated()
        l2gw_id = gw_connection.get(l2gw_const.L2GATEWAY_ID)
        seg_id = self._get_conn_seg_id(admin_ctx, gw_connection)
        bridge_cluster = self._get_bridge_cluster(admin_ctx, l2gw_id)

        # get all bridge endpoint ports
        with db_api.CONTEXT_WRITER.using(admin_ctx):
            port_filters = {'device_owner': [nsx_constants.BRIDGE_ENDPOINT]}
            ports = self._core_plugin.get_ports(admin_ctx,
                                                filters=port_filters)
            for port in ports:
                # get the nsx mapping by bridge endpoint
                if port.get('device_id'):
                    mappings = nsx_db.get_l2gw_connection_mappings_by_bridge(
                        admin_ctx.session, port['device_id'])
                    for mapping in mappings:
                        conn_id = mapping.connection_id
                        # get the matching GW connection
                        conn = self._get_l2_gateway_connection(
                            admin_ctx, conn_id)
                        con_seg_id = self._get_conn_seg_id(admin_ctx, conn)
                        if (conn and con_seg_id
                                and int(con_seg_id) == int(seg_id)):
                            # compare the bridge cluster
                            conn_bridge_cluster = self._get_bridge_cluster(
                                admin_ctx, conn.l2_gateway_id)
                            if conn_bridge_cluster == bridge_cluster:
                                msg = (_("Cannot create multiple connections "
                                         "with the same segmentation id "
                                         "%(seg_id)s for bridge cluster "
                                         "%(bridge)s") % {
                                             'seg_id': seg_id,
                                             'bridge': bridge_cluster
                                         })
                                raise n_exc.InvalidInput(error_message=msg)
Exemplo n.º 14
0
    def create_l2_gateway_connection_precommit(self, context, gw_connection):
        """Validate the L2 gateway connection
        Do not allow another connection with the same bride cluster and seg_id
        """
        admin_ctx = context.elevated()
        nsxlib = self._core_plugin.nsxlib
        l2gw_id = gw_connection.get(l2gw_const.L2GATEWAY_ID)
        devices = self._get_l2_gateway_devices(context, l2gw_id)
        bep_id = devices[0].get('device_name')
        # Check for bridge endpoint profile existence
        # if bridge endpoint profile is not found, this is likely an old
        # connection, fail with error.
        try:
            nsxlib.bridge_endpoint_profile.get_id_by_name_or_id(bep_id)
        except nsxlib_exc.ManagerError as e:
            msg = (_("Error while retrieving bridge endpoint profile "
                     "%(bep_id)s from NSX backend. Check that the profile "
                     "exits and there are not multiple profiles with "
                     "the given name. Exception: %(exc)s") % {
                         'bep_id': bep_id,
                         'exc': e
                     })
            raise n_exc.InvalidInput(error_message=msg)

        interface_name, seg_id = self._get_conn_parameters(
            admin_ctx, gw_connection)
        try:
            # Use search API for listing bridge endpoints on NSX for provided
            # VLAN id, transport zone id, and Bridge endpoint profile
            endpoints = nsxlib.search_all_resource_by_attributes(
                nsxlib.bridge_endpoint.resource_type,
                bridge_endpoint_profile_id=bep_id,
                vlan_transport_zone_id=interface_name,
                vlan=seg_id)
            endpoint_map = dict(
                (endpoint['id'], endpoint['bridge_endpoint_profile_id'])
                for endpoint in endpoints)
        except nsxlib_exc.ManagerError as e:
            msg = (_("Error while retrieving endpoints for bridge endpoint "
                     "profile %(bep_id)s s from NSX backend. "
                     "Exception: %(exc)s") % {
                         'bep_id': bep_id,
                         'exc': e
                     })
            raise n_exc.InvalidInput(error_message=msg)

        # get all bridge endpoint ports
        with db_api.CONTEXT_WRITER.using(admin_ctx):
            port_filters = {'device_owner': [nsx_constants.BRIDGE_ENDPOINT]}
            ports = self._core_plugin.get_ports(admin_ctx,
                                                filters=port_filters)
            for port in ports:
                device_id = port.get('device_id')
                if endpoint_map.get(device_id) == bep_id:
                    # This device is using the same vlan id and bridge endpoint
                    # profile as the one requested. Not ok.
                    msg = (_("Cannot create multiple connections with the "
                             "same segmentation id %(seg_id)s for bridge "
                             "endpoint profile %(bep_id)s") % {
                                 'seg_id': seg_id,
                                 'bep_id': bep_id
                             })
                    raise n_exc.InvalidInput(error_message=msg)