API-PleskExpand

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for Perl extension API::PleskExpand.

1.00 May 25 20:08:15 SAMST 2008
    - The first public release
1.01 Jun 1 19:07:04 SAMST 2008
    - Fix syntax error in Build.PL :(
    - Fix errors in documentation
1.02 Jun 8 13:32:18 SAMST 2008
    - Full support all ways of choosing a Plesk server, where the client will be created (autoselect and manual)
1.03 Jun 14 12:16:24 SAMST 2008 
    - Fix documentation, add tests
1.04 Jun 22 05:21:18 SAMST 2008
    - Add ability to attaching domains and accounts to templates
1.05 Jul 29 23:33:12 SAMST 2008
    - New function -- get all domains from Expand
1.06 Jul 31 17:34:55 SAMST 2008
    - Fixed Build.pl ( Test::LongString not in prereqs_build  list but required )
    - Add URI.pm as required module
1.07 Sep 12 01:04:09 SAMST 2008

lib/API/PleskExpand/Accounts.pm  view on Meta::CPAN

=cut

=head1 METHODS

=over 3

=item create()

Params:

  'select'             => 'optimal',
  'template-id'        =>  1,
  'attach_to_template' => 1, # attach account to a certain template
  'general_info'  => {
    login   => 'plesk_login',
    pname   => 'perldonal name',
    passwd  => 'userpasswd',
    status  => 0,                   # active
    cname   => '',                  # company name
    phone   => '',
    fax     => '',
    email   => '',
    address => '',
    city    => '',
    state   => '',                  # state, for USA only
    pcode   => '',
    country => 'RU',
  }

You can let Plesk Expand automatically select a Plesk server based on certain filtering parameters (params for 'select' field):

    'optimal' -- Least Integral Estimate (% used) selects the least loaded server (integrally estimated).
    'min_domains' -- Least Domains (% used) registers a client on the server with the minimum number of domains.
    'max_diskspace' -- Least Disk Space (% used) registers a client on the server with the minimum disk space used.
    '' -- Select manually, Specify the target Plesk server by selecting its name from the list.
 	
When choosing a 'manual' (select => '') option you should set server_id!
For 'optimal', 'min_domains', 'max_diskspace' you can ask additional server group id ('group_id' params) or server keyword ('server_keyword' param);


Return (Data::Dumper output):

  VAR1 = bless( {
    'answer_data'   => [ {
      'server_id'   => '1',
      'status'      => 'ok',
      'expiration'  => '-1',

lib/API/PleskExpand/Accounts.pm  view on Meta::CPAN

    if (ref $params{'general_info'} eq 'HASH') {
        my $template = '';
        
        if ($params{'template-id'}) {
            $template = create_node('tmpl_id', $params{'template-id'}) . 
                ( $params{'attach_to_template'} ? create_node('attach_to_template', '') : '' );
        } else {
            return ''; # template required
        }

        my $select = '';

        if ($params{'select'}) {

            if ( $params{'group_id'} ) {
                $select = create_node( 'server_auto', create_node( $params{'select'}, '') . 
                    create_node( 'group_id', $params{'group_id'} )  
                );
            } elsif ( $params{'server_keyword'} ) {
                $select = create_node( 'server_auto', create_node( $params{'select'}, '')  ). 
                    create_node( 'server_keyword', $params{'server_keyword'} );
            } else {
                 $select = create_node( 'server_auto', create_node( $params{'select'}, '') );
            }
        } else {

            if ( $params{'server_id'} ) {
                $select = create_node( 'server_id', $params{'server_id'} );
            } else {
                return ''; # server_id required!
            }
        }
        
        return create_node( 'add_use_template',
            generate_info_block('gen_info', %{ $params{'general_info'} } ) . '<!-- create_client -->' . $template . $select);

    } else {
        return '';  # not enought data
    }
}


# Parse XML response
# STATIC
sub create_response_parse {

t/expand.t  view on Meta::CPAN

{
    our $our_warning;
    local $SIG{__DIE__} = sub { $our_warning = shift; }; # confess <=> die
    eval { API::PleskExpand->new(%TestData::online_expand_valid_params)->aaa__bbbccc() };
    like($our_warning, qr/aaa__bbbccc/,
         'Checking AUTOLOAD by calling undefined method.');
}


my %create_account_data = (
    'select'        => 'optimal',
    'template-id'   =>  1,
    'general_info'  => {
        login   => 'suxdffffxx',
        pname   => 'stdsdffafff',
        passwd  => '1234d5678',
        status  => 0,
        cname   => '',
        phone   => '',
        fax     => '',
        email   => '',

t/expand.t  view on Meta::CPAN

is_string($create_request, $_, 'create account test') for 
'<add_use_template><gen_info><address></address><city></city><cname></cname>'        .
'<country>RU</country><email></email><fax></fax><login>suxdffffxx</login>'           .
'<passwd>1234d5678</passwd><pcode></pcode><phone></phone><pname>stdsdffafff</pname>' .
'<state></state><status>0</status></gen_info><!-- create_client -->'                 .
'<tmpl_id>1</tmpl_id><attach_to_template></attach_to_template><server_auto>'         .
'<optimal></optimal></server_auto></add_use_template>';


is_deeply(
    API::PleskExpand::Accounts::create( %create_account_data, select => ''),  
    '',
    'Manual select without server_id param'
);

like(
    API::PleskExpand::Accounts::create( %create_account_data, select => '', server_id => 5),  
    qr#<tmpl_id>1</tmpl_id><server_id>5</server_id></add_use_template>$#,
    'Manual select without server_id param'
);

like(
    API::PleskExpand::Accounts::create(
        %create_account_data,
        select   => 'optimal',
        group_id => 2
    ),
    qr#<tmpl_id>1</tmpl_id><server_auto><optimal></optimal><group_id>2</group_id></server_auto></add_use_template>$#x,
    'Select "Optimal server" with group_id',
);

like(
    API::PleskExpand::Accounts::create(
        %create_account_data,
        select         => 'optimal',
        server_keyword => 'Hosting'
    ),
    qr#<server_auto><optimal></optimal></server_auto><server_keyword>Hosting</server_keyword></add_use_template>$#,
    'Select "Optimal server" with keyword',
);

like(
    API::PleskExpand::Accounts::create( %create_account_data, select => 'min_domains', server_keyword => 'Hosting'),
    qr#<server_auto><min_domains></min_domains></server_auto><server_keyword>Hosting</server_keyword></add_use_template>$#x,
    'Select server has "max_diskspace" with keyword',
);


like(
    API::PleskExpand::Accounts::create( %create_account_data, select => 'max_diskspace', server_keyword => 'Hosting'),
    qr#<server_auto><max_diskspace></max_diskspace></server_auto><server_keyword>Hosting</server_keyword></add_use_template>$#,
    'Select server has "min_domains" with keyword',
);



my $delete_query = API::PleskExpand::Accounts::delete( id => 15 );

is_deeply( $delete_query . "\n", <<DOC, 'delete account test');
<del><!-- del_client --><filter><id>15</id></filter></del>

t/expand.t  view on Meta::CPAN


exit unless $ENV{'online_stress_tests'};

my ($domain_template_id, $client_template_id);
$domain_template_id = $client_template_id = $ENV{template_id} || 1;

diag "Online tests start!";
# 5 tests -- full set !!!
my $login = $ENV{'online_stress_tests_login'} || 'expandtestaccount';
my $create_account_result = $expand_client->Accounts->create(
    'select'             => 'optimal',
    'template-id'        =>  $client_template_id,
    'attach_to_template' => 1,
    'general_info'  => {
        login   => $login,
        pname   => $login,
        passwd  => 'asdasdasd',
        status  => 0,
        cname   => '',
        phone   => '',
        fax     => '',



( run in 0.557 second using v1.01-cache-2.11-cpan-49f99fa48dc )