From 989302de16420ec1e1069c02b6e18f3363ac4f6d Mon Sep 17 00:00:00 2001 From: pauhull Date: Tue, 5 Dec 2023 11:46:29 +0100 Subject: [PATCH] feat: add missing properties `hcloud.Server.LoadBalancers` and `Datacenter.ServerTypes.AvailableForMigration` were missing, even though they are documented in the API docs. --- hcloud/datacenter.go | 5 +- hcloud/schema/datacenter.go | 20 ++++--- hcloud/schema/server.go | 1 + hcloud/schema/server_type.go | 2 + hcloud/schema_gen.go | 10 ++++ hcloud/server.go | 1 + hcloud/server_type.go | 2 + hcloud/zz_schema.go | 111 +++++++++++++++++++++++------------ 8 files changed, 103 insertions(+), 49 deletions(-) diff --git a/hcloud/datacenter.go b/hcloud/datacenter.go index b1fc1c1e4..42c443da3 100644 --- a/hcloud/datacenter.go +++ b/hcloud/datacenter.go @@ -20,8 +20,9 @@ type Datacenter struct { // DatacenterServerTypes represents the server types available and supported in a datacenter. type DatacenterServerTypes struct { - Supported []*ServerType - Available []*ServerType + Supported []*ServerType + AvailableForMigration []*ServerType + Available []*ServerType } // DatacenterClient is a client for the datacenter API. diff --git a/hcloud/schema/datacenter.go b/hcloud/schema/datacenter.go index eaa12429f..54590d2a2 100644 --- a/hcloud/schema/datacenter.go +++ b/hcloud/schema/datacenter.go @@ -2,14 +2,18 @@ package schema // Datacenter defines the schema of a datacenter. type Datacenter struct { - ID int64 `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Location Location `json:"location"` - ServerTypes struct { - Supported []int64 `json:"supported"` - Available []int64 `json:"available"` - } `json:"server_types"` + ID int64 `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Location Location `json:"location"` + ServerTypes DatacenterServerTypes `json:"server_types"` +} + +// DatacenterServerTypes defines the schema of the server types available in a datacenter. +type DatacenterServerTypes struct { + Supported []int64 `json:"supported"` + AvailableForMigration []int64 `json:"available_for_migration"` + Available []int64 `json:"available"` } // DatacenterGetResponse defines the schema of the response when retrieving a single datacenter. diff --git a/hcloud/schema/server.go b/hcloud/schema/server.go index 39a10b064..068b3e81f 100644 --- a/hcloud/schema/server.go +++ b/hcloud/schema/server.go @@ -25,6 +25,7 @@ type Server struct { Volumes []int64 `json:"volumes"` PrimaryDiskSize int `json:"primary_disk_size"` PlacementGroup *PlacementGroup `json:"placement_group"` + LoadBalancers []int64 `json:"load_balancers"` } // ServerProtection defines the schema of a server's resource protection. diff --git a/hcloud/schema/server_type.go b/hcloud/schema/server_type.go index 0920a5ee1..87af56876 100644 --- a/hcloud/schema/server_type.go +++ b/hcloud/schema/server_type.go @@ -13,6 +13,8 @@ type ServerType struct { Architecture string `json:"architecture"` IncludedTraffic int64 `json:"included_traffic"` Prices []PricingServerTypePrice `json:"prices"` + // Deprecated: Use Deprecation instead + Deprecated bool `json:"deprecated"` DeprecatableResource } diff --git a/hcloud/schema_gen.go b/hcloud/schema_gen.go index a95d4c0cb..7d8ef2e44 100644 --- a/hcloud/schema_gen.go +++ b/hcloud/schema_gen.go @@ -25,6 +25,8 @@ import ( // goverter:extend int64FromServer // goverter:extend networkFromInt64 // goverter:extend int64FromNetwork +// goverter:extend loadBalancerFromInt64 +// goverter:extend int64FromLoadBalancer // goverter:extend volumeFromInt64 // goverter:extend int64FromVolume // goverter:extend certificateFromInt64 @@ -366,6 +368,14 @@ func int64FromNetwork(network Network) int64 { return network.ID } +func loadBalancerFromInt64(id int64) LoadBalancer { + return LoadBalancer{ID: id} +} + +func int64FromLoadBalancer(lb LoadBalancer) int64 { + return lb.ID +} + func volumeFromInt64(id int64) *Volume { return &Volume{ID: id} } diff --git a/hcloud/server.go b/hcloud/server.go index d85699c92..fe8bf934c 100644 --- a/hcloud/server.go +++ b/hcloud/server.go @@ -38,6 +38,7 @@ type Server struct { Volumes []*Volume PrimaryDiskSize int PlacementGroup *PlacementGroup + LoadBalancers []*LoadBalancer } // ServerProtection represents the protection level of a server. diff --git a/hcloud/server_type.go b/hcloud/server_type.go index 029fe1ff6..248e2e92d 100644 --- a/hcloud/server_type.go +++ b/hcloud/server_type.go @@ -23,6 +23,8 @@ type ServerType struct { // IncludedTraffic is the free traffic per month in bytes IncludedTraffic int64 Pricings []ServerTypeLocationPricing + // Deprecated: Use DeprecatableResource instead + Deprecated bool DeprecatableResource } diff --git a/hcloud/zz_schema.go b/hcloud/zz_schema.go index 5ba9b6c84..c36c13c1f 100755 --- a/hcloud/zz_schema.go +++ b/hcloud/zz_schema.go @@ -85,7 +85,7 @@ func (c *converterImpl) DatacenterFromSchema(source schema.Datacenter) *Datacent hcloudDatacenter.Name = source.Name hcloudDatacenter.Description = source.Description hcloudDatacenter.Location = c.LocationFromSchema(source.Location) - hcloudDatacenter.ServerTypes = c.unnamedToHcloudDatacenterServerTypes(source.ServerTypes) + hcloudDatacenter.ServerTypes = c.schemaDatacenterServerTypesToHcloudDatacenterServerTypes(source.ServerTypes) return &hcloudDatacenter } func (c *converterImpl) DeprecationFromSchema(source *schema.DeprecationInfo) *DeprecationInfo { @@ -567,7 +567,7 @@ func (c *converterImpl) SchemaFromDatacenter(source *Datacenter) schema.Datacent schemaDatacenter2.Name = (*source).Name schemaDatacenter2.Description = (*source).Description schemaDatacenter2.Location = c.SchemaFromLocation((*source).Location) - schemaDatacenter2.ServerTypes = c.hcloudDatacenterServerTypesToUnnamed((*source).ServerTypes) + schemaDatacenter2.ServerTypes = c.hcloudDatacenterServerTypesToSchemaDatacenterServerTypes((*source).ServerTypes) schemaDatacenter = schemaDatacenter2 } return schemaDatacenter @@ -1139,6 +1139,14 @@ func (c *converterImpl) SchemaFromServer(source *Server) schema.Server { schemaServer2.Volumes = int64List schemaServer2.PrimaryDiskSize = (*source).PrimaryDiskSize schemaServer2.PlacementGroup = c.pHcloudPlacementGroupToPSchemaPlacementGroup((*source).PlacementGroup) + var int64List2 []int64 + if (*source).LoadBalancers != nil { + int64List2 = make([]int64, len((*source).LoadBalancers)) + for k := 0; k < len((*source).LoadBalancers); k++ { + int64List2[k] = c.pHcloudLoadBalancerToInt64((*source).LoadBalancers[k]) + } + } + schemaServer2.LoadBalancers = int64List2 schemaServer = schemaServer2 } return schemaServer @@ -1218,6 +1226,7 @@ func (c *converterImpl) SchemaFromServerType(source *ServerType) schema.ServerTy } } schemaServerType2.Prices = schemaPricingServerTypePriceList + schemaServerType2.Deprecated = (*source).Deprecated schemaServerType2.DeprecatableResource = c.hcloudDeprecatableResourceToSchemaDeprecatableResource((*source).DeprecatableResource) schemaServerType = schemaServerType2 } @@ -1290,6 +1299,15 @@ func (c *converterImpl) ServerFromSchema(source schema.Server) *Server { hcloudServer.Volumes = pHcloudVolumeList hcloudServer.PrimaryDiskSize = source.PrimaryDiskSize hcloudServer.PlacementGroup = c.pSchemaPlacementGroupToPHcloudPlacementGroup(source.PlacementGroup) + var pHcloudLoadBalancerList []*LoadBalancer + if source.LoadBalancers != nil { + pHcloudLoadBalancerList = make([]*LoadBalancer, len(source.LoadBalancers)) + for k := 0; k < len(source.LoadBalancers); k++ { + hcloudLoadBalancer := loadBalancerFromInt64(source.LoadBalancers[k]) + pHcloudLoadBalancerList[k] = &hcloudLoadBalancer + } + } + hcloudServer.LoadBalancers = pHcloudLoadBalancerList return &hcloudServer } func (c *converterImpl) ServerMetricsFromSchema(source *schema.ServerGetMetricsResponse) (*ServerMetrics, error) { @@ -1387,6 +1405,7 @@ func (c *converterImpl) ServerTypeFromSchema(source schema.ServerType) *ServerTy } } hcloudServerType.Pricings = hcloudServerTypeLocationPricingList + hcloudServerType.Deprecated = source.Deprecated hcloudServerType.DeprecatableResource = c.schemaDeprecatableResourceToHcloudDeprecatableResource(source.DeprecatableResource) return &hcloudServerType } @@ -1418,14 +1437,8 @@ func (c *converterImpl) hcloudCertificateUsedByRefToSchemaCertificateUsedByRef(s schemaCertificateUsedByRef.Type = string(source.Type) return schemaCertificateUsedByRef } -func (c *converterImpl) hcloudDatacenterServerTypesToUnnamed(source DatacenterServerTypes) struct { - Supported []int64 `json:"supported"` - Available []int64 `json:"available"` -} { - var unnamed struct { - Supported []int64 `json:"supported"` - Available []int64 `json:"available"` - } +func (c *converterImpl) hcloudDatacenterServerTypesToSchemaDatacenterServerTypes(source DatacenterServerTypes) schema.DatacenterServerTypes { + var schemaDatacenterServerTypes schema.DatacenterServerTypes var int64List []int64 if source.Supported != nil { int64List = make([]int64, len(source.Supported)) @@ -1433,16 +1446,24 @@ func (c *converterImpl) hcloudDatacenterServerTypesToUnnamed(source DatacenterSe int64List[i] = int64FromServerType(source.Supported[i]) } } - unnamed.Supported = int64List + schemaDatacenterServerTypes.Supported = int64List var int64List2 []int64 + if source.AvailableForMigration != nil { + int64List2 = make([]int64, len(source.AvailableForMigration)) + for j := 0; j < len(source.AvailableForMigration); j++ { + int64List2[j] = int64FromServerType(source.AvailableForMigration[j]) + } + } + schemaDatacenterServerTypes.AvailableForMigration = int64List2 + var int64List3 []int64 if source.Available != nil { - int64List2 = make([]int64, len(source.Available)) - for j := 0; j < len(source.Available); j++ { - int64List2[j] = int64FromServerType(source.Available[j]) + int64List3 = make([]int64, len(source.Available)) + for k := 0; k < len(source.Available); k++ { + int64List3[k] = int64FromServerType(source.Available[k]) } } - unnamed.Available = int64List2 - return unnamed + schemaDatacenterServerTypes.Available = int64List3 + return schemaDatacenterServerTypes } func (c *converterImpl) hcloudDeprecatableResourceToSchemaDeprecatableResource(source DeprecatableResource) schema.DeprecatableResource { var schemaDeprecatableResource schema.DeprecatableResource @@ -1859,6 +1880,13 @@ func (c *converterImpl) pHcloudLoadBalancerTargetServerToPSchemaLoadBalancerTarg } return pSchemaLoadBalancerTargetServer } +func (c *converterImpl) pHcloudLoadBalancerToInt64(source *LoadBalancer) int64 { + var xint64 int64 + if source != nil { + xint64 = int64FromLoadBalancer((*source)) + } + return xint64 +} func (c *converterImpl) pHcloudLoadBalancerUpdateServiceOptsHTTPToPSchemaLoadBalancerActionUpdateServiceRequestHTTP(source *LoadBalancerUpdateServiceOptsHTTP) *schema.LoadBalancerActionUpdateServiceRequestHTTP { var pSchemaLoadBalancerActionUpdateServiceRequestHTTP *schema.LoadBalancerActionUpdateServiceRequestHTTP if source != nil { @@ -2197,6 +2225,34 @@ func (c *converterImpl) schemaCertificateUsedByRefToHcloudCertificateUsedByRef(s hcloudCertificateUsedByRef.Type = CertificateUsedByRefType(source.Type) return hcloudCertificateUsedByRef } +func (c *converterImpl) schemaDatacenterServerTypesToHcloudDatacenterServerTypes(source schema.DatacenterServerTypes) DatacenterServerTypes { + var hcloudDatacenterServerTypes DatacenterServerTypes + var pHcloudServerTypeList []*ServerType + if source.Supported != nil { + pHcloudServerTypeList = make([]*ServerType, len(source.Supported)) + for i := 0; i < len(source.Supported); i++ { + pHcloudServerTypeList[i] = serverTypeFromInt64(source.Supported[i]) + } + } + hcloudDatacenterServerTypes.Supported = pHcloudServerTypeList + var pHcloudServerTypeList2 []*ServerType + if source.AvailableForMigration != nil { + pHcloudServerTypeList2 = make([]*ServerType, len(source.AvailableForMigration)) + for j := 0; j < len(source.AvailableForMigration); j++ { + pHcloudServerTypeList2[j] = serverTypeFromInt64(source.AvailableForMigration[j]) + } + } + hcloudDatacenterServerTypes.AvailableForMigration = pHcloudServerTypeList2 + var pHcloudServerTypeList3 []*ServerType + if source.Available != nil { + pHcloudServerTypeList3 = make([]*ServerType, len(source.Available)) + for k := 0; k < len(source.Available); k++ { + pHcloudServerTypeList3[k] = serverTypeFromInt64(source.Available[k]) + } + } + hcloudDatacenterServerTypes.Available = pHcloudServerTypeList3 + return hcloudDatacenterServerTypes +} func (c *converterImpl) schemaDeprecatableResourceToHcloudDeprecatableResource(source schema.DeprecatableResource) DeprecatableResource { var hcloudDeprecatableResource DeprecatableResource hcloudDeprecatableResource.Deprecation = c.DeprecationFromSchema(source.Deprecation) @@ -2443,26 +2499,3 @@ func (c *converterImpl) serverTypePricingFromSchema(source schema.PricingServerT func (c *converterImpl) timeTimeToTimeTime(source time.Time) time.Time { return source } -func (c *converterImpl) unnamedToHcloudDatacenterServerTypes(source struct { - Supported []int64 `json:"supported"` - Available []int64 `json:"available"` -}) DatacenterServerTypes { - var hcloudDatacenterServerTypes DatacenterServerTypes - var pHcloudServerTypeList []*ServerType - if source.Supported != nil { - pHcloudServerTypeList = make([]*ServerType, len(source.Supported)) - for i := 0; i < len(source.Supported); i++ { - pHcloudServerTypeList[i] = serverTypeFromInt64(source.Supported[i]) - } - } - hcloudDatacenterServerTypes.Supported = pHcloudServerTypeList - var pHcloudServerTypeList2 []*ServerType - if source.Available != nil { - pHcloudServerTypeList2 = make([]*ServerType, len(source.Available)) - for j := 0; j < len(source.Available); j++ { - pHcloudServerTypeList2[j] = serverTypeFromInt64(source.Available[j]) - } - } - hcloudDatacenterServerTypes.Available = pHcloudServerTypeList2 - return hcloudDatacenterServerTypes -}