def render(self, session, logger, list, domain, sandbox, force, **arguments): dbbranch, dbauthor = get_branch_and_author(session, logger, domain=domain, sandbox=sandbox, compel=True) if hasattr(dbbranch, "allow_manage") and not dbbranch.allow_manage: raise ArgumentError("Managing hosts to {0:l} is not allowed." .format(dbbranch)) check_hostlist_size(self.command, self.config, list) dbhosts = hostlist_to_hosts(session, list) failed = [] dbsource, dbsource_author = validate_branch_author(dbhosts) for dbhost in dbhosts: # check if any host in the list is a cluster node if dbhost.cluster: failed.append("Cluster nodes must be managed at the " "cluster level; {0} is a member of {1:l}." .format(dbhost.fqdn, dbhost.cluster)) if failed: raise ArgumentError("Cannot modify the following hosts:\n%s" % "\n".join(failed)) if not force: validate_branch_commits(dbsource, dbsource_author, dbbranch, dbauthor, logger, self.config) plenaries = PlenaryCollection(logger=logger) for dbhost in dbhosts: plenaries.append(Plenary.get_plenary(dbhost)) dbhost.branch = dbbranch dbhost.sandbox_author = dbauthor session.flush() # We're crossing domains, need to lock everything. with CompileKey.merge([CompileKey(domain=dbsource.name, logger=logger), CompileKey(domain=dbbranch.name, logger=logger)]): plenaries.stash() try: plenaries.write(locked=True) except: plenaries.restore_stash() raise return
def render(self, session, logger, domain, sandbox, archetype, personality, pancinclude, pancexclude, pancdebug, cleandeps, **arguments): dbdomain = None dbauthor = None if domain or sandbox: (dbdomain, dbauthor) = get_branch_and_author(session, logger, domain=domain, sandbox=sandbox, compel=True) dbpersonality = Personality.get_unique(session, name=personality, archetype=archetype, compel=True) if pancdebug: pancinclude = r'.*' pancexclude = r'components/spma/functions' q = session.query(Host) q = q.filter_by(personality=dbpersonality) if dbdomain: q = q.filter_by(branch=dbdomain) if dbauthor: q = q.filter_by(sandbox_author=dbauthor) host_list = q.all() if not host_list: return # If the domain was not specified, set it to the domain of first host dbdomain, dbauthor = validate_branch_author(host_list) plenaries = PlenaryCollection(logger=logger) for host in host_list: plenaries.append(Plenary.get_plenary(host)) dom = TemplateDomain(dbdomain, dbauthor, logger=logger) with plenaries.get_key(): dom.compile(session, only=plenaries.object_templates, panc_debug_include=pancinclude, panc_debug_exclude=pancexclude, cleandeps=cleandeps, locked=True) return
def render(self, session, logger, list, **arguments): check_hostlist_size(self.command, self.config, list) dbhosts = hostlist_to_hosts(session, list) dbbranch, dbauthor = validate_branch_author(dbhosts) failed = [] compileable = [] # Do any cross-list or dependency checks for dbhost in dbhosts: if dbhost.status.name == 'ready': failed.append("{0:l} is in ready status, " "advertised status can be reset only " "when host is in non ready state.".format(dbhost)) if failed: raise ArgumentError("Cannot modify the following hosts:\n%s" % "\n".join(failed)) plenaries = PlenaryCollection(logger=logger) for dbhost in dbhosts: dbhost.advertise_status = False plenaries.append(Plenary.get_plenary(dbhost)) session.flush() td = TemplateDomain(dbbranch, dbauthor, logger=logger) with plenaries.get_key(): plenaries.stash() try: plenaries.write(locked=True) td.compile(session, only=compileable, locked=True) except: plenaries.restore_stash() raise return
def reconfigure_list(self, session, logger, dbhosts, archetype, personality, keepbindings, buildstatus, osname, osversion, grn, eon_id, cleargrn, **arguments): failed = [] # Check all the parameters up front. # Some of these could be more intelligent about defaults # (either by checking for unique entries or relying on the list) # - starting simple. if archetype: dbarchetype = Archetype.get_unique(session, archetype, compel=True) if dbarchetype.cluster_type is not None: raise ArgumentError("Archetype %s is a cluster archetype" % dbarchetype.name) # TODO: Once OS is a first class object this block needs # to check that either OS is also being reset or that the # OS is valid for the new archetype. else: dbarchetype = None if personality: dbpersonality = Personality.get_unique(session, name=personality, archetype=dbarchetype, compel=True) if osname and not osversion: raise ArgumentError("Please specify --osversion for OS %s." % osname) if osversion: if not osname: raise ArgumentError("Please specify --osname to use with " "OS version %s." % osversion) # Linux model names are the same under aurora and aquilon, so # allowing to omit --archetype would not be useful if not archetype: raise ArgumentError("Please specify --archetype for OS " "%s, version %s." % (osname, osversion)) dbos = OperatingSystem.get_unique(session, name=osname, version=osversion, archetype=dbarchetype, compel=True) else: dbos = None if buildstatus: dbstatus = HostLifecycle.get_instance(session, buildstatus) if grn or eon_id: dbgrn = lookup_grn(session, grn, eon_id, logger=logger, config=self.config) # Take a shortcut if there's nothing to do, but only after all the other # parameters have been checked if not dbhosts: return dbbranch, dbauthor = validate_branch_author(dbhosts) personalities = {} # Do any final cross-list or dependency checks before entering # the Chooser loop. for dbhost in dbhosts: if dbos and not dbarchetype and dbhost.archetype != dbos.archetype: failed.append("{0}: Cannot change operating system because it " "needs {1:l} instead of " "{2:l}.".format(dbhost.fqdn, dbhost.archetype, dbos.archetype)) if dbarchetype and not dbos and \ dbhost.operating_system.archetype != dbarchetype: failed.append("{0}: Cannot change archetype because {1:l} needs " "{2:l}.".format(dbhost.fqdn, dbhost.operating_system, dbhost.operating_system.archetype)) if (personality and dbhost.cluster and len(dbhost.cluster.allowed_personalities) > 0 and dbpersonality not in dbhost.cluster.allowed_personalities): allowed = ["%s/%s" % (p.archetype.name, p.name) for p in dbhost.cluster.allowed_personalities] failed.append("{0}: The {1:l} is not allowed by {2}. " "Specify one of {3}.".format( dbhost.fqdn, dbpersonality, dbhost.cluster, allowed)) if personality: personalities[dbhost.fqdn] = dbpersonality elif archetype: # This is a strange case - changing archetype while keeping # the personality try: pers = Personality.get_unique(session, name=dbhost.personality.name, archetype=dbarchetype, compel=True) personalities[dbhost.fqdn] = pers except NotFoundException, err: failed.append("%s: %s" % (dbhost.fqdn, err)) if grn or eon_id: dbhost.owner_grn = dbgrn if cleargrn: dbhost.owner_grn = None