<s> from ironicclient . common import cliutils <EOL> from ironicclient . common import utils <EOL> from ironicclient . v1 import resource_fields as res_fields <EOL> def _print_port_show ( port , fields = None , json = False ) : <EOL> if fields is None : <EOL> fields = res_fields . PORT_DETAILED_RESOURCE . fields <EOL> data = dict ( [ ( f , getattr ( port , f , '<STR_LIT>' ) ) for f in fields ] ) <EOL> cliutils . print_dict ( data , wrap = <NUM_LIT> , json_flag = json ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT:port>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , <EOL> dest = '<STR_LIT:address>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = '<STR_LIT>' ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , <EOL> nargs = '<STR_LIT:+>' , <EOL> dest = '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> action = '<STR_LIT>' , <EOL> default = [ ] , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def do_port_show ( cc , args ) : <EOL> """<STR_LIT>""" <EOL> fields = args . fields [ <NUM_LIT:0> ] if args . fields else None <EOL> utils . check_for_invalid_fields ( <EOL> fields , res_fields . PORT_DETAILED_RESOURCE . fields ) <EOL> if args . address : <EOL> port = cc . port . get_by_address ( args . port , fields = fields ) <EOL> else : <EOL> utils . check_empty_arg ( args . port , '<STR_LIT>' ) <EOL> port = cc . port . get ( args . port , fields = fields ) <EOL> _print_port_show ( port , fields = fields , json = args . json ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> type = int , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> choices = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> help = '<STR_LIT>' ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , <EOL> nargs = '<STR_LIT:+>' , <EOL> dest = '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> action = '<STR_LIT>' , <EOL> default = [ ] , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def do_port_list ( cc , args ) : <EOL> """<STR_LIT>""" <EOL> params = { } <EOL> if args . address is not None : <EOL> params [ '<STR_LIT:address>' ] = args . address <EOL> if args . detail : <EOL> fields = res_fields . PORT_DETAILED_RESOURCE . fields <EOL> field_labels = res_fields . PORT_DETAILED_RESOURCE . labels <EOL> elif args . fields : <EOL> utils . check_for_invalid_fields ( <EOL> args . fields [ <NUM_LIT:0> ] , res_fields . PORT_DETAILED_RESOURCE . fields ) <EOL> resource = res_fields . Resource ( args . fields [ <NUM_LIT:0> ] ) <EOL> fields = resource . fields <EOL> field_labels = resource . labels <EOL> else : <EOL> fields = res_fields . PORT_RESOURCE . fields <EOL> field_labels = res_fields . PORT_RESOURCE . labels <EOL> sort_fields = res_fields . PORT_DETAILED_RESOURCE . sort_fields <EOL> sort_field_labels = res_fields . PORT_DETAILED_RESOURCE . sort_labels <EOL> params . update ( utils . common_params_for_list ( args , <EOL> sort_fields , <EOL> sort_field_labels ) ) <EOL> port = cc . port . list ( ** params ) <EOL> cliutils . print_list ( port , fields , <EOL> field_labels = field_labels , <EOL> sortby_index = None , <EOL> json_flag = args . json ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> required = True , <EOL> help = '<STR_LIT>' ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> required = True , <EOL> help = '<STR_LIT>' ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> action = '<STR_LIT>' , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> def do_port_create ( cc , args ) : <EOL> """<STR_LIT>""" <EOL> field_list = [ '<STR_LIT:address>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> fields = dict ( ( k , v ) for ( k , v ) in vars ( args ) . items ( ) <EOL> if k in field_list and not ( v is None ) ) <EOL> fields = utils . args_array_to_dict ( fields , '<STR_LIT>' ) <EOL> port = cc . port . create ( ** fields ) <EOL> data = dict ( [ ( f , getattr ( port , f , '<STR_LIT>' ) ) for f in field_list ] ) <EOL> cliutils . print_dict ( data , wrap = <NUM_LIT> , json_flag = args . json ) <EOL> @ cliutils . arg ( '<STR_LIT:port>' , metavar = '<STR_LIT>' , nargs = '<STR_LIT:+>' , help = "<STR_LIT>" ) <EOL> def do_port_delete ( cc , args ) : <EOL> """<STR_LIT>""" <EOL> for p in args . port : <EOL> cc . port . delete ( p ) <EOL> print ( '<STR_LIT>' % p ) <EOL> @ cliutils . arg ( '<STR_LIT:port>' , metavar = '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> choices = [ '<STR_LIT>' , '<STR_LIT:replace>' , '<STR_LIT>' ] , <EOL> help = "<STR_LIT>" ) <EOL> @ cliutils . arg ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> nargs = '<STR_LIT:+>' , <EOL> action = '<STR_LIT>' , <EOL> default = [ ] , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def do_port_update ( cc , args ) : <EOL> """<STR_LIT>""" <EOL> patch = utils . args_array_to_patch ( args . op , args . attributes [ <NUM_LIT:0> ] ) <EOL> port = cc . port . update ( args . port , patch ) <EOL> _print_port_show ( port , json = args . json ) </s>
