#!/usr/bin/perl # # Module: test_rest_api.pl # # **** License **** # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # This code was originally developed by Vyatta, Inc. # Portions created by Vyatta are Copyright (C) 2009-2010 Vyatta, Inc. # All Rights Reserved. # # Author: Stig Thormodsrud # Date: August 2010 # Description: Script to use show examples using Vyatta::RestApi.pm # # **** End License **** # use strict; use warnings; use RestApi; my $cli = RestApi->new(); $cli->auth('172.16.117.2', 'vyatta', 'vyatta'); my ($cmd, $err, $output); # # Run op mode command # $cmd = "show version"; ($err, $output) = $cli->run_op_cmd($cmd); print "run_op_cmd [$cmd]\n"; print "Error $err\n" if defined $err; print $output, "\n" if defined $output; # # Change conf mode # print "Changing host-name to 'uffda'\n"; # 1) enter configure mode $err = $cli->configure(); print "configure error $err\n" if defined $err; # 2) set/delete $err = $cli->set('set system host-nam uffda'); print "set error $err\n" if defined $err; # 3) commit $err = $cli->commit(); print "commit error $err\n" if defined $err; # 4) save $err = $cli->save(); print "save error $err\n" if defined $err; # 5) exit $err = $cli->configure_exit(); print "exit error $err\n" if defined $err; # 6) verify change print "show host name\n"; ($err, $output) = $cli->run_op_cmd('show host name'); print "show error $err\n" if defined $err; print $output, "\n" if defined $output; # # Run batch of conf mode cmds # print "Run batch conf mode\n"; my @conf_cmds = ('set system host-name r1', 'set system time-zone US/Pacific', ); $cli->batch_conf_cmds(@conf_cmds); print "show host name\n"; ($err, $output) = $cli->run_op_cmd('show host name'); print "show error $err\n" if defined $err; print $output, "\n" if defined $output; # end of file ------------------- stig@io:~$ ./test_rest2.pl run_op_cmd [show version] Version: 999.larkspurse.08040054 Description: 999.larkspurse.08040054 Copyright: 2006-2010 Vyatta, Inc. Built by: autobuild@vyatta.com Built on: Wed Aug 4 07:54:16 UTC 2010 Build ID: 1008040754-036ba5e Boot via: image Uptime: 11:47:45 up 19:57, 1 user, load average: 0.00, 0.00, 0.00 Changing host-name to 'uffda' set error set error on put [https://172.16.117.2/rest/conf/BC38F2EB1E531D08/set/system/host-nam/uffda] - 400 Bad Request show host name r1 Run batch conf mode show host name r1