Created
September 6, 2024 15:06
-
-
Save synopse/8de2f206718caa2b0c28771a151f640d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit ultravisor.api; | |
{$I mormot.defines.inc} | |
interface | |
{ | |
-------------------------------------------------------------------- | |
ULTRAVISOR API client as TUltravisorClient class | |
Generated 6 Sep 2024 by ab via mormot2tests - DO NOT MODIFY BY HAND! | |
-------------------------------------------------------------------- | |
} | |
uses | |
classes, | |
sysutils, | |
mormot.core.base, | |
mormot.core.unicode, | |
mormot.core.text, | |
mormot.core.buffers, | |
mormot.core.datetime, | |
mormot.core.rtti, | |
mormot.core.json, | |
mormot.core.variants, | |
mormot.net.client; | |
type | |
{ ************ Enumerations and Sets } | |
TEnumUltravisor1 = ( | |
eu1None, eu1LXC, eu1Parallels, eu1VirtualBox); | |
TEnumUltravisor2 = ( | |
eu2None, eu2Off, eu2Running, eu2Starting, eu2Stopping); | |
TEnumUltravisor3 = ( | |
eu3None, eu3Rdp, eu3Ssh); | |
TEnumUltravisor4 = ( | |
eu4None, eu4Admin, eu4Hypervisors, eu4Templates, eu4Vms); | |
TEnumUltravisor4Set = set of TEnumUltravisor4; | |
{ ************ Data Transfert Objects } | |
THypervisorShort = packed record | |
_Type: TEnumUltravisor1; | |
Url: RawUtf8; | |
MaxOwnedVms: integer; | |
QueueSize: integer; | |
Priority: integer; | |
Configuration: variant; | |
end; | |
PHypervisorShort = ^THypervisorShort; | |
TComputerCapabilities = packed record | |
Architecture: RawUtf8; | |
Os: RawUtf8; | |
OsVersion: RawUtf8; | |
OsPrettyName: RawUtf8; | |
Tags: TRawUtf8DynArray; | |
end; | |
PComputerCapabilities = ^TComputerCapabilities; | |
TAccountPost = packed record | |
Login: RawUtf8; | |
AuthorizedUsers: TRawUtf8DynArray; | |
GrantAuthUsers: TRawUtf8DynArray; | |
end; | |
PAccountPost = ^TAccountPost; | |
TAccountPostDynArray = array of TAccountPost; | |
TBaseVirtualMachine = packed record | |
Name: RawUtf8; | |
ExpirationDate: TDateTime; | |
Owner: RawUtf8; | |
end; | |
PBaseVirtualMachine = ^TBaseVirtualMachine; | |
THypervisorVirtualMachine = packed record | |
Name: RawUtf8; | |
ExpirationDate: TDateTime; | |
Owner: RawUtf8; | |
Accounts: TAccountPostDynArray; | |
end; | |
PHypervisorVirtualMachine = ^THypervisorVirtualMachine; | |
THypervisorVirtualMachineDynArray = array of THypervisorVirtualMachine; | |
THypervisorTemplate = packed record | |
Name: RawUtf8; | |
DisplayName: RawUtf8; | |
Priority: integer; | |
Capabilities: TComputerCapabilities; | |
TTL: integer; | |
Accounts: TAccountPostDynArray; | |
Vms: THypervisorVirtualMachineDynArray; | |
end; | |
PHypervisorTemplate = ^THypervisorTemplate; | |
THypervisorTemplateDynArray = array of THypervisorTemplate; | |
TBaseErrorResponse = packed record | |
Status: integer; | |
Message: RawUtf8; | |
end; | |
PBaseErrorResponse = ^TBaseErrorResponse; | |
TDatabaseObject = packed record | |
Uuid: RawUtf8; | |
CreatedOn: TDateTime; | |
UpdatedOn: TDateTime; | |
end; | |
PDatabaseObject = ^TDatabaseObject; | |
TUserShort = packed record | |
Name: RawUtf8; | |
end; | |
PUserShort = ^TUserShort; | |
TDbUserShort = packed record | |
Name: RawUtf8; | |
Uuid: RawUtf8; | |
CreatedOn: TDateTime; | |
UpdatedOn: TDateTime; | |
end; | |
PDbUserShort = ^TDbUserShort; | |
TDbUserShortDynArray = array of TDbUserShort; | |
TAccount = packed record | |
Login: RawUtf8; | |
AuthorizedUsers: TDbUserShortDynArray; | |
GrantAuthUsers: TDbUserShortDynArray; | |
end; | |
PAccount = ^TAccount; | |
THypervisorTypePatch = packed record | |
Priority: integer; | |
end; | |
PHypervisorTypePatch = ^THypervisorTypePatch; | |
THypervisorPatch = packed record | |
_Type: TEnumUltravisor1; | |
Url: RawUtf8; | |
MaxOwnedVms: integer; | |
QueueSize: integer; | |
Priority: integer; | |
Configuration: variant; | |
end; | |
PHypervisorPatch = ^THypervisorPatch; | |
TExternalVirtualMachine = packed record | |
Name: TEnumUltravisor1; | |
Uuid: RawUtf8; | |
State: TEnumUltravisor2; | |
end; | |
PExternalVirtualMachine = ^TExternalVirtualMachine; | |
TExternalVirtualMachineDynArray = array of TExternalVirtualMachine; | |
THypervisorQueue = packed record | |
Owner: TUserShort; | |
Priority: integer; | |
Timestamp: TDateTime; | |
Uuid: RawUtf8; | |
end; | |
PHypervisorQueue = ^THypervisorQueue; | |
THypervisorQueueDynArray = array of THypervisorQueue; | |
TVirtualMachinePatch = packed record | |
Capabilities: TComputerCapabilities; | |
Name: RawUtf8; | |
ExpirationDate: TDateTime; | |
end; | |
PVirtualMachinePatch = ^TVirtualMachinePatch; | |
TComputerSession = packed record | |
Login: RawUtf8; | |
_Type: TEnumUltravisor3; | |
Count: integer; | |
end; | |
PComputerSession = ^TComputerSession; | |
TComputerSessionDynArray = array of TComputerSession; | |
TVmStatus = packed record | |
Ip: RawUtf8; | |
State: TEnumUltravisor2; | |
Sessions: TComputerSessionDynArray; | |
Additionals: variant; | |
end; | |
PVmStatus = ^TVmStatus; | |
TDbAccount = packed record | |
Login: RawUtf8; | |
AuthorizedUsers: TDbUserShortDynArray; | |
GrantAuthUsers: TDbUserShortDynArray; | |
Uuid: RawUtf8; | |
CreatedOn: TDateTime; | |
UpdatedOn: TDateTime; | |
end; | |
PDbAccount = ^TDbAccount; | |
TDbAccountDynArray = array of TDbAccount; | |
TVmUsers = packed record | |
Owner: TDbUserShort; | |
Admins: TDbUserShortDynArray; | |
Accounts: TDbAccountDynArray; | |
end; | |
PVmUsers = ^TVmUsers; | |
TUserPubkey = packed record | |
Key: RawUtf8; | |
end; | |
PUserPubkey = ^TUserPubkey; | |
TValidationErrorResponse = packed record | |
Status: integer; | |
Message: RawUtf8; | |
end; | |
PValidationErrorResponse = ^TValidationErrorResponse; | |
TUnauthorizedResponse = packed record | |
Status: integer; | |
Message: RawUtf8; | |
end; | |
PUnauthorizedResponse = ^TUnauthorizedResponse; | |
TForbiddenResponse = packed record | |
Status: integer; | |
Message: RawUtf8; | |
end; | |
PForbiddenResponse = ^TForbiddenResponse; | |
TResourceNotFoundError = packed record | |
Status: integer; | |
Message: RawUtf8; | |
end; | |
PResourceNotFoundError = ^TResourceNotFoundError; | |
TIntegrityErrorResponse = packed record | |
Status: integer; | |
Message: RawUtf8; | |
end; | |
PIntegrityErrorResponse = ^TIntegrityErrorResponse; | |
THypervisor = packed record | |
_Type: TEnumUltravisor1; | |
Url: RawUtf8; | |
MaxOwnedVms: integer; | |
QueueSize: integer; | |
Priority: integer; | |
Configuration: variant; | |
Templates: THypervisorTemplateDynArray; | |
Accounts: TAccountPostDynArray; | |
end; | |
PHypervisor = ^THypervisor; | |
TDbHypervisorShort = packed record | |
Uuid: RawUtf8; | |
CreatedOn: TDateTime; | |
UpdatedOn: TDateTime; | |
_Type: TEnumUltravisor1; | |
Url: RawUtf8; | |
MaxOwnedVms: integer; | |
QueueSize: integer; | |
Priority: integer; | |
Configuration: variant; | |
end; | |
PDbHypervisorShort = ^TDbHypervisorShort; | |
TDbHypervisorShortDynArray = array of TDbHypervisorShort; | |
TDbTemplateShort = packed record | |
Uuid: RawUtf8; | |
CreatedOn: TDateTime; | |
UpdatedOn: TDateTime; | |
Name: RawUtf8; | |
DisplayName: RawUtf8; | |
Priority: integer; | |
Capabilities: TComputerCapabilities; | |
TTL: integer; | |
Hypervisor: TDbHypervisorShort; | |
end; | |
PDbTemplateShort = ^TDbTemplateShort; | |
TDbTemplateShortDynArray = array of TDbTemplateShort; | |
TDbVirtualMachineShort = packed record | |
Uuid: RawUtf8; | |
CreatedOn: TDateTime; | |
UpdatedOn: TDateTime; | |
Name: RawUtf8; | |
ExpirationDate: TDateTime; | |
Owner: RawUtf8; | |
Hypervisor: TDbHypervisorShort; | |
Template: TDbTemplateShort; | |
Capabilities: TComputerCapabilities; | |
end; | |
PDbVirtualMachineShort = ^TDbVirtualMachineShort; | |
TDbVirtualMachineShortDynArray = array of TDbVirtualMachineShort; | |
TDbHypervisor = packed record | |
Uuid: RawUtf8; | |
CreatedOn: TDateTime; | |
UpdatedOn: TDateTime; | |
_Type: TEnumUltravisor1; | |
Url: RawUtf8; | |
MaxOwnedVms: integer; | |
QueueSize: integer; | |
Priority: integer; | |
Configuration: variant; | |
Templates: TDbTemplateShortDynArray; | |
Vms: TDbVirtualMachineShortDynArray; | |
Accounts: TDbAccountDynArray; | |
end; | |
PDbHypervisor = ^TDbHypervisor; | |
TDbHypervisorTypeShort = packed record | |
Uuid: RawUtf8; | |
CreatedOn: TDateTime; | |
UpdatedOn: TDateTime; | |
Name: TEnumUltravisor1; | |
Priority: integer; | |
end; | |
PDbHypervisorTypeShort = ^TDbHypervisorTypeShort; | |
TDbHypervisorTypeShortDynArray = array of TDbHypervisorTypeShort; | |
TDbHypervisorType = packed record | |
Uuid: RawUtf8; | |
CreatedOn: TDateTime; | |
UpdatedOn: TDateTime; | |
Name: TEnumUltravisor1; | |
Priority: integer; | |
Instances: TDbHypervisorShortDynArray; | |
end; | |
PDbHypervisorType = ^TDbHypervisorType; | |
TTemplate = packed record | |
Name: RawUtf8; | |
DisplayName: RawUtf8; | |
Priority: integer; | |
Capabilities: TComputerCapabilities; | |
TTL: integer; | |
Accounts: TAccountPostDynArray; | |
Vms: THypervisorVirtualMachineDynArray; | |
HypervisorUuid: RawUtf8; | |
end; | |
PTemplate = ^TTemplate; | |
TDbTemplate = packed record | |
Uuid: RawUtf8; | |
CreatedOn: TDateTime; | |
UpdatedOn: TDateTime; | |
Name: RawUtf8; | |
DisplayName: RawUtf8; | |
Priority: integer; | |
Capabilities: TComputerCapabilities; | |
TTL: integer; | |
Hypervisor: TDbHypervisorShort; | |
Vms: TDbVirtualMachineShortDynArray; | |
Accounts: TDbAccountDynArray; | |
end; | |
PDbTemplate = ^TDbTemplate; | |
TDbTemplateDynArray = array of TDbTemplate; | |
TDbVirtualMachine = packed record | |
Uuid: RawUtf8; | |
CreatedOn: TDateTime; | |
UpdatedOn: TDateTime; | |
Name: RawUtf8; | |
ExpirationDate: TDateTime; | |
Owner: RawUtf8; | |
Hypervisor: TDbHypervisorShort; | |
Template: TDbTemplateShort; | |
Capabilities: TComputerCapabilities; | |
Accounts: TDbAccountDynArray; | |
Admins: TDbUserShortDynArray; | |
end; | |
PDbVirtualMachine = ^TDbVirtualMachine; | |
TDbVirtualMachineDynArray = array of TDbVirtualMachine; | |
TUserRegister = packed record | |
Name: RawUtf8; | |
Sid: RawUtf8; | |
VmPriority: integer; | |
SshPubCert: RawUtf8; | |
end; | |
PUserRegister = ^TUserRegister; | |
TDbUser = packed record | |
Name: RawUtf8; | |
Sid: RawUtf8; | |
VmPriority: integer; | |
SshPubCert: RawUtf8; | |
Uuid: RawUtf8; | |
CreatedOn: TDateTime; | |
UpdatedOn: TDateTime; | |
OwnedVms: TDbVirtualMachineShortDynArray; | |
end; | |
PDbUser = ^TDbUser; | |
TDbUserMe = packed record | |
Name: RawUtf8; | |
Sid: RawUtf8; | |
VmPriority: integer; | |
SshPubCert: RawUtf8; | |
Uuid: RawUtf8; | |
CreatedOn: TDateTime; | |
UpdatedOn: TDateTime; | |
OwnedVms: TDbVirtualMachineShortDynArray; | |
Roles: TEnumUltravisor4Set; | |
end; | |
PDbUserMe = ^TDbUserMe; | |
TVirtualMachinePost = packed record | |
Capabilities: TComputerCapabilities; | |
Name: RawUtf8; | |
ExpirationDate: TDateTime; | |
HypervisorUuid: RawUtf8; | |
TemplateUuid: RawUtf8; | |
Uuid: RawUtf8; | |
Accounts: TAccountPostDynArray; | |
end; | |
PVirtualMachinePost = ^TVirtualMachinePost; | |
TExternalHypervisorVirtualMachine = packed record | |
Name: TEnumUltravisor1; | |
Uuid: RawUtf8; | |
State: TEnumUltravisor2; | |
HypervisorUuid: RawUtf8; | |
end; | |
PExternalHypervisorVirtualMachine = ^TExternalHypervisorVirtualMachine; | |
TExternalHypervisorVirtualMachineDynArray = array of TExternalHypervisorVirtualMachine; | |
const | |
// define how enums/sets are actually transmitted as JSON array of string | |
ENUMULTRAVISOR1_TXT: array[TEnumUltravisor1] of RawUtf8 = ( | |
'', 'LXC', 'Parallels', 'VirtualBox'); | |
ENUMULTRAVISOR2_TXT: array[TEnumUltravisor2] of RawUtf8 = ( | |
'', 'off', 'running', 'starting', 'stopping'); | |
ENUMULTRAVISOR3_TXT: array[TEnumUltravisor3] of RawUtf8 = ( | |
'', 'rdp', 'ssh'); | |
ENUMULTRAVISOR4_TXT: array[TEnumUltravisor4] of RawUtf8 = ( | |
'', 'admin', 'hypervisors', 'templates', 'vms'); | |
type | |
{ ************ Custom Exceptions } | |
EValidationErrorResponse = class(EJsonClient) | |
protected | |
fError: TValidationErrorResponse; | |
public | |
constructor CreateResp(const Format: RawUtf8; const Args: array of const; | |
const Resp: TJsonResponse); override; | |
property Error: TValidationErrorResponse | |
read fError; | |
end; | |
EUnauthorizedResponse = class(EJsonClient) | |
protected | |
fError: TUnauthorizedResponse; | |
public | |
constructor CreateResp(const Format: RawUtf8; const Args: array of const; | |
const Resp: TJsonResponse); override; | |
property Error: TUnauthorizedResponse | |
read fError; | |
end; | |
EForbiddenResponse = class(EJsonClient) | |
protected | |
fError: TForbiddenResponse; | |
public | |
constructor CreateResp(const Format: RawUtf8; const Args: array of const; | |
const Resp: TJsonResponse); override; | |
property Error: TForbiddenResponse | |
read fError; | |
end; | |
EResourceNotFoundError = class(EJsonClient) | |
protected | |
fError: TResourceNotFoundError; | |
public | |
constructor CreateResp(const Format: RawUtf8; const Args: array of const; | |
const Resp: TJsonResponse); override; | |
property Error: TResourceNotFoundError | |
read fError; | |
end; | |
EIntegrityErrorResponse = class(EJsonClient) | |
protected | |
fError: TIntegrityErrorResponse; | |
public | |
constructor CreateResp(const Format: RawUtf8; const Args: array of const; | |
const Resp: TJsonResponse); override; | |
property Error: TIntegrityErrorResponse | |
read fError; | |
end; | |
{ ************ Main TUltravisorClient Class } | |
TUltravisorClient = class | |
private | |
fClient: IJsonClient; | |
// TOnJsonClientError event handlers | |
procedure OnError1(const Sender: IJsonClient; | |
const Response: TJsonResponse; const ErrorMsg: shortstring); | |
procedure OnError2(const Sender: IJsonClient; | |
const Response: TJsonResponse; const ErrorMsg: shortstring); | |
procedure OnError3(const Sender: IJsonClient; | |
const Response: TJsonResponse; const ErrorMsg: shortstring); | |
procedure OnError4(const Sender: IJsonClient; | |
const Response: TJsonResponse; const ErrorMsg: shortstring); | |
procedure OnError5(const Sender: IJsonClient; | |
const Response: TJsonResponse; const ErrorMsg: shortstring); | |
public | |
// initialize this Client with an associated HTTP/JSON request | |
constructor Create(const aClient: IJsonClient = nil); | |
// Accounts methods | |
procedure DeleteAccountRes(const Uuid: RawUtf8); | |
function GetAccountRes(const Uuid: RawUtf8): TDbAccount; | |
function PatchAccountRes(const Uuid: RawUtf8; const Payload: TAccountPost): TDbAccount; | |
function PostAccountResAddGrantAuth(const Uuid: RawUtf8; const Payload: TUserShort): TDbAccount; | |
function PostAccountResAuthorize(const Uuid: RawUtf8; const Payload: TUserShort): TDbAccount; | |
function PostAccountResReloadAuthorizedKeys(const Uuid: RawUtf8): TDbAccount; | |
function DeleteAccountResRevokeGrantAuth(const Uuid: RawUtf8; const Payload: TUserShort): TDbAccount; | |
function DeleteAccountResUnauthorize(const Uuid: RawUtf8; const Payload: TUserShort): TDbAccount; | |
// Hypervisors methods | |
function PostHypervisorsRes(const Payload: THypervisor; Force: boolean = false): TDbHypervisor; | |
function GetHypervisorsRes(_Type: TEnumUltravisor1 = eu1None): TDbHypervisorShortDynArray; | |
function GetHypervisorsResTypes(): TDbHypervisorTypeShortDynArray; | |
function PatchHypervisorTypeRes(Name: TEnumUltravisor1; const Payload: THypervisorTypePatch): TDbHypervisorType; | |
function GetHypervisorTypeRes(Name: TEnumUltravisor1): TDbHypervisorType; | |
procedure DeleteHypervisorRes(const Uuid: RawUtf8; Force: boolean = false; | |
DeleteVms: boolean = false); | |
function GetHypervisorRes(const Uuid: RawUtf8): TDbHypervisor; | |
function PatchHypervisorRes(const Uuid: RawUtf8; const Payload: THypervisorPatch; | |
Force: boolean = false): TDbHypervisor; | |
function GetHypervisorResExternalVms(const Uuid: RawUtf8): TExternalVirtualMachineDynArray; | |
function GetHypervisorResQueue(const Uuid: RawUtf8; const Owner: RawUtf8 = ''): THypervisorQueueDynArray; | |
function GetHypervisorResTemplates(const Uuid: RawUtf8; Sort: boolean = false; | |
const Name: RawUtf8 = ''; const Os: RawUtf8 = ''; const OsVersion: RawUtf8 = ''; | |
const OsPrettyName: RawUtf8 = ''; const Architecture: RawUtf8 = ''): TDbTemplateShortDynArray; | |
procedure DeleteHypervisorResVm(const Uuid: RawUtf8; const Name: RawUtf8); | |
function GetHypervisorResVms(const Uuid: RawUtf8; const TemplateName: RawUtf8 = ''; | |
const Owner: RawUtf8 = ''; const Name: RawUtf8 = ''; const Os: RawUtf8 = ''; | |
const OsVersion: RawUtf8 = ''; const OsPrettyName: RawUtf8 = ''; | |
const Architecture: RawUtf8 = ''): TDbVirtualMachineShortDynArray; | |
// Templates methods | |
function PostTemplatesRes(const Payload: TTemplate; Force: boolean = false): TDbTemplate; | |
function GetTemplatesRes(Sort: boolean = false; const Name: RawUtf8 = ''; | |
const Os: RawUtf8 = ''; const OsVersion: RawUtf8 = ''; const OsPrettyName: RawUtf8 = ''; | |
const Architecture: RawUtf8 = ''): TDbTemplateShortDynArray; | |
procedure DeleteTemplateRes(const Uuid: RawUtf8; Force: boolean = false; | |
DeleteVms: boolean = false); | |
function GetTemplateRes(const Uuid: RawUtf8): TDbTemplateDynArray; | |
function PatchTemplateRes(const Uuid: RawUtf8; const Payload: TDbTemplateShort; | |
Force: boolean = false; DetachVms: boolean = false): TTemplate; | |
function GetTemplateResAccounts(const Uuid: RawUtf8): TDbAccountDynArray; | |
function PostTemplateResClone(const Uuid: RawUtf8; const Payload: TBaseVirtualMachine): TDbVirtualMachine; | |
function PostTemplateResRegisterAccount(const Uuid: RawUtf8; const Payload: TAccountPost; | |
Recursive: boolean = false): TDbAccountDynArray; | |
function GetTemplateResVms(const Uuid: RawUtf8; const Owner: RawUtf8 = ''; | |
const Name: RawUtf8 = ''; const Os: RawUtf8 = ''; const OsVersion: RawUtf8 = ''; | |
const OsPrettyName: RawUtf8 = ''; const Architecture: RawUtf8 = ''): TDbVirtualMachineShortDynArray; | |
// Users methods | |
function PostUsersRes(const Payload: TUserRegister): TDbUser; | |
function GetUsersRes(): TDbUserShortDynArray; | |
function GetUsersResMe(): TDbUserMe; | |
procedure DeleteUserRes(const Uuid: RawUtf8); | |
function GetUserRes(const Uuid: RawUtf8): TDbUser; | |
function PatchUserRes(const Uuid: RawUtf8; const Payload: TUserRegister): TDbUser; | |
function PatchUserResSetSshPubkey(const Uuid: RawUtf8; const Payload: TUserPubkey): TDbUser; | |
// Virtual Machines methods | |
function PostVirtualMachinesRes(const Payload: TVirtualMachinePost; Force: boolean = false): TDbVirtualMachine; | |
function GetVirtualMachinesRes(const TemplateName: RawUtf8 = ''; const Owner: RawUtf8 = ''; | |
const Name: RawUtf8 = ''; const Os: RawUtf8 = ''; const OsVersion: RawUtf8 = ''; | |
const OsPrettyName: RawUtf8 = ''; const Architecture: RawUtf8 = ''): TDbVirtualMachineShortDynArray; | |
function GetVirtualMachinesResExternals(): TExternalHypervisorVirtualMachineDynArray; | |
function PostVirtualMachinesResRequestClone(const ExpirationDate: RawUtf8 = ''; | |
const Owner: RawUtf8 = ''; const Name: RawUtf8 = ''; const Os: RawUtf8 = ''; | |
const OsVersion: RawUtf8 = ''; const OsPrettyName: RawUtf8 = ''; | |
const Architecture: RawUtf8 = ''): TDbVirtualMachineDynArray; | |
procedure DeleteVirtualMachineRes(const Uuid: RawUtf8); | |
function GetVirtualMachineRes(const Uuid: RawUtf8): TDbVirtualMachine; | |
function PatchVirtualMachineRes(const Uuid: RawUtf8; const Payload: TVirtualMachinePatch): TDbVirtualMachine; | |
function GetVirtualMachineResAccounts(const Uuid: RawUtf8): TDbAccountDynArray; | |
function GetVirtualMachineAccountRes(const Uuid: RawUtf8; const Login: RawUtf8): TDbAccount; | |
function PostVirtualMachineAccountResAuthorize(const Uuid: RawUtf8; const Login: RawUtf8; | |
const Payload: TUserShort): TDbAccount; | |
function PostVirtualMachineAccountResReloadAuthorizedKeys(const Uuid: RawUtf8; | |
const Login: RawUtf8): TDbAccount; | |
function PostVirtualMachineAccountResUnauthorize(const Uuid: RawUtf8; const Login: RawUtf8; | |
const Payload: TUserShort): TDbAccount; | |
function PostVirtualMachineResAddAdmin(const Uuid: RawUtf8; const Payload: TUserShort): TDbVirtualMachine; | |
function PostVirtualMachineResCreateAccount(const Uuid: RawUtf8; const Payload: TAccountPost): TDbAccountDynArray; | |
function PostVirtualMachineResRegisterAccount(const Uuid: RawUtf8; const Payload: TAccountPost): TDbAccountDynArray; | |
function PostVirtualMachineResRemoveAdmin(const Uuid: RawUtf8; const Payload: TUserShort): TDbVirtualMachine; | |
function PostVirtualMachineResSetOwner(const Uuid: RawUtf8; const Payload: TUserShort): TDbVirtualMachine; | |
function PostVirtualMachineResStart(const Uuid: RawUtf8): TVmStatus; | |
function GetVirtualMachineResStatus(const Uuid: RawUtf8): TVmStatus; | |
function PostVirtualMachineResStop(const Uuid: RawUtf8): TVmStatus; | |
procedure DeleteVirtualMachineResUnregister(const Uuid: RawUtf8); | |
function GetVirtualMachineResUsers(const Uuid: RawUtf8): TVmUsers; | |
// access to the associated HTTP/JSON request | |
property JsonClient: IJsonClient | |
read fClient write fClient; | |
end; | |
implementation | |
{ ************ Custom Exceptions } | |
{ EValidationErrorResponse } | |
constructor EValidationErrorResponse.CreateResp(const Format: RawUtf8; | |
const Args: array of const; const Resp: TJsonResponse); | |
begin | |
inherited CreateResp(Format, Args, Resp); | |
LoadJson(fError, Resp.Content, TypeInfo(TValidationErrorResponse)); | |
end; | |
{ EUnauthorizedResponse } | |
constructor EUnauthorizedResponse.CreateResp(const Format: RawUtf8; | |
const Args: array of const; const Resp: TJsonResponse); | |
begin | |
inherited CreateResp(Format, Args, Resp); | |
LoadJson(fError, Resp.Content, TypeInfo(TUnauthorizedResponse)); | |
end; | |
{ EForbiddenResponse } | |
constructor EForbiddenResponse.CreateResp(const Format: RawUtf8; | |
const Args: array of const; const Resp: TJsonResponse); | |
begin | |
inherited CreateResp(Format, Args, Resp); | |
LoadJson(fError, Resp.Content, TypeInfo(TForbiddenResponse)); | |
end; | |
{ EResourceNotFoundError } | |
constructor EResourceNotFoundError.CreateResp(const Format: RawUtf8; | |
const Args: array of const; const Resp: TJsonResponse); | |
begin | |
inherited CreateResp(Format, Args, Resp); | |
LoadJson(fError, Resp.Content, TypeInfo(TResourceNotFoundError)); | |
end; | |
{ EIntegrityErrorResponse } | |
constructor EIntegrityErrorResponse.CreateResp(const Format: RawUtf8; | |
const Args: array of const; const Resp: TJsonResponse); | |
begin | |
inherited CreateResp(Format, Args, Resp); | |
LoadJson(fError, Resp.Content, TypeInfo(TIntegrityErrorResponse)); | |
end; | |
{ ************ Main TUltravisorClient Class } | |
{ TUltravisorClient} | |
constructor TUltravisorClient.Create(const aClient: IJsonClient); | |
begin | |
fClient := aClient; | |
fClient.UrlEncoder := | |
[ueEncodeNames, ueSkipVoidString, ueSkipVoidValue, ueStarNameIsCsv]; | |
end; | |
procedure TUltravisorClient.OnError1(const Sender: IJsonClient; | |
const Response: TJsonResponse; const ErrorMsg: shortstring); | |
var | |
e: EJsonClientClass; | |
begin | |
case Response.Status of | |
400: | |
e := EValidationErrorResponse; | |
401: | |
e := EUnauthorizedResponse; | |
403: | |
e := EForbiddenResponse; | |
404: | |
e := EResourceNotFoundError; | |
422: | |
e := EIntegrityErrorResponse; | |
else | |
e := EJsonClient; | |
end; | |
raise e.CreateResp('%.%', [self, ErrorMsg], Response); | |
end; | |
procedure TUltravisorClient.OnError2(const Sender: IJsonClient; | |
const Response: TJsonResponse; const ErrorMsg: shortstring); | |
var | |
e: EJsonClientClass; | |
begin | |
case Response.Status of | |
400: | |
e := EValidationErrorResponse; | |
401: | |
e := EUnauthorizedResponse; | |
403: | |
e := EForbiddenResponse; | |
404: | |
e := EResourceNotFoundError; | |
else | |
e := EJsonClient; | |
end; | |
raise e.CreateResp('%.%', [self, ErrorMsg], Response); | |
end; | |
procedure TUltravisorClient.OnError3(const Sender: IJsonClient; | |
const Response: TJsonResponse; const ErrorMsg: shortstring); | |
var | |
e: EJsonClientClass; | |
begin | |
case Response.Status of | |
400: | |
e := EValidationErrorResponse; | |
401: | |
e := EUnauthorizedResponse; | |
403: | |
e := EForbiddenResponse; | |
else | |
e := EJsonClient; | |
end; | |
raise e.CreateResp('%.%', [self, ErrorMsg], Response); | |
end; | |
procedure TUltravisorClient.OnError4(const Sender: IJsonClient; | |
const Response: TJsonResponse; const ErrorMsg: shortstring); | |
var | |
e: EJsonClientClass; | |
begin | |
case Response.Status of | |
401: | |
e := EUnauthorizedResponse; | |
403: | |
e := EForbiddenResponse; | |
else | |
e := EJsonClient; | |
end; | |
raise e.CreateResp('%.%', [self, ErrorMsg], Response); | |
end; | |
procedure TUltravisorClient.OnError5(const Sender: IJsonClient; | |
const Response: TJsonResponse; const ErrorMsg: shortstring); | |
var | |
e: EJsonClientClass; | |
begin | |
case Response.Status of | |
401: | |
e := EUnauthorizedResponse; | |
403: | |
e := EForbiddenResponse; | |
404: | |
e := EResourceNotFoundError; | |
else | |
e := EJsonClient; | |
end; | |
raise e.CreateResp('%.%', [self, ErrorMsg], Response); | |
end; | |
procedure TUltravisorClient.DeleteAccountRes(const Uuid: RawUtf8); | |
begin | |
fClient.Request('DELETE', '/api/accounts/%/', [Uuid], [], [], OnError1); | |
end; | |
function TUltravisorClient.GetAccountRes(const Uuid: RawUtf8): TDbAccount; | |
begin | |
fClient.Request('GET', '/api/accounts/%/', [Uuid], [], [], | |
result, TypeInfo(TDbAccount), OnError2); | |
end; | |
function TUltravisorClient.PatchAccountRes(const Uuid: RawUtf8; const Payload: TAccountPost): TDbAccount; | |
begin | |
fClient.Request('PATCH', '/api/accounts/%/', [Uuid], [], [], | |
Payload, result, TypeInfo(TAccountPost), TypeInfo(TDbAccount), OnError1); | |
end; | |
function TUltravisorClient.PostAccountResAddGrantAuth(const Uuid: RawUtf8; | |
const Payload: TUserShort): TDbAccount; | |
begin | |
fClient.Request('POST', '/api/accounts/%/add-grant-auth/', [Uuid], [], [], | |
Payload, result, TypeInfo(TUserShort), TypeInfo(TDbAccount), OnError1); | |
end; | |
function TUltravisorClient.PostAccountResAuthorize(const Uuid: RawUtf8; | |
const Payload: TUserShort): TDbAccount; | |
begin | |
fClient.Request('POST', '/api/accounts/%/authorize/', [Uuid], [], [], | |
Payload, result, TypeInfo(TUserShort), TypeInfo(TDbAccount), OnError1); | |
end; | |
function TUltravisorClient.PostAccountResReloadAuthorizedKeys(const Uuid: RawUtf8): TDbAccount; | |
begin | |
fClient.Request('POST', '/api/accounts/%/reload-authorized-keys/', [Uuid], [], [], | |
result, TypeInfo(TDbAccount), OnError1); | |
end; | |
function TUltravisorClient.DeleteAccountResRevokeGrantAuth(const Uuid: RawUtf8; | |
const Payload: TUserShort): TDbAccount; | |
begin | |
fClient.Request('DELETE', '/api/accounts/%/revoke-grant-auth/', [Uuid], [], [], | |
Payload, result, TypeInfo(TUserShort), TypeInfo(TDbAccount), OnError1); | |
end; | |
function TUltravisorClient.DeleteAccountResUnauthorize(const Uuid: RawUtf8; | |
const Payload: TUserShort): TDbAccount; | |
begin | |
fClient.Request('DELETE', '/api/accounts/%/unauthorize/', [Uuid], [], [], | |
Payload, result, TypeInfo(TUserShort), TypeInfo(TDbAccount), OnError1); | |
end; | |
function TUltravisorClient.PostHypervisorsRes(const Payload: THypervisor; | |
Force: boolean): TDbHypervisor; | |
begin | |
fClient.Request('POST', '/api/hypervisors/', [], [ | |
'force', Force], [], | |
Payload, result, TypeInfo(THypervisor), TypeInfo(TDbHypervisor), OnError1); | |
end; | |
function TUltravisorClient.GetHypervisorsRes(_Type: TEnumUltravisor1): TDbHypervisorShortDynArray; | |
begin | |
fClient.Request('GET', '/api/hypervisors/', [], [ | |
'type', ENUMULTRAVISOR1_TXT[_Type]], [], | |
result, TypeInfo(TDbHypervisorShortDynArray), OnError3); | |
end; | |
function TUltravisorClient.GetHypervisorsResTypes(): TDbHypervisorTypeShortDynArray; | |
begin | |
fClient.Request('GET', '/api/hypervisors/types/', [], [], [], | |
result, TypeInfo(TDbHypervisorTypeShortDynArray), OnError4); | |
end; | |
function TUltravisorClient.PatchHypervisorTypeRes(Name: TEnumUltravisor1; | |
const Payload: THypervisorTypePatch): TDbHypervisorType; | |
begin | |
fClient.Request('PATCH', '/api/hypervisors/types/%/', [ENUMULTRAVISOR1_TXT[Name]], [], [], | |
Payload, result, TypeInfo(THypervisorTypePatch), TypeInfo(TDbHypervisorType), OnError2); | |
end; | |
function TUltravisorClient.GetHypervisorTypeRes(Name: TEnumUltravisor1): TDbHypervisorType; | |
begin | |
fClient.Request('GET', '/api/hypervisors/types/%/', [ENUMULTRAVISOR1_TXT[Name]], [], [], | |
result, TypeInfo(TDbHypervisorType), OnError2); | |
end; | |
procedure TUltravisorClient.DeleteHypervisorRes(const Uuid: RawUtf8; Force: boolean; | |
DeleteVms: boolean); | |
begin | |
fClient.Request('DELETE', '/api/hypervisors/%/', [Uuid], [ | |
'force', Force, | |
'delete_vms', DeleteVms], [], OnError1); | |
end; | |
function TUltravisorClient.GetHypervisorRes(const Uuid: RawUtf8): TDbHypervisor; | |
begin | |
fClient.Request('GET', '/api/hypervisors/%/', [Uuid], [], [], | |
result, TypeInfo(TDbHypervisor), OnError2); | |
end; | |
function TUltravisorClient.PatchHypervisorRes(const Uuid: RawUtf8; const Payload: THypervisorPatch; | |
Force: boolean): TDbHypervisor; | |
begin | |
fClient.Request('PATCH', '/api/hypervisors/%/', [Uuid], [ | |
'force', Force], [], | |
Payload, result, TypeInfo(THypervisorPatch), TypeInfo(TDbHypervisor), OnError1); | |
end; | |
function TUltravisorClient.GetHypervisorResExternalVms(const Uuid: RawUtf8): TExternalVirtualMachineDynArray; | |
begin | |
fClient.Request('GET', '/api/hypervisors/%/external-vms/', [Uuid], [], [], | |
result, TypeInfo(TExternalVirtualMachineDynArray), OnError2); | |
end; | |
function TUltravisorClient.GetHypervisorResQueue(const Uuid: RawUtf8; const Owner: RawUtf8): THypervisorQueueDynArray; | |
begin | |
fClient.Request('GET', '/api/hypervisors/%/queue/', [Uuid], [ | |
'owner', Owner], [], | |
result, TypeInfo(THypervisorQueueDynArray), OnError2); | |
end; | |
function TUltravisorClient.GetHypervisorResTemplates(const Uuid: RawUtf8; | |
Sort: boolean; const Name: RawUtf8; const Os: RawUtf8; const OsVersion: RawUtf8; | |
const OsPrettyName: RawUtf8; const Architecture: RawUtf8): TDbTemplateShortDynArray; | |
begin | |
fClient.Request('GET', '/api/hypervisors/%/templates/', [Uuid], [ | |
'sort', Sort, | |
'name', Name, | |
'os', Os, | |
'os_version', OsVersion, | |
'os_pretty_name', OsPrettyName, | |
'architecture', Architecture], [], | |
result, TypeInfo(TDbTemplateShortDynArray), OnError2); | |
end; | |
procedure TUltravisorClient.DeleteHypervisorResVm(const Uuid: RawUtf8; | |
const Name: RawUtf8); | |
begin | |
fClient.Request('DELETE', '/api/hypervisors/%/vm/', [Uuid], [ | |
'name', Name], [], OnError2); | |
end; | |
function TUltravisorClient.GetHypervisorResVms(const Uuid: RawUtf8; const TemplateName: RawUtf8; | |
const Owner: RawUtf8; const Name: RawUtf8; const Os: RawUtf8; const OsVersion: RawUtf8; | |
const OsPrettyName: RawUtf8; const Architecture: RawUtf8): TDbVirtualMachineShortDynArray; | |
begin | |
fClient.Request('GET', '/api/hypervisors/%/vms/', [Uuid], [ | |
'template_name', TemplateName, | |
'owner', Owner, | |
'name', Name, | |
'os', Os, | |
'os_version', OsVersion, | |
'os_pretty_name', OsPrettyName, | |
'architecture', Architecture], [], | |
result, TypeInfo(TDbVirtualMachineShortDynArray), OnError2); | |
end; | |
function TUltravisorClient.PostTemplatesRes(const Payload: TTemplate; Force: boolean): TDbTemplate; | |
begin | |
fClient.Request('POST', '/api/templates/', [], [ | |
'force', Force], [], | |
Payload, result, TypeInfo(TTemplate), TypeInfo(TDbTemplate), OnError1); | |
end; | |
function TUltravisorClient.GetTemplatesRes(Sort: boolean; const Name: RawUtf8; | |
const Os: RawUtf8; const OsVersion: RawUtf8; const OsPrettyName: RawUtf8; | |
const Architecture: RawUtf8): TDbTemplateShortDynArray; | |
begin | |
fClient.Request('GET', '/api/templates/', [], [ | |
'sort', Sort, | |
'name', Name, | |
'os', Os, | |
'os_version', OsVersion, | |
'os_pretty_name', OsPrettyName, | |
'architecture', Architecture], [], | |
result, TypeInfo(TDbTemplateShortDynArray), OnError3); | |
end; | |
procedure TUltravisorClient.DeleteTemplateRes(const Uuid: RawUtf8; Force: boolean; | |
DeleteVms: boolean); | |
begin | |
fClient.Request('DELETE', '/api/templates/%/', [Uuid], [ | |
'force', Force, | |
'delete_vms', DeleteVms], [], OnError1); | |
end; | |
function TUltravisorClient.GetTemplateRes(const Uuid: RawUtf8): TDbTemplateDynArray; | |
begin | |
fClient.Request('GET', '/api/templates/%/', [Uuid], [], [], | |
result, TypeInfo(TDbTemplateDynArray), OnError2); | |
end; | |
function TUltravisorClient.PatchTemplateRes(const Uuid: RawUtf8; const Payload: TDbTemplateShort; | |
Force: boolean; DetachVms: boolean): TTemplate; | |
begin | |
fClient.Request('PATCH', '/api/templates/%/', [Uuid], [ | |
'force', Force, | |
'detach_vms', DetachVms], [], | |
Payload, result, TypeInfo(TDbTemplateShort), TypeInfo(TTemplate), OnError1); | |
end; | |
function TUltravisorClient.GetTemplateResAccounts(const Uuid: RawUtf8): TDbAccountDynArray; | |
begin | |
fClient.Request('GET', '/api/templates/%/accounts/', [Uuid], [], [], | |
result, TypeInfo(TDbAccountDynArray), OnError2); | |
end; | |
function TUltravisorClient.PostTemplateResClone(const Uuid: RawUtf8; const Payload: TBaseVirtualMachine): TDbVirtualMachine; | |
begin | |
fClient.Request('POST', '/api/templates/%/clone/', [Uuid], [], [], | |
Payload, result, TypeInfo(TBaseVirtualMachine), TypeInfo(TDbVirtualMachine), OnError2); | |
end; | |
function TUltravisorClient.PostTemplateResRegisterAccount(const Uuid: RawUtf8; | |
const Payload: TAccountPost; Recursive: boolean): TDbAccountDynArray; | |
begin | |
fClient.Request('POST', '/api/templates/%/register-account/', [Uuid], [ | |
'recursive', Recursive], [], | |
Payload, result, TypeInfo(TAccountPost), TypeInfo(TDbAccountDynArray), OnError1); | |
end; | |
function TUltravisorClient.GetTemplateResVms(const Uuid: RawUtf8; const Owner: RawUtf8; | |
const Name: RawUtf8; const Os: RawUtf8; const OsVersion: RawUtf8; const OsPrettyName: RawUtf8; | |
const Architecture: RawUtf8): TDbVirtualMachineShortDynArray; | |
begin | |
fClient.Request('GET', '/api/templates/%/vms/', [Uuid], [ | |
'owner', Owner, | |
'name', Name, | |
'os', Os, | |
'os_version', OsVersion, | |
'os_pretty_name', OsPrettyName, | |
'architecture', Architecture], [], | |
result, TypeInfo(TDbVirtualMachineShortDynArray), OnError2); | |
end; | |
function TUltravisorClient.PostUsersRes(const Payload: TUserRegister): TDbUser; | |
begin | |
fClient.Request('POST', '/api/users/', [], [], [], | |
Payload, result, TypeInfo(TUserRegister), TypeInfo(TDbUser), OnError4); | |
end; | |
function TUltravisorClient.GetUsersRes(): TDbUserShortDynArray; | |
begin | |
fClient.Request('GET', '/api/users/', [], [], [], | |
result, TypeInfo(TDbUserShortDynArray), OnError4); | |
end; | |
function TUltravisorClient.GetUsersResMe(): TDbUserMe; | |
begin | |
fClient.Request('GET', '/api/users/me/', [], [], [], | |
result, TypeInfo(TDbUserMe), OnError4); | |
end; | |
procedure TUltravisorClient.DeleteUserRes(const Uuid: RawUtf8); | |
begin | |
fClient.Request('DELETE', '/api/users/%/', [Uuid], [], [], OnError5); | |
end; | |
function TUltravisorClient.GetUserRes(const Uuid: RawUtf8): TDbUser; | |
begin | |
fClient.Request('GET', '/api/users/%/', [Uuid], [], [], | |
result, TypeInfo(TDbUser), OnError5); | |
end; | |
function TUltravisorClient.PatchUserRes(const Uuid: RawUtf8; const Payload: TUserRegister): TDbUser; | |
begin | |
fClient.Request('PATCH', '/api/users/%/', [Uuid], [], [], | |
Payload, result, TypeInfo(TUserRegister), TypeInfo(TDbUser), OnError5); | |
end; | |
function TUltravisorClient.PatchUserResSetSshPubkey(const Uuid: RawUtf8; | |
const Payload: TUserPubkey): TDbUser; | |
begin | |
fClient.Request('PATCH', '/api/users/%/set-ssh-pubkey/', [Uuid], [], [], | |
Payload, result, TypeInfo(TUserPubkey), TypeInfo(TDbUser), OnError5); | |
end; | |
function TUltravisorClient.PostVirtualMachinesRes(const Payload: TVirtualMachinePost; | |
Force: boolean): TDbVirtualMachine; | |
begin | |
fClient.Request('POST', '/api/vms/', [], [ | |
'force', Force], [], | |
Payload, result, TypeInfo(TVirtualMachinePost), TypeInfo(TDbVirtualMachine), OnError1); | |
end; | |
function TUltravisorClient.GetVirtualMachinesRes(const TemplateName: RawUtf8; | |
const Owner: RawUtf8; const Name: RawUtf8; const Os: RawUtf8; const OsVersion: RawUtf8; | |
const OsPrettyName: RawUtf8; const Architecture: RawUtf8): TDbVirtualMachineShortDynArray; | |
begin | |
fClient.Request('GET', '/api/vms/', [], [ | |
'template_name', TemplateName, | |
'owner', Owner, | |
'name', Name, | |
'os', Os, | |
'os_version', OsVersion, | |
'os_pretty_name', OsPrettyName, | |
'architecture', Architecture], [], | |
result, TypeInfo(TDbVirtualMachineShortDynArray), OnError3); | |
end; | |
function TUltravisorClient.GetVirtualMachinesResExternals(): TExternalHypervisorVirtualMachineDynArray; | |
begin | |
fClient.Request('GET', '/api/vms/externals/', [], [], [], | |
result, TypeInfo(TExternalHypervisorVirtualMachineDynArray), OnError4); | |
end; | |
function TUltravisorClient.PostVirtualMachinesResRequestClone(const ExpirationDate: RawUtf8; | |
const Owner: RawUtf8; const Name: RawUtf8; const Os: RawUtf8; const OsVersion: RawUtf8; | |
const OsPrettyName: RawUtf8; const Architecture: RawUtf8): TDbVirtualMachineDynArray; | |
begin | |
fClient.Request('POST', '/api/vms/request-clone/', [], [ | |
'expiration_date', ExpirationDate, | |
'owner', Owner, | |
'name', Name, | |
'os', Os, | |
'os_version', OsVersion, | |
'os_pretty_name', OsPrettyName, | |
'architecture', Architecture], [], | |
result, TypeInfo(TDbVirtualMachineDynArray), OnError3); | |
end; | |
procedure TUltravisorClient.DeleteVirtualMachineRes(const Uuid: RawUtf8); | |
begin | |
fClient.Request('DELETE', '/api/vms/%/', [Uuid], [], [], OnError2); | |
end; | |
function TUltravisorClient.GetVirtualMachineRes(const Uuid: RawUtf8): TDbVirtualMachine; | |
begin | |
fClient.Request('GET', '/api/vms/%/', [Uuid], [], [], | |
result, TypeInfo(TDbVirtualMachine), OnError2); | |
end; | |
function TUltravisorClient.PatchVirtualMachineRes(const Uuid: RawUtf8; | |
const Payload: TVirtualMachinePatch): TDbVirtualMachine; | |
begin | |
fClient.Request('PATCH', '/api/vms/%/', [Uuid], [], [], | |
Payload, result, TypeInfo(TVirtualMachinePatch), TypeInfo(TDbVirtualMachine), OnError1); | |
end; | |
function TUltravisorClient.GetVirtualMachineResAccounts(const Uuid: RawUtf8): TDbAccountDynArray; | |
begin | |
fClient.Request('GET', '/api/vms/%/accounts/', [Uuid], [], [], | |
result, TypeInfo(TDbAccountDynArray), OnError2); | |
end; | |
function TUltravisorClient.GetVirtualMachineAccountRes(const Uuid: RawUtf8; | |
const Login: RawUtf8): TDbAccount; | |
begin | |
fClient.Request('GET', '/api/vms/%/accounts/%/', [Uuid, Login], [], [], | |
result, TypeInfo(TDbAccount), OnError2); | |
end; | |
function TUltravisorClient.PostVirtualMachineAccountResAuthorize(const Uuid: RawUtf8; | |
const Login: RawUtf8; const Payload: TUserShort): TDbAccount; | |
begin | |
fClient.Request('POST', '/api/vms/%/accounts/%/authorize/', [Uuid, Login], [], [], | |
Payload, result, TypeInfo(TUserShort), TypeInfo(TDbAccount), OnError1); | |
end; | |
function TUltravisorClient.PostVirtualMachineAccountResReloadAuthorizedKeys( | |
const Uuid: RawUtf8; const Login: RawUtf8): TDbAccount; | |
begin | |
fClient.Request('POST', '/api/vms/%/accounts/%/reload-authorized-keys/', [Uuid, Login], [], [], | |
result, TypeInfo(TDbAccount), OnError1); | |
end; | |
function TUltravisorClient.PostVirtualMachineAccountResUnauthorize(const Uuid: RawUtf8; | |
const Login: RawUtf8; const Payload: TUserShort): TDbAccount; | |
begin | |
fClient.Request('POST', '/api/vms/%/accounts/%/unauthorize/', [Uuid, Login], [], [], | |
Payload, result, TypeInfo(TUserShort), TypeInfo(TDbAccount), OnError1); | |
end; | |
function TUltravisorClient.PostVirtualMachineResAddAdmin(const Uuid: RawUtf8; | |
const Payload: TUserShort): TDbVirtualMachine; | |
begin | |
fClient.Request('POST', '/api/vms/%/add-admin/', [Uuid], [], [], | |
Payload, result, TypeInfo(TUserShort), TypeInfo(TDbVirtualMachine), OnError1); | |
end; | |
function TUltravisorClient.PostVirtualMachineResCreateAccount(const Uuid: RawUtf8; | |
const Payload: TAccountPost): TDbAccountDynArray; | |
begin | |
fClient.Request('POST', '/api/vms/%/create-account/', [Uuid], [], [], | |
Payload, result, TypeInfo(TAccountPost), TypeInfo(TDbAccountDynArray), OnError1); | |
end; | |
function TUltravisorClient.PostVirtualMachineResRegisterAccount(const Uuid: RawUtf8; | |
const Payload: TAccountPost): TDbAccountDynArray; | |
begin | |
fClient.Request('POST', '/api/vms/%/register-account/', [Uuid], [], [], | |
Payload, result, TypeInfo(TAccountPost), TypeInfo(TDbAccountDynArray), OnError1); | |
end; | |
function TUltravisorClient.PostVirtualMachineResRemoveAdmin(const Uuid: RawUtf8; | |
const Payload: TUserShort): TDbVirtualMachine; | |
begin | |
fClient.Request('POST', '/api/vms/%/remove-admin/', [Uuid], [], [], | |
Payload, result, TypeInfo(TUserShort), TypeInfo(TDbVirtualMachine), OnError1); | |
end; | |
function TUltravisorClient.PostVirtualMachineResSetOwner(const Uuid: RawUtf8; | |
const Payload: TUserShort): TDbVirtualMachine; | |
begin | |
fClient.Request('POST', '/api/vms/%/set-owner/', [Uuid], [], [], | |
Payload, result, TypeInfo(TUserShort), TypeInfo(TDbVirtualMachine), OnError1); | |
end; | |
function TUltravisorClient.PostVirtualMachineResStart(const Uuid: RawUtf8): TVmStatus; | |
begin | |
fClient.Request('POST', '/api/vms/%/start/', [Uuid], [], [], | |
result, TypeInfo(TVmStatus), OnError2); | |
end; | |
function TUltravisorClient.GetVirtualMachineResStatus(const Uuid: RawUtf8): TVmStatus; | |
begin | |
fClient.Request('GET', '/api/vms/%/status/', [Uuid], [], [], | |
result, TypeInfo(TVmStatus), OnError2); | |
end; | |
function TUltravisorClient.PostVirtualMachineResStop(const Uuid: RawUtf8): TVmStatus; | |
begin | |
fClient.Request('POST', '/api/vms/%/stop/', [Uuid], [], [], | |
result, TypeInfo(TVmStatus), OnError2); | |
end; | |
procedure TUltravisorClient.DeleteVirtualMachineResUnregister(const Uuid: RawUtf8); | |
begin | |
fClient.Request('DELETE', '/api/vms/%/unregister/', [Uuid], [], [], OnError2); | |
end; | |
function TUltravisorClient.GetVirtualMachineResUsers(const Uuid: RawUtf8): TVmUsers; | |
begin | |
fClient.Request('GET', '/api/vms/%/users/', [Uuid], [], [], | |
result, TypeInfo(TVmUsers), OnError2); | |
end; | |
{ ************ Custom RTTI/JSON initialization } | |
const | |
// exact definition of the DTOs expected JSON serialization | |
_THypervisorShort = 'type:TEnumUltravisor1 url:RawUtf8 max_owned_vms:integer ' + | |
'queue_size:integer priority:integer configuration:variant'; | |
_TComputerCapabilities = 'architecture:RawUtf8 os:RawUtf8 os_version:RawUtf8 ' + | |
'os_pretty_name:RawUtf8 tags:TRawUtf8DynArray'; | |
_TAccountPost = 'login:RawUtf8 authorized_users:TRawUtf8DynArray grant_auth_users:TRawUtf8DynArray'; | |
_TBaseVirtualMachine = 'name:RawUtf8 expiration_date:TDateTime owner:RawUtf8'; | |
_THypervisorVirtualMachine = 'name:RawUtf8 expiration_date:TDateTime owner:RawUtf8 ' + | |
'accounts:array of TAccountPost'; | |
_THypervisorTemplate = 'name:RawUtf8 display_name:RawUtf8 priority:integer ' + | |
'capabilities:TComputerCapabilities TTL:integer accounts:array of TAccountPost ' + | |
'vms:array of THypervisorVirtualMachine'; | |
_TBaseErrorResponse = 'status:integer message:RawUtf8'; | |
_TDatabaseObject = 'uuid:RawUtf8 created_on:TDateTime updated_on:TDateTime'; | |
_TUserShort = 'name:RawUtf8'; | |
_TDbUserShort = 'name:RawUtf8 uuid:RawUtf8 created_on:TDateTime updated_on:TDateTime'; | |
_TAccount = 'login:RawUtf8 authorized_users:array of TDbUserShort grant_auth_users:array of TDbUserShort'; | |
_THypervisorTypePatch = 'priority:integer'; | |
_THypervisorPatch = 'type:TEnumUltravisor1 url:RawUtf8 max_owned_vms:integer ' + | |
'queue_size:integer priority:integer configuration:variant'; | |
_TExternalVirtualMachine = 'name:TEnumUltravisor1 uuid:RawUtf8 state:TEnumUltravisor2'; | |
_THypervisorQueue = 'owner:TUserShort priority:integer timestamp:TDateTime ' + | |
'uuid:RawUtf8'; | |
_TVirtualMachinePatch = 'capabilities:TComputerCapabilities name:RawUtf8 ' + | |
'expiration_date:TDateTime'; | |
_TComputerSession = 'login:RawUtf8 type:TEnumUltravisor3 count:integer'; | |
_TVmStatus = 'ip:RawUtf8 state:TEnumUltravisor2 sessions:array of TComputerSession ' + | |
'additionals:variant'; | |
_TDbAccount = 'login:RawUtf8 authorized_users:array of TDbUserShort grant_auth_users:array of TDbUserShort ' + | |
'uuid:RawUtf8 created_on:TDateTime updated_on:TDateTime'; | |
_TVmUsers = 'owner:TDbUserShort admins:array of TDbUserShort accounts:array of TDbAccount'; | |
_TUserPubkey = 'key:RawUtf8'; | |
_TValidationErrorResponse = 'status:integer message:RawUtf8'; | |
_TUnauthorizedResponse = 'status:integer message:RawUtf8'; | |
_TForbiddenResponse = 'status:integer message:RawUtf8'; | |
_TResourceNotFoundError = 'status:integer message:RawUtf8'; | |
_TIntegrityErrorResponse = 'status:integer message:RawUtf8'; | |
_THypervisor = 'type:TEnumUltravisor1 url:RawUtf8 max_owned_vms:integer ' + | |
'queue_size:integer priority:integer configuration:variant templates:array of THypervisorTemplate ' + | |
'accounts:array of TAccountPost'; | |
_TDbHypervisorShort = 'uuid:RawUtf8 created_on:TDateTime updated_on:TDateTime ' + | |
'type:TEnumUltravisor1 url:RawUtf8 max_owned_vms:integer queue_size:integer ' + | |
'priority:integer configuration:variant'; | |
_TDbTemplateShort = 'uuid:RawUtf8 created_on:TDateTime updated_on:TDateTime ' + | |
'name:RawUtf8 display_name:RawUtf8 priority:integer capabilities:TComputerCapabilities ' + | |
'TTL:integer hypervisor:TDbHypervisorShort'; | |
_TDbVirtualMachineShort = 'uuid:RawUtf8 created_on:TDateTime updated_on:TDateTime ' + | |
'name:RawUtf8 expiration_date:TDateTime owner:RawUtf8 hypervisor:TDbHypervisorShort ' + | |
'template:TDbTemplateShort capabilities:TComputerCapabilities'; | |
_TDbHypervisor = 'uuid:RawUtf8 created_on:TDateTime updated_on:TDateTime ' + | |
'type:TEnumUltravisor1 url:RawUtf8 max_owned_vms:integer queue_size:integer ' + | |
'priority:integer configuration:variant templates:array of TDbTemplateShort ' + | |
'vms:array of TDbVirtualMachineShort accounts:array of TDbAccount'; | |
_TDbHypervisorTypeShort = 'uuid:RawUtf8 created_on:TDateTime updated_on:TDateTime ' + | |
'name:TEnumUltravisor1 priority:integer'; | |
_TDbHypervisorType = 'uuid:RawUtf8 created_on:TDateTime updated_on:TDateTime ' + | |
'name:TEnumUltravisor1 priority:integer instances:array of TDbHypervisorShort'; | |
_TTemplate = 'name:RawUtf8 display_name:RawUtf8 priority:integer capabilities:TComputerCapabilities ' + | |
'TTL:integer accounts:array of TAccountPost vms:array of THypervisorVirtualMachine ' + | |
'hypervisor_uuid:RawUtf8'; | |
_TDbTemplate = 'uuid:RawUtf8 created_on:TDateTime updated_on:TDateTime ' + | |
'name:RawUtf8 display_name:RawUtf8 priority:integer capabilities:TComputerCapabilities ' + | |
'TTL:integer hypervisor:TDbHypervisorShort vms:array of TDbVirtualMachineShort ' + | |
'accounts:array of TDbAccount'; | |
_TDbVirtualMachine = 'uuid:RawUtf8 created_on:TDateTime updated_on:TDateTime ' + | |
'name:RawUtf8 expiration_date:TDateTime owner:RawUtf8 hypervisor:TDbHypervisorShort ' + | |
'template:TDbTemplateShort capabilities:TComputerCapabilities accounts:array of TDbAccount ' + | |
'admins:array of TDbUserShort'; | |
_TUserRegister = 'name:RawUtf8 sid:RawUtf8 vm_priority:integer ssh_pub_cert:RawUtf8'; | |
_TDbUser = 'name:RawUtf8 sid:RawUtf8 vm_priority:integer ssh_pub_cert:RawUtf8 ' + | |
'uuid:RawUtf8 created_on:TDateTime updated_on:TDateTime owned_vms:array of TDbVirtualMachineShort'; | |
_TDbUserMe = 'name:RawUtf8 sid:RawUtf8 vm_priority:integer ssh_pub_cert:RawUtf8 ' + | |
'uuid:RawUtf8 created_on:TDateTime updated_on:TDateTime owned_vms:array of TDbVirtualMachineShort ' + | |
'roles:TEnumUltravisor4Set'; | |
_TVirtualMachinePost = 'capabilities:TComputerCapabilities name:RawUtf8 ' + | |
'expiration_date:TDateTime hypervisor_uuid:RawUtf8 template_uuid:RawUtf8 ' + | |
'uuid:RawUtf8 accounts:array of TAccountPost'; | |
_TExternalHypervisorVirtualMachine = 'name:TEnumUltravisor1 uuid:RawUtf8 ' + | |
'state:TEnumUltravisor2 hypervisor_uuid:RawUtf8'; | |
procedure RegisterRtti; | |
begin | |
TRttiJson.RegisterCustomEnumValues([ | |
TypeInfo(TEnumUltravisor1), nil, @ENUMULTRAVISOR1_TXT, | |
TypeInfo(TEnumUltravisor2), nil, @ENUMULTRAVISOR2_TXT, | |
TypeInfo(TEnumUltravisor3), nil, @ENUMULTRAVISOR3_TXT, | |
TypeInfo(TEnumUltravisor4), TypeInfo(TEnumUltravisor4Set), @ENUMULTRAVISOR4_TXT]); | |
Rtti.RegisterFromText([ | |
TypeInfo(THypervisorShort), _THypervisorShort, | |
TypeInfo(TComputerCapabilities), _TComputerCapabilities, | |
TypeInfo(TAccountPost), _TAccountPost, | |
TypeInfo(TBaseVirtualMachine), _TBaseVirtualMachine, | |
TypeInfo(THypervisorVirtualMachine), _THypervisorVirtualMachine, | |
TypeInfo(THypervisorTemplate), _THypervisorTemplate, | |
TypeInfo(TBaseErrorResponse), _TBaseErrorResponse, | |
TypeInfo(TDatabaseObject), _TDatabaseObject, | |
TypeInfo(TUserShort), _TUserShort, | |
TypeInfo(TDbUserShort), _TDbUserShort, | |
TypeInfo(TAccount), _TAccount, | |
TypeInfo(THypervisorTypePatch), _THypervisorTypePatch, | |
TypeInfo(THypervisorPatch), _THypervisorPatch, | |
TypeInfo(TExternalVirtualMachine), _TExternalVirtualMachine, | |
TypeInfo(THypervisorQueue), _THypervisorQueue, | |
TypeInfo(TVirtualMachinePatch), _TVirtualMachinePatch, | |
TypeInfo(TComputerSession), _TComputerSession, | |
TypeInfo(TVmStatus), _TVmStatus, | |
TypeInfo(TDbAccount), _TDbAccount, | |
TypeInfo(TVmUsers), _TVmUsers, | |
TypeInfo(TUserPubkey), _TUserPubkey, | |
TypeInfo(TValidationErrorResponse), _TValidationErrorResponse, | |
TypeInfo(TUnauthorizedResponse), _TUnauthorizedResponse, | |
TypeInfo(TForbiddenResponse), _TForbiddenResponse, | |
TypeInfo(TResourceNotFoundError), _TResourceNotFoundError, | |
TypeInfo(TIntegrityErrorResponse), _TIntegrityErrorResponse, | |
TypeInfo(THypervisor), _THypervisor, | |
TypeInfo(TDbHypervisorShort), _TDbHypervisorShort, | |
TypeInfo(TDbTemplateShort), _TDbTemplateShort, | |
TypeInfo(TDbVirtualMachineShort), _TDbVirtualMachineShort, | |
TypeInfo(TDbHypervisor), _TDbHypervisor, | |
TypeInfo(TDbHypervisorTypeShort), _TDbHypervisorTypeShort, | |
TypeInfo(TDbHypervisorType), _TDbHypervisorType, | |
TypeInfo(TTemplate), _TTemplate, | |
TypeInfo(TDbTemplate), _TDbTemplate, | |
TypeInfo(TDbVirtualMachine), _TDbVirtualMachine, | |
TypeInfo(TUserRegister), _TUserRegister, | |
TypeInfo(TDbUser), _TDbUser, | |
TypeInfo(TDbUserMe), _TDbUserMe, | |
TypeInfo(TVirtualMachinePost), _TVirtualMachinePost, | |
TypeInfo(TExternalHypervisorVirtualMachine), _TExternalHypervisorVirtualMachine]); | |
end; | |
initialization | |
RegisterRtti; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment