首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用PHP NETCONF配置Juniper路由器

用PHP NETCONF配置Juniper路由器
EN

Stack Overflow用户
提问于 2015-11-27 15:10:31
回答 2查看 1.4K关注 0票数 1

我正在为NETCONF:https://github.com/Juniper/netconf-php使用PHP库。到目前为止,我已经成功地获得了脚本所需的配置部件,但最近的挑战仍然是将新配置加载到路由器中。我路由器上的日志:

代码语言:javascript
复制
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'

它一直抱怨不能重建论点。这就是我想要得到的剧本:

代码语言:javascript
复制
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();

我已经在netconf { ssh {树下设置了跟踪,这是输出之一(一切似乎都正常):

代码语言:javascript
复制
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>]]>]]>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-11-30 12:24:43

我在操作中显示的第一批日志没有说什么,而是告诉我出了问题。然而,在我尝试锁定/解锁配置之后,跟踪选项告诉了我一些重要的信息:

代码语言:javascript
复制
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: ]]>]]>

快速搜索“修改配置数据库”意味着仍有一些未提交的更改( US/junos13.3/topics/topic-map/junos-script-automation-service-template-automation.html,底部页):

代码语言:javascript
复制
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.

只要在配置模式中输入'commit‘,错误就会消失。我希望我将来能帮助别人。

票数 0
EN

Stack Overflow用户

发布于 2016-07-14 15:03:35

不确定PHP中的netconf (仍在使用),但在Python中,最好始终使用“配置私有”:

代码语言:javascript
复制
junos_dev.open()
with Config(junos_dev, mode='private') as cu:
  cu.load(some_string, format='set')
  #print cu.diff()
  cu.commit()
junos_dev.close()

(现在我也在这里找到了相关的函数): /** *这个方法应该被调用,以便在‘私有’模式下进行加载操作。*@param模式*打开配置的模式。*允许模式:“私有”*/公共功能open_configuration($mode)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33960241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档