- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
python API NetMRI send variable to run Script broker->script->run
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-08-2018 07:28 AM
Hello,
i used your python example to run a script.
Now i would send variable informations to the script.
But in the job there ist no values.
devices = broker.find( op_DeviceName='like', val_c_DeviceName=args.device_id, select=['DeviceID'] ) script_broker = client.get_broker('Script') # submit the job to the NetMRI job_id = script_broker.run( name=script_name, device_ids=[x.DeviceID for x in devices], script_variables = "$commands_to_be_executed 'show version'", )
"script_variables = "$commands_to_be_executed 'show version'" will not be used.
Can you send me a example with one and two variables ?
Re: python API NetMRI send variable to run Script broker->script->run
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-08-2018 10:22 AM
Re: python API NetMRI send variable to run Script broker->script->run
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-08-2018 09:46 PM
Hello JBelamaric,
thanks for your reply.
But in the API Dokumentation - Python - v3_2_0.ScriptBroker "broker.run - INPUTS" i found:
script_variables Required:False type: String Optional variables to be passed to the script. Any variable name starting with $ will be passed through as input to the script.
But it will not work.
Re: python API NetMRI send variable to run Script broker->script->run
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-09-2018 08:14 AM
Re: python API NetMRI send variable to run Script broker->script->run
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-16-2018 08:29 AM
Hello JBelamari,
what ist wrong on this line ?
script_variables = "$commands_to_be_executed 'show version'",
Complete Lines:
job_id = script_broker.run( name=script_name, device_ids=[x.DeviceID for x in devices], script_variables = "$commands_to_be_executed 'show version'", )
The JOB starts but with no commdand 'show version'.
What is wrong ?
Re: python API NetMRI send variable to run Script broker->script->run
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-16-2018 09:20 AM
Re: python API NetMRI send variable to run Script broker->script->run
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-16-2018 09:25 AM
job_id = script_broker.run(
name=script_name,
device_ids=[x.DeviceID for x in devices],
”$commands_to_be_executed”="show version",
)
Though it might need to be a bit different syntax in Python.
Re: python API NetMRI send variable to run Script broker->script->run
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-16-2018 10:23 PM
Your Example did not work:
job_id = script_broker.run( name=script_name, device_ids=[x.DeviceID for x in devices], "$commands_to_be_executed"="show version", )
I get this error message: "SyntaxError: keyword can't be an expression"
Re: python API NetMRI send variable to run Script broker->script->run
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-17-2018 05:21 AM
Here is python script function from Sif that I adapted/adopted, it uses the api instead of the broker. The device id is hard coded:
def run_adhoc(): data = client.api_request( 'scripts/run', params={ 'name': "Ad Hoc Command Batch", '$commands_to_be_executed': "sh version", 'device_ids': "290", 'credential_mode':'requestor', } )
-Lon
Re: python API NetMRI send variable to run Script broker->script->run
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-17-2018 07:09 AM
The last example in the Perl Tutorial in the documentation shows how to do it in Perl:
# run the script against the devices specified on the
# command line.
my($job_id) = $client->broker->script->run({
name => 'API Example 9 - Synchronous Perl Job',
device_ids => \@ARGV,
'$command' => 'show version',
})->{JobID};
# fetch the Job object
my $job = $client->broker->job->show({ JobID => $job_id })->{job};
John
Re: python API NetMRI send variable to run Script broker->script->run
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-17-2018 07:58 AM
I have the solution
This tip helps me: Python - External Script to Run the "Ad Hoc Command Batch" on NetMRI
defaults = { "host": hostname, "username": username, "password": password, } client = InfobloxNetMRI( defaults.get("host"), defaults.get("username"), defaults.get("password"), # api_version=2.8, ) # get broker for specific API Object broker = client.get_broker('Device') # get devices job_commmands = "show version" devices = broker.find( op_DeviceName='like', val_c_DeviceName=args.device_id, select=['DeviceID'] ) script_broker = client.get_broker('Script') save_new = { "name" : script_name, "device_ids" : [x.DeviceID for x in devices], "$commands_to_be_executed" : job_commmands, "job_name" : "Show config", } job_id = script_broker.run(**save_new)
Thies Person inspired me (thanks to): JBelamaric, SBaksh, LThompson