Skip to content

Commit

Permalink
Import endpoints, statuses, ssh keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Serge Huijsen authored and Serge Huijsen committed Nov 29, 2024
1 parent e82d9e6 commit 32b2d51
Show file tree
Hide file tree
Showing 3 changed files with 1,186 additions and 0 deletions.
139 changes: 139 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,145 @@ $status = VirtualizorAdmin::vps()->getHaStatus(16);

// Get raw API response
$response = VirtualizorAdmin::vps()->getHaStatus(null, raw: true);

// Reset bandwidth for a VPS
$success = VirtualizorAdmin::vps()->resetBandwidth(123); // returns true/false

// Get raw API response
$response = VirtualizorAdmin::vps()->resetBandwidth(123, raw: true);

// Get status for a single VPS
$status = VirtualizorAdmin::vps()->status(123);

// Get status for multiple VPSes
$statuses = VirtualizorAdmin::vps()->status([123, 124, 125]);

// Get raw API response
$response = VirtualizorAdmin::vps()->status([123, 124], raw: true);

// Update network rules for a VPS
$success = VirtualizorAdmin::vps()->updateNetworkRules(123); // returns true/false

// Get raw API response
$response = VirtualizorAdmin::vps()->updateNetworkRules(123, raw: true);

// Import OS templates from SolusVM
$templates = VirtualizorAdmin::vps()->importSolusvm('os', [
'changeserid' => 3, // Optional: Server ID where SolusVM is installed
'solusvm_os' => 1, // Import OS templates
'kvm_2' => '334', // Map SolusVM template ID to Virtualizor template ID
'kvm_5' => '334' // Map another template
]);

// Import users from SolusVM
$users = VirtualizorAdmin::vps()->importSolusvm('users', [
'solusvm_users' => 1 // Import users
]);

// Get raw API response
$response = VirtualizorAdmin::vps()->importSolusvm('os', [], raw: true);

// Import VPS from Proxmox
$vpsData = VirtualizorAdmin::vps()->importProxmox('vps', [
'changeserid' => 3, // Optional: Server ID where Proxmox is installed
'proxmox_vps' => 1 // Import VPS
]);

// Import users from Proxmox
$users = VirtualizorAdmin::vps()->importProxmox('users', [
'proxmox_users' => 1 // Import users
]);

// Get raw API response
$response = VirtualizorAdmin::vps()->importProxmox('vps', [], raw: true);

// Import VPS from Feathur
$vpsData = VirtualizorAdmin::vps()->importFeathur('vps', [
'changeserid' => 3, // Optional: Server ID where Feathur is installed
'feathur_vps' => 1 // Import VPS
]);

// Import users from Feathur
$users = VirtualizorAdmin::vps()->importFeathur('users', [
'feathur_users' => 1 // Import users
]);

// Get raw API response
$response = VirtualizorAdmin::vps()->importFeathur('vps', [], raw: true);

// Import VPS from HyperVM
$vpsData = VirtualizorAdmin::vps()->importHypervm('vps', [
'changeserid' => 3, // Optional: Server ID where HyperVM is installed
'hypervm_vps' => 1 // Import VPS
]);

// Import users from HyperVM
$users = VirtualizorAdmin::vps()->importHypervm('users', [
'hypervm_users' => 1 // Import users
]);

// Get raw API response
$response = VirtualizorAdmin::vps()->importHypervm('vps', [], raw: true);

// List importable OpenVZ VPSes
$vpsData = VirtualizorAdmin::vps()->importOpenvz(3); // Server ID 3

// Import specific OpenVZ VPSes
$result = VirtualizorAdmin::vps()->importOpenvz(3, [
'121' => [ // VPS name/ID
'bandwidth' => 2,
'user_id' => 15
],
'99013' => [ // Another VPS
'bandwidth' => 2,
'user_id' => 15
]
]);

// Get raw API response
$response = VirtualizorAdmin::vps()->importOpenvz(3, [], raw: true);

// List importable XEN Server VPSes
$vpsData = VirtualizorAdmin::vps()->importXenServer(3); // Server ID 3

// Import specific XEN Server VPSes
$result = VirtualizorAdmin::vps()->importXenServer(3, [
'v1032' => [ // VPS name/ID
'bandwidth' => 2,
'user_id' => 15
],
'v1025' => [ // Another VPS
'bandwidth' => 2,
'user_id' => 15
]
]);

// Get raw API response
$response = VirtualizorAdmin::vps()->importXenServer(3, [], raw: true);

// List importable OpenVZ 7 VPSes
$vpsData = VirtualizorAdmin::vps()->importOpenvz7(3); // Server ID 3

