#NEWLINE# @ argh_named ( 'add-node' ) #NEWLINE# @ arg_verbose #NEWLINE# @ arg_full_match #NEWLINE# @ argh . arg ( 'node' , type = str , help = "name of the node, '{id}' is replaced with the node number" ) #NEWLINE# @ argh . arg ( '-n' , '--count' , metavar = 'N..M' , type = str , default = '1' , help = "number of nodes ('N' or 'N..M')" ) #NEWLINE# @ argh . arg ( '-H' , '--host' , metavar = 'HOST' , type = str , default = '' , dest = 'host' , help = 'host address' ) #NEWLINE# @ argh . arg ( '-i' , '--inherit-node' , metavar = 'NODE' , type = str , default = '' , dest = 'inherit_node' , help = 'inherit from node (regexp)' ) #NEWLINE# @ arg_flag ( '-c' , '--copy-props' , help = "copy parent node's properties" ) #NEWLINE# @ expects_obj #NEWLINE# def handle_add_node( self , arg ) : #NEWLINE# #INDENT# 'add a new node' #NEWLINE# confman = self . get_confman ( arg . root_dir ) #NEWLINE# if arg . inherit_node : #NEWLINE# #INDENT# nodes = list ( confman . find ( arg . inherit_node , full_match = arg . full_match ) ) #NEWLINE# if ( len ( nodes ) == 0 ) : #NEWLINE# #INDENT# raise errors . UserError ( ( 'pattern %r does not match any nodes' % arg . inherit_node ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( nodes ) > 1 ) : #NEWLINE# #INDENT# raise errors . UserError ( ( 'pattern %r matches multiple nodes: %s' % ( arg . inherit_node , ', ' . join ( ( n . name for n in nodes ) ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# parent_node_name = nodes [ 0 ] . name #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# parent_node_name = None #NEWLINE# #UNINDENT# if arg . verbose : #NEWLINE# #INDENT# logger = self . log . info #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logger = self . log . debug #NEWLINE# #UNINDENT# ( n , m ) = util . parse_count ( arg . count ) #NEWLINE# for n in range ( n , m ) : #NEWLINE# #INDENT# node_name = arg . node . format ( id = n ) #NEWLINE# host = arg . host . format ( id = n ) #NEWLINE# confman . create_node ( node_name , host = host , parent_node_name = parent_node_name , copy_props = arg . copy_props ) #NEWLINE# if parent_node_name : #NEWLINE# #INDENT# msg = ( ' <= %s' % parent_node_name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg = '' #NEWLINE# #UNINDENT# logger ( 'node added: %s%s' , node_name , msg )