<s> import logging <EOL> import os <EOL> import sys <EOL> import warnings <EOL> from cliff import app <EOL> from cliff import commandmanager <EOL> from keystoneauth1 import exceptions <EOL> from keystoneauth1 import loading <EOL> from gnocchiclient import benchmark <EOL> from gnocchiclient import client <EOL> from gnocchiclient import noauth <EOL> from gnocchiclient . v1 import archive_policy_cli <EOL> from gnocchiclient . v1 import archive_policy_rule_cli as ap_rule_cli <EOL> from gnocchiclient . v1 import capabilities_cli <EOL> from gnocchiclient . v1 import metric_cli <EOL> from gnocchiclient . v1 import resource_cli <EOL> from gnocchiclient . v1 import resource_type_cli <EOL> from gnocchiclient . v1 import status_cli <EOL> from gnocchiclient . version import __version__ <EOL> class GnocchiCommandManager ( commandmanager . CommandManager ) : <EOL> SHELL_COMMANDS = { <EOL> "<STR_LIT:status>" : status_cli . CliStatusShow , <EOL> "<STR_LIT>" : resource_cli . CliResourceList , <EOL> "<STR_LIT>" : resource_cli . CliResourceShow , <EOL> "<STR_LIT>" : resource_cli . CliResourceHistory , <EOL> "<STR_LIT>" : resource_cli . CliResourceSearch , <EOL> "<STR_LIT>" : resource_cli . CliResourceCreate , <EOL> "<STR_LIT>" : resource_cli . CliResourceUpdate , <EOL> "<STR_LIT>" : resource_cli . CliResourceDelete , <EOL> "<STR_LIT>" : resource_cli . CliResourceTypeList , <EOL> "<STR_LIT>" : resource_type_cli . CliResourceTypeList , <EOL> "<STR_LIT>" : resource_type_cli . CliResourceTypeCreate , <EOL> "<STR_LIT>" : resource_type_cli . CliResourceTypeShow , <EOL> "<STR_LIT>" : resource_type_cli . CliResourceTypeDelete , <EOL> "<STR_LIT>" : archive_policy_cli . CliArchivePolicyList , <EOL> "<STR_LIT>" : archive_policy_cli . CliArchivePolicyShow , <EOL> "<STR_LIT>" : archive_policy_cli . CliArchivePolicyCreate , <EOL> "<STR_LIT>" : archive_policy_cli . CliArchivePolicyDelete , <EOL> "<STR_LIT>" : ap_rule_cli . CliArchivePolicyRuleList , <EOL> "<STR_LIT>" : ap_rule_cli . CliArchivePolicyRuleShow , <EOL> "<STR_LIT>" : ap_rule_cli . CliArchivePolicyRuleCreate , <EOL> "<STR_LIT>" : ap_rule_cli . CliArchivePolicyRuleDelete , <EOL> "<STR_LIT>" : metric_cli . CliMetricList , <EOL> "<STR_LIT>" : metric_cli . CliMetricShow , <EOL> "<STR_LIT>" : metric_cli . CliMetricCreate , <EOL> "<STR_LIT>" : metric_cli . CliMetricDelete , <EOL> "<STR_LIT>" : metric_cli . CliMeasuresShow , <EOL> "<STR_LIT>" : metric_cli . CliMeasuresAdd , <EOL> "<STR_LIT>" : metric_cli . CliMetricsMeasuresBatch , <EOL> "<STR_LIT>" : <EOL> metric_cli . CliResourcesMetricsMeasuresBatch , <EOL> "<STR_LIT>" : metric_cli . CliMeasuresAggregation , <EOL> "<STR_LIT>" : capabilities_cli . CliCapabilitiesList , <EOL> "<STR_LIT>" : benchmark . CliBenchmarkMetricCreate , <EOL> "<STR_LIT>" : benchmark . CliBenchmarkMetricShow , <EOL> "<STR_LIT>" : benchmark . CliBenchmarkMeasuresAdd , <EOL> "<STR_LIT>" : benchmark . CliBenchmarkMeasuresShow , <EOL> } <EOL> def load_commands ( self , namespace ) : <EOL> for name , command_class in self . SHELL_COMMANDS . items ( ) : <EOL> self . add_command ( name , command_class ) <EOL> class GnocchiShell ( app . App ) : <EOL> def __init__ ( self ) : <EOL> super ( GnocchiShell , self ) . __init__ ( <EOL> description = '<STR_LIT>' , <EOL> version = __version__ , <EOL> command_manager = GnocchiCommandManager ( None ) , <EOL> deferred_help = True , <EOL> ) <EOL> self . _client = None <EOL> def build_option_parser ( self , description , version ) : <EOL> """<STR_LIT>""" <EOL> parser = super ( GnocchiShell , self ) . build_option_parser ( <EOL> description , <EOL> version , <EOL> argparse_kwargs = { '<STR_LIT>' : False } ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> default = os . environ . get ( '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> choices = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> default = os . environ . get ( '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> default = os . environ . get ( '<STR_LIT>' , '<STR_LIT:1>' ) , <EOL> help = '<STR_LIT>' ) <EOL> loading . register_session_argparse_arguments ( parser = parser ) <EOL> plugin = loading . register_auth_argparse_arguments ( <EOL> parser = parser , argv = sys . argv , default = "<STR_LIT:password>" ) <EOL> if not isinstance ( plugin , noauth . GnocchiNoAuthLoader ) : <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> default = os . environ . get ( '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' ) <EOL> return parser <EOL> @ property <EOL> def client ( self ) : <EOL> if self . _client is None : <EOL> if hasattr ( self . options , "<STR_LIT>" ) : <EOL> endpoint_override = self . options . endpoint <EOL> else : <EOL> endpoint_override = None <EOL> auth_plugin = loading . load_auth_from_argparse_arguments ( <EOL> self . options ) <EOL> session = loading . load_session_from_argparse_arguments ( <EOL> self . options , auth = auth_plugin ) <EOL> self . _client = client . Client ( self . options . gnocchi_api_version , <EOL> session = session , <EOL> interface = self . options . interface , <EOL> region_name = self . options . region_name , <EOL> endpoint_override = endpoint_override ) <EOL> return self . _client <EOL> def clean_up ( self , cmd , result , err ) : <EOL> if err and isinstance ( err , exceptions . HttpError ) : <EOL> try : <EOL> error = err . response . json ( ) <EOL> except Exception : <EOL> pass <EOL> else : <EOL> print ( error [ '<STR_LIT:description>' ] ) <EOL> def configure_logging ( self ) : <EOL> if self . options . debug : <EOL> self . options . verbose_level = <NUM_LIT:3> <EOL> super ( GnocchiShell , self ) . configure_logging ( ) <EOL> root_logger = logging . getLogger ( '<STR_LIT>' ) <EOL> if self . options . verbose_level == <NUM_LIT:0> : <EOL> root_logger . setLevel ( logging . ERROR ) <EOL> warnings . simplefilter ( "<STR_LIT:ignore>" ) <EOL> elif self . options . verbose_level == <NUM_LIT:1> : <EOL> root_logger . setLevel ( logging . WARNING ) <EOL> warnings . simplefilter ( "<STR_LIT:ignore>" ) <EOL> elif self . options . verbose_level == <NUM_LIT:2> : <EOL> root_logger . setLevel ( logging . INFO ) <EOL> warnings . simplefilter ( "<STR_LIT>" ) <EOL> elif self . options . verbose_level >= <NUM_LIT:3> : <EOL> root_logger . setLevel ( logging . DEBUG ) <EOL> requests_log = logging . getLogger ( "<STR_LIT>" ) <EOL> cliff_log = logging . getLogger ( '<STR_LIT>' ) <EOL> stevedore_log = logging . getLogger ( '<STR_LIT>' ) <EOL> iso8601_log = logging . getLogger ( "<STR_LIT>" ) <EOL> cliff_log . setLevel ( logging . ERROR ) <EOL> stevedore_log . setLevel ( logging . ERROR ) <EOL> iso8601_log . setLevel ( logging . ERROR ) <EOL> if self . options . debug : <EOL> requests_log . setLevel ( logging . DEBUG ) <EOL> else : <EOL> requests_log . setLevel ( logging . ERROR ) <EOL> def main ( args = None ) : <EOL> if args is None : <EOL> args = sys . argv [ <NUM_LIT:1> : ] <EOL> return GnocchiShell ( ) . run ( args ) </s>
