def render(self, session, logger, list, archetype, personality, buildstatus, osname, osversion, **arguments): check_hostlist_size(self.command, self.config, list) dbhosts = hostlist_to_hosts(session, list) self.reconfigure_list(session, logger, dbhosts, archetype, personality, buildstatus, osname, osversion, **arguments)
def render(self, session, logger, list, **arguments): check_hostlist_size(self.command, self.config, list) # The default is now --configure, but that does not play nice with # --status. Turn --configure off if --status is present if arguments.get("status", False): arguments["configure"] = None user = self.config.get("broker", "installfe_user") command = self.config.get("broker", "installfe") args = [command] args.append("--cfgfile") args.append("/dev/null") args.append("--sshdir") args.append(self.config.get("broker", "installfe_sshdir")) args.append("--logfile") logdir = self.config.get("broker", "logdir") args.append("%s/aii-installfe.log" % logdir) servers = dict() groups = dict() failed = [] for host in list: try: dbhost = hostname_to_host(session, host) if arguments.get( "install", None) and (dbhost.status.name == "ready" or dbhost.status.name == "almostready"): failed.append("%s: You should change the build status " "before switching the PXE link to install." % host) # Find what "bootserver" instance we're bound to dbservice = Service.get_unique(session, "bootserver", compel=True) si = get_host_bound_service(dbhost, dbservice) if not si: failed.append("%s: Host has no bootserver." % host) else: if si.name in groups: groups[si.name].append(dbhost) else: # for that instance, find what servers are bound to it. servers[si.name] = [ host.fqdn for host in si.server_hosts ] groups[si.name] = [dbhost] except NotFoundException, nfe: failed.append("%s: %s" % (host, nfe)) except ArgumentError, ae: failed.append("%s: %s" % (host, ae))
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, list, **arguments): check_hostlist_size(self.command, self.config, list) # The default is now --configure, but that does not play nice with # --status. Turn --configure off if --status is present if arguments.get("status", False): arguments["configure"] = None user = self.config.get("broker", "installfe_user") command = self.config.get("broker", "installfe") args = [command] args.append("--cfgfile") args.append("/dev/null") args.append("--sshdir") args.append(self.config.get("broker", "installfe_sshdir")) args.append("--logfile") logdir = self.config.get("broker", "logdir") args.append("%s/aii-installfe.log" % logdir) servers = dict() groups = dict() failed = [] for host in list: try: dbhost = hostname_to_host(session, host) if arguments.get("install", None) and (dbhost.status.name == "ready" or dbhost.status.name == "almostready"): failed.append("%s: You should change the build status " "before switching the PXE link to install." % host) # Find what "bootserver" instance we're bound to dbservice = Service.get_unique(session, "bootserver", compel=True) si = get_host_bound_service(dbhost, dbservice) if not si: failed.append("%s: Host has no bootserver." % host) else: if si.name in groups: groups[si.name].append(dbhost) else: # for that instance, find what servers are bound to it. servers[si.name] = [host.fqdn for host in si.server_hosts] groups[si.name] = [dbhost] except NotFoundException, nfe: failed.append("%s: %s" % (host, nfe)) except ArgumentError, ae: failed.append("%s: %s" % (host, ae))
def render(self, session, logger, target, grn, eon_id, hostname, list, personality, archetype, **arguments): dbgrn = lookup_grn(session, grn, eon_id, logger=logger, config=self.config) plenaries = PlenaryCollection(logger=logger) if hostname: objs = [hostname_to_host(session, hostname)] config_key = "host_grn_targets" elif list: check_hostlist_size(self.command, self.config, list) objs = hostlist_to_hosts(session, list) config_key = "host_grn_targets" elif personality: objs = [Personality.get_unique(session, name=personality, archetype=archetype, compel=True)] config_key = "personality_grn_targets" for obj in objs: section = "archetype_" + obj.archetype.name if self.config.has_option(section, config_key): valid_targets = [s.strip() for s in self.config.get(section, config_key).split(",")] else: raise ArgumentError("{0} has no valid GRN targets configured." .format(obj.archetype)) if target not in valid_targets: raise ArgumentError("Invalid target %s for archetype %s, please " "choose from: %s." % (target, obj.archetype.name, ", ".join(valid_targets))) plenaries.append(Plenary.get_plenary(obj)) self._update_dbobj(obj, target, dbgrn) session.flush() plenaries.write() 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 render(self, session, logger, target, grn, eon_id, hostname, list, personality, archetype, **arguments): dbgrn = lookup_grn(session, grn, eon_id, logger=logger, config=self.config) target_type = "personality" if personality else "host" if hostname: objs = [hostname_to_host(session, hostname)] elif list: check_hostlist_size(self.command, self.config, list) objs = hostlist_to_hosts(session, list) elif personality: objs = [Personality.get_unique(session, name=personality, archetype=archetype, compel=True)] for obj in objs: # INFO: Fails for archetypes other than 'aquilon', 'vmhost' valid_targets = self.config.get("archetype_" + obj.archetype.name, target_type + "_grn_targets") if target not in map(lambda s: s.strip(), valid_targets.split(",")): raise ArgumentError("Invalid %s target %s for archetype %s, please " "choose from %s" % (target_type, target, obj.archetype.name, valid_targets)) self._update_dbobj(obj, target, dbgrn) session.flush() if personality: plenary = PlenaryPersonality(objs[0], logger=logger) plenary.write() return
def render(self, session, logger, target, hostname, list, personality, archetype, **arguments): target_type = "personality" if personality else "host" if hostname: objs = [hostname_to_host(session, hostname)] elif list: check_hostlist_size(self.command, self.config, list) objs = hostlist_to_hosts(session, list) elif personality: objs = [Personality.get_unique(session, name=personality, archetype=archetype, compel=True)] plenaries = PlenaryCollection(logger=logger) for obj in objs: # INFO: Fails for archetypes other than 'aquilon', 'vmhost' valid_targets = self.config.get("archetype_" + obj.archetype.name, target_type + "_grn_targets") if target not in [s.strip() for s in valid_targets.split(",")]: raise ArgumentError("Invalid %s target %s for archetype %s, please " "choose from %s" % (target_type, target, obj.archetype.name, valid_targets)) for grn_rec in obj._grns[:]: if target == grn_rec.target: obj._grns.remove(grn_rec) plenaries.append(Plenary.get_plenary(obj)) session.flush() plenaries.write() return
def render(self, session, logger, list, **arguments): check_hostlist_size(self.command, self.config, list) dbhosts = hostlist_to_hosts(session, list) self.reconfigure_list(session, logger, dbhosts, **arguments)
def render(self, session, logger, list, **arguments): check_hostlist_size(self.command, self.config, list) dbhosts = hostlist_to_hosts(session, list) self.resetadvertisedstatus_list(session, logger, dbhosts)
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 = [] branches = defaultdict(ListType) authors = defaultdict(ListType) for dbhost in dbhosts: branches[dbhost.branch].append(dbhost) authors[dbhost.sandbox_author].append(dbhost) # 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 len(branches) > 1: keys = branches.keys() branch_sort = lambda x, y: cmp(len(branches[x]), len(branches[y])) keys.sort(cmp=branch_sort) stats = ["{0:d} hosts in {1:l}".format(len(branches[branch]), branch) for branch in keys] raise ArgumentError("All hosts must be in the same domain or " "sandbox:\n%s" % "\n".join(stats)) # check if all hosts are from the same sandbox author if len(authors) > 1: keys = authors.keys() author_sort = lambda x, y: cmp(len(authors[x]), len(authors[y])) keys.sort(cmp=author_sort) stats = ["{0:d} hosts with sandbox author {1:l}" .format(len(authors[author]), author.name) for author in keys] raise ArgumentError("All hosts must be managed by the same " "sandbox author:\n%s" % "\n".join(stats)) # since we have already checked if all hosts in list are within the # same branch, we only need one dbsource to validate the branch dbhost = dbhosts[0] dbsource = dbhost.branch dbsource_author = dbhost.sandbox_author if not force: validate_branch_commits(dbsource, dbsource_author, dbbranch, dbauthor, logger, self.config) old_branch = branches.keys()[0].name plenaries = PlenaryCollection(logger=logger) for dbhost in dbhosts: dbhost.branch = dbbranch dbhost.sandbox_author = dbauthor plenaries.append(Plenary.get_plenary(dbhost)) session.flush() # We're crossing domains, need to lock everything. key = CompileKey(logger=logger) try: lock_queue.acquire(key) plenaries.stash() plenaries.cleanup(old_branch, locked=True) plenaries.write(locked=True) except: plenaries.restore_stash() raise finally: lock_queue.release(key) return
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 = [] branches = defaultdict(ListType) authors = defaultdict(ListType) for dbhost in dbhosts: branches[dbhost.branch].append(dbhost) authors[dbhost.sandbox_author].append(dbhost) # 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 len(branches) > 1: keys = branches.keys() branch_sort = lambda x, y: cmp(len(branches[x]), len(branches[y])) keys.sort(cmp=branch_sort) stats = [ "{0:d} hosts in {1:l}".format(len(branches[branch]), branch) for branch in keys ] raise ArgumentError("All hosts must be in the same domain or " "sandbox:\n%s" % "\n".join(stats)) # check if all hosts are from the same sandbox author if len(authors) > 1: keys = authors.keys() author_sort = lambda x, y: cmp(len(authors[x]), len(authors[y])) keys.sort(cmp=author_sort) stats = [ "{0:d} hosts with sandbox author {1:l}".format( len(authors[author]), author.name) for author in keys ] raise ArgumentError("All hosts must be managed by the same " "sandbox author:\n%s" % "\n".join(stats)) # since we have already checked if all hosts in list are within the # same branch, we only need one dbsource to validate the branch dbhost = dbhosts[0] dbsource = dbhost.branch dbsource_author = dbhost.sandbox_author if not force: validate_branch_commits(dbsource, dbsource_author, dbbranch, dbauthor, logger, self.config) old_branch = branches.keys()[0].name plenaries = PlenaryCollection(logger=logger) for dbhost in dbhosts: dbhost.branch = dbbranch dbhost.sandbox_author = dbauthor plenaries.append(Plenary.get_plenary(dbhost)) session.flush() # We're crossing domains, need to lock everything. key = CompileKey(logger=logger) try: lock_queue.acquire(key) plenaries.stash() plenaries.cleanup(old_branch, locked=True) plenaries.write(locked=True) except: plenaries.restore_stash() raise finally: lock_queue.release(key) return
def render(self, session, logger, list, **arguments): check_hostlist_size(self.command, self.config, list) # The default is now --configure, but that does not play nice with # --status. Turn --configure off if --status is present if arguments.get("status", False): arguments["configure"] = None user = self.config.get("broker", "installfe_user") command = self.config.get("broker", "installfe") args = [command] args.append("--cfgfile") args.append("/dev/null") args.append("--sshdir") args.append(self.config.get("broker", "installfe_sshdir")) args.append("--logfile") logdir = self.config.get("broker", "logdir") args.append("%s/aii-installfe.log" % logdir) dbservice = Service.get_unique(session, "bootserver", compel=True) dbhosts = hostlist_to_hosts(session, list) hosts_per_instance = defaultdict(ListType) failed = [] for dbhost in dbhosts: if arguments.get("install", None) and (dbhost.status.name == "ready" or dbhost.status.name == "almostready"): failed.append("{0}: You should change the build status " "before switching the PXE link to install." .format(dbhost)) # Find what "bootserver" instance we're bound to si = get_host_bound_service(dbhost, dbservice) if not si: failed.append("{0} has no bootserver.".format(dbhost)) else: hosts_per_instance[si].append(dbhost) if failed: raise ArgumentError("Invalid hosts in list:\n%s" % "\n".join(failed)) for (si, hostlist) in hosts_per_instance.items(): # create temporary file, point aii-installfe at that file. groupargs = args[:] with NamedTemporaryFile() as tmpfile: tmpfile.writelines([x.fqdn + "\n" for x in hostlist]) tmpfile.flush() for (option, mapped) in self._option_map.items(): if arguments[option]: groupargs.append(mapped) groupargs.append(tmpfile.name) if groupargs[-1] == command: raise ArgumentError("Missing required target parameter.") servers = [] for srv in si.servers: # The primary name is the address to be used for delivering # configuration to a host, so we should use that even if the # service itself is bound to a different IP address if srv.host: servers.append(srv.host.fqdn) else: servers.append(srv.fqdn) groupargs.append("--servers") groupargs.append(" ".join(["%s@%s" % (user, s) for s in servers])) # it would be nice to parallelize this.... run_command(groupargs, logger=logger, loglevel=CLIENT_INFO)