Ejemplo n.º 1
0
 def _process_commit_phase(self, context):
     if hasattr(context, 'commit_phase'):
         if not gutils.is_precommit_policy_driver_configured() and (
                 context.commit_phase == gp_cts.PRE_COMMIT):
             # The following is a bit of a hack to no-op
             # the call from the postcommit policy driver
             # during the pre-commit phase.
             return True
         if gutils.is_precommit_policy_driver_configured() and (
                 context.commit_phase == gp_cts.POST_COMMIT):
             instance = self.get_servicechain_instance(
                 context, context.servicechain_instance['id'])
             self._call_deploy_sc_node(context, instance)
             return instance
Ejemplo n.º 2
0
 def _process_commit_phase(self, context):
     if hasattr(context, 'commit_phase'):
         if not gutils.is_precommit_policy_driver_configured() and (
             context.commit_phase == gp_cts.PRE_COMMIT):
             # The following is a bit of a hack to no-op
             # the call from the postcommit policy driver
             # during the pre-commit phase.
             return True
         if gutils.is_precommit_policy_driver_configured() and (
             context.commit_phase == gp_cts.POST_COMMIT):
             instance = self.get_servicechain_instance(
                 context, context.servicechain_instance['id'])
             self._call_deploy_sc_node(context, instance)
             return instance
Ejemplo n.º 3
0
    def create_servicechain_instance(self, context, servicechain_instance):
        """Instance created.

        When a Servicechain Instance is created, all its nodes need to be
        instantiated.
        """
        instance = self._process_commit_phase(context)
        if instance:
            return instance

        deployers = {}
        # REVISIT: Consider adding ensure_tenant() call here
        with db_api.CONTEXT_WRITER.using(context):
            instance = super(NodeCompositionPlugin,
                             self).create_servicechain_instance(
                                 context, servicechain_instance)
            if len(instance['servicechain_specs']) > 1:
                raise exc.OneSpecPerInstanceAllowed()
            deployers = self._get_scheduled_drivers(context, instance,
                                                    'deploy')
        if not gutils.is_precommit_policy_driver_configured():
            # Actual node deploy
            try:
                self._deploy_servicechain_nodes(context, deployers)
            except Exception:
                # Some node could not be deployed
                with excutils.save_and_reraise_exception():
                    LOG.error(
                        "Node deployment failed, "
                        "deleting servicechain_instance %s", instance['id'])
                    self.delete_servicechain_instance(context, instance['id'])

        return instance
Ejemplo n.º 4
0
    def create_servicechain_instance(self, context, servicechain_instance):
        """Instance created.

        When a Servicechain Instance is created, all its nodes need to be
        instantiated.
        """
        instance = self._process_commit_phase(context)
        if instance:
            return instance

        session = context.session
        deployers = {}
        with session.begin(subtransactions=True):
            instance = super(NodeCompositionPlugin,
                             self).create_servicechain_instance(
                                 context, servicechain_instance)
            if len(instance['servicechain_specs']) > 1:
                raise exc.OneSpecPerInstanceAllowed()
            deployers = self._get_scheduled_drivers(context, instance,
                                                    'deploy')
        if not gutils.is_precommit_policy_driver_configured():
            # Actual node deploy
            try:
                self._deploy_servicechain_nodes(context, deployers)
            except Exception:
                # Some node could not be deployed
                with excutils.save_and_reraise_exception():
                    LOG.error(
                        _LE("Node deployment failed, "
                            "deleting servicechain_instance %s"),
                        instance['id'])
                    self.delete_servicechain_instance(context, instance['id'])

        return instance
Ejemplo n.º 5
0
    def create_servicechain_instance(self, context, servicechain_instance):
        """Instance created.

        When a Servicechain Instance is created, all its nodes need to be
        instantiated.
        """
        instance = self._process_commit_phase(context)
        if instance:
            return instance

        deployers = {}
        # REVISIT: Consider adding ensure_tenant() call here
        with db_api.context_manager.writer.using(context):
            instance = super(NodeCompositionPlugin,
                             self).create_servicechain_instance(
                                 context, servicechain_instance)
            if len(instance['servicechain_specs']) > 1:
                raise exc.OneSpecPerInstanceAllowed()
            deployers = self._get_scheduled_drivers(context, instance,
                                                    'deploy')
        if not gutils.is_precommit_policy_driver_configured():
            # Actual node deploy
            try:
                self._deploy_servicechain_nodes(context, deployers)
            except Exception:
                # Some node could not be deployed
                with excutils.save_and_reraise_exception():
                    LOG.error("Node deployment failed, "
                              "deleting servicechain_instance %s",
                              instance['id'])
                    self.delete_servicechain_instance(context, instance['id'])

        return instance
Ejemplo n.º 6
0
 def precommit_wrapper_for_chain_mapping(self, caller_method, context):
     # This wrapper is called from both precommit and postcommit for
     # deciding ordering for execution of precommit and postcommit
     if 'precommit' in caller_method:
         context._plugin_context.commit_phase = gconst.PRE_COMMIT
         # In case of aim_mapping driver (or a similar precommit driver),
         # postcommit functionality will be executed as a part of precommit
         if gutils.is_precommit_policy_driver_configured():
             if 'delete_policy_target_group' in caller_method:
                 context.ptg_chain_map = self._get_ptg_servicechain_mapping(
                     context._plugin_context.session,
                     context.current['id'])
                 self._cleanup_redirect_action(context)
             else:
                 method = getattr(self, '_' + caller_method.replace(
                                      'precommit', 'postcommit'))
                 method(context)
     else:
         context._plugin_context.commit_phase = gconst.POST_COMMIT
         # If driver is not aim_mapping (or a similar precommit driver),
         # then postcommit functionality will  be executed by the call
         # from gbp plugin
         if not gutils.is_precommit_policy_driver_configured():
                 method = getattr(self, '_' + caller_method)
                 method(context)
         elif 'create_policy_target_group' in caller_method or (
             'create_external_policy' in caller_method):
             if hasattr(context, 'provider_context') and (
                 hasattr(context, 'servicechain_attrs')):
                 context.provider_context.commit_phase = (
                     context._plugin_context.commit_phase)
                 context.provider_context.servicechain_instance = (
                     context._plugin_context.servicechain_instance)
                 super(ChainMappingDriver,
                     self)._create_servicechain_instance(
                         context.provider_context,
                         context.servicechain_attrs)
Ejemplo n.º 7
0
 def precommit_wrapper_for_chain_mapping(self, caller_method, context):
     # This wrapper is called from both precommit and postcommit for
     # deciding ordering for execution of precommit and postcommit
     if 'precommit' in caller_method:
         context._plugin_context.commit_phase = gconst.PRE_COMMIT
         # In case of aim_mapping driver (or a similar precommit driver),
         # postcommit functionality will be executed as a part of precommit
         if gutils.is_precommit_policy_driver_configured():
             if 'delete_policy_target_group' in caller_method:
                 context.ptg_chain_map = self._get_ptg_servicechain_mapping(
                     context._plugin_context.session,
                     context.current['id'])
                 self._cleanup_redirect_action(context)
             else:
                 method = getattr(self, '_' + caller_method.replace(
                                      'precommit', 'postcommit'))
                 method(context)
     else:
         context._plugin_context.commit_phase = gconst.POST_COMMIT
         # If driver is not aim_mapping (or a similar precommit driver),
         # then postcommit functionality will  be executed by the call
         # from gbp plugin
         if not gutils.is_precommit_policy_driver_configured():
                 method = getattr(self, '_' + caller_method)
                 method(context)
         elif 'create_policy_target_group' in caller_method or (
             'create_external_policy' in caller_method):
             if hasattr(context, 'provider_context') and (
                 hasattr(context, 'servicechain_attrs')):
                 context.provider_context.commit_phase = (
                     context._plugin_context.commit_phase)
                 context.provider_context.servicechain_instance = (
                     context._plugin_context.servicechain_instance)
                 super(ChainMappingDriver,
                     self)._create_servicechain_instance(
                         context.provider_context,
                         context.servicechain_attrs)
Ejemplo n.º 8
0
    def update_servicechain_instance(self, context, servicechain_instance_id,
                                     servicechain_instance):
        """Instance updated.

        When a Servicechain Instance is updated and the spec changed, all the
        nodes of the previous spec should be destroyed and the newer ones
        created.
        """
        instance = self._process_commit_phase(context)
        if instance:
            return instance

        session = context.session
        deployers = {}
        updaters = {}
        destroyers = {}
        with session.begin(subtransactions=True):
            original_instance = self.get_servicechain_instance(
                context, servicechain_instance_id)
            updated_instance = super(NodeCompositionPlugin,
                                     self).update_servicechain_instance(
                                         context, servicechain_instance_id,
                                         servicechain_instance)

            if (original_instance['servicechain_specs'] !=
                    updated_instance['servicechain_specs']):
                if len(updated_instance['servicechain_specs']) > 1:
                    raise exc.OneSpecPerInstanceAllowed()
                destroyers = self._get_scheduled_drivers(
                    context, original_instance, 'destroy')
            else:  # Could be classifier update
                updaters = self._get_scheduled_drivers(context,
                                                       original_instance,
                                                       'update')

        if (original_instance['servicechain_specs'] !=
                updated_instance['servicechain_specs']):
            self._destroy_servicechain_nodes(context, destroyers)
            deployers = self._get_scheduled_drivers(context, updated_instance,
                                                    'deploy')
            context.deployers = deployers
            context.servicechain_instance = updated_instance
            if not gutils.is_precommit_policy_driver_configured():
                self._deploy_servicechain_nodes(context, deployers)
        else:
            self._update_servicechain_nodes(context, updaters)
        return updated_instance
Ejemplo n.º 9
0
    def update_servicechain_instance(self, context, servicechain_instance_id,
                                     servicechain_instance):
        """Instance updated.

        When a Servicechain Instance is updated and the spec changed, all the
        nodes of the previous spec should be destroyed and the newer ones
        created.
        """
        instance = self._process_commit_phase(context)
        if instance:
            return instance

        deployers = {}
        updaters = {}
        destroyers = {}
        with db_api.context_manager.writer.using(context):
            original_instance = self.get_servicechain_instance(
                context, servicechain_instance_id)
            updated_instance = super(
                NodeCompositionPlugin, self).update_servicechain_instance(
                context, servicechain_instance_id, servicechain_instance)

            if (original_instance['servicechain_specs'] !=
                    updated_instance['servicechain_specs']):
                if len(updated_instance['servicechain_specs']) > 1:
                    raise exc.OneSpecPerInstanceAllowed()
                destroyers = self._get_scheduled_drivers(
                    context, original_instance, 'destroy')
            else:  # Could be classifier update
                updaters = self._get_scheduled_drivers(
                    context, original_instance, 'update')

        if (original_instance['servicechain_specs'] !=
            updated_instance['servicechain_specs']):
            self._destroy_servicechain_nodes(context, destroyers)
            deployers = self._get_scheduled_drivers(
                        context, updated_instance, 'deploy')
            context.deployers = deployers
            context.servicechain_instance = updated_instance
            if not gutils.is_precommit_policy_driver_configured():
                self._deploy_servicechain_nodes(context, deployers)
        else:
            self._update_servicechain_nodes(context, updaters)
        return updated_instance