// Import specific OpenVZ 7 VPSes
$result = VirtualizorAdmin::vps()->importOpenvz7(3, [
'v1032' => [ // VPS name/ID
'bandwidth' => 2,
'user_id' => 15
],
'v1025' => [ // Another VPS
'bandwidth' => 2,
'user_id' => 15
]
]);

// Get raw API response
$response = VirtualizorAdmin::vps()->importOpenvz7(3, [], raw: true);

// List SSH keys for a user
$keys = VirtualizorAdmin::vps()->listSshKeys(123);

// Get raw API response
$response = VirtualizorAdmin::vps()->listSshKeys(123, raw: true);
```

Manage VPS Response:
Expand Down
170 changes: 170 additions & 0 deletions src/Api/AdminApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -990,5 +990,175 @@ public function getHaStatus(?int $serverGroupId = null): array
return $this->makeRequest('index.php?act=ha', $params);
}

/**
* Reset bandwidth for a virtual server
*
* @param int $vpsId VPS ID to reset bandwidth
* @return array
*/
public function resetBandwidth(int $vpsId): array
{
return $this->makeRequest("index.php?act=vs&bwreset={$vpsId}");
}

/**
* Get status for virtual server(s)
*
* @param array|int $vpsIds Single VPS ID or array of VPS IDs
* @return array
*/
public function getVpsStatus(array|int $vpsIds): array
{
$ids = is_array($vpsIds) ? $vpsIds : [$vpsIds];
return $this->makeRequest("index.php?act=vs&vs_status=" . implode(',', $ids));
}

/**
* Update network rules for a virtual server
*
* @param int $vpsId VPS ID to update network rules
* @return array
*/
public function updateVpsNetworkRules(int $vpsId): array
{
return $this->makeRequest("index.php?act=vs&action=vs_netrestrict&vpsid={$vpsId}");
}

/**
* Import from SolusVM
*
* @param array{
* ta: string,
* changeserid?: int,
* solusvm_ng?: int,
* solusvm_plans?: int,
* solusvm_users?: int,
* solusvm_ips?: int,
* solusvm_os?: int,
* solusvm_vps?: int
* } $params Import parameters
* @return array
*/
public function importSolusvm(array $params): array
{
return $this->makeRequest('index.php?act=import&sa=solusvm', $params);
}

/**
* Import from Proxmox
*
* @param array{
* ta: string,
* changeserid?: int,
* proxmox_users?: int,
* proxmox_storages?: int,
* proxmox_vps?: int
* } $params Import parameters
* @return array
*/
public function importProxmox(array $params): array
{
return $this->makeRequest('index.php?act=import&sa=proxmox', $params);
}

/**
* Import from Feathur
*
* @param array{
* ta: string,
* changeserid?: int,
* feathur_users?: int,
* feathur_ips?: int,
* feathur_os?: int,
* feathur_vps?: int
* } $params Import parameters
* @return array
*/
public function importFeathur(array $params): array
{
return $this->makeRequest('index.php?act=import&sa=feathur', $params);
}

/**
* Import from HyperVM
*
* @param array{
* ta: string,
* changeserid?: int,
* hypervm_plans?: int,
* hypervm_users?: int,
* hypervm_ips?: int,
* hypervm_os?: int,
* hypervm_vps?: int
* } $params Import parameters
* @return array
*/
public function importHypervm(array $params): array
{
return $this->makeRequest('index.php?act=import&sa=hypervm', $params);
}

/**
* Import from OpenVZ
*
* @param array{
* changeserid: int,
* importvps?: int,
* vsbw_*?: int,
* vsuser_*?: int
* } $params Import parameters
* @return array
*/
public function importOpenvz(array $params): array
{
return $this->makeRequest('index.php?act=import&sa=openvz', $params);
}

/**
* Import from XEN Server
*
* @param array{
* changeserid: int,
* importvps?: int,
* vsbw_*?: int,
* vsuser_*?: int
* } $params Import parameters
* @return array
*/
public function importXenServer(array $params): array
{
return $this->makeRequest('index.php?act=import&sa=xcp', $params);
}

/**
* Import from OpenVZ 7
*
* @param array{
* changeserid: int,
* importvps?: int,
* vsbw_*?: int,
* vsuser_*?: int
* } $params Import parameters
* @return array
*/
public function importOpenvz7(array $params): array
{
return $this->makeRequest('index.php?act=import&sa=openvz7', $params);
}

/**
* List SSH keys
*
* @param int $userId User ID to list SSH keys for
* @return array
*/
public function listSshKeys(int $userId): array
{
return $this->makeRequest('index.php?act=users', [
'list_ssh_keys' => 1,
'uid' => $userId
]);
}

// Add other admin API methods here
}
Loading

0 comments on commit 32b2d51

Please sign in to comment.