+def AutoArchiveJobs(opts, args):
+ """Archive jobs based on age.
+
+ This will archive jobs based on their age, or all jobs if a 'all' is
+ passed.
+
+ @param opts: the command line options selected by the user
+ @type args: list
+ @param args: should contain only one element, the age as a time spec
+ that can be parsed by L{ganeti.cli.ParseTimespec} or the
+ keyword I{all}, which will cause all jobs to be archived
+ @rtype: int
+ @return: the desired exit code
+
+ """
+ client = GetClient()
+
+ age = args[0]
+
+ if age == 'all':
+ age = -1
+ else:
+ age = ParseTimespec(age)
+
+ (archived_count, jobs_left) = client.AutoArchiveJobs(age)
+ ToStdout("Archived %s jobs, %s unchecked left", archived_count, jobs_left)
+
+ return 0
+
+