def assert_node_groups(self, group_names, node_names, mod_op='replace'): # apply the groups to the nodes for name in node_names: node_obj = WallabyHelpers.get_node(self.session, self.config_store, name) result = node_obj.modifyMemberships(mod_op, group_names, {}) if result.status != 0: sys.stderr.write("Failed to set groups for %s: (%d, %s)\n" % (name, result.status, result.text)) raise WallabyStoreError(result.text)
def assert_node_features(self, feature_names, node_names, mod_op='replace'): for feat in feature_names: if not feat in self.feat_names: emsg = "Feature %s not in config store" % (feat) raise Exception(emsg) # apply feature list to nodes for name in node_names: node_obj = WallabyHelpers.get_node(self.session, self.config_store, name) group_name = WallabyHelpers.get_id_group_name(node_obj, self.session) group_obj = WallabyHelpers.get_group(self.session, self.config_store, group_name) if mod_op == 'insert': result = group_obj.modifyFeatures('replace', feature_names + group_obj.features, {}) else: result = group_obj.modifyFeatures(mod_op, feature_names, {}) if result.status != 0: sys.stderr.write("Failed to set features for %s: (%d, %s)\n" % (name, result.status, result.text)) raise WallabyStoreError(result.text)
def clear_nodes(self, node_names): for name in node_names: node_obj = WallabyHelpers.get_node(self.session, self.config_store, name) result = node_obj.modifyMemberships('replace', [], {}) if result.status != 0: sys.stderr.write("Failed to clear groups from %s: (%d, %s)\n" % (name, result.status, result.text)) raise WallabyStoreError("Failed to clear groups") group_name = WallabyHelpers.get_id_group_name(node_obj, self.session) group_obj = WallabyHelpers.get_group(self.session, self.config_store, group_name) result = group_obj.modifyFeatures('replace', [], {}) if result.status != 0: sys.stderr.write("Failed to clear features from %s: (%d, %s)\n" % (name, result.status, result.text)) raise WallabyStoreError("Failed to clear features") result = group_obj.modifyParams('replace', {}, {}) if result.status != 0: sys.stderr.write("Failed to clear params from %s: (%d, %s)\n" % (name, result.status, result.text)) raise WallabyStoreError("Failed to clear params")
def list_nodes(self, with_all_feats=None, without_any_feats=None, with_all_groups=None, without_any_groups=None, checkin_since=None): r = [] for node in self.node_names: node_obj = WallabyHelpers.get_node(self.session, self.config_store, node) sys.stdout.write(" list_nodes: node=%s checkin= %s\n" % (node, node_obj.last_checkin)) if (checkin_since != None) and ((node_obj.last_checkin / 1000000) < checkin_since): continue nodefeats = [] if (with_all_feats != None) or (without_any_feats != None): nodefeats = WallabyHelpers.get_node_features(node_obj, self.session, self.config_store) if (with_all_feats != None) and (False in [x in nodefeats for x in with_all_feats]): continue if (without_any_feats != None) and (True in [x in nodefeats for x in without_any_feats]): continue nodegroups = [] if (with_all_groups != None) or (without_any_groups != None): nodegroups = [WallabyHelpers.get_id_group_name(node_obj, self.session)] + node_obj.memberships + ['+++DEFAULT'] if (with_all_groups != None) and (False in [x in nodegroups for x in with_all_groups]): continue if (without_any_groups != None) and (True in [x in nodegroups for x in without_any_groups]): continue r += [node] return r