示例#1
0
文件: cluster.py 项目: zzxwill/senlin
    def update_policy(self, ctx, policy_id, **values):
        """Update a policy that is already attached to a cluster.

        Note this method must be called with the cluster locked.
        :param ctx: A context for DB operation.
        :param policy_id: ID of the policy object.
        :param values: Optional dictionary containing new binding properties.

        :returns: A tuple containing a boolean result and a string reason.
        """
        # Check if policy has already been attached
        found = False
        for existing in self.policies:
            if existing.id == policy_id:
                found = True
                break
        if not found:
            return False, _('Policy not attached.')

        enabled = values.get('enabled', None)
        if enabled is None:
            return True, _('No update is needed.')

        params = {'enabled': bool(enabled)}

        db_api.cluster_policy_update(ctx, self.id, policy_id, params)
        return True, _('Policy updated.')
示例#2
0
    def update_policy(self, ctx, policy_id, **values):
        """Update a policy that is already attached to a cluster.

        Note this method must be called with the cluster locked.
        :param ctx: A context for DB operation.
        :param policy_id: ID of the policy object.
        :param values: Optional dictionary containing new binding properties.

        :returns: A tuple containing a boolean result and a string reason.
        """
        # Check if policy has already been attached
        found = False
        for existing in self.policies:
            if existing.id == policy_id:
                found = True
                break
        if not found:
            return False, _('Policy not attached.')

        enabled = values.get('enabled', None)
        if enabled is None:
            return True, _('No update is needed.')

        params = {'enabled': bool(enabled)}

        db_api.cluster_policy_update(ctx, self.id, policy_id, params)
        return True, _('Policy updated.')
示例#3
0
    def do_update_policy(self):
        policy_id = self.inputs.get('policy_id', None)
        if not policy_id:
            return self.RES_ERROR, _('Policy not specified.')

        # Check if policy has already been attached
        found = False
        for existing in self.cluster.policies:
            if existing.id == policy_id:
                found = True
                break
        if not found:
            return self.RES_ERROR, _('Policy not attached.')

        values = {}
        cooldown = self.inputs.get('cooldown')
        if cooldown is not None:
            values['cooldown'] = cooldown
        level = self.inputs.get('level')
        if level is not None:
            values['level'] = level
        priority = self.inputs.get('priority')
        if priority is not None:
            values['priority'] = priority
        enabled = self.inputs.get('enabled')
        if enabled is not None:
            values['enabled'] = bool(enabled)
        if not values:
            return self.RES_OK, _('No update is needed.')

        db_api.cluster_policy_update(self.context, self.cluster.id, policy_id,
                                     values)

        return self.RES_OK, _('Policy updated.')
示例#4
0
    def store(self, context):
        '''Store the binding record into database table.'''
        values = {
            'enabled': self.enabled,
            'data': self.data,
            'last_op': self.last_op,
            'priority': self.priority
        }

        if self.id:
            db_api.cluster_policy_update(context, self.cluster_id,
                                         self.policy_id, values)
        else:
            binding = db_api.cluster_policy_attach(context, self.cluster_id,
                                                   self.policy_id, values)
            self.cluster_name = binding.cluster.name
            self.policy_name = binding.policy.name
            self.policy_type = binding.policy.type
            self.id = binding.id

        return self.id
示例#5
0
    def do_update_policy(self):
        """Handler for the CLUSTER_UPDATE_POLICY action.

        :returns: A tuple containing the result and the corresponding reason.
        """
        policy_id = self.inputs.get('policy_id', None)
        if not policy_id:
            return self.RES_ERROR, _('Policy not specified.')

        # Check if policy has already been attached
        found = False
        for existing in self.cluster.policies:
            if existing.id == policy_id:
                found = True
                break
        if not found:
            return self.RES_ERROR, _('Policy not attached.')

        values = {}
        cooldown = self.inputs.get('cooldown')
        if cooldown is not None:
            values['cooldown'] = cooldown
        level = self.inputs.get('level')
        if level is not None:
            values['level'] = level
        priority = self.inputs.get('priority')
        if priority is not None:
            values['priority'] = priority
        enabled = self.inputs.get('enabled')
        if enabled is not None:
            values['enabled'] = bool(enabled)
        if not values:
            return self.RES_OK, _('No update is needed.')

        db_api.cluster_policy_update(self.context, self.cluster.id, policy_id,
                                     values)

        return self.RES_OK, _('Policy updated.')
示例#6
0
    def do_update_policy(self):
        """Handler for the CLUSTER_UPDATE_POLICY action.

        :returns: A tuple containing the result and the corresponding reason.
        """
        policy_id = self.inputs.get('policy_id', None)
        if not policy_id:
            return self.RES_ERROR, _('Policy not specified.')

        # Check if policy has already been attached
        found = False
        for existing in self.cluster.policies:
            if existing.id == policy_id:
                found = True
                break
        if not found:
            return self.RES_ERROR, _('Policy not attached.')

        values = {}
        cooldown = self.inputs.get('cooldown')
        if cooldown is not None:
            values['cooldown'] = cooldown
        level = self.inputs.get('level')
        if level is not None:
            values['level'] = level
        priority = self.inputs.get('priority')
        if priority is not None:
            values['priority'] = priority
        enabled = self.inputs.get('enabled')
        if enabled is not None:
            values['enabled'] = bool(enabled)
        if not values:
            return self.RES_OK, _('No update is needed.')

        db_api.cluster_policy_update(self.context, self.cluster.id, policy_id,
                                     values)

        return self.RES_OK, _('Policy updated.')
示例#7
0
    def do_update_policy(self, cluster, policy_data):
        policy_id = self.inputs.get('policy_id', None)
        if not policy_id:
            raise exception.PolicyNotSpecified()

        values = {}
        cooldown = self.inputs.get('cooldown')
        if cooldown is not None:
            values['cooldown'] = cooldown
        level = self.inputs.get('level')
        if level is not None:
            values['level'] = level
        priority = self.inputs.get('priority')
        if priority is not None:
            values['priority'] = priority
        enabled = self.inputs.get('enabled')
        if enabled is not None:
            values['enabled'] = bool(enabled)

        db_api.cluster_policy_update(self.context, cluster.id, policy_id,
                                     values)

        return self.RES_OK, 'Policy updated'
示例#8
0
 def update(cls, context, cluster_id, policy_id, values):
     db_api.cluster_policy_update(context, cluster_id, policy_id, values)
示例#9
0
 def update(cls, context, cluster_id, policy_id, values):
     db_api.cluster_policy_update(context, cluster_id, policy_id, values)