#NEWLINE# @ classmethod #NEWLINE# def create_for_model( cls , data , instance , graph_type = None ) : #NEWLINE# #INDENT# "Create graph attached to model instance with given type.\n\n        This method is recommended to create or update graphs.\n\n        :param data: graph data\n        :type data: dict\n        :param instance: external model\n        :type instance: models.Cluster|models.Plugin|models.Release\n        :param graph_type: graph type, default is 'default'\n        :type graph_type: basestring\n        :return: models.DeploymentGraph\n        " #NEWLINE# if ( graph_type is None ) : #NEWLINE# #INDENT# graph_type = consts . DEFAULT_DEPLOYMENT_GRAPH_TYPE #NEWLINE# #UNINDENT# graph = cls . get_for_model ( instance , graph_type = graph_type ) #NEWLINE# if ( not cls ) : #NEWLINE# #INDENT# graph = cls . create ( data ) #NEWLINE# cls . attach_to_model ( graph , instance , graph_type ) #NEWLINE# return graph #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise errors . AlreadyExists ( 'Graph of given type already exists for this model.' )