<s> """<STR_LIT>""" <EOL> import copy <EOL> from distutils . version import StrictVersion <EOL> import itertools <EOL> import yaml <EOL> from nailgun import consts <EOL> from nailgun . db . sqlalchemy import models <EOL> from nailgun . objects import DeploymentGraph <EOL> from nailgun . objects import NailgunCollection <EOL> from nailgun . objects import NailgunObject <EOL> from nailgun . objects . serializers import release as release_serializer <EOL> from nailgun . orchestrator import graph_configuration <EOL> from nailgun . plugins . manager import PluginManager <EOL> from nailgun . settings import settings <EOL> class Release ( NailgunObject ) : <EOL> """<STR_LIT>""" <EOL> model = models . Release <EOL> serializer = release_serializer . ReleaseSerializer <EOL> @ classmethod <EOL> def create ( cls , data ) : <EOL> """<STR_LIT>""" <EOL> data . pop ( "<STR_LIT>" , None ) <EOL> deployment_tasks = data . pop ( "<STR_LIT>" , [ ] ) <EOL> release_obj = super ( Release , cls ) . create ( data ) <EOL> DeploymentGraph . create_for_model ( <EOL> { '<STR_LIT>' : deployment_tasks } , release_obj ) <EOL> return release_obj <EOL> @ classmethod <EOL> def update ( cls , instance , data ) : <EOL> """<STR_LIT>""" <EOL> data . pop ( "<STR_LIT>" , None ) <EOL> deployment_tasks = data . pop ( "<STR_LIT>" , None ) <EOL> release_obj = super ( Release , cls ) . update ( instance , data ) <EOL> if deployment_tasks : <EOL> deployment_graph_instance = DeploymentGraph . get_for_model ( instance ) <EOL> DeploymentGraph . update ( deployment_graph_instance , <EOL> { '<STR_LIT>' : deployment_tasks } ) <EOL> return release_obj <EOL> @ classmethod <EOL> def update_role ( cls , instance , role ) : <EOL> """<STR_LIT>""" <EOL> instance . roles_metadata [ role [ '<STR_LIT:name>' ] ] = role [ '<STR_LIT>' ] <EOL> instance . volumes_metadata [ '<STR_LIT>' ] [ role [ '<STR_LIT:name>' ] ] = role . get ( '<STR_LIT>' , [ ] ) <EOL> instance . volumes_metadata . changed ( ) <EOL> @ classmethod <EOL> def remove_role ( cls , instance , role_name ) : <EOL> result = instance . roles_metadata . pop ( role_name , None ) <EOL> instance . volumes_metadata [ '<STR_LIT>' ] . pop ( role_name , None ) <EOL> instance . volumes_metadata . changed ( ) <EOL> return bool ( result ) <EOL> @ classmethod <EOL> def is_deployable ( cls , instance ) : <EOL> """<STR_LIT>""" <EOL> if instance . state == consts . RELEASE_STATES . unavailable : <EOL> return False <EOL> if '<STR_LIT>' in settings . VERSION [ '<STR_LIT>' ] : <EOL> return True <EOL> return instance . state == consts . RELEASE_STATES . available <EOL> @ classmethod <EOL> def is_granular_enabled ( cls , instance ) : <EOL> """<STR_LIT>""" <EOL> return ( StrictVersion ( instance . environment_version ) >= <EOL> StrictVersion ( consts . FUEL_GRANULAR_DEPLOY ) ) <EOL> @ classmethod <EOL> def is_lcm_supported ( cls , instance ) : <EOL> """<STR_LIT>""" <EOL> return ( <EOL> StrictVersion ( instance . environment_version ) >= <EOL> StrictVersion ( consts . FUEL_LCM_AVAILABLE ) <EOL> ) <EOL> @ classmethod <EOL> def is_external_mongo_enabled ( cls , instance ) : <EOL> """<STR_LIT>""" <EOL> return ( StrictVersion ( instance . environment_version ) >= <EOL> StrictVersion ( consts . FUEL_EXTERNAL_MONGO ) ) <EOL> @ classmethod <EOL> def is_multiple_floating_ranges_enabled ( cls , instance ) : <EOL> """<STR_LIT>""" <EOL> return ( StrictVersion ( instance . environment_version ) >= <EOL> StrictVersion ( consts . FUEL_MULTIPLE_FLOATING_IP_RANGES ) ) <EOL> @ classmethod <EOL> def get_deployment_tasks ( cls , instance , graph_type = None ) : <EOL> """<STR_LIT>""" <EOL> if graph_type is None : <EOL> graph_type = consts . DEFAULT_DEPLOYMENT_GRAPH_TYPE <EOL> env_version = instance . environment_version <EOL> deployment_graph = DeploymentGraph . get_for_model ( instance , graph_type ) <EOL> if deployment_graph : <EOL> deployment_tasks = DeploymentGraph . get_tasks ( deployment_graph ) <EOL> else : <EOL> deployment_tasks = [ ] <EOL> if graph_type == consts . DEFAULT_DEPLOYMENT_GRAPH_TYPE and not deployment_tasks : <EOL> if env_version . startswith ( '<STR_LIT>' ) : <EOL> deployment_tasks = yaml . load ( <EOL> graph_configuration . DEPLOYMENT_50 ) <EOL> elif env_version . startswith ( '<STR_LIT>' ) or env_version . startswith ( '<STR_LIT>' ) : <EOL> deployment_tasks = yaml . load ( <EOL> graph_configuration . DEPLOYMENT_51_60 ) <EOL> if deployment_graph : <EOL> if deployment_tasks : <EOL> DeploymentGraph . update ( <EOL> deployment_graph , { '<STR_LIT>' : deployment_tasks } ) <EOL> else : <EOL> DeploymentGraph . create_for_model ( <EOL> { '<STR_LIT>' : deployment_tasks } , instance ) <EOL> return deployment_tasks <EOL> @ classmethod <EOL> def get_min_controller_count ( cls , instance ) : <EOL> return instance . roles_metadata [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> @ classmethod <EOL> def get_all_components ( cls , instance ) : <EOL> """<STR_LIT>""" <EOL> plugin_components = PluginManager . get_components_metadata ( instance ) <EOL> components = copy . deepcopy ( <EOL> instance . components_metadata + plugin_components ) <EOL> for comp_i , comp_j in itertools . permutations ( components , <NUM_LIT:2> ) : <EOL> if cls . _check_relation ( comp_j , comp_i , '<STR_LIT>' ) : <EOL> comp_i . setdefault ( '<STR_LIT>' , [ ] ) . append ( { <EOL> '<STR_LIT:name>' : comp_j [ '<STR_LIT:name>' ] , <EOL> '<STR_LIT:message>' : "<STR_LIT>" . format ( <EOL> comp_j . get ( '<STR_LIT:label>' ) or comp_j . get ( '<STR_LIT:name>' ) ) } ) <EOL> if cls . _check_relation ( comp_j , comp_i , '<STR_LIT>' ) : <EOL> comp_i . setdefault ( '<STR_LIT>' , [ ] ) . append ( { <EOL> '<STR_LIT:name>' : comp_j [ '<STR_LIT:name>' ] } ) <EOL> return components <EOL> @ classmethod <EOL> def _check_relation ( cls , a , b , relation ) : <EOL> """<STR_LIT>""" <EOL> return ( cls . _contain ( a . get ( relation , [ ] ) , b [ '<STR_LIT:name>' ] ) and not <EOL> cls . _contain ( b . get ( relation , [ ] ) , a [ '<STR_LIT:name>' ] ) ) <EOL> @ staticmethod <EOL> def _contain ( components , name ) : <EOL> """<STR_LIT>""" <EOL> prefixes = ( comp [ '<STR_LIT:name>' ] . split ( '<STR_LIT:*>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] for comp in components ) <EOL> return any ( name . startswith ( x ) for x in prefixes ) <EOL> @ classmethod <EOL> def get_supported_dpdk_drivers ( cls , instance ) : <EOL> """<STR_LIT>""" <EOL> metadata = instance . networks_metadata <EOL> return metadata . get ( '<STR_LIT>' , { } ) <EOL> class ReleaseCollection ( NailgunCollection ) : <EOL> """<STR_LIT>""" <EOL> single = Release </s>
