def load_all(cls, context, cluster_id, filters=None, sort=None): """Retrieve all policies attached to a specific cluster.""" bindings = db_api.cluster_policy_get_all(context, cluster_id, filters=filters, sort=sort) return [cls._from_db_record(context, b) for b in bindings]
def load_all(cls, context, cluster_id, filters=None, sort_keys=None, sort_dir=None): '''Retrieve all policies attached to a specific cluster.''' bindings = db_api.cluster_policy_get_all(context, cluster_id, filters=filters, sort_keys=sort_keys, sort_dir=sort_dir) return [cls._from_db_record(context, b) for b in bindings]
def _load_runtime_data(self, context): if self.id is None: return policies = [] bindings = db_api.cluster_policy_get_all(context, self.id) for b in bindings: # Detect policy type conflicts policy = policy_base.Policy.load(context, b.policy_id) policies.append(policy) self.rt = { 'profile': profile_base.Profile.load(context, self.profile_id), 'nodes': node_mod.Node.load_all(context, cluster_id=self.id), 'policies': policies }
def _load_runtime_data(self, context): if self.id is None or self.deleted_time is not None: return policies = [] bindings = db_api.cluster_policy_get_all(context, self.id) for b in bindings: # Detect policy type conflicts policy = policy_base.Policy.load(context, b.policy_id) policies.append(policy) self.rt = { 'profile': profile_base.Profile.load(context, self.profile_id), 'nodes': node_mod.Node.load_all(context, cluster_id=self.id), 'policies': policies }
def _load_runtime_data(self, context): if self.id is None or self.deleted_time is not None: return policies = [] bindings = db_api.cluster_policy_get_all(context, self.id) for b in bindings: # Detect policy type conflicts policy = policy_base.Policy.load(context, b.policy_id) policies.append(policy) self.rt = { # TODO(Yanyan Hu): Use permission to control access privilege # of profile. 'profile': profile_base.Profile.load(context, self.profile_id, project_safe=False), 'nodes': node_mod.Node.load_all(context, cluster_id=self.id), 'policies': policies }
def do_attach_policy(self, cluster, policy_data): '''Attach policy to the cluster. ''' policy_id = self.inputs.get('policy_id', None) if not policy_id: raise exception.PolicyNotSpecified() policy = policy_mod.Policy.load(self.context, policy_id) # Check if policy has already been attached all = db_api.cluster_policy_get_all(self.context, cluster.id) for existing in all: # Policy already attached if existing.policy_id == policy_id: return self.RES_OK, 'Policy already attached' # Detect policy type conflicts curr = policy_mod.Policy.load(self.context, existing.policy_id) if curr.type == policy.type: raise exception.PolicyExists(policy_type=policy.type) res = policy.attach(self.context, cluster, policy_data) if not res: return self.RES_ERROR, 'Failed attaching policy' values = { 'cooldown': self.inputs.get('cooldown', policy.cooldown), 'level': self.inputs.get('level', policy.level), 'priority': self.inputs.get('priority', 50), 'enabled': self.inputs.get('enabled', True), } db_api.cluster_policy_attach(self.context, cluster.id, policy_id, values) cluster.attach(policy) return self.RES_OK, 'Policy attached'
def policy_check(self, cluster_id, target): """Check all policies attached to cluster and give result. :param target: A tuple of ('when', action_name) :return: A dictionary that contains the check result. """ # Initialize an empty dict for policy check result data = policy_mod.PolicyData() if target not in ['BEFORE', 'AFTER']: return data # Get list of policy IDs attached to cluster bindings = db_api.cluster_policy_get_all(self.context, cluster_id, sort_keys=['priority'], filters={'enabled': True}) for p in bindings: policy = policy_mod.Policy.load(self.context, p.policy_id) if (target, self.action) not in policy.TARGET: continue if target == 'BEFORE': method = getattr(policy, 'pre_op') else: # target == 'AFTER' method = getattr(policy, 'post_op') # Pass data from one policy to another data = method(cluster_id, self, data) # Abort policy checking if failures found if data.status == policy_mod.CHECK_ERROR: LOG.warning(_('Failed policy checking: %s'), data.reason) return data return data
def get_all(cls, context, cluster_id, **kwargs): return db_api.cluster_policy_get_all(context, cluster_id, **kwargs)
def get_all(cls, context, cluster_id, **kwargs): objs = db_api.cluster_policy_get_all(context, cluster_id, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs]