<s> import copy <EOL> import os <EOL> import uuid <EOL> import jsonschema <EOL> from oslo_config import cfg <EOL> from oslo_serialization import jsonutils as json <EOL> import six <EOL> from sahara import conductor <EOL> from sahara . db . templates import utils as u <EOL> from sahara . i18n import _LI <EOL> from sahara . i18n import _LW <EOL> from sahara . service . validations import cluster_template_schema as clt <EOL> from sahara . service . validations import node_group_template_schema as ngt <EOL> from sahara . utils import api_validator <EOL> LOG = None <EOL> CONF = None <EOL> def set_logger ( log ) : <EOL> global LOG <EOL> LOG = log <EOL> def set_conf ( conf ) : <EOL> global CONF <EOL> CONF = conf <EOL> ng_validator = api_validator . ApiValidator ( ngt . NODE_GROUP_TEMPLATE_SCHEMA ) <EOL> ct_validator = api_validator . ApiValidator ( clt . CLUSTER_TEMPLATE_SCHEMA ) <EOL> node_group_template_opts = [ <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) , <EOL> cfg . BoolOpt ( '<STR_LIT>' , <EOL> default = False , <EOL> help = '<STR_LIT>' ) , <EOL> cfg . ListOpt ( '<STR_LIT>' , <EOL> default = [ ] , <EOL> help = '<STR_LIT>' ) <EOL> ] <EOL> cluster_template_opts = [ <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) ] <EOL> all_template_opts = node_group_template_opts + cluster_template_opts <EOL> node_group_template_opt_names = [ o . name for o in node_group_template_opts ] <EOL> cluster_template_opt_names = [ o . name for o in cluster_template_opts ] <EOL> class Handled ( Exception ) : <EOL> pass <EOL> class Context ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , is_admin = False , tenant_id = None ) : <EOL> self . is_admin = is_admin <EOL> self . tenant_id = tenant_id <EOL> def check_usage_of_existing ( ctx , ng_templates , cl_templates ) : <EOL> '''<STR_LIT>''' <EOL> error = False <EOL> clusters = conductor . API . cluster_get_all ( ctx ) <EOL> for ng_info in ng_templates : <EOL> ng = u . find_node_group_template_by_name ( ctx , <EOL> ng_info [ "<STR_LIT>" ] [ "<STR_LIT:name>" ] ) <EOL> if ng : <EOL> cluster_users , template_users = u . check_node_group_template_usage ( <EOL> ng [ "<STR_LIT:id>" ] , clusters ) <EOL> if cluster_users : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> name = ng [ "<STR_LIT:name>" ] , clusters = cluster_users ) ) <EOL> if template_users : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> name = ng [ "<STR_LIT:name>" ] , templates = template_users ) ) <EOL> if cluster_users or template_users : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( name = ng [ "<STR_LIT:name>" ] ) ) <EOL> error = True <EOL> for cl_info in cl_templates : <EOL> cl = u . find_cluster_template_by_name ( ctx , cl_info [ "<STR_LIT>" ] [ "<STR_LIT:name>" ] ) <EOL> if cl : <EOL> cluster_users = u . check_cluster_template_usage ( cl [ "<STR_LIT:id>" ] , clusters ) <EOL> if cluster_users : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> name = cl [ "<STR_LIT:name>" ] , clusters = cluster_users ) ) <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( name = cl [ "<STR_LIT:name>" ] ) ) <EOL> error = True <EOL> return error <EOL> def log_skipping_dir ( path , reason = "<STR_LIT>" ) : <EOL> if reason : <EOL> reason = "<STR_LIT:U+002CU+0020>" + reason <EOL> LOG . warning ( _LW ( "<STR_LIT>" ) . format ( <EOL> dir = path , reason = reason ) ) <EOL> def check_cluster_templates_valid ( ng_templates , cl_templates ) : <EOL> if ng_templates : <EOL> dummy_uuid = uuid . uuid4 ( ) <EOL> ng_ids = { ng [ "<STR_LIT>" ] [ "<STR_LIT:name>" ] : dummy_uuid for ng in ng_templates } <EOL> else : <EOL> ng_ids = { } <EOL> for cl in cl_templates : <EOL> template = copy . deepcopy ( cl [ "<STR_LIT>" ] ) <EOL> u . substitute_ng_ids ( template , ng_ids ) <EOL> try : <EOL> ct_validator . validate ( template ) <EOL> except jsonschema . ValidationError as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" ) . format ( <EOL> path = cl [ "<STR_LIT:path>" ] , reason = e ) ) <EOL> return True <EOL> return False <EOL> def add_config_section ( section_name , options ) : <EOL> if section_name and hasattr ( CONF , section_name ) : <EOL> return <EOL> if section_name : <EOL> group = cfg . OptGroup ( name = section_name ) <EOL> CONF . register_group ( group ) <EOL> CONF . register_opts ( options , group ) <EOL> else : <EOL> CONF . register_opts ( options ) <EOL> def add_config_section_for_template ( template ) : <EOL> '''<STR_LIT>''' <EOL> sections = list ( CONF . list_all_sections ( ) ) <EOL> unique_name = "<STR_LIT>" . format ( ** template ) <EOL> fullname = "<STR_LIT>" . format ( ** template ) <EOL> plugin_version = "<STR_LIT>" . format ( ** template ) <EOL> plugin = "<STR_LIT>" . format ( ** template ) <EOL> section_name = None <EOL> if unique_name in sections : <EOL> section_name = unique_name <EOL> elif fullname in sections : <EOL> section_name = fullname <EOL> if section_name : <EOL> if u . is_node_group ( template ) : <EOL> opts = node_group_template_opts <EOL> else : <EOL> opts = cluster_template_opts <EOL> else : <EOL> if plugin_version in sections : <EOL> section_name = plugin_version <EOL> elif plugin in sections : <EOL> section_name = plugin <EOL> opts = all_template_opts <EOL> add_config_section ( section_name , opts ) <EOL> return section_name <EOL> def substitute_config_values ( configs , template , path ) : <EOL> if u . is_node_group ( template ) : <EOL> opt_names = node_group_template_opt_names <EOL> else : <EOL> opt_names = cluster_template_opt_names <EOL> for opt , value in six . iteritems ( configs ) : <EOL> if opt in opt_names and opt in template : <EOL> template [ opt ] = value <EOL> def get_configs ( section ) : <EOL> if section is None : <EOL> return dict ( CONF ) <EOL> return dict ( CONF [ section ] ) <EOL> def get_plugin_name ( ) : <EOL> if CONF . command . name == "<STR_LIT>" and ( <EOL> not CONF . command . plugin_name and ( <EOL> hasattr ( CONF , "<STR_LIT>" ) and CONF . plugins ) ) : <EOL> return CONF . plugins <EOL> return CONF . command . plugin_name <EOL> def process_files ( dirname , files ) : <EOL> node_groups = [ ] <EOL> clusters = [ ] <EOL> plugin_name = get_plugin_name ( ) <EOL> try : <EOL> for fname in files : <EOL> if os . path . splitext ( fname ) [ <NUM_LIT:1> ] == "<STR_LIT>" : <EOL> fpath = os . path . join ( dirname , fname ) <EOL> with open ( fpath , '<STR_LIT:r>' ) as fp : <EOL> try : <EOL> data = fp . read ( ) <EOL> template = json . loads ( data ) <EOL> except ValueError as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( path = fpath , reason = e ) ) <EOL> raise Handled ( "<STR_LIT>" ) <EOL> if not u . check_basic_fields ( template ) or ( <EOL> not u . check_plugin_name_and_version ( <EOL> template , <EOL> plugin_name , <EOL> CONF . command . plugin_version ) ) : <EOL> continue <EOL> section = add_config_section_for_template ( template ) <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( section = section , path = fpath ) ) <EOL> substitute_config_values ( get_configs ( section ) , <EOL> template , fpath ) <EOL> file_entry = { '<STR_LIT>' : template , <EOL> '<STR_LIT:path>' : fpath } <EOL> if u . is_node_group ( template ) : <EOL> try : <EOL> ng_validator . validate ( template ) <EOL> except jsonschema . ValidationError as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( path = fpath , <EOL> reason = e ) ) <EOL> raise Handled ( <EOL> "<STR_LIT>" ) <EOL> node_groups . append ( file_entry ) <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( path = fpath ) ) <EOL> else : <EOL> clusters . append ( file_entry ) <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( path = fpath ) ) <EOL> except Handled as e : <EOL> log_skipping_dir ( dirname , str ( e ) ) <EOL> node_groups = [ ] <EOL> clusters = [ ] <EOL> except Exception as e : <EOL> log_skipping_dir ( dirname , <EOL> "<STR_LIT>" . format ( reason = e ) ) <EOL> node_groups = [ ] <EOL> clusters = [ ] <EOL> return node_groups , clusters <EOL> def delete_node_group_template ( ctx , template , rollback = False ) : <EOL> rollback_msg = "<STR_LIT>" if rollback else "<STR_LIT>" <EOL> if not rollback : <EOL> clusters = conductor . API . cluster_get_all ( ctx ) <EOL> cluster_templates = conductor . API . cluster_template_get_all ( ctx ) <EOL> cluster_users , template_users = u . check_node_group_template_usage ( <EOL> template [ "<STR_LIT:id>" ] , clusters , cluster_templates ) <EOL> if cluster_users : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( template ) , <EOL> clusters = cluster_users ) ) <EOL> if template_users : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( template ) , <EOL> templates = template_users ) ) <EOL> if cluster_users or template_users : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( info = u . name_and_id ( template ) ) ) <EOL> return <EOL> try : <EOL> conductor . API . node_group_template_destroy ( ctx , template [ "<STR_LIT:id>" ] , <EOL> ignore_prot_on_def = True ) <EOL> except Exception as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( template ) , <EOL> reason = e , <EOL> rollback = rollback_msg ) ) <EOL> else : <EOL> LOG . info ( _LI ( "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( template ) , rollback = rollback_msg ) ) <EOL> def reverse_node_group_template_creates ( ctx , templates ) : <EOL> for template in templates : <EOL> delete_node_group_template ( ctx , template , rollback = True ) <EOL> def reverse_node_group_template_updates ( ctx , update_info ) : <EOL> for template , values in update_info : <EOL> try : <EOL> conductor . API . node_group_template_update ( ctx , <EOL> template [ "<STR_LIT:id>" ] , values , <EOL> ignore_prot_on_def = True ) <EOL> except Exception as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( template ) , <EOL> reason = e ) ) <EOL> else : <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( template ) ) ) <EOL> def add_node_group_templates ( ctx , node_groups ) : <EOL> error = False <EOL> ng_info = { "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] } <EOL> def do_reversals ( ng_info ) : <EOL> reverse_node_group_template_updates ( ctx , ng_info [ "<STR_LIT>" ] ) <EOL> reverse_node_group_template_creates ( ctx , ng_info [ "<STR_LIT>" ] ) <EOL> return { } , True <EOL> try : <EOL> for ng in node_groups : <EOL> template = ng [ '<STR_LIT>' ] <EOL> current = u . find_node_group_template_by_name ( ctx , template [ '<STR_LIT:name>' ] ) <EOL> if current : <EOL> updated_fields = u . value_diff ( current . to_dict ( ) , template ) <EOL> try : <EOL> template = conductor . API . node_group_template_update ( <EOL> ctx , current [ '<STR_LIT:id>' ] , template , ignore_prot_on_def = True ) <EOL> except Exception as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( current ) , <EOL> reason = e ) ) <EOL> raise Handled ( ) <EOL> if template [ '<STR_LIT>' ] != current [ '<STR_LIT>' ] : <EOL> ng_info [ "<STR_LIT>" ] . append ( ( template , updated_fields ) ) <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( template ) , <EOL> path = ng [ "<STR_LIT:path>" ] ) ) <EOL> else : <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( <EOL> info = u . name_and_id ( current ) , <EOL> path = ng [ '<STR_LIT:path>' ] ) ) <EOL> else : <EOL> template [ '<STR_LIT>' ] = True <EOL> try : <EOL> template = conductor . API . node_group_template_create ( <EOL> ctx , template ) <EOL> except Exception as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> path = ng [ '<STR_LIT:path>' ] , reason = e ) ) <EOL> raise Handled ( ) <EOL> ng_info [ "<STR_LIT>" ] . append ( template ) <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( info = u . name_and_id ( template ) , <EOL> path = ng [ "<STR_LIT:path>" ] ) ) <EOL> ng_info [ "<STR_LIT>" ] [ template [ '<STR_LIT:name>' ] ] = template [ '<STR_LIT:id>' ] <EOL> except Handled : <EOL> ng_info , error = do_reversals ( ng_info ) <EOL> except Exception as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( reason = e ) ) <EOL> ng_info , error = do_reversals ( ng_info ) <EOL> return ng_info , error <EOL> def delete_cluster_template ( ctx , template , rollback = False ) : <EOL> rollback_msg = "<STR_LIT>" if rollback else "<STR_LIT>" <EOL> if not rollback : <EOL> clusters = conductor . API . cluster_get_all ( ctx ) <EOL> cluster_users = u . check_cluster_template_usage ( template [ "<STR_LIT:id>" ] , <EOL> clusters ) <EOL> if cluster_users : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( template ) , <EOL> clusters = cluster_users ) ) <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( info = u . name_and_id ( template ) ) ) <EOL> return <EOL> try : <EOL> conductor . API . cluster_template_destroy ( ctx , template [ "<STR_LIT:id>" ] , <EOL> ignore_prot_on_def = True ) <EOL> except Exception as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( info = u . name_and_id ( template ) , <EOL> reason = e , <EOL> rollback = rollback_msg ) ) <EOL> else : <EOL> LOG . info ( _LI ( "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( template ) , rollback = rollback_msg ) ) <EOL> def reverse_cluster_template_creates ( ctx , templates ) : <EOL> for template in templates : <EOL> delete_cluster_template ( ctx , template , rollback = True ) <EOL> def reverse_cluster_template_updates ( ctx , update_info ) : <EOL> for template , values in update_info : <EOL> try : <EOL> conductor . API . cluster_template_update ( ctx , <EOL> template [ "<STR_LIT:id>" ] , values , <EOL> ignore_prot_on_def = True ) <EOL> except Exception as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( template ) , <EOL> reason = e ) ) <EOL> else : <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( template ) ) ) <EOL> def add_cluster_templates ( ctx , clusters , ng_dict ) : <EOL> '''<STR_LIT>''' <EOL> error = False <EOL> created = [ ] <EOL> updated = [ ] <EOL> def do_reversals ( created , updated ) : <EOL> reverse_cluster_template_updates ( ctx , updated ) <EOL> reverse_cluster_template_creates ( ctx , created ) <EOL> return True <EOL> try : <EOL> for cl in clusters : <EOL> template = cl [ '<STR_LIT>' ] <EOL> u . substitute_ng_ids ( template , ng_dict ) <EOL> current = u . find_cluster_template_by_name ( ctx , template [ '<STR_LIT:name>' ] ) <EOL> if current : <EOL> updated_fields = u . value_diff ( current . to_dict ( ) , template ) <EOL> try : <EOL> template = conductor . API . cluster_template_update ( <EOL> ctx , current [ '<STR_LIT:id>' ] , template , ignore_prot_on_def = True ) <EOL> except Exception as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( current ) , reason = e ) ) <EOL> raise Handled ( ) <EOL> if template [ '<STR_LIT>' ] != current [ '<STR_LIT>' ] : <EOL> updated . append ( ( template , updated_fields ) ) <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( template ) , <EOL> path = cl [ '<STR_LIT:path>' ] ) ) <EOL> else : <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( info = u . name_and_id ( current ) , <EOL> path = cl [ "<STR_LIT:path>" ] ) ) <EOL> else : <EOL> template [ "<STR_LIT>" ] = True <EOL> try : <EOL> template = conductor . API . cluster_template_create ( ctx , <EOL> template ) <EOL> except Exception as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> path = cl [ '<STR_LIT:path>' ] , <EOL> reason = e ) ) <EOL> raise Handled ( ) <EOL> created . append ( template ) <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( info = u . name_and_id ( template ) , <EOL> path = cl [ '<STR_LIT:path>' ] ) ) <EOL> except Handled : <EOL> error = do_reversals ( created , updated ) <EOL> except Exception as e : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( reason = e ) ) <EOL> error = do_reversals ( created , updated ) <EOL> return error <EOL> def do_update ( ) : <EOL> '''<STR_LIT>''' <EOL> ctx = Context ( tenant_id = CONF . command . tenant_id ) <EOL> start_dir = os . path . abspath ( CONF . command . directory ) <EOL> for root , dirs , files in os . walk ( start_dir ) : <EOL> node_groups , clusters = process_files ( root , files ) <EOL> if check_cluster_templates_valid ( node_groups , clusters ) : <EOL> log_skipping_dir ( root , "<STR_LIT>" ) <EOL> elif check_usage_of_existing ( ctx , node_groups , clusters ) : <EOL> log_skipping_dir ( root , "<STR_LIT>" ) <EOL> else : <EOL> ng_info , error = add_node_group_templates ( ctx , node_groups ) <EOL> if error : <EOL> log_skipping_dir ( root , "<STR_LIT>" ) <EOL> elif add_cluster_templates ( ctx , clusters , ng_info [ "<STR_LIT>" ] ) : <EOL> log_skipping_dir ( root , "<STR_LIT>" ) <EOL> reverse_node_group_template_updates ( ctx , ng_info [ "<STR_LIT>" ] ) <EOL> reverse_node_group_template_creates ( ctx , ng_info [ "<STR_LIT>" ] ) <EOL> if CONF . command . norecurse : <EOL> break <EOL> def do_delete ( ) : <EOL> '''<STR_LIT>''' <EOL> ctx = Context ( tenant_id = CONF . command . tenant_id ) <EOL> for plugin in get_plugin_name ( ) : <EOL> kwargs = { '<STR_LIT>' : True } <EOL> kwargs [ '<STR_LIT>' ] = plugin <EOL> lst = conductor . API . cluster_template_get_all ( ctx , ** kwargs ) <EOL> for l in lst : <EOL> if not u . check_plugin_version ( l , CONF . command . plugin_version ) : <EOL> continue <EOL> delete_cluster_template ( ctx , l ) <EOL> lst = conductor . API . node_group_template_get_all ( ctx , ** kwargs ) <EOL> for l in lst : <EOL> if not u . check_plugin_version ( l , CONF . command . plugin_version ) : <EOL> continue <EOL> delete_node_group_template ( ctx , l ) <EOL> def do_node_group_template_delete ( ) : <EOL> ctx = Context ( tenant_id = CONF . command . tenant_id ) <EOL> template_name = CONF . command . template_name <EOL> t = u . find_node_group_template_by_name ( ctx , template_name ) <EOL> if t : <EOL> delete_node_group_template ( ctx , t ) <EOL> else : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( name = template_name ) ) <EOL> def do_node_group_template_delete_by_id ( ) : <EOL> ctx = Context ( is_admin = True ) <EOL> t = conductor . API . node_group_template_get ( ctx , CONF . command . id ) <EOL> if t : <EOL> if t [ "<STR_LIT>" ] : <EOL> delete_node_group_template ( ctx , t ) <EOL> else : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( t ) ) ) <EOL> else : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( id = CONF . command . id ) ) <EOL> def do_cluster_template_delete ( ) : <EOL> ctx = Context ( tenant_id = CONF . command . tenant_id ) <EOL> template_name = CONF . command . template_name <EOL> t = u . find_cluster_template_by_name ( ctx , template_name ) <EOL> if t : <EOL> delete_cluster_template ( ctx , t ) <EOL> else : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( name = template_name ) ) <EOL> def do_cluster_template_delete_by_id ( ) : <EOL> ctx = Context ( is_admin = True ) <EOL> t = conductor . API . cluster_template_get ( ctx , CONF . command . id ) <EOL> if t : <EOL> if t [ "<STR_LIT>" ] : <EOL> delete_cluster_template ( ctx , t ) <EOL> else : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> info = u . name_and_id ( t ) ) ) <EOL> else : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( id = CONF . command . id ) ) </s>
