Migrate to Provisioning API nested root

This commit is contained in:
Ondrej Ezr 2023-08-10 17:05:57 +02:00 committed by Thomas Lavocat
parent f147d5f4fe
commit 1e37a6ece9
4 changed files with 360 additions and 181 deletions

View file

@ -111,7 +111,7 @@
"value": { "value": {
"amount": 1, "amount": 1,
"image_id": "08a48fed-de87-40ab-a571-f64e30bd0aa8", "image_id": "08a48fed-de87-40ab-a571-f64e30bd0aa8",
"launch_template_name": "", "launch_template_id": "",
"machine_type": "e2-micro", "machine_type": "e2-micro",
"name_pattern": "my-instance", "name_pattern": "my-instance",
"poweroff": false, "poweroff": false,
@ -134,7 +134,7 @@
"instance_id": "3003942005876582747" "instance_id": "3003942005876582747"
} }
], ],
"launch_template_name": "template-1", "launch_template_id": "4883371230199373111",
"machine_type": "e2-micro", "machine_type": "e2-micro",
"name_pattern": "my-instance", "name_pattern": "my-instance",
"poweroff": false, "poweroff": false,
@ -150,7 +150,7 @@
"gcp_operation_name": "operation-1686646674436-5fdff07e43209-66146b7e-f3f65ec5", "gcp_operation_name": "operation-1686646674436-5fdff07e43209-66146b7e-f3f65ec5",
"image_id": "08a48fed-de87-40ab-a571-f64e30bd0aa8", "image_id": "08a48fed-de87-40ab-a571-f64e30bd0aa8",
"instances": [], "instances": [],
"launch_template_name": "template-1", "launch_template_id": "4883371230199373111",
"machine_type": "e2-micro", "machine_type": "e2-micro",
"name_pattern": "my-instance", "name_pattern": "my-instance",
"poweroff": false, "poweroff": false,
@ -179,56 +179,58 @@
} }
}, },
"v1.GenericReservationResponsePayloadListExample": { "v1.GenericReservationResponsePayloadListExample": {
"value": [ "value": {
{ "data": [
"created_at": "2013-05-13T19:20:15Z", {
"error": "", "created_at": "2013-05-13T19:20:15Z",
"finished_at": null, "error": "",
"id": 1310, "finished_at": null,
"provider": 1, "id": 1310,
"status": "Started Ensure public key", "provider": 1,
"step": 1, "status": "Started Ensure public key",
"step_titles": [ "step": 1,
"Ensure public key", "step_titles": [
"Launch instance(s)", "Ensure public key",
"Fetch instance(s) description" "Launch instance(s)",
], "Fetch instance(s) description"
"steps": 3, ],
"success": null "steps": 3,
}, "success": null
{ },
"created_at": "2013-05-13T19:20:15Z", {
"error": "", "created_at": "2013-05-13T19:20:15Z",
"finished_at": "2013-05-13T19:20:25Z", "error": "",
"id": 1305, "finished_at": "2013-05-13T19:20:25Z",
"provider": 1, "id": 1305,
"status": "Finished Fetch instance(s) description", "provider": 1,
"step": 3, "status": "Finished Fetch instance(s) description",
"step_titles": [ "step": 3,
"Ensure public key", "step_titles": [
"Launch instance(s)", "Ensure public key",
"Fetch instance(s) description" "Launch instance(s)",
], "Fetch instance(s) description"
"steps": 3, ],
"success": true "steps": 3,
}, "success": true
{ },
"created_at": "2013-05-13T19:20:15Z", {
"error": "cannot launch ec2 instance: VPCIdNotSpecified: No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC", "created_at": "2013-05-13T19:20:15Z",
"finished_at": "2013-05-13T19:20:25Z", "error": "cannot launch ec2 instance: VPCIdNotSpecified: No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC",
"id": 1313, "finished_at": "2013-05-13T19:20:25Z",
"provider": 1, "id": 1313,
"status": "Finished Launch instance(s)", "provider": 1,
"step": 2, "status": "Finished Launch instance(s)",
"step_titles": [ "step": 2,
"Ensure public key", "step_titles": [
"Launch instance(s)", "Ensure public key",
"Fetch instance(s) description" "Launch instance(s)",
], "Fetch instance(s) description"
"steps": 3, ],
"success": false "steps": 3,
} "success": false
] }
]
}
}, },
"v1.GenericReservationResponsePayloadPendingExample": { "v1.GenericReservationResponsePayloadPendingExample": {
"value": { "value": {
@ -267,55 +269,63 @@
} }
}, },
"v1.InstanceTypesAWSResponse": { "v1.InstanceTypesAWSResponse": {
"value": [ "value": {
{ "data": [
"arch": "x86_64", {
"cores": 16, "arch": "x86_64",
"memory_mib": 65536, "cores": 16,
"name": "c5a.8xlarge", "memory_mib": 65536,
"storage_gb": 0, "name": "c5a.8xlarge",
"supported": true, "storage_gb": 0,
"vcpus": 32 "supported": true,
} "vcpus": 32
] }
]
}
}, },
"v1.InstanceTypesAzureResponse": { "v1.InstanceTypesAzureResponse": {
"value": [ "value": {
{ "data": [
"arch": "x86_64", {
"azure": { "arch": "x86_64",
"gen_v1": true, "azure": {
"gen_v2": true "gen_v1": true,
}, "gen_v2": true
"cores": 64, },
"memory_mib": 2000000, "cores": 64,
"name": "Standard_M128s", "memory_mib": 2000000,
"storage_gb": 4096, "name": "Standard_M128s",
"supported": true, "storage_gb": 4096,
"vcpus": 128 "supported": true,
} "vcpus": 128
] }
]
}
}, },
"v1.InstanceTypesGCPResponse": { "v1.InstanceTypesGCPResponse": {
"value": [ "value": {
{ "data": [
"arch": "x86_64", {
"cores": 0, "arch": "x86_64",
"memory_mib": 15623, "cores": 0,
"name": "e2-highcpu-16", "memory_mib": 15623,
"storage_gb": 0, "name": "e2-highcpu-16",
"supported": true, "storage_gb": 0,
"vcpus": 16 "supported": true,
} "vcpus": 16
] }
]
}
}, },
"v1.LaunchTemplateListResponse": { "v1.LaunchTemplateListResponse": {
"value": [ "value": {
{ "data": [
"id": "lt-9843797432897342", {
"name": "XXL large backend API" "id": "lt-9843797432897342",
} "name": "XXL large backend API"
] }
]
}
}, },
"v1.NoopReservationResponsePayloadExample": { "v1.NoopReservationResponsePayloadExample": {
"value": { "value": {
@ -323,16 +333,18 @@
} }
}, },
"v1.PubkeyListResponseExample": { "v1.PubkeyListResponseExample": {
"value": [ "value": {
{ "data": [
"body": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEhnn80ZywmjeBFFOGm+cm+5HUwm62qTVnjKlOdYFLHN lzap", {
"fingerprint": "gL/y6MvNmJ8jDXtsL/oMmK8jUuIefN39BBuvYw/Rndk=", "body": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEhnn80ZywmjeBFFOGm+cm+5HUwm62qTVnjKlOdYFLHN lzap",
"fingerprint_legacy": "ee:f1:d4:62:99:ab:17:d9:3b:00:66:62:32:b2:55:9e", "fingerprint": "gL/y6MvNmJ8jDXtsL/oMmK8jUuIefN39BBuvYw/Rndk=",
"id": 1, "fingerprint_legacy": "ee:f1:d4:62:99:ab:17:d9:3b:00:66:62:32:b2:55:9e",
"name": "My key", "id": 1,
"type": "ssh-ed25519" "name": "My key",
} "type": "ssh-ed25519"
] }
]
}
}, },
"v1.PubkeyRequestExample": { "v1.PubkeyRequestExample": {
"value": { "value": {
@ -351,20 +363,22 @@
} }
}, },
"v1.SourceListResponseExample": { "v1.SourceListResponseExample": {
"value": [ "value": {
{ "data": [
"id": "654321", {
"name": "My AWS account", "id": "654321",
"source_type_id": "", "name": "My AWS account",
"uid": "" "source_type_id": "",
}, "uid": ""
{ },
"id": "543621", {
"name": "My other AWS account", "id": "543621",
"source_type_id": "", "name": "My other AWS account",
"uid": "" "source_type_id": "",
} "uid": ""
] }
]
}
}, },
"v1.SourceUploadInfoAWSResponse": { "v1.SourceUploadInfoAWSResponse": {
"value": { "value": {
@ -676,7 +690,7 @@
"image_id": { "image_id": {
"type": "string" "type": "string"
}, },
"launch_template_name": { "launch_template_id": {
"type": "string" "type": "string"
}, },
"machine_type": { "machine_type": {
@ -735,7 +749,7 @@
}, },
"type": "array" "type": "array"
}, },
"launch_template_name": { "launch_template_id": {
"type": "string" "type": "string"
}, },
"machine_type": { "machine_type": {
@ -764,7 +778,7 @@
}, },
"type": "object" "type": "object"
}, },
"v1.GenericReservationResponsePayload": { "v1.GenericReservationResponse": {
"properties": { "properties": {
"created_at": { "created_at": {
"format": "date-time", "format": "date-time",
@ -861,6 +875,184 @@
}, },
"type": "object" "type": "object"
}, },
"v1.ListGenericReservationResponse": {
"properties": {
"data": {
"items": {
"properties": {
"created_at": {
"format": "date-time",
"type": "string"
},
"error": {
"type": "string"
},
"finished_at": {
"format": "date-time",
"nullable": true,
"type": "string"
},
"id": {
"format": "int64",
"type": "integer"
},
"provider": {
"type": "integer"
},
"status": {
"type": "string"
},
"step": {
"format": "int32",
"type": "integer"
},
"step_titles": {
"items": {
"type": "string"
},
"type": "array"
},
"steps": {
"format": "int32",
"type": "integer"
},
"success": {
"nullable": true,
"type": "boolean"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"v1.ListInstaceTypeResponse": {
"properties": {
"data": {
"items": {
"properties": {
"architecture": {
"type": "string"
},
"azure": {
"properties": {
"gen_v1": {
"type": "boolean"
},
"gen_v2": {
"type": "boolean"
}
},
"type": "object"
},
"cores": {
"format": "int32",
"type": "integer"
},
"memory_mib": {
"format": "int64",
"type": "integer"
},
"name": {
"type": "string"
},
"storage_gb": {
"format": "int64",
"type": "integer"
},
"supported": {
"type": "boolean"
},
"vcpus": {
"format": "int32",
"type": "integer"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"v1.ListLaunchTemplateResponse": {
"properties": {
"data": {
"items": {
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"v1.ListPubkeyResponse": {
"properties": {
"data": {
"items": {
"properties": {
"body": {
"type": "string"
},
"fingerprint": {
"type": "string"
},
"fingerprint_legacy": {
"type": "string"
},
"id": {
"format": "int64",
"type": "integer"
},
"name": {
"type": "string"
},
"type": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"v1.ListSourceResponse": {
"properties": {
"data": {
"items": {
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"source_type_id": {
"type": "string"
},
"uid": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"v1.NoopReservationResponse": { "v1.NoopReservationResponse": {
"properties": { "properties": {
"reservation_id": { "reservation_id": {
@ -994,7 +1186,7 @@
"name": "GPL-3.0" "name": "GPL-3.0"
}, },
"title": "provisioning-api", "title": "provisioning-api",
"version": "1.2.0" "version": "1.4.0"
}, },
"openapi": "3.0.0", "openapi": "3.0.0",
"paths": { "paths": {
@ -1076,10 +1268,7 @@
} }
}, },
"schema": { "schema": {
"items": { "$ref": "#/components/schemas/v1.ListInstaceTypeResponse"
"$ref": "#/components/schemas/v1.InstanceTypeResponse"
},
"type": "array"
} }
} }
}, },
@ -1111,10 +1300,7 @@
} }
}, },
"schema": { "schema": {
"items": { "$ref": "#/components/schemas/v1.ListPubkeyResponse"
"$ref": "#/components/schemas/v1.PubkeyResponse"
},
"type": "array"
} }
} }
}, },
@ -1260,10 +1446,7 @@
} }
}, },
"schema": { "schema": {
"items": { "$ref": "#/components/schemas/v1.ListGenericReservationResponse"
"$ref": "#/components/schemas/v1.GenericReservationResponsePayload"
},
"type": "array"
} }
} }
}, },
@ -1587,7 +1770,7 @@
} }
}, },
"schema": { "schema": {
"$ref": "#/components/schemas/v1.GenericReservationResponsePayload" "$ref": "#/components/schemas/v1.GenericReservationResponse"
} }
} }
}, },
@ -1633,10 +1816,7 @@
} }
}, },
"schema": { "schema": {
"items": { "$ref": "#/components/schemas/v1.ListSourceResponse"
"$ref": "#/components/schemas/v1.SourceResponse"
},
"type": "array"
} }
} }
}, },
@ -1722,10 +1902,7 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"items": { "$ref": "#/components/schemas/v1.ListInstaceTypeResponse"
"$ref": "#/components/schemas/v1.InstanceTypeResponse"
},
"type": "array"
} }
} }
}, },
@ -1778,10 +1955,7 @@
} }
}, },
"schema": { "schema": {
"items": { "$ref": "#/components/schemas/v1.ListLaunchTemplateResponse"
"$ref": "#/components/schemas/v1.LaunchTemplatesResponse"
},
"type": "array"
} }
} }
}, },

