def detach_policy(self, ctx, policy_id): """Detach policy object from the 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. :returns: A tuple containing a boolean result and a reason string. """ # Check if policy has already been attached found = None for existing in self.policies: if existing.id == policy_id: found = existing break if found is None: return False, _('Policy not attached.') policy = policy_base.Policy.load(ctx, policy_id) res, reason = policy.detach(self) if not res: return res, reason db_api.cluster_policy_detach(ctx, self.id, policy_id) self.rt['policies'].remove(found) return True, _('Policy detached.')
def do_detach_policy(self): """Handler for the CLUSTER_DETACH_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_OK, _('Policy not attached.') policy = policy_mod.Policy.load(self.context, policy_id) res, data = policy.detach(self.cluster) if not res: return self.RES_ERROR, data db_api.cluster_policy_detach(self.context, self.cluster.id, policy_id) self.cluster.remove_policy(policy) return self.RES_OK, _('Policy detached.')
def do_detach_policy(self): '''Attach policy to the cluster.''' 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_OK, _('Policy not attached.') policy = policy_mod.Policy.load(self.context, policy_id) res, data = policy.detach(self.cluster) if not res: return self.RES_ERROR, data db_api.cluster_policy_detach(self.context, self.cluster.id, policy_id) self.cluster.remove_policy(policy) return self.RES_OK, _('Policy detached.')
def do_detach_policy(self, cluster, policy_data): policy_id = self.inputs.get('policy_id', None) if not policy_id: raise exception.PolicyNotSpecified() policy = policy_mod.Policy.load(self.context, policy_id) res = policy.detach(self.context, cluster, policy_data) if not res: return self.RES_ERROR, 'Failed detaching policy' db_api.cluster_policy_detach(self.context, cluster.id, policy_id) cluster.detach(policy.policy_id) return self.RES_OK, 'Policy detached'
def delete(cls, context, cluster_id, policy_id): db_api.cluster_policy_detach(context, cluster_id, policy_id)