API IP Pool

From Virtualizor Wiki
Jump to: navigation, search

Create a IP Pool

Parameters Description
iptype 4 for IPv4, 6 for IPv6
serid An array containing server ids
ippool_name The name for the IP Pool
gateway The ip of the gateway
netmask The netmask address
ns1 Name server address 1
ns2 Name server address 2 if any
firstip The first IP of the IP range
lastip The last IP of the IP range
nat On or off, if nat is supported( Xen and KVM )
ips An array containing ips to be added
macs An array containing mac addresses for the ips
ipv6_1 The first field of the Ipv6 address
ipv6_2 The second field of the Ipv6 address
ipv6_3 The third field of the Ipv6 address
ipv6_4 The fourth field of the Ipv6 address
ipv6_5 The fifth field of the Ipv6 address
ipv6_6 The sixth field of the Ipv6 address
ipv6_num The number of Ipv6 addresses

Example Code

<?php

    require_once('admin.php');

    $key =  'uketenhrhpunty5lhgwkcuxxxxxxxxxx';

    $pass = 'yrsofc3tg3tre7bjpfppspxxxxxxxxxx';

    $ip = 'xxx.xxx.xxx.xxx';

    $admin = new Virtualizor_Admin_API($ip, $key, $pass);

    $post = array();
    $post['iptype']     = 4;
    $post['serid']      = array('0_group');
    $post['ippool_name']= 'apitest';
    $post['gateway']    = 'xxx.xxx.xxx.xxx';
    $post['netmask']    = '255.255.255.0';
    $post['ns1']        = '8.8.8.8';
    $post['ns2']        = '8.8.4.4';
    $post['firstip']    = 'xxx.xxx.xxx.200';
    $post['lastip']     = 'xxx.xxx.xxx.210';
    //$post['nat']		= 'on';
    $post['ips']        = array('xxx.xxx.xxx.xxx', 'xxx.xxx.xxx.xxx','xxx.xxx.xxx.xxx', 'xxx.xxx.xxx.xxx');
    $post['macs']       = array('xx:xx:xx:11:22:23', 'xx:xx:xx:11:22:23', 'xx:xx:xx:11:22:23');
    $post['ipv6_1']     = '';
    $post['ipv6_2']     = '';
    $post['ipv6_3']     = '';
    $post['ipv6_4']     = '';
    $post['ipv6_5']     = '';
    $post['ipv6_6']     = '';
    $post['ipv6_num']   = 50; 

    $output = $admin->addippool($post);
    print_r($output);
?>

Returns:

Array
(
    [title] => Add IP Pool
    [done] => Array
        (
            [ippid] => 257
            [range] => Array
                (
                    [3733] => xxx.xxx.xxx.xxx
                    [3734] => xxx.xxx.xxx.xxx
                    [3735] => xxx.xxx.xxx.xxx
                    [3736] => xxx.xxx.xxx.xxx
                    [3737] => xxx.xxx.xxx.xxx
                    [3738] => xxx.xxx.xxx.xxx
                )

            [done] => 1
        )

    [timenow] => 1402906749
    [time_taken] => 0.019
)