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, **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, hostname, **arguments): # 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 dbhost = hostname_to_host(session, hostname) if arguments.get("install", None) and (dbhost.status.name == "ready" or dbhost.status.name == "almostready"): raise ArgumentError("You should change the build status before " "switching the PXE link to install.") # 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: raise ArgumentError("{0} has no bootserver.".format(dbhost)) # for that instance, find what servers are bound to it. servers = [host.fqdn for host in si.server_hosts] command = self.config.get("broker", "installfe") args = [command] for (option, mapped) in self._option_map.items(): if arguments[option]: args.append(mapped) args.append(dbhost.fqdn) if args[-1] == command: raise ArgumentError("Missing required target parameter.") args.append("--cfgfile") args.append("/dev/null") args.append("--servers") user = self.config.get("broker", "installfe_user") args.append(" ".join(["%s@%s" % (user, s) for s in servers])) 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) run_command(args, logger=logger, loglevel=CLIENT_INFO)
def render(self, session, logger, hostname, service, **arguments): dbhost = hostname_to_host(session, hostname) for srv in (dbhost.archetype.services + dbhost.personality.services): if srv.name == service: raise ArgumentError("Cannot unbind a required service. " "Perhaps you want to rebind?") dbservice = Service.get_unique(session, service, compel=True) si = get_host_bound_service(dbhost, dbservice) if si: logger.info("Removing client binding") dbhost.services_used.remove(si) session.flush() plenaries = PlenaryCollection(logger=logger) plenaries.append(PlenaryHost(dbhost, logger=logger)) plenaries.append(PlenaryServiceInstanceServer(si, logger=logger)) plenaries.write() 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)