Author Topic: Perl SOAP machine w/o access to soap.zeus.com for methods  (Read 1920 times)

paulh

  • Member
  • **
  • Posts: 6
    • View Profile
Perl SOAP machine w/o access to soap.zeus.com for methods
« on: July 20, 2011, 04:47:23 pm »
The admin box running Perl to collect backups exists only on a management network.  It doesn't have internet access.
The sample Perl scripts have a uri  with soap.zeus.com.  Is there a way to download the commands under zstm (URI: http://soap.zeus.com/zxtm/1.0/System/Backups/) so that I can make them accessible for running backups?

Owen

  • Wizard
  • *****
  • Posts: 61
  • Zeus developer, "borrowed" by marketing
    • View Profile
    • Splash
    • Email
Re: Perl SOAP machine w/o access to soap.zeus.com for methods
« Reply #1 on: July 20, 2011, 05:25:04 pm »
The URI in the WSDL specification is not a web address; you can't resolve and download it.  Using a 'fake' URI is the usual convention for defining a unique namespace.

If you want to create a SOAP client, then you need to investigate the SOAP library support in your preferred language.  Some SOAP libraries require access to the WSDL file (which you can download from the admin interface - https://zeus:9090/apps/zxtm/help.fcgi?section=Manuals), and some are more lax and infer the WSDL specification (e.g. Perl SOAP::Lite).

There are simple examples for a range of languages on the Zeus community:

    http://www.zeus.com/community/search/list%20running%20virtual%20servers%20using

These examples compare and contrast the approaches used by each language to invoke the same SOAP methods

paulh

  • Member
  • **
  • Posts: 6
    • View Profile
Re: Perl SOAP machine w/o access to soap.zeus.com for methods
« Reply #2 on: July 22, 2011, 02:57:40 pm »
I reviewed the different coding examples. I'm trying to pull backups via either perl or php from a ZTM via a server without Internet access. This managment server will only use https (not http) to provide access to wsdl files that are local to the box.

I've pulled the wsdl file from the ZTM to the local system.
I've had some success using the php virtual server name script example.  I tweaked it to call the backup.wsdl file for testing. 

The script can access the wsdl file and list the embedded functions.
$conn = new SoapClient( "full path to .../System.Backups.wsdl",
$function_names = $conn->__getFunctions();
this piece works to dump the functions using a 'for' loop on the array.

Then I get
*********
Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in ...
*********
PHP example indicates that the wsdl file may need to directly call the ZTM.
For the test I updated the wsdl file soap:address to include the ZTM IP.

     soap:address location="https://user:password@x.x.x.x:9090/soap"

This is the first attempt to use soap to.  I used the unmodified wsdl file, then added my specific ZTM IP, then added the user:password. 
I've also added the 'login' and 'password' array elements to the PHP SoapClient call.
I tested the proxy_login/password and proxy_host (ZTM IP) elements in the SoapClient call as well. So far I can't get a connection.  I'm sure I'm missing something very basic.

Using the Perl example I get "unknown function called" no matter what the perl script is configured for.  I've pointed it at the ZTM for the wsdl, at the file system, at an https directory on the local server I'm running the script on.

I 'think' I'm closer to a php solution if I can figure out how to make the script access the ZTM since I can already read the wsdl file locally.
Sugguestions ?
Thanks

Owen

  • Wizard
  • *****
  • Posts: 61
  • Zeus developer, "borrowed" by marketing
    • View Profile
    • Splash
    • Email
Re: Perl SOAP machine w/o access to soap.zeus.com for methods
« Reply #3 on: July 22, 2011, 06:51:14 pm »
Hi Paul,

For more details on using Perl, this may help:

http://www.zeus.com/community/articles/how-can-i-use-perls-soaplite-zeus-control-api

Chapter 5 of the Control API manual has a bunch of debugging and troubleshooting tips that may help.

If you can get the ListVS php or perl examples working, then use these as templates and modify them to use the other methods you want to access.  Once you hit a block where you make a modification and it stops working, post here and we'll do our best to help

Owen

paulh

  • Member
  • **
  • Posts: 6
    • View Profile
Re: Perl SOAP machine w/o access to soap.zeus.com for methods
« Reply #4 on: July 27, 2011, 05:02:16 pm »
I'm making good progress and have the PHP script generating backups on a device.  I'm able to transfer the file to my server as well.  As long as I modify the wsdl file with the host IP and credientials. 
Is there a way to pass the wsdl file the hostname and logon/password so I don't have to directly modify the wsdl file?  I've tried adding parameters to the soapClient array without success.

In the wsdl file I have to change this:
<soap:address location="https://admin_server:9090/soap"/>
to this:
<soap:address location="https://username:passwordxyz@x.x.x.x:9090/soap"/>

PHPP script....
$conn = new SoapClient( "...fullpath/System.Backups.wsdl",
  array('login'=>"username",
        'password'=>"passwordxyz",
        'cache_wsdl' => 0)

Is there a way to pass "admin_server" as a variable to the wsdl file.  I've already tried defining 'admin_server' in the array options.  Didn't take.
Unless there is a way to pass this info into the wsdl I'll have to update the 'soap:address' line for each device I access.  That is workable but not as clean as passing a parameter if possible.
Thanks for any info.

Owen

  • Wizard
  • *****
  • Posts: 61
  • Zeus developer, "borrowed" by marketing
    • View Profile
    • Splash
    • Email
Re: Perl SOAP machine w/o access to soap.zeus.com for methods
« Reply #5 on: July 28, 2011, 09:57:21 am »
Hi Paul,

This might help?

http://www.php.net/manual/en/soapclient.setlocation.php

I've not tried it, but please let us know if it solves the problem (and I'll update the knowledgehub example if so)

regards

Owen

paulh

  • Member
  • **
  • Posts: 6
    • View Profile
Re: Perl SOAP machine w/o access to soap.zeus.com for methods
« Reply #6 on: August 02, 2011, 03:36:46 pm »
I think I have the kinks worked out now.  The script below will generate a backup and download it to the local Unix/Linux system.  The wsdl file is unmodified.  You would need to change the device_username and password to match your ZTM access credentials.  Useage is 'zeus.php -ip=x.x.x.x'
Sorry for any typos introduced by stripping out my specific paths/credientals...

#!/usr/bin/php
<?
// This script will generate a backup on the ZTM and then download it to the
// local file system.  The wsdl file in this example is passed to the SoapClient
// using a full path to the file itself rather than an URL (which could also be used).
// Error handling is used to prevent errors from terminating the script.  This would
// be useful if accessing several devices in series or for debugging.

//Set the soap handler
set_exception_handler('exception_handler');

// Break out the CLI parameters
foreach($argv as $arg)
  {
  print "Current arg: ".$arg."\n";
  if (strstr($arg,"-ip"))
    { $result = explode('=',$arg); $ip = trim($result[1]); print "\nProcessing ip ".$ip."\n"; }
  }

if(!$ip){echo "No IP address given\nI'm expecting zeus.php -ip=x.x.x.x\n";exit();}

// Make a connection...put your full path to the wsdl or http reference here
$conn = new SoapClient( "/usr/local/zeus/System.Backups.wsdl",
  array('login'=>"device_username",
        'password'=>"device_password",
        'location'=>"https://".$ip.":9090/soap",
        'cache_wsdl' => 0)
);
//Delete backup file name as trying to create a backup with the same name
//as one that exists will generate an error.  Multiple names can be
//loaded for deletion.
$bk_names = array("testbackup");
try { $res = $conn->deleteBackups($bk_names);}
catch(SoapFault $exc){echo $exc->faultstring;}

echo "Now generate the backup on the ZTM\n";
try {$res = $conn->createBackup("testbackup","testbackup description");}
catch(SoapFault $exc){echo $exc->faultstring;}
//If you access the ZTM now you should see 'testbackup' listed among others
//generated by the GUI

echo "Downloading the backup\n";
// Configuration will be loaded into '$backup' variable
$backup = $conn->downloadBackup("testbackup");
//Write contents to a file...
file_put_contents("testbackup.tar",$backup);

//Function to catch and print out errors
function exception_handler($exception) {
  echo "Uncaught exception: " , $exception->getMessage(), "\n";
}
?>

Owen

  • Wizard
  • *****
  • Posts: 61
  • Zeus developer, "borrowed" by marketing
    • View Profile
    • Splash
    • Email
Re: Perl SOAP machine w/o access to soap.zeus.com for methods
« Reply #7 on: August 02, 2011, 05:03:03 pm »
Good find - I've updated the Community article with your tip concerning the location and cache_wsdl parameters.  http://www.zeus.com/community/code-samples/list-running-virtual-servers-using-php5  Regards, Owen