Infoblox Exchange Cybersecurity Roadshow 2020 – Join us!
North America | Europe | Middle East/Africa | Asia-Pacific

Network Change & Configuration Management

Reply
Accepted Solution

Perl API NetMRI send variable to run Script broker->script->run

csi-net
Techie
Posts: 14
1847     0

Hello I'd like to use python to execute a CSS script in netmri.

The CSS script is very simple:

 

Ad Hoc Command Batch:

 

Script-Filter:
    true

Script-Variables:
    $Commands_to_be_Executed    text        "Enter commands here, one per line"

########################################################################
Action:
    Execute Command Batch

Action-Description:
    Execute the commands contained in the Commands_to_be_Executed variable.

Action-Commands:
    $Commands_to_be_Executed

########################################################################

 

 

The python script is:

....

 

$Commands_to_be_Executed = "show clock"

 

script_broker = client.get_broker('Script')
     job_id = script_broker.run(name=Ad Hoc Command Batch,device_ids='switch01", script_variables=$Commands_to_be_Executed)

 

...

 

The issue is that in python you can't define variables with $, ho can we manage script_broker.run call in this case ?

 

 

 

 

Re: Perl API NetMRI send variable to run Script broker->script->run

Adviser
Posts: 407
1847     0

Are you just trying to pass a variable into Python or did you want to pass it to another script?

 

 

    # BEGIN-SCRIPT-BLOCK
    #
    # Script-Filter:
    #     true
    #
    # Script-Variables:
    #     $command word "show version"
    #
    # END-SCRIPT-BLOCK

    #command will be provided by NenMRI, just use command variable

    defaults = {
    "api_url": api_url,
    "http_username": http_username,
    "http_password": http_password,
    "job_id": job_id,
    "device_id": device_id,
    "batch_id": batch_id
    }

    # Create NetMRI context manager. It will close session after execution
    with NetMRIEasy(**defaults) as easy:
        easy.send_command(command)
Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

Re: Perl API NetMRI send variable to run Script broker->script->run

Adviser
Posts: 407
1847     0

To run a script you can edit the following for ConfigTemplate

 

Where $sif : 'siftest' is passing data to a variable Smiley Happy

 

broker = myeasy.broker('ConfigTemplate')
sif = {
#this is a TemplateID "id" : '35', "device_ids" : device_id, "$sif" : 'siftest', "$templatemode" : 'bulk' } broker.run (**sif)

 

 

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

Re: Perl API NetMRI send variable to run Script broker->script->run

csi-net
Techie
Posts: 14
1847     0

I'm scripting in python (on a linux Centos machine) and I'd like to pass variable to a CSS Netmri script the defined variable in CSS script is:

Script-Variables:
    $Commands_to_be_Executed

 

I tried you way:

..

    script_broker = client.get_broker('Script')
    sif = {
    "name" : 'Ad Hoc Command Batch',
    "device_ids" : '83',
    "$Commands_to_be_Executed" : 'show clock'
    }
    job_id = script_broker.run(**sif)

..

 

The Job is executed by the Netmri but the variable $Commands_to_be_Executed doesn't seams to be passed as 'show clock'.

 

07:40:29  Script-Variables 
 07:40:29   $commands_to_be_executed = '' 

 

 

Highlighted

Re: Perl API NetMRI send variable to run Script broker->script->run

csi-net
Techie
Posts: 14
1847     0

...

finally in work ..

 

"$commands_to_be_executed" : 'show clock'

 

As to be lowercase !!!! even if in the CSS isn't !

Re: Perl API NetMRI send variable to run Script broker->script->run

Adviser
Posts: 407
1848     0

That is correct, I miss that you were running it from an External box

Everything in NetMRI is lowercase and space is "_"

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh
Showing results for 
Search instead for 
Do you mean 

Recommended for You