Closed Bradherbert closed 1 year ago
Can you post the Python code that you are trying to use and the error that you get?
Good day Kirk
Thank you for the prompt reply. The issue was the 5M at the end. I found a way using Paramiko. if you can guide me on Netmiko I would still appreciate it
net_connect=ConnectHandler(device_type=platform, ip=host, username=username, password=password, global_delay_factor=3)
cmd='configure private'
output = net_connect.send_command(
cmd,
expect_string=r'#'
)
output += net_connect.send_command('\n', expect_string=r'#')
print(output)
interface="set groups CUSTOMER-AINX-SDN001 interfaces ge-2/1/0 unit 1240 description"
output = net_connect.send_command(
'set groups CUSTOMER-AINX-SDN001 interfaces ge-2/1/0 unit 1240 description',
'"CUSTOMER-ENS|SDN001|WIER-KATHU|ZN-NE-TER-DCE-1|TO|MTN-CPE|N/A|5M|"',
expect_string=r'#'
)
output += net_connect.send_command('\n', expect_string=r'#')
print(output)
this was the code for Juniper. connecting was not the issue. The above may be a bit of a mess, I tried every option I could find on the net. (newbee)
@Bradherbert
Your syntax above looks wrong i.e. in your send_command() call.
You should probably be using send_config_set
:
net_connect=ConnectHandler(
device_type=platform,
ip=host,
username=username,
password=password
)
command = (
'set groups CUSTOMER-AINX-SDN001 interfaces ge-2/1/0 unit 1240 description '
'"CUSTOMER-ENS|SDN001|WIER-KATHU|ZN-NE-TER-DCE-1|TO|MTN-CPE|N/A|5M|"'
)
net_connect.send_config_set(command)
You would also need to do commit.
Let me know if the above works.
Good day Kirk
Thank you again. The script itself does work, but looking at the logs on the juniper, once the "command" is sent it automatically logs out before running the next command, being "commit and-quit"
Juniper logs Jan 11 10:37:41 GP-ID-DCE-1 mgd[22088]: UI_CFG_AUDIT_SET: User 'brad' set: [groups CUSTOMER-AINX-SDN001 interfaces ge-2/1/0 unit 1240 description] "CUSTOMER-ENS|SDN001|WIER-KATHU|GP-ID-DCE-1|TO|MTN-CPE|N/A|7M| -> "CUSTOMER-ENS|SDN001|WIER-KATHU|ZN-NE-TER-DCE-1|TO|MTN-CPE|N/A|12M|" Jan 11 10:37:41 GP-ID-DCE-1 mgd[22088]: UI_DBASE_LOGOUT_EVENT: User 'brad' exiting configuration mode Jan 11 10:37:41 GP-ID-DCE-1 mgd[22088]: UI_DBASE_LOGIN_EVENT: User 'brad' entering configuration mode Jan 11 10:37:41 GP-ID-DCE-1 mgd[22088]: UI_COMMIT: User 'brad' requested 'commit' operation (comment: none) Jan 11 10:37:41 GP-ID-DCE-1 mgd[22088]: UI_DBASE_LOGOUT_EVENT: User 'brad' exiting configuration mode
code is as follows
net_connect=ConnectHandler(device_type=platform, ip=host, username=username, password=password, global_delay_factor=3)
cmd= ( "configure private" ) net_connect.send_command( cmd, expect_string=r'#' ) command = ( "set groups CUSTOMER-AINX-SDN001 interfaces ge-2/1/0 unit 1240 description " '"CUSTOMER-ENS|SDN001|WIER-KATHU|ZN-NE-TER-DCE-1|TO|MTN-CPE|N/A|12M|"' ) net_connect.send_config_set( command )
logout = ( 'commit and-quit' ) net_connect.send_config_set(logout)
On Wed, Jan 11, 2023 at 3:51 AM Kirk Byers @.***> wrote:
@Bradherbert https://github.com/Bradherbert
Your syntax above looks wrong i.e. in your send_command() call.
You should probably be using send_config_set:
net_connect=ConnectHandler( device_type=platform, ip=host, username=username, password=password )command = ( "set groups CUSTOMER-AINX-SDN001 interfaces ge-2/1/0 unit 1240 description " '"CUSTOMER-ENS|SDN001|WIER-KATHU|ZN-NE-TER-DCE-1|TO|MTN-CPE|N/A|5M|"' )net_connect.send_config_set(command)
You would also need to do commit.
Let me know if the above works.
— Reply to this email directly, view it on GitHub https://github.com/ktbyers/netmiko/issues/3075#issuecomment-1378140741, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5E5PEJFRBAHLHRUVNLY5HDWRYGZ3ANCNFSM6AAAAAATVMMRCQ . You are receiving this because you were mentioned.Message ID: @.***>
The Juniper driver has a commit()
method, it is probably better if you use that instead.
Good day Kirk
'exit_config_mode=False' added in the send.config.set prevented Netmiko exiting after sending the commands. This then allowed me to send 'commit'. Thank you for your assistance. copy of code for reference if ever needed.
from netmiko import ConnectHandler
host = input("IP address of device: ") username = xxx password = xxx platform = "juniper_junos"
net_connect = ConnectHandler(device_type=platform, ip=host, username=username, password=password, global_delay_factor=3)
cmd = ( "edit private" ) net_connect.send_command( cmd, expect_string=r'#' )
customer=input("Customer group: ") interface=input("Interface: ") vlan = input("VLAN ID: ") int_des = input("interface descriptions: ")
command = ( "set groups " + customer + " interfaces " + interface + " unit " + vlan + " description "'"' + int_des + '"' "" ) output = net_connect.send_config_set( command, exit_config_mode=False ) print(output)
net_connect.commit()
net_connect.disconnect()
print("") print("") print("Interface descriptions have been updated ;) ")
On Wed, Jan 11, 2023 at 8:09 PM Kirk Byers @.***> wrote:
The Juniper driver has a commit() method, it is probably better if you use that instead.
— Reply to this email directly, view it on GitHub https://github.com/ktbyers/netmiko/issues/3075#issuecomment-1379289815, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5E5PEKFOQOL56OP6ZRNXHDWR3ZMJANCNFSM6AAAAAATVMMRCQ . You are receiving this because you were mentioned.Message ID: @.***>
I have no issues creating scripts to pull information, what I cannot get right is changing the interface descriptions with special characters, such as a |
the description I want to send is as follows : set groups CUSTOMER-AINX-SDN001 interfaces ge-2/1/0 unit 1240 description "CUSTOMER-ENS|SDN001|WIER-KATHU|ZN-NE-TER-DCE-1|TO|MTN-CPE|N/A||5M"
anyony know how to overcome this? I have tried various programs and none seem to work.