#NEWLINE# @ auth #NEWLINE# def _PUT( self , * param , **params ) : #NEWLINE# #INDENT# host_id = self . chk_hostby1 ( param ) #NEWLINE# if ( host_id is None ) : #NEWLINE# #INDENT# return web . notfound ( ) #NEWLINE# #UNINDENT# if ( not validates_general ( self ) ) : #NEWLINE# #INDENT# self . logger . debug ( 'Change network general failed. Did not validate.' ) #NEWLINE# return web . badrequest ( self . view . alert ) #NEWLINE# #UNINDENT# modules = [ 'network' , 'resolv' , 'hosts' ] #NEWLINE# host = findbyhost1 ( self . orm , host_id ) #NEWLINE# dop = read_conf ( modules , self , host ) #NEWLINE# if ( dop is False ) : #NEWLINE# #INDENT# self . logger . error ( 'Change network general failed. Failed read conf.' ) #NEWLINE# return web . internalerror ( 'Internal Server Error. (Read Conf)' ) #NEWLINE# #UNINDENT# gateway = self . input . gateway #NEWLINE# hostname = self . input . fqdn #NEWLINE# nameservers = self . input . nameserver . strip ( ) . split ( ) #NEWLINE# domainname = re . sub ( '^[^\\.]+\\.' , '' , hostname ) #NEWLINE# hostname_short = re . sub ( ( '\\.%s$' % domainname ) , '' , hostname ) #NEWLINE# old_domainname = dop . get ( 'resolv' , [ 'domain' ] ) #NEWLINE# if ( old_domainname is False ) : #NEWLINE# #INDENT# old_domainname = dop . get ( 'network' , [ 'DOMAINNAME' ] ) #NEWLINE# #UNINDENT# if ( old_domainname is False ) : #NEWLINE# #INDENT# old_domainname = re . sub ( '^[^\\.]+\\.' , '' , os . uname ( ) [ 1 ] ) #NEWLINE# #UNINDENT# old_hostname = dop . get ( 'network' , [ 'HOSTNAME' ] ) #NEWLINE# if ( old_hostname is False ) : #NEWLINE# #INDENT# old_hostname = os . uname ( ) [ 1 ] #NEWLINE# #UNINDENT# old_hostname_short = re . sub ( ( '\\.%s$' % old_domainname ) , '' , old_hostname ) #NEWLINE# hosts_arr = dop . getconf ( 'hosts' ) #NEWLINE# for ( _k , _v ) in hosts_arr . iteritems ( ) : #NEWLINE# #INDENT# _host = dop . get ( 'hosts' , [ _k ] ) #NEWLINE# _value = _host [ 0 ] #NEWLINE# _comment = _host [ 1 ] #NEWLINE# _values = _value . strip ( ) . split ( ) #NEWLINE# new_values = [ ] #NEWLINE# for _entry in _values : #NEWLINE# #INDENT# if ( _entry == old_hostname ) : #NEWLINE# #INDENT# _entry = hostname #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( _entry == old_hostname_short ) : #NEWLINE# #INDENT# _entry = hostname_short #NEWLINE# #UNINDENT# #UNINDENT# new_values . append ( _entry ) #NEWLINE# #UNINDENT# new_value = ' ' . join ( new_values ) #NEWLINE# dop . set ( 'hosts' , [ _k ] , [ new_value , _comment ] ) #NEWLINE# #UNINDENT# dop . set ( 'network' , [ 'GATEWAY' ] , _v ) #NEWLINE# dop . set ( 'resolv' , [ 'nameserver' ] , nameservers ) #NEWLINE# dop . set ( 'resolv' , [ 'domain' ] , domainname ) #NEWLINE# dop . set ( 'network' , [ 'DOMAINNAME' ] , domainname ) #NEWLINE# dop . set ( 'network' , [ 'HOSTNAME' ] , hostname ) #NEWLINE# retval = write_conf ( dop , self , host ) #NEWLINE# if ( retval is False ) : #NEWLINE# #INDENT# self . logger . error ( 'Change network general failed. Failed write conf.' ) #NEWLINE# return web . internalerror ( 'Internal Server Error. (Write Conf)' ) #NEWLINE# #UNINDENT# return web . accepted ( url = web . ctx . path )