@@ -545,12 +545,23 @@ class PCUGroupTypeDetailsDescriptor:
545545 disk_cache: the amount of disk cache for this PCU type.
546546 """
547547
548- v_cpu : int
549- memory : str
550- disk_cache : str
548+ v_cpu : int | None = None
549+ memory : str | None = None
550+ disk_cache : str | None = None
551551
552552 def __repr__ (self ) -> str :
553- body = f"v_cpu={ self .v_cpu } , memory={ self .memory } , disk_cache={ self .disk_cache } "
553+ pieces = [
554+ pc
555+ for pc in (
556+ f"v_cpu={ self .v_cpu } " if self .v_cpu is not None else None ,
557+ f"memory={ self .memory } " if self .memory is not None else None ,
558+ f"disk_cache={ self .disk_cache } "
559+ if self .disk_cache is not None
560+ else None ,
561+ )
562+ if pc is not None
563+ ]
564+ body = ", " .join (pieces )
554565 return f"{ self .__class__ .__name__ } ({ body } )"
555566
556567 def as_dict (self ) -> dict [str , Any ]:
@@ -559,9 +570,13 @@ def as_dict(self) -> dict[str, Any]:
559570 """
560571
561572 return {
562- "vCPU" : self .v_cpu ,
563- "memory" : self .memory ,
564- "disk_cache" : self .disk_cache ,
573+ k : v
574+ for k , v in {
575+ "vCPU" : self .v_cpu ,
576+ "memory" : self .memory ,
577+ "disk_cache" : self .disk_cache ,
578+ }.items ()
579+ if v is not None
565580 }
566581
567582 @classmethod
@@ -581,9 +596,9 @@ def _from_dict(cls, raw_dict: dict[str, Any]) -> PCUGroupTypeDetailsDescriptor:
581596 },
582597 )
583598 return PCUGroupTypeDetailsDescriptor (
584- v_cpu = raw_dict [ "vCPU" ] ,
585- memory = raw_dict [ "memory" ] ,
586- disk_cache = raw_dict [ "disk_cache" ] ,
599+ v_cpu = raw_dict . get ( "vCPU" ) ,
600+ memory = raw_dict . get ( "memory" ) ,
601+ disk_cache = raw_dict . get ( "disk_cache" ) ,
587602 )
588603
589604
@@ -603,7 +618,7 @@ class PCUGroupTypeDescriptor:
603618 type : str
604619 region : str | None
605620 cloud_provider : str | None
606- details : PCUGroupTypeDetailsDescriptor
621+ details : PCUGroupTypeDetailsDescriptor | None
607622
608623 def __repr__ (self ) -> str :
609624 pieces = [
@@ -614,7 +629,7 @@ def __repr__(self) -> str:
614629 f"cloud_provider={ self .cloud_provider } "
615630 if self .cloud_provider is not None
616631 else None ,
617- "details=..." ,
632+ "details=..." if self . details is not None else None ,
618633 )
619634 if pc is not None
620635 ]
@@ -632,7 +647,7 @@ def as_dict(self) -> dict[str, Any]:
632647 "type" : self .type ,
633648 "region" : self .region ,
634649 "provider" : self .cloud_provider ,
635- "details" : self .details .as_dict (),
650+ "details" : self .details .as_dict () if self . details is not None else None ,
636651 }.items ()
637652 if v is not None
638653 }
@@ -658,7 +673,9 @@ def _from_dict(cls, raw_dict: dict[str, Any]) -> PCUGroupTypeDescriptor:
658673 type = raw_dict ["type" ],
659674 region = raw_dict .get ("region" ),
660675 cloud_provider = raw_dict ["provider" ] if "provider" in raw_dict else None ,
661- details = PCUGroupTypeDetailsDescriptor ._from_dict (raw_dict ["details" ]),
676+ details = PCUGroupTypeDetailsDescriptor ._from_dict (raw_dict ["details" ])
677+ if "details" in raw_dict
678+ else None ,
662679 )
663680
664681
@@ -689,26 +706,36 @@ class PCUGroupDescriptor:
689706 """
690707
691708 id : str
692- org_id : str
693- title : str
709+ org_id : str | None
710+ title : str | None
694711 cloud_provider : str
695712 region : str
696- instance_type : str
697- pcu_type : PCUGroupTypeDescriptor
698- provision_type : str
699- min : int
700- max : int
701- description : str
713+ instance_type : str | None
714+ pcu_type : PCUGroupTypeDescriptor | None
715+ provision_type : str | None
716+ min : int | None
717+ max : int | None
718+ description : str | None
702719 created_at : datetime .datetime | None
703720 updated_at : datetime .datetime | None
704- created_by : str
705- updated_by : str
706- status : str
721+ created_by : str | None
722+ updated_by : str | None
723+ status : str | None
707724 reserved : int | None = None
708725
709726 def __repr__ (self ) -> str :
710- body = f"id={ self .id } , org_id={ self .org_id } , title={ self .title } , status={ self .status } , ..."
711- return f"{ self .__class__ .__name__ } ({ body } )"
727+ pieces = [
728+ pc
729+ for pc in (
730+ f"id={ self .id } " if self .id is not None else None ,
731+ f"org_id={ self .org_id } " if self .org_id is not None else None ,
732+ f"title={ self .title } " if self .title is not None else None ,
733+ f"status={ self .status } " if self .status is not None else None ,
734+ )
735+ if pc is not None
736+ ]
737+ body = ", " .join (pieces )
738+ return f"{ self .__class__ .__name__ } ({ body } , ...)"
712739
713740 def as_dict (self ) -> dict [str , Any ]:
714741 """
@@ -724,7 +751,9 @@ def as_dict(self) -> dict[str, Any]:
724751 "cloudProvider" : self .cloud_provider ,
725752 "region" : self .region ,
726753 "instanceType" : self .instance_type ,
727- "pcuType" : self .pcu_type .as_dict (),
754+ "pcuType" : self .pcu_type .as_dict ()
755+ if self .pcu_type is not None
756+ else None ,
728757 "provisionType" : self .provision_type ,
729758 "min" : self .min ,
730759 "max" : self .max ,
@@ -775,20 +804,22 @@ def _from_dict(cls, raw_dict: dict[str, Any]) -> PCUGroupDescriptor:
775804 )
776805 return PCUGroupDescriptor (
777806 id = raw_dict ["uuid" ],
778- org_id = raw_dict [ "orgId" ] ,
779- title = raw_dict [ "title" ] ,
807+ org_id = raw_dict . get ( "orgId" ) ,
808+ title = raw_dict . get ( "title" ) ,
780809 cloud_provider = raw_dict ["cloudProvider" ],
781810 region = raw_dict ["region" ],
782- instance_type = raw_dict ["instanceType" ],
783- pcu_type = PCUGroupTypeDescriptor ._from_dict (raw_dict ["pcuType" ]),
784- provision_type = raw_dict ["provisionType" ],
785- min = raw_dict ["min" ],
786- max = raw_dict ["max" ],
811+ instance_type = raw_dict .get ("instanceType" ),
812+ pcu_type = PCUGroupTypeDescriptor ._from_dict (raw_dict ["pcuType" ])
813+ if "pcuType" in raw_dict
814+ else None ,
815+ provision_type = raw_dict .get ("provisionType" ),
816+ min = raw_dict .get ("min" ),
817+ max = raw_dict .get ("max" ),
787818 reserved = raw_dict .get ("reserved" ),
788- description = raw_dict [ "description" ] ,
819+ description = raw_dict . get ( "description" ) ,
789820 created_at = _failsafe_parse_date (raw_dict .get ("createdAt" )),
790821 updated_at = _failsafe_parse_date (raw_dict .get ("updatedAt" )),
791- created_by = raw_dict [ "createdBy" ] ,
792- updated_by = raw_dict [ "updatedBy" ] ,
793- status = raw_dict [ "status" ] ,
822+ created_by = raw_dict . get ( "createdBy" ) ,
823+ updated_by = raw_dict . get ( "updatedBy" ) ,
824+ status = raw_dict . get ( "status" ) ,
794825 )
0 commit comments