#NEWLINE# @ image_actions_group . command ( name = 'image-actions' , context_settings = CONTEXT_SETTINGS ) #NEWLINE# @ click . option ( '--transfer' , '-T' , type = int , help = 'transfer given image id to region' , metavar = '<3812352>' ) #NEWLINE# @ click . option ( '--region' , '-r' , type = click . Choice ( [ 'nyc1' , 'nyc2' , 'nyc3' , 'ams1' , 'ams2' , 'ams3' , 'sfo1' , 'sgp1' , 'lon1' , 'fra1' ] ) , help = 'transfer image to given region' , metavar = '<nyc1>' ) #NEWLINE# @ click . option ( '--convert' , '-c' , type = int , help = 'convert given image id' , metavar = '<3812352>' ) #NEWLINE# @ click . option ( '--action' , '-a' , type = int , help = 'get action details for given image id' , metavar = '<3812352>' ) #NEWLINE# @ click . option ( '--action-id' , '-i' , type = int , help = 'get action details from given action id' , metavar = '<3812352>' ) #NEWLINE# @ click . option ( '--token' , '-t' , type = str , help = 'digital ocean authentication token' , metavar = '<token>' ) #NEWLINE# @ click . option ( '--tablefmt' , '-f' , type = click . Choice ( [ 'fancy_grid' , 'simple' , 'plain' , 'grid' , 'pipe' , 'orgtbl' , 'psql' , 'rst' , 'mediawiki' , 'html' , 'latex' , 'latex_booktabs' , 'tsv' ] ) , help = 'output table format' , default = 'fancy_grid' , metavar = '<format>' ) #NEWLINE# @ click . option ( '--proxy' , '-p' , help = 'proxy url to be used for this call' , metavar = '<http://ip:port>' ) #NEWLINE# @ click . pass_context #NEWLINE# def image_actions( ctx , transfer , region , convert , action , action_id , token , tablefmt , proxy ) : #NEWLINE# #INDENT# '\n\tImage actions are commands that can be given to a DigitalOcean image.\n\t' #NEWLINE# if ( ( not ctx . params [ 'transfer' ] ) and ( not ctx . params [ 'region' ] ) and ( not ctx . params [ 'convert' ] ) and ( not ctx . params [ 'action' ] ) and ( not ctx . params [ 'action_id' ] ) ) : #NEWLINE# #INDENT# return click . echo ( ctx . get_help ( ) ) #NEWLINE# #UNINDENT# option_list = [ 'transfer' , 'convert' , 'action' ] #NEWLINE# if validate ( ctx . params , option_list ) : #NEWLINE# #INDENT# if transfer : #NEWLINE# #INDENT# params = { #NEWLINE# #INDENT# 'type' : 'transfer' , #NEWLINE# 'region' : region , #NEWLINE# #UNINDENT# } #NEWLINE# record = 'image transfer' #NEWLINE# return run_command ( token , proxy , transfer , params , record ) #NEWLINE# #UNINDENT# if convert : #NEWLINE# #INDENT# params = { #NEWLINE# #INDENT# 'type' : 'convert' , #NEWLINE# #UNINDENT# } #NEWLINE# record = 'image convert' #NEWLINE# return run_command ( action_id , proxy , convert , params , record ) #NEWLINE# #UNINDENT# if action : #NEWLINE# #INDENT# method = 'GET' #NEWLINE# url = ( ( ( IMAGES + str ( action ) ) + '/' ) + str ( action_id ) ) #NEWLINE# result = DigitalOcean . do_request ( method , url , token = token , proxy = proxy ) #NEWLINE# if result [ 'has_error' ] : #NEWLINE# #INDENT# click . echo ( ) #NEWLINE# click . echo ( ( 'Error: %s' % result [ 'error_message' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# record = 'image action' #NEWLINE# headers = [ 'Fields' , 'Values' ] #NEWLINE# dic = result [ 'action' ] #NEWLINE# table = [ [ 'Id' , dic [ 'id' ] ] , [ 'Status' , dic [ 'status' ] ] , [ 'Type' , click . style ( dic [ 'type' ] , fg = 'blue' ) ] , [ 'Started at' , dic [ 'started_at' ] ] , [ 'Completed at' , dic [ 'completed_at' ] ] , [ 'Resource id' , dic [ 'resource_id' ] ] , [ 'Resource type' , dic [ 'resource_type' ] ] , [ 'Region' , dic [ 'region' ] ] ] #NEWLINE# data = { #NEWLINE# #INDENT# 'headers' : headers , #NEWLINE# 'table_data' : table , #NEWLINE# #UNINDENT# } #NEWLINE# print_table ( tablefmt , data , record )