|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | + STACKIT File Storage (SFS) |
| 5 | +
|
| 6 | + API used to create and manage NFS Shares. |
| 7 | +
|
| 8 | + The version of the OpenAPI document: 1.0.0 |
| 9 | + Generated by OpenAPI Generator (https://openapi-generator.tech) |
| 10 | +
|
| 11 | + Do not edit the class manually. |
| 12 | +""" # noqa: E501 |
| 13 | + |
| 14 | +from __future__ import annotations |
| 15 | + |
| 16 | +import json |
| 17 | +import pprint |
| 18 | +import re # noqa: F401 |
| 19 | +from datetime import datetime |
| 20 | +from typing import Any, ClassVar, Dict, List, Optional, Set |
| 21 | + |
| 22 | +from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator |
| 23 | +from typing_extensions import Self |
| 24 | + |
| 25 | + |
| 26 | +class SnapshotPolicySnapshotPolicySchedule(BaseModel): |
| 27 | + """ |
| 28 | + SnapshotPolicySnapshotPolicySchedule |
| 29 | + """ # noqa: E501 |
| 30 | + |
| 31 | + created_at: Optional[datetime] = Field(default=None, alias="createdAt") |
| 32 | + id: Optional[StrictStr] = Field(default=None, description="ID of the Schedule") |
| 33 | + interval: Optional[StrictStr] = Field( |
| 34 | + default=None, description="Interval of the Schedule (follows the cron schedule expression in Unix-like systems)" |
| 35 | + ) |
| 36 | + name: Optional[StrictStr] = Field(default=None, description="Name of the Schedule") |
| 37 | + prefix: Optional[StrictStr] = Field( |
| 38 | + default=None, description="Prefix used for the snapshots created by this policy" |
| 39 | + ) |
| 40 | + retention_count: Optional[StrictInt] = Field(default=None, description="Retention Count", alias="retentionCount") |
| 41 | + retention_period: Optional[StrictStr] = Field( |
| 42 | + default=None, description='Retention Period (ISO 8601 format or "infinite")', alias="retentionPeriod" |
| 43 | + ) |
| 44 | + __properties: ClassVar[List[str]] = [ |
| 45 | + "createdAt", |
| 46 | + "id", |
| 47 | + "interval", |
| 48 | + "name", |
| 49 | + "prefix", |
| 50 | + "retentionCount", |
| 51 | + "retentionPeriod", |
| 52 | + ] |
| 53 | + |
| 54 | + @field_validator("created_at", mode="before") |
| 55 | + def created_at_change_year_zero_to_one(cls, value): |
| 56 | + """Workaround which prevents year 0 issue""" |
| 57 | + if isinstance(value, str): |
| 58 | + # Check for year "0000" at the beginning of the string |
| 59 | + # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ |
| 60 | + if value.startswith("0000-01-01T") and re.match( |
| 61 | + r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$", value |
| 62 | + ): |
| 63 | + # Workaround: Replace "0000" with "0001" |
| 64 | + return "0001" + value[4:] # Take "0001" and append the rest of the string |
| 65 | + return value |
| 66 | + |
| 67 | + model_config = ConfigDict( |
| 68 | + populate_by_name=True, |
| 69 | + validate_assignment=True, |
| 70 | + protected_namespaces=(), |
| 71 | + ) |
| 72 | + |
| 73 | + def to_str(self) -> str: |
| 74 | + """Returns the string representation of the model using alias""" |
| 75 | + return pprint.pformat(self.model_dump(by_alias=True)) |
| 76 | + |
| 77 | + def to_json(self) -> str: |
| 78 | + """Returns the JSON representation of the model using alias""" |
| 79 | + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead |
| 80 | + return json.dumps(self.to_dict()) |
| 81 | + |
| 82 | + @classmethod |
| 83 | + def from_json(cls, json_str: str) -> Optional[Self]: |
| 84 | + """Create an instance of SnapshotPolicySnapshotPolicySchedule from a JSON string""" |
| 85 | + return cls.from_dict(json.loads(json_str)) |
| 86 | + |
| 87 | + def to_dict(self) -> Dict[str, Any]: |
| 88 | + """Return the dictionary representation of the model using alias. |
| 89 | +
|
| 90 | + This has the following differences from calling pydantic's |
| 91 | + `self.model_dump(by_alias=True)`: |
| 92 | +
|
| 93 | + * `None` is only added to the output dict for nullable fields that |
| 94 | + were set at model initialization. Other fields with value `None` |
| 95 | + are ignored. |
| 96 | + """ |
| 97 | + excluded_fields: Set[str] = set([]) |
| 98 | + |
| 99 | + _dict = self.model_dump( |
| 100 | + by_alias=True, |
| 101 | + exclude=excluded_fields, |
| 102 | + exclude_none=True, |
| 103 | + ) |
| 104 | + return _dict |
| 105 | + |
| 106 | + @classmethod |
| 107 | + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: |
| 108 | + """Create an instance of SnapshotPolicySnapshotPolicySchedule from a dict""" |
| 109 | + if obj is None: |
| 110 | + return None |
| 111 | + |
| 112 | + if not isinstance(obj, dict): |
| 113 | + return cls.model_validate(obj) |
| 114 | + |
| 115 | + _obj = cls.model_validate( |
| 116 | + { |
| 117 | + "createdAt": obj.get("createdAt"), |
| 118 | + "id": obj.get("id"), |
| 119 | + "interval": obj.get("interval"), |
| 120 | + "name": obj.get("name"), |
| 121 | + "prefix": obj.get("prefix"), |
| 122 | + "retentionCount": obj.get("retentionCount"), |
| 123 | + "retentionPeriod": obj.get("retentionPeriod"), |
| 124 | + } |
| 125 | + ) |
| 126 | + return _obj |
0 commit comments