<s> """<STR_LIT>""" <EOL> import sys <EOL> from cliff import command <EOL> from cliff import lister <EOL> from cliff import show <EOL> from keystoneclient import exceptions <EOL> from oslo_log import log as logging <EOL> from oslo_serialization import jsonutils <EOL> import six <EOL> from congressclient . common import utils <EOL> def _format_rule ( rule ) : <EOL> """<STR_LIT>""" <EOL> rule_split = jsonutils . dumps ( rule ) . split ( "<STR_LIT>" ) <EOL> formatted_string = rule_split [ <NUM_LIT:0> ] + "<STR_LIT>" <EOL> for rule in rule_split [ <NUM_LIT:1> ] . split ( "<STR_LIT>" ) : <EOL> formatted_string += rule + '<STR_LIT:\n>' <EOL> return formatted_string <EOL> def get_rule_id_from_name ( client , parsed_args ) : <EOL> results = client . list_policy_rules ( parsed_args . policy_name ) [ '<STR_LIT>' ] <EOL> rule_id = None <EOL> for result in results : <EOL> if result . get ( '<STR_LIT:name>' ) == parsed_args . rule_id : <EOL> if rule_id is None : <EOL> rule_id = result . get ( '<STR_LIT:id>' ) <EOL> else : <EOL> raise exceptions . Conflict ( <EOL> "<STR_LIT>" % <EOL> parsed_args . rule_id ) <EOL> if rule_id is None : <EOL> raise exceptions . NotFound ( <EOL> "<STR_LIT>" % parsed_args . rule_id ) <EOL> return rule_id <EOL> class CreatePolicyRule ( show . ShowOne ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( __name__ + '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( CreatePolicyRule , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> self . log . debug ( '<STR_LIT>' % parsed_args ) <EOL> client = self . app . client_manager . congressclient <EOL> body = { '<STR_LIT>' : parsed_args . rule } <EOL> if parsed_args . rule_name : <EOL> body [ '<STR_LIT:name>' ] = parsed_args . rule_name <EOL> if parsed_args . comment : <EOL> body [ '<STR_LIT>' ] = parsed_args . comment <EOL> data = client . create_policy_rule ( parsed_args . policy_name , body ) <EOL> return zip ( * sorted ( six . iteritems ( data ) ) ) <EOL> class DeletePolicyRule ( command . Command ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( __name__ + '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( DeletePolicyRule , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> self . log . debug ( '<STR_LIT>' % parsed_args ) <EOL> client = self . app . client_manager . congressclient <EOL> results = client . list_policy_rules ( parsed_args . policy_name ) <EOL> rule_id = utils . get_resource_id_from_name ( <EOL> parsed_args . rule_id , results ) <EOL> client . delete_policy_rule ( parsed_args . policy_name , rule_id ) <EOL> class ListPolicyRules ( command . Command ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( __name__ + '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ListPolicyRules , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> self . log . debug ( '<STR_LIT>' % parsed_args ) <EOL> client = self . app . client_manager . congressclient <EOL> results = client . list_policy_rules ( parsed_args . policy_name ) [ '<STR_LIT>' ] <EOL> for result in results : <EOL> print ( "<STR_LIT>" % str ( result [ '<STR_LIT:id>' ] ) ) <EOL> print ( "<STR_LIT>" % str ( result . get ( '<STR_LIT:name>' ) ) ) <EOL> if result [ '<STR_LIT>' ] != "<STR_LIT:None>" and result [ '<STR_LIT>' ] : <EOL> print ( "<STR_LIT>" % str ( result [ '<STR_LIT>' ] ) ) <EOL> print ( result [ '<STR_LIT>' ] ) <EOL> print ( '<STR_LIT>' ) <EOL> return <NUM_LIT:0> <EOL> class SimulatePolicy ( command . Command ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( __name__ + '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( SimulatePolicy , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> default = None ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> self . log . debug ( '<STR_LIT>' % parsed_args ) <EOL> client = self . app . client_manager . congressclient <EOL> args = { } <EOL> args [ '<STR_LIT>' ] = parsed_args . query <EOL> args [ '<STR_LIT>' ] = parsed_args . sequence <EOL> if parsed_args . action_policy is not None : <EOL> args [ '<STR_LIT>' ] = parsed_args . action_policy <EOL> if parsed_args . delta : <EOL> args [ '<STR_LIT>' ] = parsed_args . delta <EOL> if parsed_args . trace : <EOL> args [ '<STR_LIT>' ] = parsed_args . trace <EOL> body = { '<STR_LIT>' : parsed_args . query , <EOL> '<STR_LIT>' : parsed_args . sequence , <EOL> '<STR_LIT>' : parsed_args . action_policy } <EOL> results = client . execute_policy_action ( <EOL> policy_name = parsed_args . policy , <EOL> action = "<STR_LIT>" , <EOL> trace = parsed_args . trace , <EOL> delta = parsed_args . delta , <EOL> body = body ) <EOL> for result in results [ '<STR_LIT:result>' ] : <EOL> print ( result ) <EOL> if '<STR_LIT>' in results : <EOL> print ( results [ '<STR_LIT>' ] ) <EOL> return <NUM_LIT:0> <EOL> class ListPolicyTables ( lister . Lister ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( __name__ + '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ListPolicyTables , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> self . log . debug ( '<STR_LIT>' % parsed_args ) <EOL> client = self . app . client_manager . congressclient <EOL> data = client . list_policy_tables ( parsed_args . policy_name ) [ '<STR_LIT>' ] <EOL> columns = [ '<STR_LIT:id>' ] <EOL> formatters = { '<STR_LIT>' : utils . format_list } <EOL> return ( columns , <EOL> ( utils . get_dict_properties ( s , columns , <EOL> formatters = formatters ) <EOL> for s in data ) ) <EOL> class ListPolicy ( lister . Lister ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( __name__ + '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ListPolicy , self ) . get_parser ( prog_name ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> client = self . app . client_manager . congressclient <EOL> data = client . list_policy ( ) [ '<STR_LIT>' ] <EOL> columns = [ '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:description>' ] <EOL> formatters = { '<STR_LIT>' : utils . format_list } <EOL> return ( columns , <EOL> ( utils . get_dict_properties ( s , columns , <EOL> formatters = formatters ) <EOL> for s in data ) ) <EOL> class CreatePolicy ( show . ShowOne ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( __name__ + '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( CreatePolicy , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> choices = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:action>' , '<STR_LIT>' ] , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> self . log . debug ( '<STR_LIT>' % parsed_args ) <EOL> client = self . app . client_manager . congressclient <EOL> body = { '<STR_LIT:name>' : parsed_args . policy_name , <EOL> '<STR_LIT:description>' : parsed_args . description , <EOL> '<STR_LIT>' : parsed_args . abbreviation , <EOL> '<STR_LIT>' : parsed_args . kind } <EOL> data = client . create_policy ( body ) <EOL> return zip ( * sorted ( six . iteritems ( data ) ) ) <EOL> class DeletePolicy ( command . Command ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( __name__ + '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( DeletePolicy , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> self . log . debug ( '<STR_LIT>' % parsed_args ) <EOL> client = self . app . client_manager . congressclient <EOL> client . delete_policy ( parsed_args . policy ) <EOL> class ListPolicyRows ( lister . Lister ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( __name__ + '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ListPolicyRows , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> self . log . debug ( '<STR_LIT>' % parsed_args ) <EOL> client = self . app . client_manager . congressclient <EOL> answer = client . list_policy_rows ( parsed_args . policy_name , <EOL> parsed_args . table , <EOL> parsed_args . trace ) <EOL> if '<STR_LIT>' in answer : <EOL> sys . stdout . write ( answer [ '<STR_LIT>' ] + '<STR_LIT:\n>' ) <EOL> results = answer [ '<STR_LIT>' ] <EOL> columns = [ ] <EOL> if results : <EOL> columns = [ '<STR_LIT>' % ( i ) <EOL> for i in range ( <NUM_LIT:0> , len ( results [ <NUM_LIT:0> ] [ '<STR_LIT:data>' ] ) ) ] <EOL> self . log . debug ( "<STR_LIT>" + str ( columns ) ) <EOL> return ( columns , ( x [ '<STR_LIT:data>' ] for x in results ) ) <EOL> class ShowPolicyRule ( show . ShowOne ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( __name__ + '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ShowPolicyRule , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> self . log . debug ( '<STR_LIT>' % parsed_args ) <EOL> client = self . app . client_manager . congressclient <EOL> results = client . list_policy_rules ( parsed_args . policy_name ) <EOL> rule_id = utils . get_resource_id_from_name ( <EOL> parsed_args . rule_id , results ) <EOL> data = client . show_policy_rule ( parsed_args . policy_name , rule_id ) <EOL> return zip ( * sorted ( six . iteritems ( data ) ) ) <EOL> class ShowPolicyTable ( show . ShowOne ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( __name__ + '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ShowPolicyTable , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> self . log . debug ( '<STR_LIT>' % parsed_args ) <EOL> client = self . app . client_manager . congressclient <EOL> data = client . show_policy_table ( parsed_args . policy_name , <EOL> parsed_args . table_id ) <EOL> return zip ( * sorted ( six . iteritems ( data ) ) ) <EOL> class ShowPolicy ( show . ShowOne ) : <EOL> """<STR_LIT>""" <EOL> log = logging . getLogger ( __name__ + '<STR_LIT>' ) <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ShowPolicy , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> self . log . debug ( '<STR_LIT>' % parsed_args ) <EOL> client = self . app . client_manager . congressclient <EOL> results = client . list_policy ( ) <EOL> policy_id = utils . get_resource_id_from_name ( <EOL> parsed_args . policy_name , results ) <EOL> data = client . show_policy ( policy_id ) <EOL> return zip ( * sorted ( six . iteritems ( data ) ) ) </s>
