<s> from __future__ import print_function <EOL> import sys <EOL> from oslo_config import cfg <EOL> from oslo_log import log <EOL> import pkg_resources as pkg <EOL> from sahara . db . templates import api <EOL> from sahara . i18n import _LI <EOL> from sahara import version <EOL> LOG = log . getLogger ( __name__ ) <EOL> CONF = cfg . CONF <EOL> def extra_option_checks ( ) : <EOL> if not CONF . database . connection : <EOL> print ( "<STR_LIT>" , <EOL> file = sys . stderr ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if CONF . command . name in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if CONF . command . plugin_version and not CONF . command . plugin_name : <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" , file = sys . stderr ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> if CONF . command . name == "<STR_LIT>" : <EOL> if not CONF . command . plugin_name : <EOL> if "<STR_LIT>" in CONF and CONF . plugins : <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> ) . format ( plugins = CONF . plugins ) ) <EOL> else : <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" , file = sys . stderr ) <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> def add_command_parsers ( subparsers ) : <EOL> def add_id ( parser ) : <EOL> parser . add_argument ( '<STR_LIT>' , required = True , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def add_tenant_id ( parser ) : <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , required = True , <EOL> help = '<STR_LIT>' ) <EOL> def add_name_and_tenant_id ( parser ) : <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , required = True , <EOL> help = '<STR_LIT>' ) <EOL> add_tenant_id ( parser ) <EOL> def add_plugin_name_and_version ( parser , require_plugin_name = False ) : <EOL> plugin_name_help = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if not require_plugin_name : <EOL> extra = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> plugin_name_help += extra <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , nargs = "<STR_LIT:*>" , <EOL> required = require_plugin_name , <EOL> help = plugin_name_help ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , nargs = "<STR_LIT:*>" , <EOL> help = '<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> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> fname = pkg . resource_filename ( version . version_info . package , <EOL> "<STR_LIT>" ) <EOL> parser = subparsers . add_parser ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> default = fname , <EOL> help = '<STR_LIT>' % fname ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> add_plugin_name_and_version ( parser ) <EOL> add_tenant_id ( parser ) <EOL> parser . set_defaults ( func = api . do_update ) <EOL> parser = subparsers . add_parser ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> add_plugin_name_and_version ( parser , require_plugin_name = True ) <EOL> add_tenant_id ( parser ) <EOL> parser . set_defaults ( func = api . do_delete ) <EOL> parser = subparsers . add_parser ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> add_name_and_tenant_id ( parser ) <EOL> parser . set_defaults ( func = api . do_node_group_template_delete ) <EOL> parser = subparsers . add_parser ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> add_name_and_tenant_id ( parser ) <EOL> parser . set_defaults ( func = api . do_cluster_template_delete ) <EOL> parser = subparsers . add_parser ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> add_id ( parser ) <EOL> parser . set_defaults ( func = api . do_node_group_template_delete_by_id ) <EOL> parser = subparsers . add_parser ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> add_id ( parser ) <EOL> parser . set_defaults ( func = api . do_cluster_template_delete_by_id ) <EOL> command_opt = cfg . SubCommandOpt ( '<STR_LIT>' , <EOL> title = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> handler = add_command_parsers ) <EOL> CONF . register_cli_opt ( command_opt ) <EOL> def unregister_extra_cli_opt ( name ) : <EOL> try : <EOL> for cli in CONF . _cli_opts : <EOL> if cli [ '<STR_LIT>' ] . name == name : <EOL> CONF . unregister_opt ( cli [ '<STR_LIT>' ] ) <EOL> except Exception : <EOL> pass <EOL> for extra_opt in [ "<STR_LIT>" , "<STR_LIT:host>" , "<STR_LIT:port>" ] : <EOL> unregister_extra_cli_opt ( extra_opt ) <EOL> def main ( ) : <EOL> CONF ( project = '<STR_LIT>' ) <EOL> CONF . reload_config_files ( ) <EOL> log . setup ( CONF , "<STR_LIT>" ) <EOL> extra_option_checks ( ) <EOL> LOG . info ( _LI ( "<STR_LIT>" ) . format ( command = '<STR_LIT:U+0020>' . join ( sys . argv ) ) ) <EOL> api . set_logger ( LOG ) <EOL> api . set_conf ( CONF ) <EOL> CONF . command . func ( ) <EOL> LOG . info ( _LI ( "<STR_LIT>" ) . format ( command = CONF . command . name ) ) </s>
