<s> from sahara import exceptions as ex <EOL> from sahara . i18n import _ <EOL> from sahara . service . api import v10 as api <EOL> import sahara . service . validations . base as b <EOL> from sahara . service . validations import shares <EOL> def check_node_group_template_create ( data , ** kwargs ) : <EOL> b . check_node_group_template_unique_name ( data [ '<STR_LIT:name>' ] ) <EOL> b . check_plugin_name_exists ( data [ '<STR_LIT>' ] ) <EOL> b . check_plugin_supports_version ( data [ '<STR_LIT>' ] , <EOL> data [ '<STR_LIT>' ] ) <EOL> b . check_node_group_basic_fields ( data [ '<STR_LIT>' ] , <EOL> data [ '<STR_LIT>' ] , data ) <EOL> if data . get ( '<STR_LIT>' ) : <EOL> b . check_image_registered ( data [ '<STR_LIT>' ] ) <EOL> b . check_required_image_tags ( data [ '<STR_LIT>' ] , <EOL> data [ '<STR_LIT>' ] , <EOL> data [ '<STR_LIT>' ] ) <EOL> if data . get ( '<STR_LIT>' ) : <EOL> shares . check_shares ( data [ '<STR_LIT>' ] ) <EOL> def check_node_group_template_usage ( node_group_template_id , ** kwargs ) : <EOL> cluster_users = [ ] <EOL> template_users = [ ] <EOL> for cluster in api . get_clusters ( ) : <EOL> if ( node_group_template_id in <EOL> [ node_group . node_group_template_id <EOL> for node_group in cluster . node_groups ] ) : <EOL> cluster_users += [ cluster . name ] <EOL> for cluster_template in api . get_cluster_templates ( ) : <EOL> if ( node_group_template_id in <EOL> [ node_group . node_group_template_id <EOL> for node_group in cluster_template . node_groups ] ) : <EOL> template_users += [ cluster_template . name ] <EOL> if cluster_users or template_users : <EOL> raise ex . InvalidReferenceException ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { '<STR_LIT>' : node_group_template_id , <EOL> '<STR_LIT>' : template_users and '<STR_LIT:U+002CU+0020>' . join ( template_users ) or '<STR_LIT>' , <EOL> '<STR_LIT>' : cluster_users and '<STR_LIT:U+002CU+0020>' . join ( cluster_users ) or '<STR_LIT>' } ) <EOL> def check_node_group_template_update ( node_group_template_id , data , ** kwargs ) : <EOL> if data . get ( '<STR_LIT>' ) and not data . get ( '<STR_LIT>' ) : <EOL> raise ex . InvalidReferenceException ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> if data . get ( '<STR_LIT>' ) : <EOL> plugin = data . get ( '<STR_LIT>' ) <EOL> version = data . get ( '<STR_LIT>' ) <EOL> b . check_plugin_name_exists ( plugin ) <EOL> b . check_plugin_supports_version ( plugin , version ) <EOL> else : <EOL> ngt = api . get_node_group_template ( node_group_template_id ) <EOL> plugin = ngt . plugin_name <EOL> if data . get ( '<STR_LIT>' ) : <EOL> version = data . get ( '<STR_LIT>' ) <EOL> b . check_plugin_supports_version ( plugin , version ) <EOL> else : <EOL> version = ngt . hadoop_version <EOL> if data . get ( '<STR_LIT>' ) : <EOL> b . check_image_registered ( data [ '<STR_LIT>' ] ) <EOL> b . check_required_image_tags ( plugin , <EOL> version , <EOL> data [ '<STR_LIT>' ] ) <EOL> b . check_node_group_basic_fields ( plugin , version , data ) <EOL> if data . get ( '<STR_LIT>' ) : <EOL> shares . check_shares ( data [ '<STR_LIT>' ] ) </s>
