def main(args): """ the main action """ verbosity = args.verbose layer2 = cci_boto.connect(args.region, 0, args.access_key, args.secret_key) vault_name = args.vault_name carp(verbosity > 1, "deleting %s" % vault_name) # do an LS: inventory_res = cci_boto.get_inventory(layer2, vault_name) carp(verbosity > 1, "inventory is %s" % inventory_res) # get the list of archives: archive_list = inventory_res['ArchiveList'] if verbosity > 1: dum = [print('deleting %s' % a['ArchiveId']) for a in archive_list] # delete them all noret = [ layer2.layer1.delete_archive(vault_name, a['ArchiveId']) for a in archive_list ] carp(verbosity > 1, noret) # now delete the vault: print(layer2.layer1.delete_vault(vault_name))
def main(args): """ the main action """ verbosity = args.verbose vault_name = args.vault_name save_d = args.directory carp(verbosity > 0, "retrieving all of %s to %s" % (vault_name, save_d)) layer2 = cci_boto.connect(args.region, 0, args.access_key, args.secret_key) # do an LS: inventory_res = cci_boto.get_inventory(layer2, vault_name) carp(verbosity > 0, "inventory is %s" % inventory_res) # get the list of archives: archive_list = inventory_res['ArchiveList'] if verbosity > 0: dum = [print('retrieving %s' % a['ArchiveId']) for a in archive_list] # dictionary from the requested filename to the AID fullfn2aid = {(a['ArchiveDescription'] or a['ArchiveId']): a['ArchiveId'] for a in archive_list} # the ArchiveDescription could be a *full* path name; strip it: fn2aid = {os.path.basename(k): v for k, v in fullfn2aid.iteritems()} # dictionary from req filename to the archive retrieval req job: fn2job = { k: cci_boto.init_retrieval_job(layer2, vault_name, v) for k, v in fn2aid.iteritems() } # now wait and get the results # 2FIX: add maximum timeout? for fname, job in fn2job.iteritems(): wasok = cci_boto.wait_job(layer2, vault_name, job.id) if wasok: carp(verbosity > 0, "fetching %s" % fname) vault = cci_boto.fetch_vault(layer2, vault_name) retjob = vault.get_job(job.id) if retjob.completed: filename = os.path.join(save_d, fname) retjob.download_to_file(filename)
def main(args): """ the main action """ verbosity = args.verbose layer2 = cci_boto.connect(args.region, 0, args.access_key, args.secret_key) vault_name = args.vault_name carp(verbosity > 1,"deleting %s" % vault_name) # do an LS: inventory_res = cci_boto.get_inventory(layer2, vault_name) carp(verbosity > 1,"inventory is %s" % inventory_res) # get the list of archives: archive_list = inventory_res['ArchiveList'] if verbosity > 1: dum = [ print ('deleting %s' % a['ArchiveId']) for a in archive_list ] # delete them all noret = [ layer2.layer1.delete_archive(vault_name, a['ArchiveId']) for a in archive_list ] carp(verbosity > 1,noret) # now delete the vault: print (layer2.layer1.delete_vault(vault_name))
def main(args): """ the main action """ verbosity = args.verbose vault_name = args.vault_name save_d = args.directory carp(verbosity > 0,"retrieving all of %s to %s" % (vault_name,save_d)) layer2 = cci_boto.connect(args.region, 0, args.access_key, args.secret_key) # do an LS: inventory_res = cci_boto.get_inventory(layer2, vault_name) carp(verbosity > 0,"inventory is %s" % inventory_res) # get the list of archives: archive_list = inventory_res['ArchiveList'] if verbosity > 0: dum = [ print ('retrieving %s' % a['ArchiveId']) for a in archive_list ] # dictionary from the requested filename to the AID fullfn2aid = { (a['ArchiveDescription'] or a['ArchiveId']) : a['ArchiveId'] for a in archive_list } # the ArchiveDescription could be a *full* path name; strip it: fn2aid = { os.path.basename(k) : v for k, v in fullfn2aid.iteritems() } # dictionary from req filename to the archive retrieval req job: fn2job = { k : cci_boto.init_retrieval_job(layer2, vault_name, v) for k, v in fn2aid.iteritems() } # now wait and get the results # 2FIX: add maximum timeout? for fname, job in fn2job.iteritems() : wasok = cci_boto.wait_job(layer2, vault_name, job.id) if wasok : carp(verbosity > 0,"fetching %s"%fname) vault = cci_boto.fetch_vault(layer2, vault_name) retjob = vault.get_job(job.id) if retjob.completed : filename = os.path.join(save_d,fname) retjob.download_to_file(filename)
default=os.getenv('AWS_ACCESS_KEY_ID')) parser.add_argument( '--secret_key', help= 'the AWS Secret Access Key ID; defaults to the environment variable AWS_SECRET_ACCESS_KEY', default=os.getenv('AWS_SECRET_ACCESS_KEY')) parser.add_argument( '--region', help= 'which AWS region; defaults to the environment variable AWS_REGION or us-east-1', default=os.getenv('AWS_REGION', 'us-east-1')) parser.add_argument('--completed', help='show completed jobs; default false.', dest='completed', action='store_true') parser.add_argument('--no-completed', help='do not show completed jobs; default true.', dest='completed', action='store_false') parser.add_argument('vault_name', help='the name of the vault to query') parser.set_defaults(completed=False) args = parser.parse_args() layer2 = cci_boto.connect(args.region, 0, args.access_key, args.secret_key) layer1 = layer2.layer1 print layer1.list_jobs(args.vault_name, completed=args.completed) #for vim modeline: (do not edit) # vim:ts=4:sw=4:sts=4:tw=79:sta:et:ai:nu:fdm=indent:syn=python:ft=python:tag=.py_tags;:cin:fo=croql
import sys # module as script if __name__ == "__main__": # parse arguments parser = argparse.ArgumentParser(description="get vault inventory to stdout.") parser.add_argument('--access_key', help='the AWS Access Key ID; defaults to the environment variable AWS_ACCESS_KEY_ID', default=os.getenv('AWS_ACCESS_KEY_ID')) parser.add_argument('--secret_key', help='the AWS Secret Access Key ID; defaults to the environment variable AWS_SECRET_ACCESS_KEY', default=os.getenv('AWS_SECRET_ACCESS_KEY')) parser.add_argument('--region', help='which AWS region; defaults to the environment variable AWS_REGION or us-east-1', default=os.getenv('AWS_REGION','us-east-1')) parser.add_argument('--block', '-b', help='whether to block on job completion, before printing. This can can take 4 hours. Defaults to False', action='store_true', default=False) parser.add_argument('vault_name', help='the name of the vault to inventory') parser.add_argument('job_id', help='the job ID produced by a previous request to inventory this vault; if none given, we initiate an inventory request', nargs='?', default='') args = parser.parse_args() # connect layer2 = cci_boto.connect(args.region, 0, args.access_key, args.secret_key) vault_name = args.vault_name # get or initiate job request if args.job_id : job_id = args.job_id else : job_id = cci_boto.init_inventory_job(layer2, vault_name) print(job_id) # now possibly block : if args.block : wasok = cci_boto.wait_job(layer2, vault_name, job_id) if wasok : print(cci_boto.get_job_result(layer2, vault_name, job_id)) sys.exit(0)