Automation

Expand all | Collapse all

Turn off the Juniper when you finish Nobreak battery

Jump to Best Answer
  • 1.  Turn off the Juniper when you finish Nobreak battery

    Posted 01-31-2019 08:35
    Guys, I need help, I'm a layman.
    
    I have an installed network of the SRX300, but I already had many problems with the lack of energy.
    To help you install a no-break even then a 20-minute battery life.
    I would like to know how to make a script to turn off the juniper.
    On windows I created a GPO to execute a command when I shut down the computer,
    I do not know how to create the script to turn off Juniper equipment.

     


    #power-offi
    #nobreak
    #Shutdown
    #ssh


  • 2.  RE: Turn off the Juniper when you finish Nobreak battery

    Posted 01-31-2019 09:49
     
     
    For simplicity, how can I make windows send a command to shut down a JUNIPER SRX300?

    #Windows


  • 3.  RE: Turn off the Juniper when you finish Nobreak battery
    Best Answer

     
    Posted 01-31-2019 16:50

    You can use Python to power off a Junos device from a Windows PC.

    1. Install Python (Refer to PYEZ cookbook, link at the bootom)

    2. Install Junos PYEZ library on Windows PC. (Refer to PYEZ cookbook, link at the bootom)

    3. Open PowerShell and run the following commands, you can use the same in a Python script as well

    4. Ensure netconf over ssh is enabled on SRX device

    > show configuration system services netconf
    ssh;

    Windows PowerShell
    Copyright (C) Microsoft Corporation. All rights reserved.

    PS C:\Users\jnet> python
    Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import jnpr.junos
    >>> from jnpr.junos import Device
    >>> from jnpr.junos.exception import ConnectError
    >>> srx=Device(host='<IP address of host>',user='root',password='password') << non-root should work if it has permissions.
    >>> from jnpr.junos.utils.sw import SW
    >>> srx.open()
    Device(<IP>)
    >>> sw=SW(srx)
    >>> print(sw.poweroff())
    Shutdown NOW!
    [pid 98168]
    >>> print(sw.poweroff())

     

    >>Verification

    Stopping cron.
    .
    Feb 24 20:24:58 jlaunchd: database-replication (PID 90347) terminate signal 15 sent
    Feb 24 20:24:59 jlaunchd: ethernet-connectivity-fault-management (PID 90348) terminate signal 15 sent
    Feb 24 20:24:59 jlaunchd: stats-agent (PID 90349) terminate signal 15 sent
    Feb 24 20:25:00 jlaunchd: transport-control (PID 90350) terminate signal 15 sent
    Feb 24 20:25:00 jlaunchd: SDN-Telemetry (PID 90353) terminate signal 15 sent
    Feb 24 20:25:00 jlaunchd: routing (PID 90354) terminate signal 15 sent
    Feb 24 20:25:01 jlaunchd: firewall (PID 90355) terminate signal 15 sent
    Feb 24 20:25:01 jlaunchd: chassis-control (PID 90356) terminate signal 15 sent
    Feb 24 20:25:01 jlaunchd: alarm-management (PID 90358) terminate signal 15 sent
    Feb 24 20:25:05 jlaunchd: craft-control (PID 18017) exited with status=0 Normal Exit
    Waiting (max 60 seconds) for system process `vnlru' to stop...done
    Waiting (max 60 seconds) for system process `bufdaemon' to stop...done
    Waiting (max 60 seconds) for system process `syncer' to stop...
    Syncing disks, vnodes remaining...0 0 0 0 done
    All buffers synced.
    Uptime: 49d5h6m19s
    besw0: 4 Broadcom SDK kernel threads killed
    Khelp module "jsocket" can't unload until its refcount drops from 5 to 0.

    The operating system has halted.
    Turning the system power off.

     

    >> Reference

    https://www.juniper.net/us/en/training/jnbooks/day-one/automation-series/junos-pyez-cookbook/

    https://junos-pyez.readthedocs.io/en/2.1.7/_modules/jnpr/junos/utils/sw.html

    https://www.juniper.net/documentation/en_US/junos-pyez/topics/task/program/junos-pyez-device-rebooting.html



  • 4.  RE: Turn off the Juniper when you finish Nobreak battery

    Posted 02-01-2019 05:18

    First of all I would like to thank you for answering me. I ran exactly the step-by-step and ran and hung up my Juniper. My question is that I saved the Script as PS1 (powershell) and it's error. I do not know if this is the correct procedure. I just could not automate the script.



  • 5.  RE: Turn off the Juniper when you finish Nobreak battery

     
    Posted 02-01-2019 06:52

    You can save the file as shutdown.py, complete file contents at the bottom.

    Open Powershell and change to the directory with the file in it, and execute the script

    python.exe .\shutdown.py

     

    --> Shutdown.py

    import jnpr.junos
    from jnpr.junos import Device
    from jnpr.junos.exception import ConnectError
    srx=Device(host='<IP address of host>',user='root',password='password')
    from jnpr.junos.utils.sw import SW
    srx.open()
    sw=SW(srx)
    print(sw.poweroff())

     

    Thank You,

    ==========

    Please mark the Solution as Accepted, Kudos are appreciated as well.



  • 6.  RE: Turn off the Juniper when you finish Nobreak battery

    Posted 02-01-2019 07:02

    @pranavs

     

    I performed the procedure exactly as explained, executed successfully.

     

    Helped me a lot and I hope I can help other people.

     

    Thank you very much.