API-PleskExpand
view release on metacpan or search on metacpan
lib/API/PleskExpand.pm view on Meta::CPAN
if ($res->is_success) {
$res->get_data; # return arr ref of answer blocks
}
=head1 DESCRIPTION
At present the module provides interaction with Plesk Expand 2.2.4 (API 2.2.4.1). Complete support of operations with Accounts, partial support of work with domains. Support of addition of domains to user Accounts.
API::PleskExpand module gives the convenient interface for addition of new functions. Extensions represent modules in a folder Plesk with definitions of demanded functions. Each demanded operation is described by two functions: op and op_response_par...
For example, here the set of subs in the Accounts module is those.
create / create_response_parse
modify / modify_response_parse
delete / delete_response_parse
get / get_response_parse
=head1 EXPORT
Nothing.
lib/API/PleskExpand/Accounts.pm view on Meta::CPAN
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
my $filter = '';
if ($params{'id'}) {
$filter = create_filter(login_field_name => 'id', id => $params{'id'});
} else {
return ''; # filter required!
}
return create_node('set', $filter . '<!-- modify_client -->' . create_node('values',
generate_info_block('gen_info', %{ $params{'general_info'} } ) ) );
} else {
return ''; # general_info field required !
}
# вÑклÑÑение клиенÑа
my $data=<<DOC;
<?xml version="1.0"?>
<packet version="0.0.0.110">
<set>
<filter>
<id>1</id>
</filter>
<values>
<gen_info>
<status>16</status>
</gen_info>
</values>
</set>
</packet
DOC
# вклÑÑаем клиенÑа
my $data1 = <<DOC;
<?xml version="1.0"?>
<packet version="0.0.0.110">
<set>
<filter>
<id>1</id>
</filter>
<values>
<gen_info>
<status>0</status>
</gen_info>
</values>
</set>
</packet>
DOC
}
# SET response handler
# STATIC
sub modify_response_parse {
return abstract_parser('set', +shift, []);
}
=item delete(%params)
Delete accounts.
Params:
id -- client id in Plesk
lib/API/PleskExpand/Accounts.pm view on Meta::CPAN
# Get all element data
# STATIC
sub get {
my %params = @_;
unless ($params{all}) {
return '';
}
return create_node( 'get',
create_node('filter', '') . create_node( 'dataset', create_node('gen_info') )
) . '<!-- get_client -->';
}
# GET response handler
# STATIC
sub get_response_parse {
my $answer = abstract_parser('get', +shift, [ ], 'system_error' );
if (ref $answer eq 'ARRAY') {
lib/API/PleskExpand/Domains.pm view on Meta::CPAN
'vrt_hst',
'ftp_login' => $params{'ftp_login'},
'ftp_password' => $params{'ftp_password'},
)
);
my $template_block = create_node('tmpl_id', $params{'template-id'}) .
( $params{'attach_to_template'} ? create_node('attach_to_template', '') : '' );
return create_node( 'add_use_template',
create_node(
'gen_setup',
create_node( 'name', $params{dname} ) .
create_node( 'client_id', $params{client_id} ) .
create_node( 'status', 0)
) . $hosting_block . '<!-- create_domain -->' . $template_block
);
}
# Parse XML response
# STATIC
lib/API/PleskExpand/Domains.pm view on Meta::CPAN
# Get all element data
# STATIC
sub get {
my %params = @_;
unless ($params{all}) {
return '';
}
#return '<get><filter></filter><dataset><gen_info/></dataset></get><!-- create_domain -->';
return create_node( 'get',
create_node('filter', '') . create_node( 'dataset', create_node('gen_info') )
) . '<!-- create_domain -->';
}
# GET response handler
# STATIC
sub get_response_parse {
my $answer = abstract_parser('get', +shift, [ ], 'system_error' );
if (ref $answer eq 'ARRAY') {
DOC
my $modify_query = API::PleskExpand::Accounts::modify(
id => 15,
general_info => { status => 16 } # deactivate!
);
is_string( $modify_query, $_, 'modify account test') for
'<set><filter><id>15</id></filter><!-- modify_client --><values>' .
'<gen_info><status>16</status></gen_info></values></set>';
my $modify_query_alter = API::PleskExpand::Accounts::modify(
id => 5,
general_info => { status => 0 } # deactivate!
);
is_string( $modify_query_alter, $_, 'modify account test') for
'<set><filter><id>5</id></filter><!-- modify_client --><values>' .
'<gen_info><status>0</status></gen_info></values></set>';
my %new_domain_data = (
dname => 'y2a1ddsdfandex.ru',
client_id => 16,
'template-id' => 1,
ftp_login => 'nrddgddsdasd',
ftp_password => 'dadsdasd',
);
my $create_domain = API::PleskExpand::Domains::create( %new_domain_data );
is_string( $create_domain, $_, 'modify account test') for
'<add_use_template><gen_setup><name>y2a1ddsdfandex.ru</name>' .
'<client_id>16</client_id><status>0</status></gen_setup>' .
'<hosting><vrt_hst><ftp_login>nrddgddsdasd</ftp_login>' .
'<ftp_password>dadsdasd</ftp_password></vrt_hst></hosting>' .
'<!-- create_domain --><tmpl_id>1</tmpl_id></add_use_template>';
$create_domain = API::PleskExpand::Domains::create( %new_domain_data, attach_to_template => 1 );
is_string( $create_domain, $_, 'modify account test') for
'<add_use_template><gen_setup><name>y2a1ddsdfandex.ru</name>' .
'<client_id>16</client_id><status>0</status></gen_setup>' .
'<hosting><vrt_hst><ftp_login>nrddgddsdasd</ftp_login>' .
'<ftp_password>dadsdasd</ftp_password></vrt_hst></hosting>' .
'<!-- create_domain --><tmpl_id>1</tmpl_id>' .
'<attach_to_template></attach_to_template></add_use_template>';
$expand_client->{dump_headers} = 1; # debugg =)
is_deeply(
$expand_client->_execute_query('<add_use_template><!-- create_domain --></add_use_template>'),
{
{
'server_id' => '1',
'status' => 'ok',
'tmpl_id' => '1',
'id' => '32',
'plesk_client_id' => '395',
'login' => 'aseaasdsassrews'
},
'parse success modify xml response'
) for '<?xml version="1.0" encoding="UTF-8" standalone="no" ?><packet version="2.2.4.1">' .
'<set><result><status>ok</status><id>32</id><server_id>1</server_id><tmpl_id>1</tmpl_id>' .
'<plesk_client_id>395</plesk_client_id><login>aseaasdsassrews</login></result></set></packet>';
is_deeply(
API::PleskExpand::Accounts::delete_response_parse( $_ ),
{
'server_id' => '1',
'status' => 'ok',
'id' => '33',
},
'parse success delete xml response'
server_id => 1,
},
'parse fail add domain xml response')
for '<?xml version="1.0" encoding="UTF-8" standalone="no" ?><packet version="2.2.4.1"><add_use_template>' .
'<result><status>error</status><errcode>4304</errcode><errtext>[Operator] Domain already exists.' .
" Plesk domain 'yandex.ru' is exist.</errtext><client_id>40</client_id><server_id>1</server_id>" .
'<tmpl_id>1</tmpl_id><expiration>-1</expiration></result></add_use_template></packet>';
is_string(
API::PleskExpand::Domains::get(all => 1),
'<get><filter></filter><dataset><gen_info/></dataset></get><!-- create_domain -->',
'Domains get'
);
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,
( run in 0.481 second using v1.01-cache-2.11-cpan-49f99fa48dc )