#NEWLINE# def group_instances( self ) : #NEWLINE# #INDENT# 'Group all instances' #NEWLINE# groups = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# meta = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# meta [ 'hostvars' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for node in self . driver . list_nodes ( ) : #NEWLINE# #INDENT# name = node . name #NEWLINE# meta [ 'hostvars' ] [ name ] = self . node_to_dict ( node ) #NEWLINE# zone = node . extra [ 'zone' ] . name #NEWLINE# if groups . has_key ( zone ) : #NEWLINE# #INDENT# groups [ zone ] . append ( name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# groups [ zone ] = [ name ] #NEWLINE# #UNINDENT# tags = node . extra [ 'tags' ] #NEWLINE# for t in tags : #NEWLINE# #INDENT# if t . startswith ( 'group-' ) : #NEWLINE# #INDENT# tag = t [ 6 : ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tag = ( 'tag_%s' % t ) #NEWLINE# #UNINDENT# if groups . has_key ( tag ) : #NEWLINE# #INDENT# groups [ tag ] . append ( name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# groups [ tag ] = [ name ] #NEWLINE# #UNINDENT# #UNINDENT# net = node . extra [ 'networkInterfaces' ] [ 0 ] [ 'network' ] . split ( '/' ) [ ( - 1 ) ] #NEWLINE# net = ( 'network_%s' % net ) #NEWLINE# if groups . has_key ( net ) : #NEWLINE# #INDENT# groups [ net ] . append ( name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# groups [ net ] = [ name ] #NEWLINE# #UNINDENT# machine_type = node . size #NEWLINE# if groups . has_key ( machine_type ) : #NEWLINE# #INDENT# groups [ machine_type ] . append ( name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# groups [ machine_type ] = [ name ] #NEWLINE# #UNINDENT# image = ( ( node . image and node . image ) or 'persistent_disk' ) #NEWLINE# if groups . has_key ( image ) : #NEWLINE# #INDENT# groups [ image ] . append ( name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# groups [ image ] = [ name ] #NEWLINE# #UNINDENT# status = node . extra [ 'status' ] #NEWLINE# stat = ( 'status_%s' % status . lower ( ) ) #NEWLINE# if groups . has_key ( stat ) : #NEWLINE# #INDENT# groups [ stat ] . append ( name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# groups [ stat ] = [ name ] #NEWLINE# #UNINDENT# #UNINDENT# groups [ '_meta' ] = meta #NEWLINE# return groups