Skip to content

Commit 3893f72

Browse files
authored
Merge pull request #5 from SiddarthR56/main
Update to 0.6
2 parents 19949d5 + 715e736 commit 3893f72

File tree

6 files changed

+85
-15
lines changed

6 files changed

+85
-15
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ generate-client:
44
-g python \
55
-i ./api/v1alpha1/openapi.yml \
66
-o . \
7-
--additional-properties=packageName=flightctl \
7+
--additional-properties=packageName=flightctl,useOneOfDiscriminatorLookup=true \
88
--git-user-id flightctl \
99
--git-repo-id python-client

api/v1alpha1/openapi.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4212,15 +4212,15 @@ components:
42124212
type: object
42134213
description: Current status of the resources of the device.
42144214
required:
4215-
- CPU
4216-
- Memory
4217-
- Disk
4215+
- cpu
4216+
- memory
4217+
- disk
42184218
properties:
4219-
CPU:
4219+
cpu:
42204220
$ref: "#/components/schemas/DeviceResourceStatusType"
4221-
Memory:
4221+
memory:
42224222
$ref: "#/components/schemas/DeviceResourceStatusType"
4223-
Disk:
4223+
disk:
42244224
$ref: "#/components/schemas/DeviceResourceStatusType"
42254225
DeviceResourceStatusType:
42264226
type: string

flightctl/models/device_resource_status.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import re # noqa: F401
1919
import json
2020

21-
from pydantic import BaseModel, ConfigDict, Field
21+
from pydantic import BaseModel, ConfigDict
2222
from typing import Any, ClassVar, Dict, List
2323
from flightctl.models.device_resource_status_type import DeviceResourceStatusType
2424
from typing import Optional, Set
@@ -28,10 +28,10 @@ class DeviceResourceStatus(BaseModel):
2828
"""
2929
Current status of the resources of the device.
3030
""" # noqa: E501
31-
cpu: DeviceResourceStatusType = Field(alias="CPU")
32-
memory: DeviceResourceStatusType = Field(alias="Memory")
33-
disk: DeviceResourceStatusType = Field(alias="Disk")
34-
__properties: ClassVar[List[str]] = ["CPU", "Memory", "Disk"]
31+
cpu: DeviceResourceStatusType
32+
memory: DeviceResourceStatusType
33+
disk: DeviceResourceStatusType
34+
__properties: ClassVar[List[str]] = ["cpu", "memory", "disk"]
3535

3636
model_config = ConfigDict(
3737
populate_by_name=True,
@@ -84,9 +84,9 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
8484
return cls.model_validate(obj)
8585

8686
_obj = cls.model_validate({
87-
"CPU": obj.get("CPU"),
88-
"Memory": obj.get("Memory"),
89-
"Disk": obj.get("Disk")
87+
"cpu": obj.get("cpu"),
88+
"memory": obj.get("memory"),
89+
"disk": obj.get("disk")
9090
})
9191
return _obj
9292

flightctl/models/resource_monitor.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,41 @@ def from_json(cls, json_str: str) -> Self:
9999
error_messages = []
100100
match = 0
101101

102+
# use oneOf discriminator to lookup the data type
103+
_data_type = json.loads(json_str).get("monitorType")
104+
if not _data_type:
105+
raise ValueError("Failed to lookup data type from the field `monitorType` in the input.")
106+
107+
# check if data type is `CpuResourceMonitorSpec`
108+
if _data_type == "CPU":
109+
instance.actual_instance = CpuResourceMonitorSpec.from_json(json_str)
110+
return instance
111+
112+
# check if data type is `DiskResourceMonitorSpec`
113+
if _data_type == "Disk":
114+
instance.actual_instance = DiskResourceMonitorSpec.from_json(json_str)
115+
return instance
116+
117+
# check if data type is `MemoryResourceMonitorSpec`
118+
if _data_type == "Memory":
119+
instance.actual_instance = MemoryResourceMonitorSpec.from_json(json_str)
120+
return instance
121+
122+
# check if data type is `CpuResourceMonitorSpec`
123+
if _data_type == "CpuResourceMonitorSpec":
124+
instance.actual_instance = CpuResourceMonitorSpec.from_json(json_str)
125+
return instance
126+
127+
# check if data type is `DiskResourceMonitorSpec`
128+
if _data_type == "DiskResourceMonitorSpec":
129+
instance.actual_instance = DiskResourceMonitorSpec.from_json(json_str)
130+
return instance
131+
132+
# check if data type is `MemoryResourceMonitorSpec`
133+
if _data_type == "MemoryResourceMonitorSpec":
134+
instance.actual_instance = MemoryResourceMonitorSpec.from_json(json_str)
135+
return instance
136+
102137
# deserialize data into CpuResourceMonitorSpec
103138
try:
104139
instance.actual_instance = CpuResourceMonitorSpec.from_json(json_str)

flightctl/models/rollout_device_selection.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ def from_json(cls, json_str: str) -> Self:
8383
error_messages = []
8484
match = 0
8585

86+
# use oneOf discriminator to lookup the data type
87+
_data_type = json.loads(json_str).get("strategy")
88+
if not _data_type:
89+
raise ValueError("Failed to lookup data type from the field `strategy` in the input.")
90+
91+
# check if data type is `BatchSequence`
92+
if _data_type == "BatchSequence":
93+
instance.actual_instance = BatchSequence.from_json(json_str)
94+
return instance
95+
8696
# deserialize data into BatchSequence
8797
try:
8898
instance.actual_instance = BatchSequence.from_json(json_str)

test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import flightctl
2+
from flightctl.models.device import Device
3+
from flightctl.rest import ApiException
4+
from pprint import pprint
5+
6+
# Defining the host is optional and defaults to http://localhost
7+
# See configuration.py for a list of all supported configuration parameters.
8+
configuration = flightctl.Configuration(
9+
host = "https://api.10.0.7.163.nip.io:3443"
10+
)
11+
configuration.verify_ssl = False
12+
13+
14+
# Enter a context with an instance of the API client
15+
with flightctl.ApiClient(configuration) as api_client:
16+
# Create an instance of the API class
17+
api_instance = flightctl.DeviceApi(api_client)
18+
name = 'device-ansible-example' # str | The name of the Device resource to get.
19+
20+
try:
21+
api_response = api_instance.get_device(name)
22+
print("The response of DeviceApi->get_device:\n")
23+
pprint(api_response)
24+
except Exception as e:
25+
print("Exception when calling DeviceApi->get_device: %s\n" % e)

0 commit comments

Comments
 (0)