From d9d7cd059e50d61d4fdd473fc0b72502aad00222 Mon Sep 17 00:00:00 2001 From: powerkimhub Date: Mon, 23 Dec 2024 10:39:44 +0900 Subject: [PATCH] Add constant type for ImageHandler to enhance clarity --- api/docs.go | 62 ++++++++++++++++++- api/swagger.json | 62 ++++++++++++++++++- api/swagger.yaml | 44 ++++++++++++- .../interfaces/resources/ImageHandler.go | 47 +++++++++++--- 4 files changed, 196 insertions(+), 19 deletions(-) diff --git a/api/docs.go b/api/docs.go index 797f205b..a73928a0 100644 --- a/api/docs.go +++ b/api/docs.go @@ -8465,6 +8465,7 @@ const docTemplate = `{ "OSDiskType", "OSDistribution", "OSPlatform", + "Status", "Status" ], "properties": { @@ -8494,7 +8495,11 @@ const docTemplate = `{ }, "OSArchitecture": { "description": "arm64, x86_64 etc.", - "type": "string", + "allOf": [ + { + "$ref": "#/definitions/spider.OSArchitecture" + } + ], "example": "x86_64" }, "OSDiskSize": { @@ -8514,16 +8519,37 @@ const docTemplate = `{ }, "OSPlatform": { "description": "Linux/UNIX, Windows, NA", - "type": "string", + "allOf": [ + { + "$ref": "#/definitions/spider.OSPlatform" + } + ], "example": "Linux/UNIX" }, "Status": { "description": "Available, Unavailable", - "type": "string", + "allOf": [ + { + "$ref": "#/definitions/spider.ImageStatus" + } + ], "example": "Available" } } }, + "spider.ImageStatus": { + "type": "string", + "enum": [ + "Available", + "Unavailable", + "NA" + ], + "x-enum-varnames": [ + "ImageAvailable", + "ImageUnavailable", + "ImageNA" + ] + }, "spider.ImageType": { "type": "string", "enum": [ @@ -8915,6 +8941,36 @@ const docTemplate = `{ "NodeGroupDeleting" ] }, + "spider.OSArchitecture": { + "type": "string", + "enum": [ + "arm64", + "arm64_mac", + "x86_64", + "x86_64_mac", + "NA" + ], + "x-enum-varnames": [ + "ARM64", + "ARM64_MAC", + "X86_64", + "X86_64_MAC", + "ArchitectureNA" + ] + }, + "spider.OSPlatform": { + "type": "string", + "enum": [ + "Linux/UNIX", + "Windows", + "NA" + ], + "x-enum-varnames": [ + "Linux_UNIX", + "Windows", + "PlatformNA" + ] + }, "spider.Platform": { "type": "string", "enum": [ diff --git a/api/swagger.json b/api/swagger.json index c1f9abe6..ac7a2a69 100644 --- a/api/swagger.json +++ b/api/swagger.json @@ -8462,6 +8462,7 @@ "OSDiskType", "OSDistribution", "OSPlatform", + "Status", "Status" ], "properties": { @@ -8491,7 +8492,11 @@ }, "OSArchitecture": { "description": "arm64, x86_64 etc.", - "type": "string", + "allOf": [ + { + "$ref": "#/definitions/spider.OSArchitecture" + } + ], "example": "x86_64" }, "OSDiskSize": { @@ -8511,16 +8516,37 @@ }, "OSPlatform": { "description": "Linux/UNIX, Windows, NA", - "type": "string", + "allOf": [ + { + "$ref": "#/definitions/spider.OSPlatform" + } + ], "example": "Linux/UNIX" }, "Status": { "description": "Available, Unavailable", - "type": "string", + "allOf": [ + { + "$ref": "#/definitions/spider.ImageStatus" + } + ], "example": "Available" } } }, + "spider.ImageStatus": { + "type": "string", + "enum": [ + "Available", + "Unavailable", + "NA" + ], + "x-enum-varnames": [ + "ImageAvailable", + "ImageUnavailable", + "ImageNA" + ] + }, "spider.ImageType": { "type": "string", "enum": [ @@ -8912,6 +8938,36 @@ "NodeGroupDeleting" ] }, + "spider.OSArchitecture": { + "type": "string", + "enum": [ + "arm64", + "arm64_mac", + "x86_64", + "x86_64_mac", + "NA" + ], + "x-enum-varnames": [ + "ARM64", + "ARM64_MAC", + "X86_64", + "X86_64_MAC", + "ArchitectureNA" + ] + }, + "spider.OSPlatform": { + "type": "string", + "enum": [ + "Linux/UNIX", + "Windows", + "NA" + ], + "x-enum-varnames": [ + "Linux_UNIX", + "Windows", + "PlatformNA" + ] + }, "spider.Platform": { "type": "string", "enum": [ diff --git a/api/swagger.yaml b/api/swagger.yaml index 913dd7c8..fd4976e3 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -341,9 +341,10 @@ definitions: example: ami-00aa5a103ddf4509f type: string OSArchitecture: + allOf: + - $ref: '#/definitions/spider.OSArchitecture' description: arm64, x86_64 etc. example: x86_64 - type: string OSDiskSize: description: 35, etc., GB example: "35" @@ -357,13 +358,15 @@ definitions: example: Ubuntu 22.04~ type: string OSPlatform: + allOf: + - $ref: '#/definitions/spider.OSPlatform' description: Linux/UNIX, Windows, NA example: Linux/UNIX - type: string Status: + allOf: + - $ref: '#/definitions/spider.ImageStatus' description: Available, Unavailable example: Available - type: string required: - GuestOS - IId @@ -374,7 +377,18 @@ definitions: - OSDistribution - OSPlatform - Status + - Status type: object + spider.ImageStatus: + enum: + - Available + - Unavailable + - NA + type: string + x-enum-varnames: + - ImageAvailable + - ImageUnavailable + - ImageNA spider.ImageType: enum: - PublicImage @@ -647,6 +661,30 @@ definitions: - NodeGroupInactive - NodeGroupUpdating - NodeGroupDeleting + spider.OSArchitecture: + enum: + - arm64 + - arm64_mac + - x86_64 + - x86_64_mac + - NA + type: string + x-enum-varnames: + - ARM64 + - ARM64_MAC + - X86_64 + - X86_64_MAC + - ArchitectureNA + spider.OSPlatform: + enum: + - Linux/UNIX + - Windows + - NA + type: string + x-enum-varnames: + - Linux_UNIX + - Windows + - PlatformNA spider.Platform: enum: - LINUX/UNIX diff --git a/cloud-control-manager/cloud-driver/interfaces/resources/ImageHandler.go b/cloud-control-manager/cloud-driver/interfaces/resources/ImageHandler.go index 4f9c9f60..99be8dd3 100644 --- a/cloud-control-manager/cloud-driver/interfaces/resources/ImageHandler.go +++ b/cloud-control-manager/cloud-driver/interfaces/resources/ImageHandler.go @@ -16,18 +16,45 @@ type ImageReqInfo struct { // @todo } +type OSArchitecture string + +const ( + ARM64 OSArchitecture = "arm64" + ARM64_MAC OSArchitecture = "arm64_mac" + X86_64 OSArchitecture = "x86_64" + X86_64_MAC OSArchitecture = "x86_64_mac" + ArchitectureNA OSArchitecture = "NA" +) + +type OSPlatform string + +const ( + Linux_UNIX OSPlatform = "Linux/UNIX" + Windows OSPlatform = "Windows" + PlatformNA OSPlatform = "NA" +) + +type ImageStatus string + +const ( + ImageAvailable ImageStatus = "Available" + ImageUnavailable ImageStatus = "Unavailable" + ImageNA ImageStatus = "NA" +) + // ImageInfo represents the information of an Image. type ImageInfo struct { - IId IID `json:"IId" validate:"required" description:"The ID of the image."` // {NameId, SystemId} // Deprecated - GuestOS string `json:"GuestOS" validate:"required" example:"Ubuntu 18.04" description:"The operating system of the image."` // Windows7, Ubuntu etc. // Deprecated - - Name string `json:"Name" validate:"required" example:"ami-00aa5a103ddf4509f" description:"The name of the image."` // ami-00aa5a103ddf4509f - OSArchitecture string `json:"OSArchitecture" validate:"required" example:"x86_64" description:"The architecture of the operating system of the image."` // arm64, x86_64 etc. - OSPlatform string `json:"OSPlatform" validate:"required" example:"Linux/UNIX" description:"The platform of the operating system of the image."` // Linux/UNIX, Windows, NA - OSDistribution string `json:"OSDistribution" validate:"required" example:"Ubuntu 22.04~" description:"The distribution of the operating system of the image."` // Ubuntu 22.04~, CentOS 8 etc. - OSDiskType string `json:"OSDiskType" validate:"required" example:"gp3" description:"The type of the disk of the image."` // gp3, etc. - OSDiskSize string `json:"OSDiskSize" validate:"required" example:"35" description:"The size of the disk of the image."` // 35, etc., GB - Status string `json:"Status" validate:"required" example:"Available" description:"The status of the image, e.g., Available or Unavailable."` // Available, Unavailable + IId IID `json:"IId" validate:"required" description:"The ID of the image."` // {NameId, SystemId} // Deprecated + GuestOS string `json:"GuestOS" validate:"required" example:"Ubuntu 18.04" description:"The operating system of the image."` // Windows7, Ubuntu etc. // Deprecated + Status string `json:"Status" validate:"required" example:"available" description:"The status of the image, e.g., available or unavailable."` // available, unavailable // Deprecated + + Name string `json:"Name" validate:"required" example:"ami-00aa5a103ddf4509f" description:"The name of the image."` // ami-00aa5a103ddf4509f + OSArchitecture OSArchitecture `json:"OSArchitecture" validate:"required" example:"x86_64" description:"The architecture of the operating system of the image."` // arm64, x86_64 etc. + OSPlatform OSPlatform `json:"OSPlatform" validate:"required" example:"Linux/UNIX" description:"The platform of the operating system of the image."` // Linux/UNIX, Windows, NA + OSDistribution string `json:"OSDistribution" validate:"required" example:"Ubuntu 22.04~" description:"The distribution of the operating system of the image."` // Ubuntu 22.04~, CentOS 8 etc. + OSDiskType string `json:"OSDiskType" validate:"required" example:"gp3" description:"The type of the disk of the image."` // gp3, etc. + OSDiskSize string `json:"OSDiskSize" validate:"required" example:"35" description:"The size of the disk of the image."` // 35, etc., GB + ImageStatus ImageStatus `json:"Status" validate:"required" example:"Available" description:"The status of the image, e.g., Available or Unavailable."` // Available, Unavailable KeyValueList []KeyValue `json:"KeyValueList,omitempty" validate:"omitempty" description:"A list of key-value pairs associated with the image."` }