doujinge9648 2015-11-27 15:10
浏览 199
已采纳

使用PHP NETCONF配置Juniper路由器

I'm using the PHP library for NETCONF: https://github.com/Juniper/netconf-php . So far I have managed to get the configuration parts I need for my scripts, but the recent challenge remains loading new configurations into the router. The logs on my router:

Nov 27 14:34:48  router.nl sshd[78164]: subsystem request for netconf by user user
Nov 27 14:34:48  router.nl mgd[78168]: UI_CMDLINE_READ_LINE: User 'x', command 'xml-mode netconf need-trailer '
Nov 27 14:34:48  router.nl file[78167]: UI_LOGIN_EVENT: User 'x' login, class 'j-super-user' [78167], ssh-connection 'x.x.x.x 46796 x.x.x.x 22', client-mode 'netconf'
Nov 27 14:34:48  router.nl file[78167]: UI_NETCONF_CMD: User 'x' used NETCONF client to run command 'lock cannot reconstruct arguments'
Nov 27 14:34:48  router.nl file[78167]: UI_NETCONF_CMD: User 'x' used NETCONF client to run command 'edit-config cannot reconstruct arguments default-operation=merge cannot reconstruct arguments'
Nov 27 14:34:48  router.nl file[78167]: UI_NETCONF_CMD: User 'x' used NETCONF client to run command 'unlock cannot reconstruct arguments'
Nov 27 14:34:48  router.nl file[78167]: UI_NETCONF_CMD: User 'x' used NETCONF client to run command 'close-session'

It keeps complaining about not being able to reconstruct arguments. This is the script I'm trying to get working:

require_once '../app/include/netconf/Device.php';

$deviceParams = [
    'hostname'  => 'x.x.x.x',
    'username'  => 'x',
    'password'  => 'password',
    'port'      => 22
    ];

$this->device = new Device($deviceParams);
$this->connectRouter();

$islocked = $this->device->lock_config();

$command = '<system><services><ftp/></services></system>';

if($islocked) {              
    $this->device->load_xml_configuration($command, 'merge');
}

$this->device->unlock_config();

$this->device->close();

I've set up traceoqptions under the netconf { ssh { tree and this is one of the outputs (everything seems ok):

Nov 30 10:41:57 [86546] Incoming:
<rpc><edit-config><target><candidate/></target><default-operation>merge</default-operation><config><configuration><system><services><ftp></ftp></services></system></configuration></config></edit-config></rpc>]]>]]>


Nov 30 10:41:57 [86546] Outgoing: <rpc-reply     xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/12.3R8/junos">
Nov 30 10:41:57 [86546] Outgoing: <ok/>
Nov 30 10:41:57 [86546] Outgoing: </rpc-reply>
Nov 30 10:41:57 [86546] Outgoing: ]]>]]>
Nov 30 10:41:57 [86546] Incoming: <rpc><close-session/></rpc>]]>]]>
  • 写回答

2条回答 默认 最新

  • dpi9530 2015-11-30 12:24
    关注

    The first logs I have shown in my OP do not say anything but telling me that something went wrong. The traceoptions however, did tell me important information after I tried locking/unlocking the configuration:

    Nov 30 12:06:43 [86767] Outgoing: <rpc-error>
    Nov 30 12:06:43 [86767] Outgoing: <error-type>protocol</error-type>
    Nov 30 12:06:43 [86767] Outgoing: <error-tag>operation-failed</error-tag>
    Nov 30 12:06:43 [86767] Outgoing: <error-severity>error</error-severity>
    Nov 30 12:06:43 [86767] Outgoing: <error-message>
    Nov 30 12:06:43 [86767] Outgoing: configuration database modified
    Nov 30 12:06:43 [86767] Outgoing: </error-message>
    Nov 30 12:06:43 [86767] Outgoing: </rpc-error>
    Nov 30 12:06:43 [86767] Outgoing: </rpc-reply>
    Nov 30 12:06:43 [86767] Outgoing: ]]>]]>
    

    A quick search on 'configuration database modified' implies that there were still some uncommitted changes ( http://www.juniper.net/documentation/en_US/junos13.3/topics/topic-map/junos-script-automation-service-template-automation.html , bottom page ):

    Problem
    
    You see the following message when creating, updating, or deleting a service on a device through a NETCONF session:
    
    <output>
        configuration database modified
    </output>
    
    The configuration has previously uncommitted changes, and the service script cannot commit the service configuration changes.
    

    Simply typing 'commit' in the configuration mode made the error go away. I hope I have helped / will help others in the future.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档