예제 #1
0
    def update_flow_classifier(self, chain_id, fc, auth_attr=None):
        if not auth_attr:
            LOG.warning("auth information required for n-sfc driver")
            return None

        fc_id = fc.pop('instance_id')
        fc_status = fc.pop('status')
        match_dict = fc.pop('match')
        fc.update(match_dict)

        sfc_classifier_params = self._create_classifier_params(fc)
        neutronclient_ = NeutronClient(auth_attr)
        if fc_status == constants.PENDING_UPDATE:
            fc_info = neutronclient_.flow_classifier_show(fc_id)
            for field in sfc_classifier_params:
                # If the new classifier is the same with the old one then
                # no change needed.
                if (fc_info['flow_classifier'].get(field) is not None) and \
                        (sfc_classifier_params[field] == fc_info[
                            'flow_classifier'][field]):
                    continue

                # If the new classifier has different match criteria
                # with the old one then we strip the classifier from
                # the chain we delete the old classifier and we create
                # a new one with the same name as before but with different
                # match criteria. We are not using the flow_classifier_update
                # from the n-sfc because it does not support match criteria
                # update for an existing classifier yet.
                else:
                    try:
                        self._dissociate_classifier_from_chain(chain_id,
                                                               [fc_id],
                                                               neutronclient_)
                    except Exception as e:
                        raise e
                    fc_id = neutronclient_.flow_classifier_create(
                        sfc_classifier_params)
                    if fc_id is None:
                        raise nfvo.UpdateClassifierException(
                            message="Failed to update classifiers")
                    break

        # If the new classifier is completely different from the existing
        # ones (name and match criteria) then we just create it.
        else:
            fc_id = neutronclient_.flow_classifier_create(
                sfc_classifier_params)
            if fc_id is None:
                raise nfvo.UpdateClassifierException(
                    message="Failed to update classifiers")

        return fc_id
예제 #2
0
 def _dissociate_classifier_from_chain(self, chain_id, fc_ids,
                                       neutronclient):
     pc_info = neutronclient.port_chain_show(chain_id)
     current_fc_list = pc_info['port_chain']['flow_classifiers']
     for fc_id in fc_ids:
         current_fc_list.remove(fc_id)
     pc_id = neutronclient.port_chain_update(
         chain_id, {'flow_classifiers': current_fc_list})
     if pc_id is None:
         raise nfvo.UpdateClassifierException(
             message="Failed to update classifiers")
     for fc_id in fc_ids:
         try:
             neutronclient.flow_classifier_delete(fc_id)
         except ValueError as e:
             raise e