<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import argparse <EOL> import logging <EOL> import os <EOL> import sys <EOL> from keystoneclient . auth . identity import v2 as v2_auth <EOL> from keystoneclient . auth . identity import v3 as v3_auth <EOL> from keystoneclient import discover <EOL> from keystoneclient import exceptions as ks_exc <EOL> from keystoneclient import session <EOL> from oslo_utils import encodeutils <EOL> import six . moves . urllib . parse as urlparse <EOL> from cliff import app <EOL> from cliff import commandmanager <EOL> from neutronclient . common import clientmanager <EOL> from neutronclient . common import exceptions as exc <EOL> from neutronclient . common import utils <EOL> from neutronclient . i18n import _ <EOL> from neutronclient . version import __version__ <EOL> from gbpclient . gbp . v2_0 import groupbasedpolicy as gbp <EOL> from gbpclient . gbp . v2_0 import servicechain <EOL> VERSION = '<STR_LIT>' <EOL> NEUTRON_API_VERSION = '<STR_LIT>' <EOL> clientmanager . neutron_client . API_VERSIONS = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def run_command ( cmd , cmd_parser , sub_argv ) : <EOL> _argv = sub_argv <EOL> index = - <NUM_LIT:1> <EOL> values_specs = [ ] <EOL> if '<STR_LIT>' in sub_argv : <EOL> index = sub_argv . index ( '<STR_LIT>' ) <EOL> _argv = sub_argv [ : index ] <EOL> values_specs = sub_argv [ index : ] <EOL> known_args , _values_specs = cmd_parser . parse_known_args ( _argv ) <EOL> cmd . values_specs = ( index == - <NUM_LIT:1> and _values_specs or values_specs ) <EOL> return cmd . run ( known_args ) <EOL> def env ( * _vars , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> for v in _vars : <EOL> value = os . environ . get ( v , None ) <EOL> if value : <EOL> return value <EOL> return kwargs . get ( '<STR_LIT:default>' , '<STR_LIT>' ) <EOL> def check_non_negative_int ( value ) : <EOL> try : <EOL> value = int ( value ) <EOL> except ValueError : <EOL> raise argparse . ArgumentTypeError ( _ ( "<STR_LIT>" ) % value ) <EOL> if value < <NUM_LIT:0> : <EOL> raise argparse . ArgumentTypeError ( _ ( "<STR_LIT>" ) % <EOL> value ) <EOL> return value <EOL> COMMAND_V2 = { <EOL> '<STR_LIT>' : gbp . CreatePolicyTarget , <EOL> '<STR_LIT>' : gbp . DeletePolicyTarget , <EOL> '<STR_LIT>' : gbp . UpdatePolicyTarget , <EOL> '<STR_LIT>' : gbp . ListPolicyTarget , <EOL> '<STR_LIT>' : gbp . ShowPolicyTarget , <EOL> '<STR_LIT>' : gbp . CreatePolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . DeletePolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . UpdatePolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . ListPolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . ShowPolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . CreatePolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . DeletePolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . UpdatePolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . ListPolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . ShowPolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . CreateL2Policy , <EOL> '<STR_LIT>' : gbp . DeleteL2Policy , <EOL> '<STR_LIT>' : gbp . UpdateL2Policy , <EOL> '<STR_LIT>' : gbp . ListL2Policy , <EOL> '<STR_LIT>' : gbp . ShowL2Policy , <EOL> '<STR_LIT>' : gbp . CreateL3Policy , <EOL> '<STR_LIT>' : gbp . DeleteL3Policy , <EOL> '<STR_LIT>' : gbp . UpdateL3Policy , <EOL> '<STR_LIT>' : gbp . ListL3Policy , <EOL> '<STR_LIT>' : gbp . ShowL3Policy , <EOL> '<STR_LIT>' : gbp . CreateNetworkServicePolicy , <EOL> '<STR_LIT>' : gbp . DeleteNetworkServicePolicy , <EOL> '<STR_LIT>' : gbp . UpdateNetworkServicePolicy , <EOL> '<STR_LIT>' : gbp . ListNetworkServicePolicy , <EOL> '<STR_LIT>' : gbp . ShowNetworkServicePolicy , <EOL> '<STR_LIT>' : gbp . CreateExternalPolicy , <EOL> '<STR_LIT>' : gbp . DeleteExternalPolicy , <EOL> '<STR_LIT>' : gbp . UpdateExternalPolicy , <EOL> '<STR_LIT>' : gbp . ListExternalPolicy , <EOL> '<STR_LIT>' : gbp . ShowExternalPolicy , <EOL> '<STR_LIT>' : gbp . CreateExternalSegment , <EOL> '<STR_LIT>' : gbp . DeleteExternalSegment , <EOL> '<STR_LIT>' : gbp . UpdateExternalSegment , <EOL> '<STR_LIT>' : gbp . ListExternalSegment , <EOL> '<STR_LIT>' : gbp . ShowExternalSegment , <EOL> '<STR_LIT>' : gbp . CreateNatPool , <EOL> '<STR_LIT>' : gbp . DeleteNatPool , <EOL> '<STR_LIT>' : gbp . UpdateNatPool , <EOL> '<STR_LIT>' : gbp . ListNatPool , <EOL> '<STR_LIT>' : gbp . ShowNatPool , <EOL> '<STR_LIT>' : gbp . CreatePolicyClassifier , <EOL> '<STR_LIT>' : gbp . DeletePolicyClassifier , <EOL> '<STR_LIT>' : gbp . UpdatePolicyClassifier , <EOL> '<STR_LIT>' : gbp . ListPolicyClassifier , <EOL> '<STR_LIT>' : gbp . ShowPolicyClassifier , <EOL> '<STR_LIT>' : gbp . CreatePolicyAction , <EOL> '<STR_LIT>' : gbp . DeletePolicyAction , <EOL> '<STR_LIT>' : gbp . UpdatePolicyAction , <EOL> '<STR_LIT>' : gbp . ListPolicyAction , <EOL> '<STR_LIT>' : gbp . ShowPolicyAction , <EOL> '<STR_LIT>' : gbp . CreatePolicyRule , <EOL> '<STR_LIT>' : gbp . DeletePolicyRule , <EOL> '<STR_LIT>' : gbp . UpdatePolicyRule , <EOL> '<STR_LIT>' : gbp . ListPolicyRule , <EOL> '<STR_LIT>' : gbp . ShowPolicyRule , <EOL> '<STR_LIT>' : gbp . CreatePolicyRuleSet , <EOL> '<STR_LIT>' : gbp . DeletePolicyRuleSet , <EOL> '<STR_LIT>' : gbp . UpdatePolicyRuleSet , <EOL> '<STR_LIT>' : gbp . ListPolicyRuleSet , <EOL> '<STR_LIT>' : gbp . ShowPolicyRuleSet , <EOL> '<STR_LIT>' : servicechain . ListServiceProfile , <EOL> '<STR_LIT>' : servicechain . ShowServiceProfile , <EOL> '<STR_LIT>' : servicechain . CreateServiceProfile , <EOL> '<STR_LIT>' : servicechain . DeleteServiceProfile , <EOL> '<STR_LIT>' : servicechain . UpdateServiceProfile , <EOL> '<STR_LIT>' : servicechain . ListServiceChainNode , <EOL> '<STR_LIT>' : servicechain . ShowServiceChainNode , <EOL> '<STR_LIT>' : servicechain . CreateServiceChainNode , <EOL> '<STR_LIT>' : servicechain . DeleteServiceChainNode , <EOL> '<STR_LIT>' : servicechain . UpdateServiceChainNode , <EOL> '<STR_LIT>' : servicechain . ListServiceChainSpec , <EOL> '<STR_LIT>' : servicechain . ShowServiceChainSpec , <EOL> '<STR_LIT>' : servicechain . CreateServiceChainSpec , <EOL> '<STR_LIT>' : servicechain . DeleteServiceChainSpec , <EOL> '<STR_LIT>' : servicechain . UpdateServiceChainSpec , <EOL> '<STR_LIT>' : ( <EOL> servicechain . ListServiceChainInstance <EOL> ) , <EOL> '<STR_LIT>' : ( <EOL> servicechain . ShowServiceChainInstance <EOL> ) , <EOL> '<STR_LIT>' : ( <EOL> servicechain . CreateServiceChainInstance <EOL> ) , <EOL> '<STR_LIT>' : ( <EOL> servicechain . DeleteServiceChainInstance <EOL> ) , <EOL> '<STR_LIT>' : ( <EOL> servicechain . UpdateServiceChainInstance <EOL> ) , <EOL> '<STR_LIT>' : gbp . CreatePolicyTarget , <EOL> '<STR_LIT>' : gbp . DeletePolicyTarget , <EOL> '<STR_LIT>' : gbp . UpdatePolicyTarget , <EOL> '<STR_LIT>' : gbp . ListPolicyTarget , <EOL> '<STR_LIT>' : gbp . ShowPolicyTarget , <EOL> '<STR_LIT>' : gbp . CreatePolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . DeletePolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . UpdatePolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . ListPolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . ShowPolicyTargetGroup , <EOL> '<STR_LIT>' : gbp . CreateL2Policy , <EOL> '<STR_LIT>' : gbp . DeleteL2Policy , <EOL> '<STR_LIT>' : gbp . UpdateL2Policy , <EOL> '<STR_LIT>' : gbp . ListL2Policy , <EOL> '<STR_LIT>' : gbp . ShowL2Policy , <EOL> '<STR_LIT>' : gbp . CreateL3Policy , <EOL> '<STR_LIT>' : gbp . DeleteL3Policy , <EOL> '<STR_LIT>' : gbp . UpdateL3Policy , <EOL> '<STR_LIT>' : gbp . ListL3Policy , <EOL> '<STR_LIT>' : gbp . ShowL3Policy , <EOL> '<STR_LIT>' : gbp . CreateNetworkServicePolicy , <EOL> '<STR_LIT>' : gbp . DeleteNetworkServicePolicy , <EOL> '<STR_LIT>' : gbp . UpdateNetworkServicePolicy , <EOL> '<STR_LIT>' : gbp . ListNetworkServicePolicy , <EOL> '<STR_LIT>' : gbp . ShowNetworkServicePolicy , <EOL> '<STR_LIT>' : gbp . CreateExternalPolicy , <EOL> '<STR_LIT>' : gbp . DeleteExternalPolicy , <EOL> '<STR_LIT>' : gbp . UpdateExternalPolicy , <EOL> '<STR_LIT>' : gbp . ListExternalPolicy , <EOL> '<STR_LIT>' : gbp . ShowExternalPolicy , <EOL> '<STR_LIT>' : gbp . CreateExternalSegment , <EOL> '<STR_LIT>' : gbp . DeleteExternalSegment , <EOL> '<STR_LIT>' : gbp . UpdateExternalSegment , <EOL> '<STR_LIT>' : gbp . ListExternalSegment , <EOL> '<STR_LIT>' : gbp . ShowExternalSegment , <EOL> '<STR_LIT>' : gbp . CreateNatPool , <EOL> '<STR_LIT>' : gbp . DeleteNatPool , <EOL> '<STR_LIT>' : gbp . UpdateNatPool , <EOL> '<STR_LIT>' : gbp . ListNatPool , <EOL> '<STR_LIT>' : gbp . ShowNatPool , <EOL> '<STR_LIT>' : gbp . CreatePolicyClassifier , <EOL> '<STR_LIT>' : gbp . DeletePolicyClassifier , <EOL> '<STR_LIT>' : gbp . UpdatePolicyClassifier , <EOL> '<STR_LIT>' : gbp . ListPolicyClassifier , <EOL> '<STR_LIT>' : gbp . ShowPolicyClassifier , <EOL> '<STR_LIT>' : gbp . CreatePolicyAction , <EOL> '<STR_LIT>' : gbp . DeletePolicyAction , <EOL> '<STR_LIT>' : gbp . UpdatePolicyAction , <EOL> '<STR_LIT>' : gbp . ListPolicyAction , <EOL> '<STR_LIT>' : gbp . ShowPolicyAction , <EOL> '<STR_LIT>' : gbp . CreatePolicyRule , <EOL> '<STR_LIT>' : gbp . DeletePolicyRule , <EOL> '<STR_LIT>' : gbp . UpdatePolicyRule , <EOL> '<STR_LIT>' : gbp . ListPolicyRule , <EOL> '<STR_LIT>' : gbp . ShowPolicyRule , <EOL> '<STR_LIT>' : gbp . CreatePolicyRuleSet , <EOL> '<STR_LIT>' : gbp . DeletePolicyRuleSet , <EOL> '<STR_LIT>' : gbp . UpdatePolicyRuleSet , <EOL> '<STR_LIT>' : gbp . ListPolicyRuleSet , <EOL> '<STR_LIT>' : gbp . ShowPolicyRuleSet , <EOL> '<STR_LIT>' : servicechain . ListServiceProfile , <EOL> '<STR_LIT>' : servicechain . ShowServiceProfile , <EOL> '<STR_LIT>' : servicechain . CreateServiceProfile , <EOL> '<STR_LIT>' : servicechain . DeleteServiceProfile , <EOL> '<STR_LIT>' : servicechain . UpdateServiceProfile , <EOL> '<STR_LIT>' : servicechain . ListServiceChainNode , <EOL> '<STR_LIT>' : servicechain . ShowServiceChainNode , <EOL> '<STR_LIT>' : servicechain . CreateServiceChainNode , <EOL> '<STR_LIT>' : servicechain . DeleteServiceChainNode , <EOL> '<STR_LIT>' : servicechain . UpdateServiceChainNode , <EOL> '<STR_LIT>' : servicechain . ListServiceChainSpec , <EOL> '<STR_LIT>' : servicechain . ShowServiceChainSpec , <EOL> '<STR_LIT>' : servicechain . CreateServiceChainSpec , <EOL> '<STR_LIT>' : servicechain . DeleteServiceChainSpec , <EOL> '<STR_LIT>' : servicechain . UpdateServiceChainSpec , <EOL> '<STR_LIT>' : ( <EOL> servicechain . ListServiceChainInstance <EOL> ) , <EOL> '<STR_LIT>' : ( <EOL> servicechain . ShowServiceChainInstance <EOL> ) , <EOL> '<STR_LIT>' : ( <EOL> servicechain . CreateServiceChainInstance <EOL> ) , <EOL> '<STR_LIT>' : ( <EOL> servicechain . DeleteServiceChainInstance <EOL> ) , <EOL> '<STR_LIT>' : ( <EOL> servicechain . UpdateServiceChainInstance <EOL> ) , <EOL> } <EOL> COMMANDS = { '<STR_LIT>' : COMMAND_V2 } <EOL> class HelpAction ( argparse . Action ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , parser , namespace , values , option_string = None ) : <EOL> outputs = [ ] <EOL> max_len = <NUM_LIT:0> <EOL> app = self . default <EOL> parser . print_help ( app . stdout ) <EOL> app . api_version = '<STR_LIT>' <EOL> app . stdout . write ( _ ( '<STR_LIT>' ) % app . api_version ) <EOL> command_manager = app . command_manager <EOL> for name , ep in sorted ( command_manager ) : <EOL> factory = ep . load ( ) <EOL> cmd = factory ( self , None ) <EOL> one_liner = cmd . get_description ( ) . split ( '<STR_LIT:\n>' ) [ <NUM_LIT:0> ] <EOL> outputs . append ( ( name , one_liner ) ) <EOL> max_len = max ( len ( name ) , max_len ) <EOL> for ( name , one_liner ) in outputs : <EOL> app . stdout . write ( '<STR_LIT>' % ( name . ljust ( max_len ) , one_liner ) ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> class GBPShell ( app . App ) : <EOL> WARNING_LEVEL = <NUM_LIT:0> <EOL> INFO_LEVEL = <NUM_LIT:1> <EOL> DEBUG_LEVEL = <NUM_LIT:2> <EOL> CONSOLE_MESSAGE_FORMAT = '<STR_LIT>' <EOL> DEBUG_MESSAGE_FORMAT = '<STR_LIT>' <EOL> log = logging . getLogger ( __name__ ) <EOL> def __init__ ( self , apiversion ) : <EOL> super ( GBPShell , self ) . __init__ ( <EOL> description = __doc__ . strip ( ) , <EOL> version = VERSION , <EOL> command_manager = commandmanager . CommandManager ( '<STR_LIT>' ) , ) <EOL> self . commands = COMMANDS <EOL> for k , v in self . commands [ apiversion ] . items ( ) : <EOL> self . command_manager . add_command ( k , v ) <EOL> self . auth_client = None <EOL> self . api_version = apiversion <EOL> def build_option_parser ( self , description , version ) : <EOL> """<STR_LIT>""" <EOL> parser = argparse . ArgumentParser ( <EOL> description = description , <EOL> add_help = False , ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:version>' , <EOL> version = __version__ , ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT:count>' , <EOL> dest = '<STR_LIT>' , <EOL> default = self . DEFAULT_VERBOSE_LEVEL , <EOL> help = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> const = <NUM_LIT:0> , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = HelpAction , <EOL> nargs = <NUM_LIT:0> , <EOL> default = self , <EOL> help = _ ( "<STR_LIT>" ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> type = check_non_negative_int , <EOL> default = <NUM_LIT:0> , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> self . _append_global_identity_args ( parser ) <EOL> return parser <EOL> def _append_global_identity_args ( self , parser ) : <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' , default = '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' , default = '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' , default = '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' , default = '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' , default = '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> project_name_group = parser . add_mutually_exclusive_group ( ) <EOL> project_name_group . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> project_name_group . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> default = utils . env ( '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> project_id_group = parser . add_mutually_exclusive_group ( ) <EOL> project_id_group . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> project_id_group . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> default = utils . env ( '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = utils . env ( '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> default = utils . env ( '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> default = utils . env ( '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> default = utils . env ( '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> default = utils . env ( '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> default = utils . env ( '<STR_LIT>' ) , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' , default = None ) , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> default = utils . env ( '<STR_LIT>' ) , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = utils . env ( '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' , default = None ) , type = float , <EOL> help = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> default = env ( '<STR_LIT>' ) , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = env ( '<STR_LIT>' , default = False ) , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> def _bash_completion ( self ) : <EOL> """<STR_LIT>""" <EOL> commands = set ( ) <EOL> options = set ( ) <EOL> for option , _action in self . parser . _option_string_actions . items ( ) : <EOL> options . add ( option ) <EOL> for command_name , command in self . command_manager : <EOL> commands . add ( command_name ) <EOL> cmd_factory = command . load ( ) <EOL> cmd = cmd_factory ( self , None ) <EOL> cmd_parser = cmd . get_parser ( '<STR_LIT>' ) <EOL> for option , _action in cmd_parser . _option_string_actions . items ( ) : <EOL> options . add ( option ) <EOL> print ( '<STR_LIT:U+0020>' . join ( commands | options ) ) <EOL> def run ( self , argv ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> index = <NUM_LIT:0> <EOL> command_pos = - <NUM_LIT:1> <EOL> help_pos = - <NUM_LIT:1> <EOL> help_command_pos = - <NUM_LIT:1> <EOL> for arg in argv : <EOL> if arg == '<STR_LIT>' : <EOL> self . _bash_completion ( ) <EOL> return <NUM_LIT:0> <EOL> if arg in self . commands [ self . api_version ] : <EOL> if command_pos == - <NUM_LIT:1> : <EOL> command_pos = index <EOL> elif arg in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if help_pos == - <NUM_LIT:1> : <EOL> help_pos = index <EOL> elif arg == '<STR_LIT>' : <EOL> if help_command_pos == - <NUM_LIT:1> : <EOL> help_command_pos = index <EOL> index = index + <NUM_LIT:1> <EOL> if command_pos > - <NUM_LIT:1> and help_pos > command_pos : <EOL> argv = [ '<STR_LIT>' , argv [ command_pos ] ] <EOL> if help_command_pos > - <NUM_LIT:1> and command_pos == - <NUM_LIT:1> : <EOL> argv [ help_command_pos ] = '<STR_LIT>' <EOL> self . options , remainder = self . parser . parse_known_args ( argv ) <EOL> self . configure_logging ( ) <EOL> self . interactive_mode = not remainder <EOL> self . initialize_app ( remainder ) <EOL> except Exception as err : <EOL> if self . options . verbose_level >= self . DEBUG_LEVEL : <EOL> self . log . exception ( unicode ( err ) ) <EOL> raise <EOL> else : <EOL> self . log . error ( unicode ( err ) ) <EOL> return <NUM_LIT:1> <EOL> result = <NUM_LIT:1> <EOL> if self . interactive_mode : <EOL> _argv = [ sys . argv [ <NUM_LIT:0> ] ] <EOL> sys . argv = _argv <EOL> result = self . interact ( ) <EOL> else : <EOL> result = self . run_subcommand ( remainder ) <EOL> return result <EOL> def run_subcommand ( self , argv ) : <EOL> subcommand = self . command_manager . find_command ( argv ) <EOL> cmd_factory , cmd_name , sub_argv = subcommand <EOL> cmd = cmd_factory ( self , self . options ) <EOL> err = None <EOL> result = <NUM_LIT:1> <EOL> try : <EOL> self . prepare_to_run_command ( cmd ) <EOL> full_name = ( cmd_name <EOL> if self . interactive_mode <EOL> else '<STR_LIT:U+0020>' . join ( [ self . NAME , cmd_name ] ) <EOL> ) <EOL> cmd_parser = cmd . get_parser ( full_name ) <EOL> return run_command ( cmd , cmd_parser , sub_argv ) <EOL> except Exception as err : <EOL> if self . options . verbose_level >= self . DEBUG_LEVEL : <EOL> self . log . exception ( unicode ( err ) ) <EOL> else : <EOL> self . log . error ( unicode ( err ) ) <EOL> try : <EOL> self . clean_up ( cmd , result , err ) <EOL> except Exception as err2 : <EOL> if self . options . verbose_level >= self . DEBUG_LEVEL : <EOL> self . log . exception ( unicode ( err2 ) ) <EOL> else : <EOL> self . log . error ( _ ( '<STR_LIT>' ) , unicode ( err2 ) ) <EOL> if self . options . verbose_level >= self . DEBUG_LEVEL : <EOL> raise <EOL> else : <EOL> try : <EOL> self . clean_up ( cmd , result , None ) <EOL> except Exception as err3 : <EOL> if self . options . verbose_level >= self . DEBUG_LEVEL : <EOL> self . log . exception ( unicode ( err3 ) ) <EOL> else : <EOL> self . log . error ( _ ( '<STR_LIT>' ) , unicode ( err3 ) ) <EOL> return result <EOL> def authenticate_user ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . options . os_auth_strategy == '<STR_LIT>' : <EOL> if self . options . os_token or self . options . os_url : <EOL> if not self . options . os_token : <EOL> raise exc . CommandError ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> if not self . options . os_url : <EOL> raise exc . CommandError ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> else : <EOL> project_info = ( self . options . os_tenant_name or <EOL> self . options . os_tenant_id or <EOL> ( self . options . os_project_name and <EOL> ( self . options . project_domain_name or <EOL> self . options . project_domain_id ) ) or <EOL> self . options . os_project_id ) <EOL> if ( not self . options . os_username <EOL> and not self . options . os_user_id ) : <EOL> raise exc . CommandError ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> if not self . options . os_password : <EOL> raise exc . CommandError ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> if ( not project_info ) : <EOL> raise exc . CommandError ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> if not self . options . os_auth_url : <EOL> raise exc . CommandError ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> else : <EOL> if not self . options . os_url : <EOL> raise exc . CommandError ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> auth_session = self . _get_keystone_session ( ) <EOL> self . client_manager = clientmanager . ClientManager ( <EOL> token = self . options . os_token , <EOL> url = self . options . os_url , <EOL> auth_url = self . options . os_auth_url , <EOL> tenant_name = self . options . os_tenant_name , <EOL> tenant_id = self . options . os_tenant_id , <EOL> username = self . options . os_username , <EOL> user_id = self . options . os_user_id , <EOL> password = self . options . os_password , <EOL> region_name = self . options . os_region_name , <EOL> api_version = self . api_version , <EOL> auth_strategy = self . options . os_auth_strategy , <EOL> service_type = self . options . os_service_type or <EOL> self . options . service_type , <EOL> endpoint_type = self . options . os_endpoint_type or self . endpoint_type , <EOL> insecure = self . options . insecure , <EOL> ca_cert = self . options . os_cacert , <EOL> timeout = self . options . http_timeout , <EOL> retries = self . options . retries , <EOL> raise_errors = False , <EOL> session = auth_session , <EOL> auth = auth_session . auth , <EOL> log_credentials = True ) <EOL> return <EOL> def initialize_app ( self , argv ) : <EOL> """<STR_LIT>""" <EOL> super ( GBPShell , self ) . initialize_app ( argv ) <EOL> self . api_version = { '<STR_LIT>' : self . api_version } <EOL> cmd_name = None <EOL> if argv : <EOL> cmd_info = self . command_manager . find_command ( argv ) <EOL> cmd_factory , cmd_name , sub_argv = cmd_info <EOL> if self . interactive_mode or cmd_name != '<STR_LIT>' : <EOL> self . authenticate_user ( ) <EOL> def clean_up ( self , cmd , result , err ) : <EOL> self . log . debug ( '<STR_LIT>' , cmd . __class__ . __name__ ) <EOL> if err : <EOL> self . log . debug ( '<STR_LIT>' , unicode ( err ) ) <EOL> def configure_logging ( self ) : <EOL> """<STR_LIT>""" <EOL> root_logger = logging . getLogger ( '<STR_LIT>' ) <EOL> root_logger . setLevel ( logging . DEBUG ) <EOL> console = logging . StreamHandler ( self . stderr ) <EOL> console_level = { self . WARNING_LEVEL : logging . WARNING , <EOL> self . INFO_LEVEL : logging . INFO , <EOL> self . DEBUG_LEVEL : logging . DEBUG , <EOL> } . get ( self . options . verbose_level , logging . DEBUG ) <EOL> console . setLevel ( console_level ) <EOL> if logging . DEBUG == console_level : <EOL> formatter = logging . Formatter ( self . DEBUG_MESSAGE_FORMAT ) <EOL> else : <EOL> formatter = logging . Formatter ( self . CONSOLE_MESSAGE_FORMAT ) <EOL> logging . getLogger ( '<STR_LIT>' ) . setLevel ( logging . WARNING ) <EOL> console . setFormatter ( formatter ) <EOL> root_logger . addHandler ( console ) <EOL> return <EOL> def get_v2_auth ( self , v2_auth_url ) : <EOL> return v2_auth . Password ( <EOL> v2_auth_url , <EOL> username = self . options . os_username , <EOL> password = self . options . os_password , <EOL> tenant_id = self . options . os_tenant_id , <EOL> tenant_name = self . options . os_tenant_name ) <EOL> def get_v3_auth ( self , v3_auth_url ) : <EOL> project_id = self . options . os_project_id or self . options . os_tenant_id <EOL> project_name = ( self . options . os_project_name or <EOL> self . options . os_tenant_name ) <EOL> return v3_auth . Password ( <EOL> v3_auth_url , <EOL> username = self . options . os_username , <EOL> password = self . options . os_password , <EOL> user_id = self . options . os_user_id , <EOL> user_domain_name = self . options . os_user_domain_name , <EOL> user_domain_id = self . options . os_user_domain_id , <EOL> project_id = project_id , <EOL> project_name = project_name , <EOL> project_domain_name = self . options . os_project_domain_name , <EOL> project_domain_id = self . options . os_project_domain_id <EOL> ) <EOL> def _discover_auth_versions ( self , session , auth_url ) : <EOL> try : <EOL> ks_discover = discover . Discover ( session = session , auth_url = auth_url ) <EOL> return ( ks_discover . url_for ( '<STR_LIT>' ) , ks_discover . url_for ( '<STR_LIT>' ) ) <EOL> except ks_exc . ClientException : <EOL> url_parts = urlparse . urlparse ( auth_url ) <EOL> ( scheme , netloc , path , params , query , fragment ) = url_parts <EOL> path = path . lower ( ) <EOL> if path . startswith ( '<STR_LIT>' ) : <EOL> return ( None , auth_url ) <EOL> elif path . startswith ( '<STR_LIT>' ) : <EOL> return ( auth_url , None ) <EOL> else : <EOL> msg = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> raise exc . CommandError ( msg ) <EOL> def _get_keystone_session ( self ) : <EOL> cacert = self . options . os_cacert or None <EOL> cert = self . options . os_cert or None <EOL> key = self . options . os_key or None <EOL> insecure = self . options . insecure or False <EOL> ks_session = session . Session . construct ( dict ( cacert = cacert , <EOL> cert = cert , <EOL> key = key , <EOL> insecure = insecure ) ) <EOL> ( v2_auth_url , v3_auth_url ) = self . _discover_auth_versions ( <EOL> session = ks_session , <EOL> auth_url = self . options . os_auth_url ) <EOL> user_domain_name = self . options . os_user_domain_name or None <EOL> user_domain_id = self . options . os_user_domain_id or None <EOL> project_domain_name = self . options . os_project_domain_name or None <EOL> project_domain_id = self . options . os_project_domain_id or None <EOL> domain_info = ( user_domain_name or user_domain_id or <EOL> project_domain_name or project_domain_id ) <EOL> if ( v2_auth_url and not domain_info ) or not v3_auth_url : <EOL> ks_session . auth = self . get_v2_auth ( v2_auth_url ) <EOL> else : <EOL> ks_session . auth = self . get_v3_auth ( v3_auth_url ) <EOL> return ks_session <EOL> def main ( argv = sys . argv [ <NUM_LIT:1> : ] ) : <EOL> try : <EOL> return GBPShell ( NEUTRON_API_VERSION ) . run ( map ( encodeutils . safe_decode , <EOL> argv ) ) <EOL> except exc . NeutronClientException : <EOL> return <NUM_LIT:1> <EOL> except Exception as e : <EOL> print ( unicode ( e ) ) <EOL> return <NUM_LIT:1> <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys . exit ( main ( sys . argv [ <NUM_LIT:1> : ] ) ) </s>