View file

@ -1,5 +1,4 @@
import type { V1SourceResponse } from './provisioningApi'; import type { V1ListSourceResponse } from './provisioningApi';
export const extractProvisioningList = ( export const extractProvisioningList = (list: V1ListSourceResponse) =>
list: V1SourceResponse[] | { data: V1SourceResponse[] } list?.data;
) => (Array.isArray(list) ? list : list?.data);

View file

@ -18,7 +18,7 @@ const injectedRtkApi = api.injectEndpoints({
}); });
export { injectedRtkApi as provisioningApi }; export { injectedRtkApi as provisioningApi };
export type GetSourceListApiResponse = export type GetSourceListApiResponse =
/** status 200 Returned on success. */ V1SourceResponse[]; /** status 200 Returned on success. */ V1ListSourceResponse;
export type GetSourceListApiArg = { export type GetSourceListApiArg = {
provider?: "aws" | "azure" | "gcp"; provider?: "aws" | "azure" | "gcp";
}; };
@ -28,11 +28,13 @@ export type GetSourceUploadInfoApiArg = {
/** Source ID from Sources Database */ /** Source ID from Sources Database */
id: number; id: number;
}; };
export type V1SourceResponse = { export type V1ListSourceResponse = {
id?: string; data?: {
name?: string; id?: string;
source_type_id?: string; name?: string;
uid?: string; source_type_id?: string;
uid?: string;
}[];
}; };
export type V1ResponseError = { export type V1ResponseError = {
build_time?: string; build_time?: string;

View file

@ -7,28 +7,32 @@ export const mockSourcesByProvider = (
provider: string provider: string
): GetSourceListApiResponse => { ): GetSourceListApiResponse => {
const mockSources: { [key: string]: GetSourceListApiResponse } = { const mockSources: { [key: string]: GetSourceListApiResponse } = {
aws: [ aws: {
{ data: [
id: '123', {
name: 'my_source', id: '123',
source_type_id: '1', name: 'my_source',
uid: 'de5e35d4-4c1f-49d7-9ef3-7d08e6b9c76a', source_type_id: '1',
}, uid: 'de5e35d4-4c1f-49d7-9ef3-7d08e6b9c76a',
], },
azure: [ ],
{ },
id: '666', azure: {
name: 'azureSource1', data: [
source_type_id: '3', {
uid: '9f48059c-25db-47ac-81e8-dac7f8a76170', id: '666',
}, name: 'azureSource1',
{ source_type_id: '3',
id: '667', uid: '9f48059c-25db-47ac-81e8-dac7f8a76170',
name: 'azureSource2', },
source_type_id: '3', {
uid: '73d5694c-7a28-417e-9fca-55840084f508', id: '667',
}, name: 'azureSource2',
], source_type_id: '3',
uid: '73d5694c-7a28-417e-9fca-55840084f508',
},
],
},
}; };
return mockSources[provider]; return mockSources[provider];
}; };