|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | + IaaS-API |
| 5 | +
|
| 6 | + This API allows you to create and modify IaaS resources. |
| 7 | +
|
| 8 | + The version of the OpenAPI document: 1alpha1 |
| 9 | + |
| 10 | + Generated by OpenAPI Generator (https://openapi-generator.tech) |
| 11 | +
|
| 12 | + Do not edit the class manually. |
| 13 | +""" # noqa: E501 docstring might be too long |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +import json |
| 18 | +import pprint |
| 19 | +import re |
| 20 | +from datetime import datetime |
| 21 | +from typing import Any, ClassVar, Dict, List, Optional, Set |
| 22 | + |
| 23 | +from pydantic import ( |
| 24 | + BaseModel, |
| 25 | + ConfigDict, |
| 26 | + Field, |
| 27 | + StrictBool, |
| 28 | + StrictInt, |
| 29 | + StrictStr, |
| 30 | + field_validator, |
| 31 | +) |
| 32 | +from typing_extensions import Annotated, Self |
| 33 | + |
| 34 | +from stackit.iaasalpha.models.image_config import ImageConfig |
| 35 | + |
| 36 | + |
| 37 | +class CreateImagePayload(BaseModel): |
| 38 | + """ |
| 39 | + Object that represents an Image and its parameters. Used for Creating and returning (get/list). |
| 40 | + """ |
| 41 | + |
| 42 | + config: Optional[ImageConfig] = None |
| 43 | + created_at: Optional[datetime] = Field( |
| 44 | + default=None, description="Date-time when resource was created.", alias="createdAt" |
| 45 | + ) |
| 46 | + disk_format: StrictStr = Field(description="Object that represents a disk format.", alias="diskFormat") |
| 47 | + id: Optional[Annotated[str, Field(min_length=36, strict=True, max_length=36)]] = Field( |
| 48 | + default=None, description="Universally Unique Identifier (UUID)." |
| 49 | + ) |
| 50 | + labels: Optional[Dict[str, Any]] = Field( |
| 51 | + default=None, description="Object that represents the labels of an object." |
| 52 | + ) |
| 53 | + min_disk_size: Optional[StrictInt] = Field(default=None, description="Size in Gigabyte.", alias="minDiskSize") |
| 54 | + min_ram: Optional[StrictInt] = Field(default=None, description="Size in Megabyte.", alias="minRam") |
| 55 | + name: Annotated[str, Field(strict=True, max_length=63)] = Field( |
| 56 | + description="The name for a General Object. Matches Names and also UUIDs." |
| 57 | + ) |
| 58 | + protected: Optional[StrictBool] = None |
| 59 | + status: Optional[StrictStr] = Field(default=None, description="The status of an image object.") |
| 60 | + updated_at: Optional[datetime] = Field( |
| 61 | + default=None, description="Date-time when resource was last updated.", alias="updatedAt" |
| 62 | + ) |
| 63 | + __properties: ClassVar[List[str]] = [ |
| 64 | + "config", |
| 65 | + "createdAt", |
| 66 | + "diskFormat", |
| 67 | + "id", |
| 68 | + "labels", |
| 69 | + "minDiskSize", |
| 70 | + "minRam", |
| 71 | + "name", |
| 72 | + "protected", |
| 73 | + "status", |
| 74 | + "updatedAt", |
| 75 | + ] |
| 76 | + |
| 77 | + @field_validator("id") |
| 78 | + def id_validate_regular_expression(cls, value): |
| 79 | + """Validates the regular expression""" |
| 80 | + if value is None: |
| 81 | + return value |
| 82 | + |
| 83 | + if not re.match(r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", value): |
| 84 | + raise ValueError( |
| 85 | + r"must validate the regular expression /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/" |
| 86 | + ) |
| 87 | + return value |
| 88 | + |
| 89 | + @field_validator("name") |
| 90 | + def name_validate_regular_expression(cls, value): |
| 91 | + """Validates the regular expression""" |
| 92 | + if not re.match(r"^[A-Za-z0-9]+((-|_|\s|\.)[A-Za-z0-9]+)*$", value): |
| 93 | + raise ValueError(r"must validate the regular expression /^[A-Za-z0-9]+((-|_|\s|\.)[A-Za-z0-9]+)*$/") |
| 94 | + return value |
| 95 | + |
| 96 | + model_config = ConfigDict( |
| 97 | + populate_by_name=True, |
| 98 | + validate_assignment=True, |
| 99 | + protected_namespaces=(), |
| 100 | + ) |
| 101 | + |
| 102 | + def to_str(self) -> str: |
| 103 | + """Returns the string representation of the model using alias""" |
| 104 | + return pprint.pformat(self.model_dump(by_alias=True)) |
| 105 | + |
| 106 | + def to_json(self) -> str: |
| 107 | + """Returns the JSON representation of the model using alias""" |
| 108 | + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead |
| 109 | + return json.dumps(self.to_dict()) |
| 110 | + |
| 111 | + @classmethod |
| 112 | + def from_json(cls, json_str: str) -> Optional[Self]: |
| 113 | + """Create an instance of CreateImagePayload from a JSON string""" |
| 114 | + return cls.from_dict(json.loads(json_str)) |
| 115 | + |
| 116 | + def to_dict(self) -> Dict[str, Any]: |
| 117 | + """Return the dictionary representation of the model using alias. |
| 118 | +
|
| 119 | + This has the following differences from calling pydantic's |
| 120 | + `self.model_dump(by_alias=True)`: |
| 121 | +
|
| 122 | + * `None` is only added to the output dict for nullable fields that |
| 123 | + were set at model initialization. Other fields with value `None` |
| 124 | + are ignored. |
| 125 | + * OpenAPI `readOnly` fields are excluded. |
| 126 | + * OpenAPI `readOnly` fields are excluded. |
| 127 | + * OpenAPI `readOnly` fields are excluded. |
| 128 | + * OpenAPI `readOnly` fields are excluded. |
| 129 | + """ |
| 130 | + excluded_fields: Set[str] = set( |
| 131 | + [ |
| 132 | + "created_at", |
| 133 | + "id", |
| 134 | + "status", |
| 135 | + "updated_at", |
| 136 | + ] |
| 137 | + ) |
| 138 | + |
| 139 | + _dict = self.model_dump( |
| 140 | + by_alias=True, |
| 141 | + exclude=excluded_fields, |
| 142 | + exclude_none=True, |
| 143 | + ) |
| 144 | + # override the default output from pydantic by calling `to_dict()` of config |
| 145 | + if self.config: |
| 146 | + _dict["config"] = self.config.to_dict() |
| 147 | + return _dict |
| 148 | + |
| 149 | + @classmethod |
| 150 | + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: |
| 151 | + """Create an instance of CreateImagePayload from a dict""" |
| 152 | + if obj is None: |
| 153 | + return None |
| 154 | + |
| 155 | + if not isinstance(obj, dict): |
| 156 | + return cls.model_validate(obj) |
| 157 | + |
| 158 | + _obj = cls.model_validate( |
| 159 | + { |
| 160 | + "config": ImageConfig.from_dict(obj["config"]) if obj.get("config") is not None else None, |
| 161 | + "createdAt": obj.get("createdAt"), |
| 162 | + "diskFormat": obj.get("diskFormat"), |
| 163 | + "id": obj.get("id"), |
| 164 | + "labels": obj.get("labels"), |
| 165 | + "minDiskSize": obj.get("minDiskSize"), |
| 166 | + "minRam": obj.get("minRam"), |
| 167 | + "name": obj.get("name"), |
| 168 | + "protected": obj.get("protected"), |
| 169 | + "status": obj.get("status"), |
| 170 | + "updatedAt": obj.get("updatedAt"), |
| 171 | + } |
| 172 | + ) |
| 173 | + return _obj |
0 commit comments