Previous page

Next page

Locate page in Contents

Print this page

The Complete Program Code

#!/usr/bin/perl -w

#

#Copyright (c) 2008 by SWsoft

#

use strict;

#Set $SSL_ON = 1 if you wish to use secure connection.

use constant SSL_ON => 0;

#Connection information.

use constant CONF_CONNECTION => {

ip => '192.168.0.37',

port => &SSL_ON ? 4434 : 4433,

class => &SSL_ON ? 'IO::Socket::SSL' : 'IO::Socket::INET'

};

eval "use ".&CONF_CONNECTION->{class};

die $@ if $@;

#Null-terminating character (packet separator).

use constant MSG_TERMINATOR => "\0";

local $/ = &MSG_TERMINATOR;

#Create socket

print "Connecting to Agent...\n\n";

our $socket = &CONF_CONNECTION->{class}->new(

PeerAddr => &CONF_CONNECTION->{ip},

PeerPort=> &CONF_CONNECTION->{port},

Proto => 'tcp',

);

unless($socket) {

die "Connection refused: $!"

}

#Read the greeting message from Agent.

my $hello = $socket->getline;

chomp($hello);

print $hello;

print "\n";

print "------------------------\n\n";

#XML message. Getting the list of realms.

my $request=qq~

<packet id="2">

  <data>

    <system>

      <get_realm/>

    </system>

  </data>

</packet>

~;

#Write the XML message to the socket.

print "Getting a list of realms...\n\n";

$socket->printflush($request.&MSG_TERMINATOR);

#Read the response and display it on the screen.

my $response = $socket->getline;

chomp($response);

print $response;

print "\n";

print "------------------------\n\n";

#XML message. Logging on.

#Change the name and password to your

#administrator name and password.

$request=qq~

<packet version="4.0.0" id="3">

  <data>

    <system>

      <login>

        <name>cm9vdA==</name>

        <realm>00000000-0000-0000-0000-000000000000</realm>

        <password>bXlwYXNz</password>

      </login>

    </system>

  </data>

</packet>

~;

#Write the XML message to the socket.

print "Logging on...\n\n";

$socket->printflush($request.&MSG_TERMINATOR);

#Read the response and display it on the screen.

$response = $socket->getline;

chomp($response);

print $response;

print "\n";

print "------------------------\n\n";

#XML message. Getting a list of Virtuozzo Containers.

$request=qq~

<packet version="4.0.0" id="4">

  <target>vzaenvm</target>

  <data>

    <vzaenvm>

      <get_list/>

    </vzaenvm>

  </data>

</packet>

~;

#Write the XML message to the socket.

print "Getting a list of Containers...\n\n";

$socket->printflush($request.&MSG_TERMINATOR);

#Read the response and display it on the screen.

$response = $socket->getline;

chomp($response);

print $response;

print "\n";

print "------------------------\n\n";

#XML message. Restarting a Container.

#Change the Server ID to the ID of your Container.

$request=qq~

<packet version="4.0.0" id="4">

  <target>vzaenvm</target>

  <data>

    <vzaenvm>

      <restart>

        <eid>e9ab2834-ed97-1f4b-bd41-81c27facfc30</eid>

      </restart>

    </vzaenvm>

  </data>

</packet>

~;

#Write the XML message to the socket.

print "Restarting a Container...\n\n";

$socket->printflush($request.&MSG_TERMINATOR);

#Read the response and display it on the screen.

$response = $socket->getline;

chomp($response);

print $response;

print "\n";

print "------------------------\n\n";

Please send us your feedback on this help page