#NEWLINE# def generateLogicalName( baseName ) : #NEWLINE# #INDENT# '\n    Turn a human readable name into a logical name for an instance hostname\n    ' #NEWLINE# baseName = re . sub ( '\\W' , '' , baseName ) . lower ( ) #NEWLINE# conflicts = VMSandbox . objects . filter ( logical_name__startswith = baseName ) #NEWLINE# if ( len ( conflicts ) == 0 ) : #NEWLINE# #INDENT# return baseName #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# names = [ vms . logical_name for vms in conflicts ] #NEWLINE# if ( baseName not in names ) : #NEWLINE# #INDENT# return baseName #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# counter = 1 #NEWLINE# newBaseName = ( '%s_%d' % ( baseName , counter ) ) #NEWLINE# while ( newBaseName in names ) : #NEWLINE# #INDENT# counter += 1 #NEWLINE# newBaseName = ( '%s_%d' % ( baseName , counter ) ) #NEWLINE# #UNINDENT# return newBaseName