Skip to content

Commit

Permalink
clone VM's to target storage
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwang401 committed Dec 15, 2023
1 parent e93b8f4 commit 5dbf0d1
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions app/Repositories/Proxmox/Server/ProxmoxServerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Convoy\Repositories\Proxmox\Server;

use Convoy\Data\Server\Proxmox\ServerStateData;
use Convoy\Enums\Node\Access\RealmType;
use Convoy\Exceptions\Repository\Proxmox\ProxmoxConnectionException;
use Convoy\Models\Server;
use Convoy\Models\Template;
use Webmozart\Assert\Assert;
use Convoy\Enums\Node\Access\RealmType;
use Convoy\Data\Server\Proxmox\ServerStateData;
use Convoy\Repositories\Proxmox\ProxmoxRepository;
use Convoy\Exceptions\Repository\Proxmox\ProxmoxConnectionException;
use Webmozart\Assert\Assert;

class ProxmoxServerRepository extends ProxmoxRepository
{
Expand All @@ -20,12 +20,12 @@ public function getState()
Assert::isInstanceOf($this->server, Server::class);

$response = $this->getHttpClient()
->withUrlParameters([
'node' => $this->node->cluster,
'server' => $this->server->vmid,
])
->get('/api2/json/nodes/{node}/qemu/{server}/status/current')
->json();
->withUrlParameters([
'node' => $this->node->cluster,
'server' => $this->server->vmid,
])
->get('/api2/json/nodes/{node}/qemu/{server}/status/current')
->json();

return ServerStateData::fromRaw($this->getData($response));
}
Expand All @@ -35,16 +35,17 @@ public function create(Template $template)
Assert::isInstanceOf($this->server, Server::class);

$response = $this->getHttpClient()
->withUrlParameters([
'node' => $this->node->cluster,
'template' => $template->vmid,
])
->post('/api2/json/nodes/{node}/qemu/{template}/clone', [
'target' => $this->node->cluster,
'newid' => $this->server->vmid,
'full' => true,
])
->json();
->withUrlParameters([
'node' => $this->node->cluster,
'template' => $template->vmid,
])
->post('/api2/json/nodes/{node}/qemu/{template}/clone', [
'storage' => $this->node->vm_storage,
'target' => $this->node->cluster,
'newid' => $this->server->vmid,
'full' => true,
])
->json();

return $this->getData($response);
}
Expand All @@ -59,12 +60,12 @@ public function delete()
'purge' => true,
],
])
->withUrlParameters([
'node' => $this->node->cluster,
'server' => $this->server->vmid,
])
->delete('/api2/json/nodes/{node}/qemu/{server}')
->json();
->withUrlParameters([
'node' => $this->node->cluster,
'server' => $this->server->vmid,
])
->delete('/api2/json/nodes/{node}/qemu/{server}')
->json();

return $this->getData($response);
}
Expand All @@ -74,12 +75,12 @@ public function addUser(RealmType $realmType, string $userId, string $roleId)
Assert::isInstanceOf($this->server, Server::class);

$response = $this->getHttpClient()
->put('/api2/json/access/acl', [
'path' => '/vms/'.$this->server->vmid,
'users' => $userId.'@'.$realmType->value,
'roles' => $roleId,
])
->json();
->put('/api2/json/access/acl', [
'path' => '/vms/' . $this->server->vmid,
'users' => $userId . '@' . $realmType->value,
'roles' => $roleId,
])
->json();

return $this->getData($response);
}
Expand Down

0 comments on commit 5dbf0d1

Please sign in to comment.