Add Template

Use the Add Template API to add an existing OS template to your server. These templates can be Windows templates or any other custom OS templates which can be used for the creation of Virtual Private Servers. You can also download the OS image by passing the “url” parameter. The API response will contain “done” as “1” after successful addition of the template.

For more information, you can refer this Add OS Template guide.

HTTP Request

https://hostname:4085/index.php?act=edittemplate&osid=OSID

Parameters

NameMethodValueDescriptionRequired
actGETaddtemplateThe action specified to perform operation and will return done as 1 after the template has been added successfullyYes
cplanPOSTtextThe virtualization type of the server for valid values refer below tableYes
urlPOSTtextIf you want this template to be downloaded from the Internet, please give the URL. Otherwise it will be assumed that the Template exists on the systemNo
filenamePOSTtextThe filename of the OS template, this value should be of the format ‘filepath’\filename if the OS is to be downloaded from the internet, for valid values refer below tableYes
noresizefsPOST1/0If set, the filesystem of the template would be resizedNo
perf_opsPOST1/0Extra operation that need to be performed while creating a templateNo
mgsPOSTarrayThe array of the media group ids to which the template should be assignedNo
extraPOSTtextExtra things to specified before creating a templateNo
fstypePOST1/0File system type of the template (only for xen vps)No
pygrubPOST1/0If set the pygrub will be enabled (only for xen vps)No

Valid Values

Virtualization Typecplan valuefilepath
Openvzopenvz/vz/template/cache/
XENxen/var/virtualizor/xen/
XEN-HVMxenhvm/var/virtualizor/xen/
KVMkvm/var/virtualizor/kvm/
XenServerxcp/var/virtualizor/xcp/
XenServer-HVMxcphvm/var/virtualizor/xcp/
LXClxc/var/virtualizor/lxc/
Virtuozzo Openvzvzo/vz/template/cache/
Virtuozzo KVMvzk/var/virtualizor/vzk/
Proxmox OpenVZproxo/var/virtualizor/proxo/
Proxmox KVMproxk/var/virtualizor/proxk/
Proxmox LXCproxl/var/virtualizor/proxl/

Sample Code

<?php

    require_once('/usr/local/virtualizor/sdk/admin.php');

    $key =  'your_api_key';
    $pass = 'your_api_pass';
    $ip = 'your_server_ip';

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

    $post = array();
    $post['cplan'] = 'kvm';
    $post['filename'] = 'ubuntu-mini.iso';

    $output = $admin->addtemplate($post);

    print_r(json_encode($output));

?>

Output

{
    "title": "Add OS Template",
    "done": 1,
    "mgs": {
        "1": {
            "mgid": "1",
            "mg_name": "test",
            "mg_desc": "test_desc",
            "mg_type": "openvz"
        }
    },
    "timenow": 1536079812,
    "time_taken": "0.334"
}
Was this helpful to you?