def displayGroups(show): print "Groups for %s" % opencue.rep(show) grp_format = "%-32s %-12s %8s %8s %8s %8s %8s %8s %8s %6s" print grp_format % ("Name", "Dept", "DefPri", "DefMin", "DefMax", "MaxC", "MinC", "Booked", "Cores", "Jobs") def enabled(v): if v < 0: return "off" return v def printGroup(group): name = "|%s+%-20s" % ("".join( [" " for _ in range(0, int(group.data.level))]), group.data.name) print grp_format % (name, group.data.department, enabled(group.data.default_job_priority), enabled(group.data.default_job_min_cores), enabled(group.data.default_job_max_cores), enabled( group.data.max_cores), group.data.min_cores, group.data.group_stats.running_frames, "%0.2f" % group.data.group_stats.reserved_cores, group.data.group_stats.pending_jobs) def printGroups(item): printGroup(item) for group in item.getGroups(): printGroups(group) printGroups(show.getRootGroup())
def safeReboot(hosts_): for host_ in hosts_: logger.debug("locking host and rebooting when idle %s" % opencue.rep(host_)) host_.rebootWhenIdle()
def moveHosts(hosts_, dst_): for host_ in hosts_: logger.debug("moving %s to %s" % (opencue.rep(host_), opencue.rep(dst_))) host_.setAllocation(dst_)
def handleArgs(args): if args.verbose: cueadmin.util.enableDebugLogging() if args.server: logger.debug("setting opencue host servers to %s" % args.server) opencue.Cuebot.setHosts(args.server) if args.facility: logger.debug("setting facility to %s" % args.facility) opencue.Cuebot.setFacility(args.facility) # # Query # if args.lp is not None or args.ll is not None: if args.ll is not None: args.lp = args.ll if not args.host: args.host = [] result = opencue.search.ProcSearch.byOptions( show=args.lp, host=args.host, limit=args.limit, alloc=args.alloc, job=args.job, memory=handleIntCriterion(args.memory, Convert.gigsToKB), duration=handleIntCriterion(args.duration, Convert.hoursToSeconds)) if isinstance(args.ll, list): print("\n".join([ opencue.wrappers.proc.Proc(proc).data.log_path for proc in result.procs.procs ])) else: cueadmin.output.displayProcs([ opencue.wrappers.proc.Proc(proc) for proc in result.procs.procs ]) return elif args.lh: states = [Convert.strToHardwareState(s) for s in args.state] cueadmin.output.displayHosts( opencue.api.getHosts(match=args.query, state=states, alloc=args.alloc)) return elif args.lba: allocation = opencue.api.findAllocation(args.lba) cueadmin.output.displaySubscriptions(allocation.getSubscriptions(), "All Shows") return elif args.lv is not None: if args.lv: show = opencue.api.findShow(args.lv[0]) cueadmin.output.displayServices(show.getServiceOverrides()) else: cueadmin.output.displayServices(opencue.api.getDefaultServices()) return elif args.lj: for job in opencue.search.JobSearch.byMatch(args.query).jobs.jobs: print(job.name) return elif args.lji: cueadmin.output.displayJobs([ opencue.wrappers.job.Job(job) for job in opencue.search.JobSearch.byMatch(args.query).jobs.jobs ]) return elif args.la: cueadmin.output.displayAllocations(opencue.api.getAllocations()) return elif args.lb: for show in resolveShowNames(args.lb): cueadmin.output.displaySubscriptions(show.getSubscriptions(), show.data.name) return elif args.ls: cueadmin.output.displayShows(opencue.api.getShows()) return # # Gather hosts if -host or -hostmatch was specified # host_error_msg = "No valid hosts selected, see the -host/-hostmatch options" hosts = None if args.host or args.hostmatch: hosts = resolveHostNames(args.host, args.hostmatch) # # Allocations # if args.create_alloc: fac, name, tag = args.create_alloc confirm("Create new allocation %s.%s, with tag %s" % (fac, name, tag), args.force, createAllocation, fac, name, tag) elif args.delete_alloc: allocation = opencue.api.findAllocation(args.delete_alloc) confirm("Delete allocation %s" % args.delete_alloc, args.force, allocation.delete) elif args.rename_alloc: old, new = args.rename_alloc try: new = new.split(".", 2)[1] except IndexError: raise ValueError( "Allocation names must be in the form 'facility.name'") confirm("Rename allocation from %s to %s" % (old, new), args.force, opencue.api.findAllocation(old).setName, new) elif args.transfer: src = opencue.api.findAllocation(args.transfer[0]) dst = opencue.api.findAllocation(args.transfer[1]) confirm( "Transfer hosts from from %s to %s" % (src.data.name, dst.data.name), args.force, dst.reparentHosts, src.getHosts()) elif args.tag_alloc: alloc, tag = args.tag_alloc confirm("Re-tag allocation %s with %s" % (alloc, tag), args.force, opencue.api.findAllocation(alloc).setTag, tag) # # Shows # elif args.create_show: confirm("Create new show %s" % args.create_show, args.force, opencue.api.createShow, args.create_show) elif args.delete_show: confirm("Delete show %s" % args.delete_show, args.force, opencue.api.findShow(args.delete_show).delete) elif args.disable_show: confirm("Disable show %s" % args.disable_show, args.force, opencue.api.findShow(args.disable_show).setActive, False) elif args.enable_show: confirm("Enable show %s" % args.enable_show, args.force, opencue.api.findShow(args.enable_show).setActive, True) elif args.dispatching: show = opencue.api.findShow(args.dispatching[0]) enabled = Convert.stringToBoolean(args.dispatching[1]) if not enabled: confirm("Disable dispatching on %s" % opencue.rep(show), args.force, show.enableDispatching, enabled) else: show.enableDispatching(True) elif args.booking: show = opencue.api.findShow(args.booking[0]) enabled = Convert.stringToBoolean(args.booking[1]) if not enabled: confirm("Disable booking on %s" % opencue.rep(show), args.force, show.enableBooking, False) else: show.enableBooking(True) elif args.default_min_cores: confirm( "Set the default min cores to: %s" % args.default_min_cores[1], args.force, opencue.api.findShow(args.default_min_cores[0]).setDefaultMinCores, float(int(args.default_min_cores[1]))) elif args.default_max_cores: confirm( "Set the default max cores to: %s" % args.default_max_cores[1], args.force, opencue.api.findShow(args.default_max_cores[0]).setDefaultMaxCores, float(int(args.default_max_cores[1]))) # # Hosts are handled a bit differently than the rest # of the entities. To specify a host or hosts the user # must use the -host or -hostmatch flags. This is so you can # specify more than one host in an operation. For example, # -hostmatch vrack -lock would locl all vrack hosts. # elif args.lock: if not hosts: raise ValueError(host_error_msg) for host in hosts: logger.debug("locking host: %s" % opencue.rep(host)) host.lock() elif args.unlock: if not hosts: raise ValueError(host_error_msg) for host in hosts: logger.debug("unlocking host: %s" % opencue.rep(host)) host.unlock() elif args.move: if not hosts: raise ValueError(host_error_msg) def moveHosts(hosts_, dst_): for host_ in hosts_: logger.debug("moving %s to %s" % (opencue.rep(host_), opencue.rep(dst_))) host_.setAllocation(dst_) confirm("Move %d hosts to %s" % (len(hosts), args.move), args.force, moveHosts, hosts, opencue.api.findAllocation(args.move)) elif args.delete_host: if not hosts: raise ValueError(host_error_msg) def deleteHosts(hosts_): for host_ in hosts_: logger.debug("deleting host: %s" % host_) host_.delete() confirm("Delete %s hosts" % len(hosts), args.force, deleteHosts, hosts) elif args.safe_reboot: if not hosts: raise ValueError(host_error_msg) def safeReboot(hosts_): for host_ in hosts_: logger.debug("locking host and rebooting when idle %s" % opencue.rep(host_)) host_.rebootWhenIdle() confirm("Lock and reboot %d hosts when idle" % len(hosts), args.force, safeReboot, hosts) elif args.thread: if not hosts: raise ValueError(host_error_msg) def setThreadMode(hosts_, mode): for host_ in hosts_: logger.debug("setting host %s to thread mode %s" % (host_.data.name, mode)) host_.setThreadMode(Convert.strToThreadMode(mode)) confirm("Set %d hosts to thread mode %s" % (len(hosts), args.thread), args.force, setThreadMode, hosts, args.thread) elif args.repair: if not hosts: raise ValueError(host_error_msg) def setRepairState(hosts_): for host_ in hosts_: logger.debug("setting host into the repair state %s" % host_.data.name) host_.setHardwareState(opencue.api.host_pb2.REPAIR) confirm("Set %d hosts into the Repair state?" % len(hosts), args.force, setRepairState, hosts) elif args.fixed: if not hosts: raise ValueError(host_error_msg) def setUpState(hosts_): for host_ in hosts_: logger.debug("setting host into the repair state %s" % host_.data.name) host_.setHardwareState(opencue.api.host_pb2.UP) confirm("Set %d hosts into the Up state?" % len(hosts), args.force, setUpState, hosts) elif args.create_sub: show = opencue.api.findShow(args.create_sub[0]) alloc = opencue.api.findAllocation(args.create_sub[1]) confirm( "Create subscription for %s on %s" % (opencue.rep(show), opencue.rep(alloc)), args.force, show.createSubscription, alloc.data, float(args.create_sub[2]), float(args.create_sub[3])) elif args.delete_sub: sub_name = "%s.%s" % (args.delete_sub[1], args.delete_sub[0]) confirm( "Delete %s's subscription to %s" % (args.delete_sub[0], args.delete_sub[1]), args.force, opencue.api.findSubscription(sub_name).delete) elif args.size: sub_name = "%s.%s" % (args.size[1], args.size[0]) opencue.api.findSubscription(sub_name).setSize(float(args.size[2])) elif args.burst: sub_name = "%s.%s" % (args.burst[1], args.burst[0]) sub = opencue.api.findSubscription(sub_name) burst = args.burst[2] if burst.find("%") != -1: burst = int(sub.data.size + (sub.data.size * (int(burst[0:-1]) / 100.0))) sub.setBurst(float(burst))
def handleArgs(args): # # Query # if isinstance(args.lp, list) or isinstance(args.ll, list): if isinstance(args.ll, list): args.lp = args.ll if not args.host: args.host = [] procs = opencue.search.ProcSearch().byOptions( show=args.lp, host=args.host, limit=args.limit, alloc=args.alloc, job=args.job, memory=handleIntCriterion(args.memory, Convert.gigsToKB), duration=handleIntCriterion(args.duration, Convert.hoursToSeconds)) if isinstance(args.ll, list): print "\n".join([l.data.logPath for l in procs]) else: output.displayProcs(procs) return elif args.lh: states = [Convert.strToHardwareState(s) for s in args.state] output.displayHosts( opencue.api.getHosts(match=args.query, state=states, alloc=args.alloc)) return elif args.lba: allocation = opencue.api.findAllocation(args.lba) output.displaySubscriptions(allocation.getSubscriptions(), "All Shows") return elif isinstance(args.lv, (list, )): if args.lv: show = opencue.api.findShow(args.lv[0]) output.displayServices(show.getServiceOverrides()) else: output.displayServices(opencue.api.getDefaultServices()) return # # Gather hosts if -host - hostmatch was specified # host_error_msg = "No valid hosts selected, see the -host/-hostmatch options" hosts = None if args.host or args.hostmatch: hosts = resolveHostNames(args.host, args.hostmatch) # # Allocations # if args.create_alloc: fac, name, tag = args.create_alloc confirm("Create new allocation %s.%s, with tag %s" % (fac, name, tag), args.force, createAllocation, fac, name, tag) elif args.delete_alloc: allocation = opencue.api.findAllocation(args.delete_alloc) confirm("Delete allocation %s" % args.delete_alloc, args.force, allocation.delete) elif args.rename_alloc: old, new = args.rename_alloc try: new = new.split(".", 2)[1] except Exception: msg = "Allocation names must be in the form 'facility.name'" raise Exception(msg) confirm("Rename allocation from %s to %s" % (old, new), args.force, opencue.api.findAllocation(old).setName, new) elif args.transfer: src = opencue.api.findAllocation(args.transfer[0]) dst = opencue.api.findAllocation(args.transfer[1]) confirm( "Transfer hosts from from %s to %s" % (src.data.name, dst.data.name), args.force, AllocUtil.transferHosts, src, dst) elif args.tag_alloc: alloc, tag = args.tag_alloc confirm("Re-tag allocation %s with %s" % (alloc, tag), args.force, opencue.api.findAllocation(alloc).setTag, tag) # # Shows # elif args.create_show: confirm("Create new show %s" % args.create_show, args.force, opencue.api.createShow, args.create_show) elif args.delete_show: confirm("Delete show %s" % args.delete_show, args.force, opencue.api.findShow(args.delete_show).delete) elif args.disable_show: confirm("Disable show %s" % args.disable_show, args.force, opencue.api.findShow(args.disable_show).setActive, False) elif args.enable_show: confirm("Enable show %s" % args.enable_show, args.force, opencue.api.findShow(args.enable_show).setActive, True) elif args.dispatching: show = opencue.api.findShow(args.dispatching[0]) enabled = Convert.stringToBoolean(args.dispatching[1]) if not enabled: confirm("Disable dispatching on %s" % opencue.rep(show), args.force, show.enableDispatching, enabled) else: show.enableDispatching(True) elif args.booking: show = opencue.api.findShow(args.booking[0]) enabled = Convert.stringToBoolean(args.booking[1]) if not enabled: confirm("Disable booking on %s" % opencue.rep(show), args.force, show.enableBooking, False) else: show.enableBooking(True) elif args.default_min_cores: confirm( "Set the default min cores to: %s" % args.default_min_cores[1], args.force, opencue.api.findShow(args.default_min_cores[0]).setDefaultMinCores, float(int(args.default_min_cores[1]))) elif args.default_max_cores: confirm( "Set the default max cores to: %s" % args.default_max_cores[1], args.force, opencue.api.findShow(args.default_max_cores[0]).setDefaultMaxCores, float(int(args.default_max_cores[1]))) # # Hosts are handled a bit differently than the rest # of the entities. To specify a host or hosts the user # must use the -host or -hostmatch flags. This is so you can # specify more than one host in an operation. For example, # -hostmatch vrack -lock would locl all vrack hosts. # elif args.lock: if not hosts: raise ValueError(host_error_msg) for host in hosts: logger.debug("locking host: %s" % opencue.rep(host)) host.lock() elif args.unlock: if not hosts: raise ValueError(host_error_msg) for host in hosts: logger.debug("unlocking host: %s" % opencue.rep(host)) host.unlock() elif args.move: if not hosts: raise ValueError(host_error_msg) def moveHosts(hosts_, dst_): for host_ in hosts_: logger.debug("moving %s to %s" % (opencue.rep(host_), opencue.rep(dst_))) host.setAllocation(dst_.data) confirm("Move %d hosts to %s" % (len(hosts), args.move), args.force, moveHosts, hosts, opencue.api.findAllocation(args.move)) # No Test coverage, takes up to a minute for # a host to report back in. elif args.delete_host: if not hosts: raise ValueError(host_error_msg) def deleteHosts(hosts_): for host_ in hosts_: logger.debug("deleting host: %s" % host_) try: host_.delete() except Exception, e: print "Failed to delete %s due to %s" % (host_, e) confirm("Delete %s hosts" % len(hosts), args.force, deleteHosts, hosts)
def transferHosts(src, dst): hosts = opencue.proxy(src).getHosts() logger.debug("transferring %d hosts from %s to %s" % (len(hosts), opencue.rep(src), opencue.rep(dst))) dst.proxy.reparentHosts(hosts)
def setUpState(hosts_): for host_ in hosts_: logger.debug("setting host into the repair state %s" % host_.data.name) host_.setHardwareState(opencue.api.host_pb2.UP) confirm("Set %d hosts into the Up state?" % len(hosts), args.force, setUpState, hosts) elif args.create_sub: show = opencue.api.findShow(args.create_sub[0]) alloc = opencue.api.findAllocation(args.create_sub[1]) confirm( "Create subscription for %s on %s" % (opencue.rep(show), opencue.rep(alloc)), args.force, show.createSubscription, alloc.data, float(args.create_sub[2]), float(args.create_sub[3])) elif args.delete_sub: sub_name = "%s.%s" % (args.delete_sub[1], args.delete_sub[0]) confirm( "Delete %s's subscription to %s" % (args.delete_sub[0], args.delete_sub[1]), args.force, opencue.api.findSubscription(sub_name).delete) elif args.size: sub_name = "%s.%s" % (args.size[1], args.size[0]) opencue.api.findSubscription(sub_name).setSize(float(args.size[2])) elif args.burst:
def displayNames(items): """Displays the .name of every object in the list. @type items: list<> @param items: All objects must have a .name parameter""" for item in items: print opencue.rep(item)