使用 PHP NETCONF 配置 Juniper 路由器
Configuring Juniper routers with PHP NETCONF
我正在为 NETCONF 使用 PHP 库:https://github.com/Juniper/netconf-php。到目前为止,我已经设法获得我的脚本所需的配置部分,但最近的挑战仍然是将新配置加载到路由器中。我路由器上的日志:
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'
一直抱怨无法重构参数。这是我正在尝试运行的脚本:
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 { 树下设置了 traceoqptions,这是输出之一(一切似乎都正常):
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>]]>]]>
我在 OP 中显示的第一个日志什么也没说,只是告诉我出了点问题。然而,在我尝试 locking/unlocking 配置后,traceoptions 确实告诉了我重要信息:
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: ]]>]]>
在 'configuration database modified' 上快速搜索意味着仍有一些未提交的更改(http://www.juniper.net/documentation/en_US/junos13.3/topics/topic-map/junos-script-automation-service-template-automation.html,底部页面):
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' 即可使错误消失。我希望我帮助过/将来会帮助别人。
不确定 PHP 中的 netconf(仍在潜入)但在 Python 中你应该始终优先使用 'configure private':
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()
现在我在这里也找到了相关的功能:
/**
*应该调用此方法以在 'private' 模式下进行加载操作。
*@参数模式
* 打开配置的模式。
* 允许的模式:"private"
*/
public 函数 open_configuration($模式)
我正在为 NETCONF 使用 PHP 库:https://github.com/Juniper/netconf-php。到目前为止,我已经设法获得我的脚本所需的配置部分,但最近的挑战仍然是将新配置加载到路由器中。我路由器上的日志:
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'
一直抱怨无法重构参数。这是我正在尝试运行的脚本:
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 { 树下设置了 traceoqptions,这是输出之一(一切似乎都正常):
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>]]>]]>
我在 OP 中显示的第一个日志什么也没说,只是告诉我出了点问题。然而,在我尝试 locking/unlocking 配置后,traceoptions 确实告诉了我重要信息:
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: ]]>]]>
在 'configuration database modified' 上快速搜索意味着仍有一些未提交的更改(http://www.juniper.net/documentation/en_US/junos13.3/topics/topic-map/junos-script-automation-service-template-automation.html,底部页面):
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' 即可使错误消失。我希望我帮助过/将来会帮助别人。
不确定 PHP 中的 netconf(仍在潜入)但在 Python 中你应该始终优先使用 'configure private':
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()
现在我在这里也找到了相关的功能: /** *应该调用此方法以在 'private' 模式下进行加载操作。 *@参数模式 * 打开配置的模式。 * 允许的模式:"private" */ public 函数 open_configuration($模式)