API-PleskExpand

 view release on metacpan or  search on metacpan

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

#
# DESCRIPTION:
#   Plesk Expand communicate interface. Static methods for managing Plesk user accounts from Plesk Expand.
# AUTHORS:
#   Pavel Odintsov (nrg) <pavel.odintsov@gmail.com>
#
#========================================================================

package API::PleskExpand::Accounts;

use strict;
use warnings;

use API::Plesk::Methods;
use Data::Dumper;

our $VERSION = '1.04';

=head1 NAME

API::PleskExpand::Accounts - extension module for the management Plesk user accounts from Plesk Expand.

=head1 SYNOPSIS

Directly not used, calls via API::PleskExpand.

 use API::PleskExpand;

 some code

=head1 DESCRIPTION

The module provides full support operations with Plesk accounts from Plesk Expand.

=head1 EXPORT

None by default.

=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',
      'tmpl_id'     => '1',
      'id'          => '15'
    } ], 
    'error_codes' => ''
  }, 'API::Plesk::Response' );

=cut

# Create element
# STATIC
sub create {

    my %params = @_;

    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
    }
}



( run in 0.504 second using v1.01-cache-2.11-cpan-39bf76dae61 )