spacecmd/src/bin/spacecmd | 63 +++++++++++++++++++++---------------------- spacecmd/src/lib/misc.py | 51 ++++++++++++++++++++++++---------- spacecmd/src/lib/report.py | 62 +++++++++++++++++++++++++----------------- spacecmd/src/lib/schedule.py | 10 +++--- spacecmd/src/lib/shell.py | 11 ++----- spacecmd/src/lib/system.py | 41 ++++++++++----------------- 6 files changed, 130 insertions(+), 108 deletions(-)
New commits: commit 49bf762c4817621de16a904fe9353df06f38388a Author: Aron Parsons aparsons@redhat.com Date: Fri Oct 29 12:06:18 2010 -0400
spacecmd: renamed system_addchildchannel to system_addchildchannels and system_removechildchannel to system_removechildchannels for consistency
diff --git a/spacecmd/src/lib/system.py b/spacecmd/src/lib/system.py index d48792e..6797b3a 100644 --- a/spacecmd/src/lib/system.py +++ b/spacecmd/src/lib/system.py @@ -77,9 +77,9 @@ def manipulate_child_channels(self, args, remove=False):
if len(args) < 2: if remove: - self.help_system_removechildchannel() + self.help_system_removechildchannels() else: - self.help_system_addchildchannel() + self.help_system_addchildchannels() return
# use the systems listed in the SSM @@ -1786,13 +1786,13 @@ def do_system_listchildchannels(self, args):
####################
-def help_system_addchildchannel(self): - print "system_addchildchannel: Add child channels to a system" - print 'usage: system_addchildchannel <SYSTEMS> <CHANNEL ...>' +def help_system_addchildchannels(self): + print "system_addchildchannels: Add child channels to a system" + print 'usage: system_addchildchannels <SYSTEMS> <CHANNEL ...>' print print self.HELP_SYSTEM_OPTS
-def complete_system_addchildchannel(self, text, line, beg, end): +def complete_system_addchildchannels(self, text, line, beg, end): parts = line.split(' ')
if len(parts) == 2: @@ -1800,18 +1800,18 @@ def complete_system_addchildchannel(self, text, line, beg, end): elif len(parts) > 2: return tab_completer(self.list_child_channels(), text)
-def do_system_addchildchannel(self, args): +def do_system_addchildchannels(self, args): self.manipulate_child_channels(args)
####################
-def help_system_removechildchannel(self): - print "system_removechildchannel: Remove child channels from a system" - print 'usage: system_removechildchannel <SYSTEMS> <CHANNEL ...>' +def help_system_removechildchannels(self): + print "system_removechildchannels: Remove child channels from a system" + print 'usage: system_removechildchannels <SYSTEMS> <CHANNEL ...>' print print self.HELP_SYSTEM_OPTS
-def complete_system_removechildchannel(self, text, line, beg, end): +def complete_system_removechildchannels(self, text, line, beg, end): parts = line.split(' ')
if len(parts) == 2: @@ -1819,7 +1819,7 @@ def complete_system_removechildchannel(self, text, line, beg, end): elif len(parts) > 2: return tab_completer(self.list_child_channels(), text)
-def do_system_removechildchannel(self, args): +def do_system_removechildchannels(self, args): self.manipulate_child_channels(args, True)
####################
commit 87764c5e46dbf0ade7c22c4aa31f70fc020f9f9b Author: Aron Parsons aparsons@redhat.com Date: Fri Oct 29 12:03:21 2010 -0400
spacecmd: added help topics for time and system options
diff --git a/spacecmd/src/lib/misc.py b/spacecmd/src/lib/misc.py index 22c1861..080a11f 100644 --- a/spacecmd/src/lib/misc.py +++ b/spacecmd/src/lib/misc.py @@ -33,7 +33,7 @@ group:GROUP channel:CHANNEL '''
-TIME_OPTS = '''Dates can be any of the following: +HELP_TIME_OPTS = '''Dates can be any of the following: Explicit Dates: Dates can be expressed as explicit date strings in the YYYYMMDD[HHMM] format. The year, month and day are required, while the hours and @@ -76,6 +76,14 @@ SYSTEM_SEARCH_FIELDS = ['id', 'name', 'ip', 'hostname',
####################
+def help_systems(self): + print HELP_SYSTEM_OPTS + +def help_time(self): + print HELP_TIME_OPTS + +#################### + def help_clear(self): print 'clear: clear the screen' print 'usage: clear' diff --git a/spacecmd/src/lib/schedule.py b/spacecmd/src/lib/schedule.py index efbbb94..00cc9b9 100644 --- a/spacecmd/src/lib/schedule.py +++ b/spacecmd/src/lib/schedule.py @@ -343,7 +343,7 @@ def help_schedule_listpending(self): print 'schedule_listpending: List pending actions' print 'usage: schedule_listpending [BEGINDATE] [ENDDATE]' print - print self.TIME_OPTS + print self.HELP_TIME_OPTS
def do_schedule_listpending(self, args): return self.print_schedule_summary('pending', args) @@ -354,7 +354,7 @@ def help_schedule_listcompleted(self): print 'schedule_listcompleted: List completed actions' print 'usage: schedule_listcompleted [BEGINDATE] [ENDDATE]' print - print self.TIME_OPTS + print self.HELP_TIME_OPTS
def do_schedule_listcompleted(self, args): return self.print_schedule_summary('completed', args) @@ -365,7 +365,7 @@ def help_schedule_listfailed(self): print 'schedule_listfailed: List failed actions' print 'usage: schedule_listfailed [BEGINDATE] [ENDDATE]' print - print self.TIME_OPTS + print self.HELP_TIME_OPTS
def do_schedule_listfailed(self, args): return self.print_schedule_summary('failed', args) @@ -376,7 +376,7 @@ def help_schedule_listarchived(self): print 'schedule_listarchived: List archived actions' print 'usage: schedule_listarchived [BEGINDATE] [ENDDATE]' print - print self.TIME_OPTS + print self.HELP_TIME_OPTS
def do_schedule_listarchived(self, args): return self.print_schedule_summary('archived', args) @@ -387,7 +387,7 @@ def help_schedule_list(self): print 'schedule_list: List all actions' print 'usage: schedule_list [BEGINDATE] [ENDDATE]' print - print self.TIME_OPTS + print self.HELP_TIME_OPTS
def do_schedule_list(self, args): return self.print_schedule_summary('all', args) diff --git a/spacecmd/src/lib/system.py b/spacecmd/src/lib/system.py index c4c2c49..d48792e 100644 --- a/spacecmd/src/lib/system.py +++ b/spacecmd/src/lib/system.py @@ -283,7 +283,7 @@ options: print print self.HELP_SYSTEM_OPTS print - print self.TIME_OPTS + print self.HELP_TIME_OPTS
def complete_system_runscript(self, text, line, beg, end): return self.tab_complete_systems(text)
commit 88b7aec78f87dd80fc99be73c56020d9652604b6 Author: Aron Parsons aparsons@redhat.com Date: Fri Oct 29 11:52:23 2010 -0400
spacecmd: remove old code that was checking for system IDs in system_delete
diff --git a/spacecmd/src/lib/system.py b/spacecmd/src/lib/system.py index 462a8af..c4c2c49 100644 --- a/spacecmd/src/lib/system.py +++ b/spacecmd/src/lib/system.py @@ -1211,19 +1211,6 @@ def do_system_delete(self, args): if re.match('ssm', args[0], re.I): systems = self.ssm.keys() else: - # check for system IDs - for item in args: - try: - system_id = int(item) - system_ids.append(system_id) - except ValueError: - pass - - # don't try to expand IDs below - for system_id in system_ids: - if system_id in args: - args.remove(system_id) - systems = self.expand_systems(args)
# get the system ID for each system @@ -1239,6 +1226,8 @@ def do_system_delete(self, args):
# make the column the right size colsize = max_length([ self.get_system_name(s) for s in system_ids ]) + if colsize < 7: colsize = 7 + print '%s System ID' % 'Profile'.ljust(colsize) print '%s ---------' % ('-' * colsize)
commit 318c1acfdf905adb52a614df47beee92cd340330 Author: Aron Parsons aparsons@redhat.com Date: Fri Oct 29 11:47:17 2010 -0400
spacecmd: allow the user to pass system IDs to all functions (useful when there are duplicates)
diff --git a/spacecmd/src/lib/misc.py b/spacecmd/src/lib/misc.py index 7c10ea3..22c1861 100644 --- a/spacecmd/src/lib/misc.py +++ b/spacecmd/src/lib/misc.py @@ -689,6 +689,8 @@ def expand_systems(self, args): args = args.split()
systems = [] + system_ids = [] + for item in args: if re.match('ssm', item, re.I): systems.extend(self.ssm) @@ -715,12 +717,17 @@ def expand_systems(self, args): else: logging.warning('No systems subscribed to %s' % item) else: - # just a system name - systems.append(item) + # translate system IDs that the user passes + try: + id = int(item) + system_ids.append(id) + except ValueError: + # just a system name + systems.append(item)
matches = filter_results(self.get_system_names(), systems)
- return matches + return matches + system_ids
def list_base_channels(self):
commit e5861a6cbe1a648e2982edccd42e567e79198c84 Author: Aron Parsons aparsons@redhat.com Date: Fri Oct 29 11:39:13 2010 -0400
spacecmd: cleanup the warning message when trying to perform an aciton on a duplicate profile name
diff --git a/spacecmd/src/lib/misc.py b/spacecmd/src/lib/misc.py index 68cbef8..7c10ea3 100644 --- a/spacecmd/src/lib/misc.py +++ b/spacecmd/src/lib/misc.py @@ -643,10 +643,15 @@ def get_system_id(self, name): logging.warning("Can't find system ID for %s" % name) return 0 else: - logging.warning('Multiple systems found with the same name') + logging.warning('Duplicate system profile names found') + logging.warning("You can delete duplicates with 'system_delete'") + + id_list = '%s = ' % name
for id in systems: - logging.warning('%s = %i' % (name, id)) + id_list = id_list + '%i, ' % id + + logging.warning(id_list[:-2])
return 0
commit 033c86b7fb15b195861d66562e64366f016d0d3b Author: Aron Parsons aparsons@redhat.com Date: Fri Oct 29 11:28:43 2010 -0400
spacecmd: print the system ID and last checkin in report_duplicates
diff --git a/spacecmd/src/lib/report.py b/spacecmd/src/lib/report.py index 361eaa2..fb5cb83 100644 --- a/spacecmd/src/lib/report.py +++ b/spacecmd/src/lib/report.py @@ -266,9 +266,20 @@ def do_report_duplicates(self, args): if len(dupes_by_profile): add_separator = True
- print 'Duplicate Profile Names' - print '-----------------------' - print '\n'.join(sorted(dupes_by_profile)) + for item in dupes_by_profile: + print '%s:' % item + + # get some details for each duplicate + systems = self.client.system.searchByName(self.session, + '^%s$' % item) + + print 'System ID Last Checkin' + print '---------- -----------------' + + for dupe in systems: + print '%i %s' % (dupe.get('id'), dupe.get('last_checkin')) + + if len(dupes_by_profile) > 1: print
if self.check_api_version('10.11'): dupes_by_ip = self.client.system.listDuplicatesByIp(self.session) @@ -280,45 +291,48 @@ def do_report_duplicates(self, args): if add_separator: print self.SEPARATOR add_separator = True
- print 'Duplicate IP Addresses' - print '----------------------' - for item in dupes_by_ip: - print print '%s:' % item.get('ip')
- for system in sorted(item.get('systems'), - key=itemgetter('systemName')): - print system.get('systemName') + print 'System ID Last Checkin' + print '---------- -----------------' + + for dupe in item.get('systems'): + print '%i %s' % (dupe.get('systemId'), + dupe.get('last_checkin')) + + if len(dupes_by_ip) > 1: print
if len(dupes_by_mac): if add_separator: print self.SEPARATOR add_separator = True
- print 'Duplicate MAC Addresses' - print '-----------------------' - for item in dupes_by_mac: - print print '%s:' % item.get('mac').upper()
- for system in sorted(item.get('systems'), - key=itemgetter('systemName')): - print system.get('systemName') + print 'System ID Last Checkin' + print '---------- -----------------' + + for dupe in item.get('systems'): + print '%i %s' % (dupe.get('systemId'), + dupe.get('last_checkin')) + + if len(dupes_by_mac) > 1: print
if len(dupes_by_hostname): if add_separator: print self.SEPARATOR add_separator = True
- print 'Duplicate Hostnames' - print '-------------------' - for item in dupes_by_hostname: - print print '%s:' % item.get('hostname')
- for system in sorted(item.get('systems'), - key=itemgetter('systemName')): - print system.get('systemName') + print 'System ID Last Checkin' + print '---------- -----------------' + + for dupe in item.get('systems'): + print '%i %s' % (dupe.get('systemId'), + dupe.get('last_checkin')) + + if len(dupes_by_hostname) > 1: print
# vim:ts=4:expandtab:
commit 0ca1958ee7bf6abd8aed5925d1c4cf07c8dfbb5f Author: Aron Parsons aparsons@redhat.com Date: Fri Oct 29 10:44:14 2010 -0400
spacecmd: print help messages for functions if the user passes --help
diff --git a/spacecmd/src/lib/shell.py b/spacecmd/src/lib/shell.py index 43503f3..2ccf4ad 100644 --- a/spacecmd/src/lib/shell.py +++ b/spacecmd/src/lib/shell.py @@ -128,6 +128,10 @@ class SpacewalkShell(Cmd): else: args = ''
+ # print the help message if the user passes '--help' + if re.search('--help', line): + return 'help %s' % command + # should we look for an item in the history? if command[0] != '!' or len(command) < 2: return line
commit c71de1ba513e4bc3eefa5371b215b7a259bbacfb Author: Aron Parsons aparsons@redhat.com Date: Fri Oct 29 10:38:54 2010 -0400
spacecmd: simplify the logic to print the intro when starting the shell
diff --git a/spacecmd/src/bin/spacecmd b/spacecmd/src/bin/spacecmd index 914421a..0f8d9cf 100755 --- a/spacecmd/src/bin/spacecmd +++ b/spacecmd/src/bin/spacecmd @@ -27,6 +27,13 @@ from optparse import Option, OptionParser from pwd import getpwuid from spacecmd.shell import SpacewalkShell
+_INTRO = '''Welcome to spacecmd, a command-line interface to Spacewalk. + +Type: 'help' for a list of commands + 'help <cmd>' for command-specific help + 'quit' to quit +''' + if __name__ == '__main__': optionsTable = [ Option('-u', '--username', action='store', @@ -113,8 +120,8 @@ if __name__ == '__main__': # create an instance of the shell shell = SpacewalkShell(options)
+ # run a single command from the command line if len(args): - # run a single command from the command line try: # run the command shell.onecmd(shell.precmd(' '.join(args))) @@ -134,35 +141,33 @@ if __name__ == '__main__':
sys.exit(1) else: + if not options.quiet: + print _INTRO + if not shell.do_login(''): sys.exit(1)
# stay in the interactive shell forever while True: - # use try..finally to overcome 2.4's lack of try..except..finally try: - try: - shell.cmdloop() - except KeyboardInterrupt: - print - except SystemExit: - sys.exit(0) - except Exception, detail: - # get the relevant part of a XML-RPC fault - if isinstance(detail, xmlrpclib.Fault): - detail = detail.faultString - - # the session expired - if re.search('Could not find session', detail, re.I): - shell.session = '' - - if options.debug: - # print the traceback when debugging - logging.exception(detail) - else: - logging.error(detail) - finally: - # don't print the intro again - shell.intro = '' + shell.cmdloop() + except KeyboardInterrupt: + print + except SystemExit: + sys.exit(0) + except Exception, detail: + # get the relevant part of a XML-RPC fault + if isinstance(detail, xmlrpclib.Fault): + detail = detail.faultString + + # the session expired + if re.search('Could not find session', detail, re.I): + shell.session = '' + + if options.debug: + # print the traceback when debugging + logging.exception(detail) + else: + logging.error(detail)
# vim:ts=4:expandtab: diff --git a/spacecmd/src/lib/shell.py b/spacecmd/src/lib/shell.py index 73e655e..43503f3 100644 --- a/spacecmd/src/lib/shell.py +++ b/spacecmd/src/lib/shell.py @@ -40,13 +40,6 @@ class SpacewalkShell(Cmd): # maximum length of history file HISTORY_LENGTH = 1024
- intro = ''' -Welcome to spacecmd, a command-line interface to Spacewalk. - -Type: 'help' for a list of commands - 'help <cmd>' for command-specific help - 'quit' to quit -''' cmdqueue = [] completekey = 'tab' stdout = sys.stdout
commit 86feb224d855093ddded8a8a0c9542ea925ad90d Author: Aron Parsons aparsons@redhat.com Date: Fri Oct 29 10:33:09 2010 -0400
spacecmd: exit the shell if the initial login attempt fails
diff --git a/spacecmd/src/bin/spacecmd b/spacecmd/src/bin/spacecmd index e0f14f3..914421a 100755 --- a/spacecmd/src/bin/spacecmd +++ b/spacecmd/src/bin/spacecmd @@ -134,18 +134,14 @@ if __name__ == '__main__':
sys.exit(1) else: - need_login = True + if not shell.do_login(''): + sys.exit(1)
# stay in the interactive shell forever while True: # use try..finally to overcome 2.4's lack of try..except..finally try: try: - # we need to be logged in for tab completion to work - if need_login and not shell.session: - need_login = False - shell.do_login('') - shell.cmdloop() except KeyboardInterrupt: print diff --git a/spacecmd/src/lib/misc.py b/spacecmd/src/lib/misc.py index d364288..68cbef8 100644 --- a/spacecmd/src/lib/misc.py +++ b/spacecmd/src/lib/misc.py @@ -167,7 +167,7 @@ def do_login(self, args): # logout before logging in again if len(self.session): logging.warning('You are already logged in') - return + return True
if self.options.nossl: proto = 'http' @@ -187,7 +187,7 @@ def do_login(self, args): server = self.options.server else: logging.warning('No server specified') - return + return False
server_url = '%s://%s/rpc/api' % (proto, server)
@@ -213,7 +213,7 @@ def do_login(self, args): % (self.api_version, self.MINIMUM_API_VERSION))
self.client = None - return + return False
# store the session file in the server's own directory session_file = os.path.join(self.conf_dir, server, 'session') @@ -244,8 +244,7 @@ def do_login(self, args): # check the cached credentials by doing an API call if self.session: try: - logging.debug('Using cached credentials from %s' % - session_file) + logging.debug('Using cached credentials from %s' % session_file)
self.client.user.listUsers(self.session) except: @@ -256,7 +255,7 @@ def do_login(self, args): # attempt to login if we don't have a valid session yet if not len(self.session): if len(username): - print 'Username: %s' % username + print 'Spacewalk Username: %s' % username else: if self.options.username: username = self.options.username @@ -265,7 +264,7 @@ def do_login(self, args): # again, the user is prompted for the information self.options.username = None else: - username = prompt_user('Username:', noblank = True) + username = prompt_user('Spacewalk Username:', noblank = True)
if self.options.password: password = self.options.password @@ -274,14 +273,14 @@ def do_login(self, args): # again, the user is prompted for the information self.options.password = None else: - password = getpass('Password: ') + password = getpass('Spacewalk Password: ')
# login to the server try: self.session = self.client.auth.login(username, password) except: logging.error('Invalid credentials') - return + return False
try: # make sure ~/.spacecmd/<server> exists @@ -309,6 +308,8 @@ def do_login(self, args):
logging.info('Connected to %s as %s' % (server_url, username))
+ return True + ####################
def help_logout(self):
spacewalk-commits@lists.fedorahosted.org