if op == "ADD": new_labels = current_labels + labels pass elif op == "REPLACE": new_labels = labels pass elif op == "REMOVE": new_labels = [label for label in current_labels if label not in labels] else: raise NotImplementedError("modifyLabels: operation " + op + " not understood") just_memberships = [grp for grp in memberships if grp not in label_set] new_memberships = uniq(just_memberships + [PARTITION_GROUP] + new_labels) if "ensure_partition_group" in options and options["ensure_partition_group"] is not False: if thestore is None: raise RuntimeError("store singleton must be initialized before using the ensure_partition_group option") thestore.getPartitionGroup() if "create_missing_labels" in options and options["create_missing_labels"] is not False: if thestore is None: raise RuntimeError("store singleton must be initialized before using the create_missing_labels option") for missing_label in thestore.checkGroupValidity(new_labels): thestore.addLabel(missing_label) return self.modifyMemberships("REPLACE", new_memberships, {}) proxied_attr(node, "name") proxied_attr(node, "memberships") proxied_attr(node, "identity_group") proxied_attr(node, "provisioned")
if len(options) > 0: not_implemented() return self.cm.fetch_json_resource("/config/group/%s" % urllib.quote_plus(self.name)) def explain(self): not_implemented() def modifyParams(self, command, params, **options): command = command.upper() if command == "ADD": for k, v in params.iteritems(): self.parameters[k] = v elif command == "REMOVE": for k in [k for k in params if k in self.parameters]: del self.parameters[k] elif command == "REPLACE": self.parameters = params else: fail(errors.make(errors.BAD_COMMAND, errors.GROUP), "Invalid command %s" % command) self.update() def members(self): all_nodes = [self.cm.make_proxy_object("node", node, True) for node in self.cm.list_objects("node")] return [node.name for node in all_nodes if self.name in node.memberships] membership = property(members) proxied_attr(group, "name") proxied_attr(group, "features") proxied_attr(group, "parameters")
raise NotImplementedError("modifyLabels: operation " + op + " not understood") just_memberships = [grp for grp in memberships if grp not in label_set] new_memberships = uniq(just_memberships + [PARTITION_GROUP] + new_labels) if "ensure_partition_group" in options and options[ "ensure_partition_group"] is not False: if thestore is None: raise RuntimeError( "store singleton must be initialized before using the ensure_partition_group option" ) thestore.getPartitionGroup() if "create_missing_labels" in options and options[ "create_missing_labels"] is not False: if thestore is None: raise RuntimeError( "store singleton must be initialized before using the create_missing_labels option" ) for missing_label in thestore.checkGroupValidity(new_labels): thestore.addLabel(missing_label) return self.modifyMemberships("REPLACE", new_memberships, {}) proxied_attr(node, "name") proxied_attr(node, "memberships") proxied_attr(node, "identity_group") proxied_attr(node, "provisioned")
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from proxy import Proxy, proxied_attr, proxied_attr_update from proxy import proxied_attr_get as pag, proxied_attr_set as pas, proxied_attr_getset as pags from arc_utils import arcmethod, uniq import errors from errors import not_implemented, fail from util import camelcase class subsystem(Proxy): name = property(*pags("name")) parameters = property(*pags("parameters")) setName = proxied_attr_update("name") modifyParams = arcmethod(*pags("parameters"), explain="depends on", preserve_order=False, heterogeneous=True) for attr in ["name", "parameters"]: proxied_attr(subsystem, attr)
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from proxy import Proxy, proxied_attr, proxied_attr_update from proxy import proxied_attr_get as pag, proxied_attr_set as pas, proxied_attr_getset as pags from arc_utils import arcmethod, uniq import errors from errors import not_implemented, fail from util import camelcase class subsystem(Proxy): name = property(*pags("name")) parameters = property(*pags("parameters")) setName = proxied_attr_update("name") modifyParams = arcmethod(*pags("parameters"), explain="depends on", preserve_order=False, heterogeneous=True) for attr in ["name", "parameters"]: proxied_attr(subsystem, attr)
explain="depends on", preserve_order=False) modifyConflicts = arcmethod(*pags("conflicts"), explain="conflicts with", preserve_order=False) def setName(self, nn): self.name = nn self.update() def modifyParams(command, params, **options): command = command.upper() if command == "ADD": for k, v in params.iteritems(): self.parameters[k] = v elif command == "REMOVE": for k in [k for k in params if k in self.parameters]: del self.parameters[k] elif command == "REPLACE": self.parameters = params else: fail(errors.make(errors.BAD_COMMAND, errors.FEATURE), "Invalid command %s" % command) self.update() proxied_attr(feature, "name") proxied_attr(feature, "includes") proxied_attr(feature, "conflicts") proxied_attr(feature, "depends") proxied_attr(feature, "parameters")
# Copyright (c) 2013 Red Hat, Inc. # Author: William Benton ([email protected]) # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from proxy import Proxy, proxied_attr, proxied_attr_update from proxy import proxied_attr_get as pag, proxied_attr_set as pas, proxied_attr_getset as pags class branch(Proxy): pass class tag(Proxy): pass for klass in [branch, tag]: for attr in ["name", "commit", "annotation", "meta"]: setattr(klass, "skip_q", lambda slf : True) setattr(klass, attr, property(*pags(attr))) proxied_attr(klass, attr)
def modifyParams(self, command, params, **options): command = command.upper() if command == "ADD": for k, v in params.iteritems(): self.parameters[k] = v elif command == "REMOVE": for k in [k for k in params if k in self.parameters]: del self.parameters[k] elif command == "REPLACE": self.parameters = params else: fail(errors.make(errors.BAD_COMMAND, errors.GROUP), "Invalid command %s" % command) self.update() def members(self): all_nodes = [ self.cm.make_proxy_object("node", node, True) for node in self.cm.list_objects("node") ] return [ node.name for node in all_nodes if self.name in node.memberships ] membership = property(members) proxied_attr(group, "name") proxied_attr(group, "features") proxied_attr(group, "parameters")
depends = property(*pags("depends")) conflicts = property(*pags("conflicts")) parameters = property(*pags("parameters")) modifyIncludes = arcmethod(*pags("includes"), explain="includes", preserve_order=True) modifyDepends = arcmethod(*pags("depends"), explain="depends on", preserve_order=False) modifyConflicts = arcmethod(*pags("conflicts"), explain="conflicts with", preserve_order=False) def setName(self, nn): self.name = nn self.update() def modifyParams(command, params, **options): command = command.upper() if command == "ADD": for k, v in params.iteritems(): self.parameters[k] = v elif command == "REMOVE": for k in [k for k in params if k in self.parameters]: del self.parameters[k] elif command == "REPLACE": self.parameters = params else: fail(errors.make(errors.BAD_COMMAND, errors.FEATURE), "Invalid command %s" % command) self.update() proxied_attr(feature, "name") proxied_attr(feature, "includes") proxied_attr(feature, "conflicts") proxied_attr(feature, "depends") proxied_attr(feature, "parameters")
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from proxy import Proxy, proxied_attr, proxied_attr_update from proxy import proxied_attr_get as pag, proxied_attr_set as pas, proxied_attr_getset as pags from arc_utils import arcmethod, uniq import errors from errors import not_implemented, fail from util import camelcase class parameter(Proxy): name = property(*pags("name")) depends = property(*pags("depends")) conflicts = property(*pags("conflicts")) kind = property(*pags("kind")) description = property(*pags("description")) default_val = property(*pags("default_val")) must_change = property(*pags("must_change")) requires_restart = property(*pags("requires_restart")) modifyDepends = arcmethod(*pags("depends"), explain="depends on", preserve_order=False) modifyConflicts = arcmethod(*pags("conflicts"), explain="conflicts with", preserve_order=False) for attr in ["name", "conflicts", "depends", "kind", "description", "default_val", "must_change", "visibility_level", "requires_restart"]: proxied_attr(parameter, attr) setattr(parameter, "set%s" % "".join(x.capitalize() for x in attr.split("_")), proxied_attr_update(attr))
from errors import not_implemented, fail from util import camelcase class parameter(Proxy): name = property(*pags("name")) depends = property(*pags("depends")) conflicts = property(*pags("conflicts")) kind = property(*pags("kind")) description = property(*pags("description")) default_val = property(*pags("default_val")) must_change = property(*pags("must_change")) requires_restart = property(*pags("requires_restart")) modifyDepends = arcmethod(*pags("depends"), explain="depends on", preserve_order=False) modifyConflicts = arcmethod(*pags("conflicts"), explain="conflicts with", preserve_order=False) for attr in [ "name", "conflicts", "depends", "kind", "description", "default_val", "must_change", "visibility_level", "requires_restart" ]: proxied_attr(parameter, attr) setattr(parameter, "set%s" % "".join(x.capitalize() for x in attr.split("_")), proxied_attr_update(attr))