diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/action.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/action.go index ecf9c5c7b46e..6ab2f1095dac 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/action.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/action.go @@ -120,172 +120,6 @@ func (c *ActionClient) AllWithOpts(ctx context.Context, opts ActionListOpts) ([] return c.action.All(ctx, opts) } -// WatchOverallProgress watches several actions' progress until they complete -// with success or error. This watching happens in a goroutine and updates are -// provided through the two returned channels: -// -// - The first channel receives percentage updates of the progress, based on -// the number of completed versus total watched actions. The return value -// is an int between 0 and 100. -// - The second channel returned receives errors for actions that did not -// complete successfully, as well as any errors that happened while -// querying the API. -// -// By default, the method keeps watching until all actions have finished -// processing. If you want to be able to cancel the method or configure a -// timeout, use the [context.Context]. Once the method has stopped watching, -// both returned channels are closed. -// -// WatchOverallProgress uses the [WithPollBackoffFunc] of the [Client] to wait -// until sending the next request. -func (c *ActionClient) WatchOverallProgress(ctx context.Context, actions []*Action) (<-chan int, <-chan error) { - errCh := make(chan error, len(actions)) - progressCh := make(chan int) - - go func() { - defer close(errCh) - defer close(progressCh) - - completedIDs := make([]int64, 0, len(actions)) - watchIDs := make(map[int64]struct{}, len(actions)) - for _, action := range actions { - watchIDs[action.ID] = struct{}{} - } - - retries := 0 - previousProgress := 0 - - for { - select { - case <-ctx.Done(): - errCh <- ctx.Err() - return - case <-time.After(c.action.client.pollBackoffFunc(retries)): - retries++ - } - - opts := ActionListOpts{} - for watchID := range watchIDs { - opts.ID = append(opts.ID, watchID) - } - - as, err := c.AllWithOpts(ctx, opts) - if err != nil { - errCh <- err - return - } - if len(as) == 0 { - // No actions returned for the provided IDs, they do not exist in the API. - // We need to catch and fail early for this, otherwise the loop will continue - // indefinitely. - errCh <- fmt.Errorf("failed to wait for actions: remaining actions (%v) are not returned from API", opts.ID) - return - } - - progress := 0 - for _, a := range as { - switch a.Status { - case ActionStatusRunning: - progress += a.Progress - case ActionStatusSuccess: - delete(watchIDs, a.ID) - completedIDs = append(completedIDs, a.ID) - case ActionStatusError: - delete(watchIDs, a.ID) - completedIDs = append(completedIDs, a.ID) - errCh <- fmt.Errorf("action %d failed: %w", a.ID, a.Error()) - } - } - - progress += len(completedIDs) * 100 - if progress != 0 && progress != previousProgress { - sendProgress(progressCh, progress/len(actions)) - previousProgress = progress - } - - if len(watchIDs) == 0 { - return - } - } - }() - - return progressCh, errCh -} - -// WatchProgress watches one action's progress until it completes with success -// or error. This watching happens in a goroutine and updates are provided -// through the two returned channels: -// -// - The first channel receives percentage updates of the progress, based on -// the progress percentage indicated by the API. The return value is an int -// between 0 and 100. -// - The second channel receives any errors that happened while querying the -// API, as well as the error of the action if it did not complete -// successfully, or nil if it did. -// -// By default, the method keeps watching until the action has finished -// processing. If you want to be able to cancel the method or configure a -// timeout, use the [context.Context]. Once the method has stopped watching, -// both returned channels are closed. -// -// WatchProgress uses the [WithPollBackoffFunc] of the [Client] to wait until -// sending the next request. -func (c *ActionClient) WatchProgress(ctx context.Context, action *Action) (<-chan int, <-chan error) { - errCh := make(chan error, 1) - progressCh := make(chan int) - - go func() { - defer close(errCh) - defer close(progressCh) - - retries := 0 - - for { - select { - case <-ctx.Done(): - errCh <- ctx.Err() - return - case <-time.After(c.action.client.pollBackoffFunc(retries)): - retries++ - } - - a, _, err := c.GetByID(ctx, action.ID) - if err != nil { - errCh <- err - return - } - if a == nil { - errCh <- fmt.Errorf("failed to wait for action %d: action not returned from API", action.ID) - return - } - - switch a.Status { - case ActionStatusRunning: - sendProgress(progressCh, a.Progress) - case ActionStatusSuccess: - sendProgress(progressCh, 100) - errCh <- nil - return - case ActionStatusError: - errCh <- a.Error() - return - } - } - }() - - return progressCh, errCh -} - -// sendProgress allows the user to only read from the error channel and ignore any progress updates. -func sendProgress(progressCh chan int, p int) { - select { - case progressCh <- p: - break - default: - break - } -} - // ResourceActionClient is a client for the actions API exposed by the resource. type ResourceActionClient struct { resource string diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/action_waiter.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/action_waiter.go new file mode 100644 index 000000000000..ebfe8ef4eb3e --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/action_waiter.go @@ -0,0 +1,116 @@ +package hcloud + +import ( + "context" + "fmt" + "maps" + "slices" + "time" +) + +type ActionWaiter interface { + WaitForFunc(ctx context.Context, handleUpdate func(update *Action) error, actions ...*Action) error + WaitFor(ctx context.Context, actions ...*Action) error +} + +var _ ActionWaiter = (*ActionClient)(nil) + +// WaitForFunc waits until all actions are completed by polling the API at the interval +// defined by [WithPollBackoffFunc]. An action is considered as complete when its status is +// either [ActionStatusSuccess] or [ActionStatusError]. +// +// The handleUpdate callback is called every time an action is updated. +func (c *ActionClient) WaitForFunc(ctx context.Context, handleUpdate func(update *Action) error, actions ...*Action) error { + running := make(map[int64]struct{}, len(actions)) + for _, action := range actions { + if action.Status == ActionStatusRunning { + running[action.ID] = struct{}{} + } else if handleUpdate != nil { + // We filter out already completed actions from the API polling loop; while + // this isn't a real update, the caller should be notified about the new + // state. + if err := handleUpdate(action); err != nil { + return err + } + } + } + + retries := 0 + for { + if len(running) == 0 { + break + } + + select { + case <-ctx.Done(): + return ctx.Err() + case <-time.After(c.action.client.pollBackoffFunc(retries)): + retries++ + } + + opts := ActionListOpts{ + Sort: []string{"status", "id"}, + ID: make([]int64, 0, len(running)), + } + for actionID := range running { + opts.ID = append(opts.ID, actionID) + } + slices.Sort(opts.ID) + + updates, err := c.AllWithOpts(ctx, opts) + if err != nil { + return err + } + + if len(updates) != len(running) { + // Some actions may not exist in the API, also fail early to prevent an + // infinite loop when updates == 0. + + notFound := maps.Clone(running) + for _, update := range updates { + delete(notFound, update.ID) + } + notFoundIDs := make([]int64, 0, len(notFound)) + for unknownID := range notFound { + notFoundIDs = append(notFoundIDs, unknownID) + } + + return fmt.Errorf("actions not found: %v", notFoundIDs) + } + + for _, update := range updates { + if update.Status != ActionStatusRunning { + delete(running, update.ID) + } + + if handleUpdate != nil { + if err := handleUpdate(update); err != nil { + return err + } + } + } + } + + return nil +} + +// WaitFor waits until all actions succeed by polling the API at the interval defined by +// [WithPollBackoffFunc]. An action is considered as succeeded when its status is either +// [ActionStatusSuccess]. +// +// If a single action fails, the function will stop waiting and the error set in the +// action will be returned as an [ActionError]. +// +// For more flexibility, see the [ActionClient.WaitForFunc] function. +func (c *ActionClient) WaitFor(ctx context.Context, actions ...*Action) error { + return c.WaitForFunc( + ctx, + func(update *Action) error { + if update.Status == ActionStatusError { + return update.Error() + } + return nil + }, + actions..., + ) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/action_watch.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/action_watch.go new file mode 100644 index 000000000000..db3464f11cac --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/action_watch.go @@ -0,0 +1,131 @@ +package hcloud + +import ( + "context" + "fmt" +) + +// WatchOverallProgress watches several actions' progress until they complete +// with success or error. This watching happens in a goroutine and updates are +// provided through the two returned channels: +// +// - The first channel receives percentage updates of the progress, based on +// the number of completed versus total watched actions. The return value +// is an int between 0 and 100. +// - The second channel returned receives errors for actions that did not +// complete successfully, as well as any errors that happened while +// querying the API. +// +// By default, the method keeps watching until all actions have finished +// processing. If you want to be able to cancel the method or configure a +// timeout, use the [context.Context]. Once the method has stopped watching, +// both returned channels are closed. +// +// WatchOverallProgress uses the [WithPollBackoffFunc] of the [Client] to wait +// until sending the next request. +// +// Deprecated: WatchOverallProgress is deprecated, use [WaitForFunc] instead. +func (c *ActionClient) WatchOverallProgress(ctx context.Context, actions []*Action) (<-chan int, <-chan error) { + errCh := make(chan error, len(actions)) + progressCh := make(chan int) + + go func() { + defer close(errCh) + defer close(progressCh) + + previousGlobalProgress := 0 + progressByAction := make(map[int64]int, len(actions)) + err := c.WaitForFunc(ctx, func(update *Action) error { + switch update.Status { + case ActionStatusRunning: + progressByAction[update.ID] = update.Progress + case ActionStatusSuccess: + progressByAction[update.ID] = 100 + case ActionStatusError: + progressByAction[update.ID] = 100 + errCh <- fmt.Errorf("action %d failed: %w", update.ID, update.Error()) + } + + // Compute global progress + progressSum := 0 + for _, value := range progressByAction { + progressSum += value + } + globalProgress := progressSum / len(actions) + + // Only send progress when it changed + if globalProgress != 0 && globalProgress != previousGlobalProgress { + sendProgress(progressCh, globalProgress) + previousGlobalProgress = globalProgress + } + + return nil + }, actions...) + + if err != nil { + errCh <- err + } + }() + + return progressCh, errCh +} + +// WatchProgress watches one action's progress until it completes with success +// or error. This watching happens in a goroutine and updates are provided +// through the two returned channels: +// +// - The first channel receives percentage updates of the progress, based on +// the progress percentage indicated by the API. The return value is an int +// between 0 and 100. +// - The second channel receives any errors that happened while querying the +// API, as well as the error of the action if it did not complete +// successfully, or nil if it did. +// +// By default, the method keeps watching until the action has finished +// processing. If you want to be able to cancel the method or configure a +// timeout, use the [context.Context]. Once the method has stopped watching, +// both returned channels are closed. +// +// WatchProgress uses the [WithPollBackoffFunc] of the [Client] to wait until +// sending the next request. +// +// Deprecated: WatchProgress is deprecated, use [WaitForFunc] instead. +func (c *ActionClient) WatchProgress(ctx context.Context, action *Action) (<-chan int, <-chan error) { + errCh := make(chan error, 1) + progressCh := make(chan int) + + go func() { + defer close(errCh) + defer close(progressCh) + + err := c.WaitForFunc(ctx, func(update *Action) error { + switch update.Status { + case ActionStatusRunning: + sendProgress(progressCh, update.Progress) + case ActionStatusSuccess: + sendProgress(progressCh, 100) + case ActionStatusError: + // Do not wrap the action error + return update.Error() + } + + return nil + }, action) + + if err != nil { + errCh <- err + } + }() + + return progressCh, errCh +} + +// sendProgress allows the user to only read from the error channel and ignore any progress updates. +func sendProgress(progressCh chan int, p int) { + select { + case progressCh <- p: + break + default: + break + } +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/client.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/client.go index 6fd9f29914b3..9a7da731f1af 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/client.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/client.go @@ -65,7 +65,7 @@ type Client struct { applicationVersion string userAgent string debugWriter io.Writer - instrumentationRegistry *prometheus.Registry + instrumentationRegistry prometheus.Registerer Action ActionClient Certificate CertificateClient @@ -163,7 +163,7 @@ func WithHTTPClient(httpClient *http.Client) ClientOption { } // WithInstrumentation configures a Client to collect metrics about the performed HTTP requests. -func WithInstrumentation(registry *prometheus.Registry) ClientOption { +func WithInstrumentation(registry prometheus.Registerer) ClientOption { return func(client *Client) { client.instrumentationRegistry = registry } @@ -236,6 +236,8 @@ func (c *Client) NewRequest(ctx context.Context, method, path string, body io.Re } // Do performs an HTTP request against the API. +// v can be nil, an io.Writer to write the response body to or a pointer to +// a struct to json.Unmarshal the response to. func (c *Client) Do(r *http.Request, v interface{}) (*Response, error) { var retries int var body []byte @@ -286,8 +288,8 @@ func (c *Client) Do(r *http.Request, v interface{}) (*Response, error) { return response, fmt.Errorf("hcloud: error reading response meta data: %s", err) } - if resp.StatusCode >= 400 && resp.StatusCode <= 599 { - err = errorFromResponse(resp, body) + if response.StatusCode >= 400 && response.StatusCode <= 599 { + err = errorFromResponse(response, body) if err == nil { err = fmt.Errorf("hcloud: server responded with status code %d", resp.StatusCode) } else if IsError(err, ErrorCodeConflict) { @@ -359,7 +361,7 @@ func dumpRequest(r *http.Request) ([]byte, error) { return dumpReq, nil } -func errorFromResponse(resp *http.Response, body []byte) error { +func errorFromResponse(resp *Response, body []byte) error { if !strings.HasPrefix(resp.Header.Get("Content-Type"), "application/json") { return nil } @@ -371,9 +373,16 @@ func errorFromResponse(resp *http.Response, body []byte) error { if respBody.Error.Code == "" && respBody.Error.Message == "" { return nil } - return ErrorFromSchema(respBody.Error) + + hcErr := ErrorFromSchema(respBody.Error) + hcErr.response = resp + return hcErr } +const ( + headerCorrelationID = "X-Correlation-Id" +) + // Response represents a response from the API. It embeds http.Response. type Response struct { *http.Response @@ -407,6 +416,12 @@ func (r *Response) readMeta(body []byte) error { return nil } +// internalCorrelationID returns the unique ID of the request as set by the API. This ID can help with support requests, +// as it allows the people working on identify this request in particular. +func (r *Response) internalCorrelationID() string { + return r.Header.Get(headerCorrelationID) +} + // Meta represents meta information included in an API response. type Meta struct { Pagination *Pagination diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/datacenter.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/datacenter.go index 6a1debd4d94c..f7e9283ed6d7 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/datacenter.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/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/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/error.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/error.go index ac689d110486..371a92e31edb 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/error.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/error.go @@ -1,6 +1,7 @@ package hcloud import ( + "errors" "fmt" "net" ) @@ -94,12 +95,26 @@ type Error struct { Code ErrorCode Message string Details interface{} + + response *Response } func (e Error) Error() string { + if resp := e.Response(); resp != nil { + correlationID := resp.internalCorrelationID() + if correlationID != "" { + // For easier debugging, the error string contains the Correlation ID of the response. + return fmt.Sprintf("%s (%s, %s)", e.Message, e.Code, correlationID) + } + } return fmt.Sprintf("%s (%s)", e.Message, e.Code) } +// Response returns the [Response] that contained the error if available. +func (e Error) Response() *Response { + return e.response +} + // ErrorDetailsInvalidInput contains the details of an 'invalid_input' error. type ErrorDetailsInvalidInput struct { Fields []ErrorDetailsInvalidInputField @@ -113,7 +128,8 @@ type ErrorDetailsInvalidInputField struct { // IsError returns whether err is an API error with the given error code. func IsError(err error, code ErrorCode) bool { - apiErr, ok := err.(Error) + var apiErr Error + ok := errors.As(err, &apiErr) return ok && apiErr.Code == code } diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/firewall.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/firewall.go index 138fdebfdea3..f046e7344f91 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/firewall.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/firewall.go @@ -299,6 +299,7 @@ type FirewallSetRulesOpts struct { // SetRules sets the rules of a Firewall. func (c *FirewallClient) SetRules(ctx context.Context, firewall *Firewall, opts FirewallSetRulesOpts) ([]*Action, *Response, error) { reqBody := firewallSetRulesOptsToSchema(opts) + reqBodyData, err := json.Marshal(reqBody) if err != nil { return nil, nil, err diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/hcloud.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/hcloud.go index 3d31d3251dae..2c6745c2e85e 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/hcloud.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/hcloud.go @@ -2,4 +2,4 @@ package hcloud // Version is the library's version following Semantic Versioning. -const Version = "2.4.0" // x-release-please-version +const Version = "2.8.0" // x-release-please-version diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/interface_gen.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/interface_gen.go new file mode 100644 index 000000000000..2ae8cecb497c --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/interface_gen.go @@ -0,0 +1,22 @@ +package hcloud + +//go:generate go run github.com/vburenin/ifacemaker -f action.go -f action_watch.go -f action_waiter.go -s ActionClient -i IActionClient -p hcloud -o zz_action_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f action.go -s ResourceActionClient -i IResourceActionClient -p hcloud -o zz_resource_action_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f datacenter.go -s DatacenterClient -i IDatacenterClient -p hcloud -o zz_datacenter_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f floating_ip.go -s FloatingIPClient -i IFloatingIPClient -p hcloud -o zz_floating_ip_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f image.go -s ImageClient -i IImageClient -p hcloud -o zz_image_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f iso.go -s ISOClient -i IISOClient -p hcloud -o zz_iso_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f location.go -s LocationClient -i ILocationClient -p hcloud -o zz_location_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f network.go -s NetworkClient -i INetworkClient -p hcloud -o zz_network_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f pricing.go -s PricingClient -i IPricingClient -p hcloud -o zz_pricing_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f server.go -s ServerClient -i IServerClient -p hcloud -o zz_server_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f server_type.go -s ServerTypeClient -i IServerTypeClient -p hcloud -o zz_server_type_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f ssh_key.go -s SSHKeyClient -i ISSHKeyClient -p hcloud -o zz_ssh_key_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f volume.go -s VolumeClient -i IVolumeClient -p hcloud -o zz_volume_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f load_balancer.go -s LoadBalancerClient -i ILoadBalancerClient -p hcloud -o zz_load_balancer_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f load_balancer_type.go -s LoadBalancerTypeClient -i ILoadBalancerTypeClient -p hcloud -o zz_load_balancer_type_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f certificate.go -s CertificateClient -i ICertificateClient -p hcloud -o zz_certificate_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f firewall.go -s FirewallClient -i IFirewallClient -p hcloud -o zz_firewall_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f placement_group.go -s PlacementGroupClient -i IPlacementGroupClient -p hcloud -o zz_placement_group_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f rdns.go -s RDNSClient -i IRDNSClient -p hcloud -o zz_rdns_client_iface.go +//go:generate go run github.com/vburenin/ifacemaker -f primary_ip.go -s PrimaryIPClient -i IPrimaryIPClient -p hcloud -o zz_primary_ip_client_iface.go diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/internal/instrumentation/metrics.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/internal/instrumentation/metrics.go index aa57c7107c0a..e52bd606a13d 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/internal/instrumentation/metrics.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/internal/instrumentation/metrics.go @@ -13,11 +13,11 @@ import ( type Instrumenter struct { subsystemIdentifier string // will be used as part of the metric name (hcloud__requests_total) - instrumentationRegistry *prometheus.Registry + instrumentationRegistry prometheus.Registerer } // New creates a new Instrumenter. The subsystemIdentifier will be used as part of the metric names (e.g. hcloud__requests_total). -func New(subsystemIdentifier string, instrumentationRegistry *prometheus.Registry) *Instrumenter { +func New(subsystemIdentifier string, instrumentationRegistry prometheus.Registerer) *Instrumenter { return &Instrumenter{subsystemIdentifier: subsystemIdentifier, instrumentationRegistry: instrumentationRegistry} } @@ -84,7 +84,7 @@ func (i *Instrumenter) instrumentRoundTripperEndpoint(counter *prometheus.Counte // registerOrReuse will try to register the passed Collector, but in case a conflicting collector was already registered, // it will instead return that collector. Make sure to always use the collector return by this method. // Similar to [Registry.MustRegister] it will panic if any other error occurs. -func registerOrReuse[C prometheus.Collector](registry *prometheus.Registry, collector C) C { +func registerOrReuse[C prometheus.Collector](registry prometheus.Registerer, collector C) C { err := registry.Register(collector) if err != nil { // If we get a AlreadyRegisteredError we can return the existing collector diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/load_balancer_type.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/load_balancer_type.go index 2281c1afee4f..00c852b5ecc3 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/load_balancer_type.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/load_balancer_type.go @@ -19,6 +19,7 @@ type LoadBalancerType struct { MaxTargets int MaxAssignedCertificates int Pricings []LoadBalancerTypeLocationPricing + Deprecated *string } // LoadBalancerTypeClient is a client for the Load Balancer types API. diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/metadata/client.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/metadata/client.go index 984e3e510b83..8aeb772f8514 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/metadata/client.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/metadata/client.go @@ -22,7 +22,7 @@ type Client struct { timeout time.Duration httpClient *http.Client - instrumentationRegistry *prometheus.Registry + instrumentationRegistry prometheus.Registerer } // A ClientOption is used to configure a [Client]. @@ -43,7 +43,7 @@ func WithHTTPClient(httpClient *http.Client) ClientOption { } // WithInstrumentation configures a [Client] to collect metrics about the performed HTTP requests. -func WithInstrumentation(registry *prometheus.Registry) ClientOption { +func WithInstrumentation(registry prometheus.Registerer) ClientOption { return func(client *Client) { client.instrumentationRegistry = registry } diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema.go index 59f938f91801..1f5ae42211d7 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema.go @@ -1,1271 +1,370 @@ package hcloud import ( - "fmt" - "net" - "strconv" - "time" - "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema" ) // This file provides converter functions to convert models in the // schema package to models in the hcloud package and vice versa. +var c converter + // ActionFromSchema converts a schema.Action to an Action. func ActionFromSchema(s schema.Action) *Action { - action := &Action{ - ID: s.ID, - Status: ActionStatus(s.Status), - Command: s.Command, - Progress: s.Progress, - Started: s.Started, - Resources: []*ActionResource{}, - } - if s.Finished != nil { - action.Finished = *s.Finished - } - if s.Error != nil { - action.ErrorCode = s.Error.Code - action.ErrorMessage = s.Error.Message - } - for _, r := range s.Resources { - action.Resources = append(action.Resources, &ActionResource{ - ID: r.ID, - Type: ActionResourceType(r.Type), - }) - } - return action + return c.ActionFromSchema(s) +} + +// SchemaFromAction converts an Action to a schema.Action. +func SchemaFromAction(a *Action) schema.Action { + return c.SchemaFromAction(a) } // ActionsFromSchema converts a slice of schema.Action to a slice of Action. func ActionsFromSchema(s []schema.Action) []*Action { - actions := make([]*Action, len(s)) - for i, a := range s { - actions[i] = ActionFromSchema(a) - } - return actions + return c.ActionsFromSchema(s) +} + +// SchemaFromActions converts a slice of Action to a slice of schema.Action. +func SchemaFromActions(a []*Action) []schema.Action { + return c.SchemaFromActions(a) } // FloatingIPFromSchema converts a schema.FloatingIP to a FloatingIP. func FloatingIPFromSchema(s schema.FloatingIP) *FloatingIP { - f := &FloatingIP{ - ID: s.ID, - Type: FloatingIPType(s.Type), - HomeLocation: LocationFromSchema(s.HomeLocation), - Created: s.Created, - Blocked: s.Blocked, - Protection: FloatingIPProtection{ - Delete: s.Protection.Delete, - }, - Name: s.Name, - } - if s.Description != nil { - f.Description = *s.Description - } - if s.Server != nil { - f.Server = &Server{ID: *s.Server} - } - if f.Type == FloatingIPTypeIPv4 { - f.IP = net.ParseIP(s.IP) - } else { - f.IP, f.Network, _ = net.ParseCIDR(s.IP) - } - f.DNSPtr = map[string]string{} - for _, entry := range s.DNSPtr { - f.DNSPtr[entry.IP] = entry.DNSPtr - } - f.Labels = map[string]string{} - for key, value := range s.Labels { - f.Labels[key] = value - } - return f + return c.FloatingIPFromSchema(s) +} + +// SchemaFromFloatingIP converts a FloatingIP to a schema.FloatingIP. +func SchemaFromFloatingIP(f *FloatingIP) schema.FloatingIP { + return c.SchemaFromFloatingIP(f) } // PrimaryIPFromSchema converts a schema.PrimaryIP to a PrimaryIP. func PrimaryIPFromSchema(s schema.PrimaryIP) *PrimaryIP { - f := &PrimaryIP{ - ID: s.ID, - Type: PrimaryIPType(s.Type), - AutoDelete: s.AutoDelete, - - Created: s.Created, - Blocked: s.Blocked, - Protection: PrimaryIPProtection{ - Delete: s.Protection.Delete, - }, - Name: s.Name, - AssigneeType: s.AssigneeType, - AssigneeID: s.AssigneeID, - Datacenter: DatacenterFromSchema(s.Datacenter), - } - - if f.Type == PrimaryIPTypeIPv4 { - f.IP = net.ParseIP(s.IP) - } else { - f.IP, f.Network, _ = net.ParseCIDR(s.IP) - } - f.DNSPtr = map[string]string{} - for _, entry := range s.DNSPtr { - f.DNSPtr[entry.IP] = entry.DNSPtr - } - f.Labels = map[string]string{} - for key, value := range s.Labels { - f.Labels[key] = value - } - return f + return c.PrimaryIPFromSchema(s) +} + +// SchemaFromPrimaryIP converts a PrimaryIP to a schema.PrimaryIP. +func SchemaFromPrimaryIP(p *PrimaryIP) schema.PrimaryIP { + return c.SchemaFromPrimaryIP(p) } // ISOFromSchema converts a schema.ISO to an ISO. func ISOFromSchema(s schema.ISO) *ISO { - iso := &ISO{ - ID: s.ID, - Name: s.Name, - Description: s.Description, - Type: ISOType(s.Type), - Deprecated: s.Deprecated, - DeprecatableResource: DeprecatableResource{ - DeprecationFromSchema(s.Deprecation), - }, - } - if s.Architecture != nil { - iso.Architecture = Ptr(Architecture(*s.Architecture)) - } - return iso + return c.ISOFromSchema(s) +} + +// SchemaFromISO converts an ISO to a schema.ISO. +func SchemaFromISO(i *ISO) schema.ISO { + return c.SchemaFromISO(i) } // LocationFromSchema converts a schema.Location to a Location. func LocationFromSchema(s schema.Location) *Location { - return &Location{ - ID: s.ID, - Name: s.Name, - Description: s.Description, - Country: s.Country, - City: s.City, - Latitude: s.Latitude, - Longitude: s.Longitude, - NetworkZone: NetworkZone(s.NetworkZone), - } + return c.LocationFromSchema(s) +} + +// SchemaFromLocation converts a Location to a schema.Location. +func SchemaFromLocation(l *Location) schema.Location { + return c.SchemaFromLocation(l) } // DatacenterFromSchema converts a schema.Datacenter to a Datacenter. func DatacenterFromSchema(s schema.Datacenter) *Datacenter { - d := &Datacenter{ - ID: s.ID, - Name: s.Name, - Description: s.Description, - Location: LocationFromSchema(s.Location), - ServerTypes: DatacenterServerTypes{ - Available: []*ServerType{}, - Supported: []*ServerType{}, - }, - } - for _, t := range s.ServerTypes.Available { - d.ServerTypes.Available = append(d.ServerTypes.Available, &ServerType{ID: t}) - } - for _, t := range s.ServerTypes.Supported { - d.ServerTypes.Supported = append(d.ServerTypes.Supported, &ServerType{ID: t}) - } - return d + return c.DatacenterFromSchema(s) +} + +// SchemaFromDatacenter converts a Datacenter to a schema.Datacenter. +func SchemaFromDatacenter(d *Datacenter) schema.Datacenter { + return c.SchemaFromDatacenter(d) } // ServerFromSchema converts a schema.Server to a Server. func ServerFromSchema(s schema.Server) *Server { - server := &Server{ - ID: s.ID, - Name: s.Name, - Status: ServerStatus(s.Status), - Created: s.Created, - PublicNet: ServerPublicNetFromSchema(s.PublicNet), - ServerType: ServerTypeFromSchema(s.ServerType), - IncludedTraffic: s.IncludedTraffic, - RescueEnabled: s.RescueEnabled, - Datacenter: DatacenterFromSchema(s.Datacenter), - Locked: s.Locked, - PrimaryDiskSize: s.PrimaryDiskSize, - Protection: ServerProtection{ - Delete: s.Protection.Delete, - Rebuild: s.Protection.Rebuild, - }, - } - if s.Image != nil { - server.Image = ImageFromSchema(*s.Image) - } - if s.BackupWindow != nil { - server.BackupWindow = *s.BackupWindow - } - if s.OutgoingTraffic != nil { - server.OutgoingTraffic = *s.OutgoingTraffic - } - if s.IngoingTraffic != nil { - server.IngoingTraffic = *s.IngoingTraffic - } - if s.ISO != nil { - server.ISO = ISOFromSchema(*s.ISO) - } - server.Labels = map[string]string{} - for key, value := range s.Labels { - server.Labels[key] = value - } - for _, id := range s.Volumes { - server.Volumes = append(server.Volumes, &Volume{ID: id}) - } - for _, privNet := range s.PrivateNet { - server.PrivateNet = append(server.PrivateNet, ServerPrivateNetFromSchema(privNet)) - } - if s.PlacementGroup != nil { - server.PlacementGroup = PlacementGroupFromSchema(*s.PlacementGroup) - } - return server + return c.ServerFromSchema(s) +} + +// SchemaFromServer converts a Server to a schema.Server. +func SchemaFromServer(s *Server) schema.Server { + return c.SchemaFromServer(s) } // ServerPublicNetFromSchema converts a schema.ServerPublicNet to a ServerPublicNet. func ServerPublicNetFromSchema(s schema.ServerPublicNet) ServerPublicNet { - publicNet := ServerPublicNet{ - IPv4: ServerPublicNetIPv4FromSchema(s.IPv4), - IPv6: ServerPublicNetIPv6FromSchema(s.IPv6), - } - for _, id := range s.FloatingIPs { - publicNet.FloatingIPs = append(publicNet.FloatingIPs, &FloatingIP{ID: id}) - } - for _, fw := range s.Firewalls { - publicNet.Firewalls = append(publicNet.Firewalls, - &ServerFirewallStatus{ - Firewall: Firewall{ID: fw.ID}, - Status: FirewallStatus(fw.Status)}, - ) - } - return publicNet + return c.ServerPublicNetFromSchema(s) +} + +// SchemaFromServerPublicNet converts a ServerPublicNet to a schema.ServerPublicNet. +func SchemaFromServerPublicNet(s ServerPublicNet) schema.ServerPublicNet { + return c.SchemaFromServerPublicNet(s) } // ServerPublicNetIPv4FromSchema converts a schema.ServerPublicNetIPv4 to // a ServerPublicNetIPv4. func ServerPublicNetIPv4FromSchema(s schema.ServerPublicNetIPv4) ServerPublicNetIPv4 { - return ServerPublicNetIPv4{ - ID: s.ID, - IP: net.ParseIP(s.IP), - Blocked: s.Blocked, - DNSPtr: s.DNSPtr, - } + return c.ServerPublicNetIPv4FromSchema(s) +} + +// SchemaFromServerPublicNetIPv4 converts a ServerPublicNetIPv4 to +// a schema.ServerPublicNetIPv4. +func SchemaFromServerPublicNetIPv4(s ServerPublicNetIPv4) schema.ServerPublicNetIPv4 { + return c.SchemaFromServerPublicNetIPv4(s) } // ServerPublicNetIPv6FromSchema converts a schema.ServerPublicNetIPv6 to // a ServerPublicNetIPv6. func ServerPublicNetIPv6FromSchema(s schema.ServerPublicNetIPv6) ServerPublicNetIPv6 { - ipv6 := ServerPublicNetIPv6{ - ID: s.ID, - Blocked: s.Blocked, - DNSPtr: map[string]string{}, - } - ipv6.IP, ipv6.Network, _ = net.ParseCIDR(s.IP) + return c.ServerPublicNetIPv6FromSchema(s) +} - for _, dnsPtr := range s.DNSPtr { - ipv6.DNSPtr[dnsPtr.IP] = dnsPtr.DNSPtr - } - return ipv6 +// SchemaFromServerPublicNetIPv6 converts a ServerPublicNetIPv6 to +// a schema.ServerPublicNetIPv6. +func SchemaFromServerPublicNetIPv6(s ServerPublicNetIPv6) schema.ServerPublicNetIPv6 { + return c.SchemaFromServerPublicNetIPv6(s) } // ServerPrivateNetFromSchema converts a schema.ServerPrivateNet to a ServerPrivateNet. func ServerPrivateNetFromSchema(s schema.ServerPrivateNet) ServerPrivateNet { - n := ServerPrivateNet{ - Network: &Network{ID: s.Network}, - IP: net.ParseIP(s.IP), - MACAddress: s.MACAddress, - } - for _, ip := range s.AliasIPs { - n.Aliases = append(n.Aliases, net.ParseIP(ip)) - } - return n + return c.ServerPrivateNetFromSchema(s) +} + +// SchemaFromServerPrivateNet converts a ServerPrivateNet to a schema.ServerPrivateNet. +func SchemaFromServerPrivateNet(s ServerPrivateNet) schema.ServerPrivateNet { + return c.SchemaFromServerPrivateNet(s) } // ServerTypeFromSchema converts a schema.ServerType to a ServerType. func ServerTypeFromSchema(s schema.ServerType) *ServerType { - st := &ServerType{ - ID: s.ID, - Name: s.Name, - Description: s.Description, - Cores: s.Cores, - Memory: s.Memory, - Disk: s.Disk, - StorageType: StorageType(s.StorageType), - CPUType: CPUType(s.CPUType), - Architecture: Architecture(s.Architecture), - IncludedTraffic: s.IncludedTraffic, - DeprecatableResource: DeprecatableResource{ - DeprecationFromSchema(s.Deprecation), - }, - } - for _, price := range s.Prices { - st.Pricings = append(st.Pricings, ServerTypeLocationPricing{ - Location: &Location{Name: price.Location}, - Hourly: Price{ - Net: price.PriceHourly.Net, - Gross: price.PriceHourly.Gross, - }, - Monthly: Price{ - Net: price.PriceMonthly.Net, - Gross: price.PriceMonthly.Gross, - }, - }) - } - - return st + return c.ServerTypeFromSchema(s) +} + +// SchemaFromServerType converts a ServerType to a schema.ServerType. +func SchemaFromServerType(s *ServerType) schema.ServerType { + return c.SchemaFromServerType(s) } // SSHKeyFromSchema converts a schema.SSHKey to a SSHKey. func SSHKeyFromSchema(s schema.SSHKey) *SSHKey { - sshKey := &SSHKey{ - ID: s.ID, - Name: s.Name, - Fingerprint: s.Fingerprint, - PublicKey: s.PublicKey, - Created: s.Created, - } - sshKey.Labels = map[string]string{} - for key, value := range s.Labels { - sshKey.Labels[key] = value - } - return sshKey + return c.SSHKeyFromSchema(s) +} + +// SchemaFromSSHKey converts a SSHKey to a schema.SSHKey. +func SchemaFromSSHKey(s *SSHKey) schema.SSHKey { + return c.SchemaFromSSHKey(s) } // ImageFromSchema converts a schema.Image to an Image. func ImageFromSchema(s schema.Image) *Image { - i := &Image{ - ID: s.ID, - Type: ImageType(s.Type), - Status: ImageStatus(s.Status), - Description: s.Description, - DiskSize: s.DiskSize, - Created: s.Created, - RapidDeploy: s.RapidDeploy, - OSFlavor: s.OSFlavor, - Architecture: Architecture(s.Architecture), - Protection: ImageProtection{ - Delete: s.Protection.Delete, - }, - Deprecated: s.Deprecated, - Deleted: s.Deleted, - } - if s.Name != nil { - i.Name = *s.Name - } - if s.ImageSize != nil { - i.ImageSize = *s.ImageSize - } - if s.OSVersion != nil { - i.OSVersion = *s.OSVersion - } - if s.CreatedFrom != nil { - i.CreatedFrom = &Server{ - ID: s.CreatedFrom.ID, - Name: s.CreatedFrom.Name, - } - } - if s.BoundTo != nil { - i.BoundTo = &Server{ - ID: *s.BoundTo, - } - } - i.Labels = map[string]string{} - for key, value := range s.Labels { - i.Labels[key] = value - } - return i + return c.ImageFromSchema(s) +} + +// SchemaFromImage converts an Image to a schema.Image. +func SchemaFromImage(i *Image) schema.Image { + return c.SchemaFromImage(i) } // VolumeFromSchema converts a schema.Volume to a Volume. func VolumeFromSchema(s schema.Volume) *Volume { - v := &Volume{ - ID: s.ID, - Name: s.Name, - Location: LocationFromSchema(s.Location), - Size: s.Size, - Status: VolumeStatus(s.Status), - LinuxDevice: s.LinuxDevice, - Protection: VolumeProtection{ - Delete: s.Protection.Delete, - }, - Created: s.Created, - } - if s.Server != nil { - v.Server = &Server{ID: *s.Server} - } - v.Labels = map[string]string{} - for key, value := range s.Labels { - v.Labels[key] = value - } - return v + return c.VolumeFromSchema(s) +} + +// SchemaFromVolume converts a Volume to a schema.Volume. +func SchemaFromVolume(v *Volume) schema.Volume { + return c.SchemaFromVolume(v) } // NetworkFromSchema converts a schema.Network to a Network. func NetworkFromSchema(s schema.Network) *Network { - n := &Network{ - ID: s.ID, - Name: s.Name, - Created: s.Created, - Protection: NetworkProtection{ - Delete: s.Protection.Delete, - }, - Labels: map[string]string{}, - ExposeRoutesToVSwitch: s.ExposeRoutesToVSwitch, - } - - _, n.IPRange, _ = net.ParseCIDR(s.IPRange) - - for _, subnet := range s.Subnets { - n.Subnets = append(n.Subnets, NetworkSubnetFromSchema(subnet)) - } - for _, route := range s.Routes { - n.Routes = append(n.Routes, NetworkRouteFromSchema(route)) - } - for _, serverID := range s.Servers { - n.Servers = append(n.Servers, &Server{ID: serverID}) - } - for key, value := range s.Labels { - n.Labels[key] = value - } - - return n + return c.NetworkFromSchema(s) +} + +// SchemaFromNetwork converts a Network to a schema.Network. +func SchemaFromNetwork(n *Network) schema.Network { + return c.SchemaFromNetwork(n) } // NetworkSubnetFromSchema converts a schema.NetworkSubnet to a NetworkSubnet. func NetworkSubnetFromSchema(s schema.NetworkSubnet) NetworkSubnet { - sn := NetworkSubnet{ - Type: NetworkSubnetType(s.Type), - NetworkZone: NetworkZone(s.NetworkZone), - Gateway: net.ParseIP(s.Gateway), - VSwitchID: s.VSwitchID, - } - _, sn.IPRange, _ = net.ParseCIDR(s.IPRange) - return sn + return c.NetworkSubnetFromSchema(s) +} + +// SchemaFromNetworkSubnet converts a NetworkSubnet to a schema.NetworkSubnet. +func SchemaFromNetworkSubnet(n NetworkSubnet) schema.NetworkSubnet { + return c.SchemaFromNetworkSubnet(n) } // NetworkRouteFromSchema converts a schema.NetworkRoute to a NetworkRoute. func NetworkRouteFromSchema(s schema.NetworkRoute) NetworkRoute { - r := NetworkRoute{ - Gateway: net.ParseIP(s.Gateway), - } - _, r.Destination, _ = net.ParseCIDR(s.Destination) - return r + return c.NetworkRouteFromSchema(s) +} + +// SchemaFromNetworkRoute converts a NetworkRoute to a schema.NetworkRoute. +func SchemaFromNetworkRoute(n NetworkRoute) schema.NetworkRoute { + return c.SchemaFromNetworkRoute(n) } // LoadBalancerTypeFromSchema converts a schema.LoadBalancerType to a LoadBalancerType. func LoadBalancerTypeFromSchema(s schema.LoadBalancerType) *LoadBalancerType { - lt := &LoadBalancerType{ - ID: s.ID, - Name: s.Name, - Description: s.Description, - MaxConnections: s.MaxConnections, - MaxServices: s.MaxServices, - MaxTargets: s.MaxTargets, - MaxAssignedCertificates: s.MaxAssignedCertificates, - } - for _, price := range s.Prices { - lt.Pricings = append(lt.Pricings, LoadBalancerTypeLocationPricing{ - Location: &Location{Name: price.Location}, - Hourly: Price{ - Net: price.PriceHourly.Net, - Gross: price.PriceHourly.Gross, - }, - Monthly: Price{ - Net: price.PriceMonthly.Net, - Gross: price.PriceMonthly.Gross, - }, - }) - } - return lt + return c.LoadBalancerTypeFromSchema(s) +} + +// SchemaFromLoadBalancerType converts a LoadBalancerType to a schema.LoadBalancerType. +func SchemaFromLoadBalancerType(l *LoadBalancerType) schema.LoadBalancerType { + return c.SchemaFromLoadBalancerType(l) } // LoadBalancerFromSchema converts a schema.LoadBalancer to a LoadBalancer. func LoadBalancerFromSchema(s schema.LoadBalancer) *LoadBalancer { - l := &LoadBalancer{ - ID: s.ID, - Name: s.Name, - PublicNet: LoadBalancerPublicNet{ - Enabled: s.PublicNet.Enabled, - IPv4: LoadBalancerPublicNetIPv4{ - IP: net.ParseIP(s.PublicNet.IPv4.IP), - DNSPtr: s.PublicNet.IPv4.DNSPtr, - }, - IPv6: LoadBalancerPublicNetIPv6{ - IP: net.ParseIP(s.PublicNet.IPv6.IP), - DNSPtr: s.PublicNet.IPv6.DNSPtr, - }, - }, - Location: LocationFromSchema(s.Location), - LoadBalancerType: LoadBalancerTypeFromSchema(s.LoadBalancerType), - Algorithm: LoadBalancerAlgorithm{Type: LoadBalancerAlgorithmType(s.Algorithm.Type)}, - Protection: LoadBalancerProtection{ - Delete: s.Protection.Delete, - }, - Labels: map[string]string{}, - Created: s.Created, - IncludedTraffic: s.IncludedTraffic, - } - for _, privateNet := range s.PrivateNet { - l.PrivateNet = append(l.PrivateNet, LoadBalancerPrivateNet{ - Network: &Network{ID: privateNet.Network}, - IP: net.ParseIP(privateNet.IP), - }) - } - if s.OutgoingTraffic != nil { - l.OutgoingTraffic = *s.OutgoingTraffic - } - if s.IngoingTraffic != nil { - l.IngoingTraffic = *s.IngoingTraffic - } - for _, service := range s.Services { - l.Services = append(l.Services, LoadBalancerServiceFromSchema(service)) - } - for _, target := range s.Targets { - l.Targets = append(l.Targets, LoadBalancerTargetFromSchema(target)) - } - for key, value := range s.Labels { - l.Labels[key] = value - } - return l + return c.LoadBalancerFromSchema(s) +} + +// SchemaFromLoadBalancer converts a LoadBalancer to a schema.LoadBalancer. +func SchemaFromLoadBalancer(l *LoadBalancer) schema.LoadBalancer { + return c.SchemaFromLoadBalancer(l) } // LoadBalancerServiceFromSchema converts a schema.LoadBalancerService to a LoadBalancerService. func LoadBalancerServiceFromSchema(s schema.LoadBalancerService) LoadBalancerService { - ls := LoadBalancerService{ - Protocol: LoadBalancerServiceProtocol(s.Protocol), - ListenPort: s.ListenPort, - DestinationPort: s.DestinationPort, - Proxyprotocol: s.Proxyprotocol, - HealthCheck: LoadBalancerServiceHealthCheckFromSchema(s.HealthCheck), - } - if s.HTTP != nil { - ls.HTTP = LoadBalancerServiceHTTP{ - CookieName: s.HTTP.CookieName, - CookieLifetime: time.Duration(s.HTTP.CookieLifetime) * time.Second, - RedirectHTTP: s.HTTP.RedirectHTTP, - StickySessions: s.HTTP.StickySessions, - } - for _, certificateID := range s.HTTP.Certificates { - ls.HTTP.Certificates = append(ls.HTTP.Certificates, &Certificate{ID: certificateID}) - } - } - return ls + return c.LoadBalancerServiceFromSchema(s) +} + +// SchemaFromLoadBalancerService converts a LoadBalancerService to a schema.LoadBalancerService. +func SchemaFromLoadBalancerService(l LoadBalancerService) schema.LoadBalancerService { + return c.SchemaFromLoadBalancerService(l) } // LoadBalancerServiceHealthCheckFromSchema converts a schema.LoadBalancerServiceHealthCheck to a LoadBalancerServiceHealthCheck. func LoadBalancerServiceHealthCheckFromSchema(s *schema.LoadBalancerServiceHealthCheck) LoadBalancerServiceHealthCheck { - lsh := LoadBalancerServiceHealthCheck{ - Protocol: LoadBalancerServiceProtocol(s.Protocol), - Port: s.Port, - Interval: time.Duration(s.Interval) * time.Second, - Retries: s.Retries, - Timeout: time.Duration(s.Timeout) * time.Second, - } - if s.HTTP != nil { - lsh.HTTP = &LoadBalancerServiceHealthCheckHTTP{ - Domain: s.HTTP.Domain, - Path: s.HTTP.Path, - Response: s.HTTP.Response, - StatusCodes: s.HTTP.StatusCodes, - TLS: s.HTTP.TLS, - } - } - return lsh + return c.LoadBalancerServiceHealthCheckFromSchema(s) +} + +// SchemaFromLoadBalancerServiceHealthCheck converts a LoadBalancerServiceHealthCheck to a schema.LoadBalancerServiceHealthCheck. +func SchemaFromLoadBalancerServiceHealthCheck(l LoadBalancerServiceHealthCheck) *schema.LoadBalancerServiceHealthCheck { + return c.SchemaFromLoadBalancerServiceHealthCheck(l) } // LoadBalancerTargetFromSchema converts a schema.LoadBalancerTarget to a LoadBalancerTarget. func LoadBalancerTargetFromSchema(s schema.LoadBalancerTarget) LoadBalancerTarget { - lt := LoadBalancerTarget{ - Type: LoadBalancerTargetType(s.Type), - UsePrivateIP: s.UsePrivateIP, - } - if s.Server != nil { - lt.Server = &LoadBalancerTargetServer{ - Server: &Server{ID: s.Server.ID}, - } - } - if s.LabelSelector != nil { - lt.LabelSelector = &LoadBalancerTargetLabelSelector{ - Selector: s.LabelSelector.Selector, - } - } - if s.IP != nil { - lt.IP = &LoadBalancerTargetIP{IP: s.IP.IP} - } - - for _, healthStatus := range s.HealthStatus { - lt.HealthStatus = append(lt.HealthStatus, LoadBalancerTargetHealthStatusFromSchema(healthStatus)) - } - for _, target := range s.Targets { - lt.Targets = append(lt.Targets, LoadBalancerTargetFromSchema(target)) - } - return lt + return c.LoadBalancerTargetFromSchema(s) +} + +// SchemaFromLoadBalancerTarget converts a LoadBalancerTarget to a schema.LoadBalancerTarget. +func SchemaFromLoadBalancerTarget(l LoadBalancerTarget) schema.LoadBalancerTarget { + return c.SchemaFromLoadBalancerTarget(l) } // LoadBalancerTargetHealthStatusFromSchema converts a schema.LoadBalancerTarget to a LoadBalancerTarget. func LoadBalancerTargetHealthStatusFromSchema(s schema.LoadBalancerTargetHealthStatus) LoadBalancerTargetHealthStatus { - return LoadBalancerTargetHealthStatus{ - ListenPort: s.ListenPort, - Status: LoadBalancerTargetHealthStatusStatus(s.Status), - } + return c.LoadBalancerTargetHealthStatusFromSchema(s) +} + +// SchemaFromLoadBalancerTargetHealthStatus converts a LoadBalancerTarget to a schema.LoadBalancerTarget. +func SchemaFromLoadBalancerTargetHealthStatus(l LoadBalancerTargetHealthStatus) schema.LoadBalancerTargetHealthStatus { + return c.SchemaFromLoadBalancerTargetHealthStatus(l) } // CertificateFromSchema converts a schema.Certificate to a Certificate. func CertificateFromSchema(s schema.Certificate) *Certificate { - c := &Certificate{ - ID: s.ID, - Name: s.Name, - Type: CertificateType(s.Type), - Certificate: s.Certificate, - Created: s.Created, - NotValidBefore: s.NotValidBefore, - NotValidAfter: s.NotValidAfter, - DomainNames: s.DomainNames, - Fingerprint: s.Fingerprint, - } - if s.Status != nil { - c.Status = &CertificateStatus{ - Issuance: CertificateStatusType(s.Status.Issuance), - Renewal: CertificateStatusType(s.Status.Renewal), - } - if s.Status.Error != nil { - certErr := ErrorFromSchema(*s.Status.Error) - c.Status.Error = &certErr - } - } - if len(s.Labels) > 0 { - c.Labels = s.Labels - } - if len(s.UsedBy) > 0 { - c.UsedBy = make([]CertificateUsedByRef, len(s.UsedBy)) - for i, ref := range s.UsedBy { - c.UsedBy[i] = CertificateUsedByRef{ID: ref.ID, Type: CertificateUsedByRefType(ref.Type)} - } - } - - return c + return c.CertificateFromSchema(s) +} + +// SchemaFromCertificate converts a Certificate to a schema.Certificate. +func SchemaFromCertificate(ct *Certificate) schema.Certificate { + return c.SchemaFromCertificate(ct) } // PaginationFromSchema converts a schema.MetaPagination to a Pagination. func PaginationFromSchema(s schema.MetaPagination) Pagination { - return Pagination{ - Page: s.Page, - PerPage: s.PerPage, - PreviousPage: s.PreviousPage, - NextPage: s.NextPage, - LastPage: s.LastPage, - TotalEntries: s.TotalEntries, - } + return c.PaginationFromSchema(s) +} + +// SchemaFromPagination converts a Pagination to a schema.MetaPagination. +func SchemaFromPagination(p Pagination) schema.MetaPagination { + return c.SchemaFromPagination(p) } // ErrorFromSchema converts a schema.Error to an Error. func ErrorFromSchema(s schema.Error) Error { - e := Error{ - Code: ErrorCode(s.Code), - Message: s.Message, - } - - if d, ok := s.Details.(schema.ErrorDetailsInvalidInput); ok { - details := ErrorDetailsInvalidInput{ - Fields: []ErrorDetailsInvalidInputField{}, - } - for _, field := range d.Fields { - details.Fields = append(details.Fields, ErrorDetailsInvalidInputField{ - Name: field.Name, - Messages: field.Messages, - }) - } - e.Details = details - } - return e + return c.ErrorFromSchema(s) +} + +// SchemaFromError converts an Error to a schema.Error. +func SchemaFromError(e Error) schema.Error { + return c.SchemaFromError(e) } // PricingFromSchema converts a schema.Pricing to a Pricing. func PricingFromSchema(s schema.Pricing) Pricing { - p := Pricing{ - Image: ImagePricing{ - PerGBMonth: Price{ - Currency: s.Currency, - VATRate: s.VATRate, - Net: s.Image.PricePerGBMonth.Net, - Gross: s.Image.PricePerGBMonth.Gross, - }, - }, - FloatingIP: FloatingIPPricing{ - Monthly: Price{ - Currency: s.Currency, - VATRate: s.VATRate, - Net: s.FloatingIP.PriceMonthly.Net, - Gross: s.FloatingIP.PriceMonthly.Gross, - }, - }, - Traffic: TrafficPricing{ - PerTB: Price{ - Currency: s.Currency, - VATRate: s.VATRate, - Net: s.Traffic.PricePerTB.Net, - Gross: s.Traffic.PricePerTB.Gross, - }, - }, - ServerBackup: ServerBackupPricing{ - Percentage: s.ServerBackup.Percentage, - }, - Volume: VolumePricing{ - PerGBMonthly: Price{ - Currency: s.Currency, - VATRate: s.VATRate, - Net: s.Volume.PricePerGBPerMonth.Net, - Gross: s.Volume.PricePerGBPerMonth.Gross, - }, - }, - } - for _, floatingIPType := range s.FloatingIPs { - var pricings []FloatingIPTypeLocationPricing - for _, price := range floatingIPType.Prices { - p := FloatingIPTypeLocationPricing{ - Location: &Location{Name: price.Location}, - Monthly: Price{ - Currency: s.Currency, - VATRate: s.VATRate, - Net: price.PriceMonthly.Net, - Gross: price.PriceMonthly.Gross, - }, - } - pricings = append(pricings, p) - } - p.FloatingIPs = append(p.FloatingIPs, FloatingIPTypePricing{Type: FloatingIPType(floatingIPType.Type), Pricings: pricings}) - } - for _, primaryIPType := range s.PrimaryIPs { - var pricings []PrimaryIPTypePricing - for _, price := range primaryIPType.Prices { - p := PrimaryIPTypePricing{ - Location: price.Location, - Monthly: PrimaryIPPrice{ - Net: price.PriceMonthly.Net, - Gross: price.PriceMonthly.Gross, - }, - Hourly: PrimaryIPPrice{ - Net: price.PriceHourly.Net, - Gross: price.PriceHourly.Gross, - }, - } - pricings = append(pricings, p) - } - p.PrimaryIPs = append(p.PrimaryIPs, PrimaryIPPricing{Type: primaryIPType.Type, Pricings: pricings}) - } - for _, serverType := range s.ServerTypes { - var pricings []ServerTypeLocationPricing - for _, price := range serverType.Prices { - pricings = append(pricings, ServerTypeLocationPricing{ - Location: &Location{Name: price.Location}, - Hourly: Price{ - Currency: s.Currency, - VATRate: s.VATRate, - Net: price.PriceHourly.Net, - Gross: price.PriceHourly.Gross, - }, - Monthly: Price{ - Currency: s.Currency, - VATRate: s.VATRate, - Net: price.PriceMonthly.Net, - Gross: price.PriceMonthly.Gross, - }, - }) - } - p.ServerTypes = append(p.ServerTypes, ServerTypePricing{ - ServerType: &ServerType{ - ID: serverType.ID, - Name: serverType.Name, - }, - Pricings: pricings, - }) - } - for _, loadBalancerType := range s.LoadBalancerTypes { - var pricings []LoadBalancerTypeLocationPricing - for _, price := range loadBalancerType.Prices { - pricings = append(pricings, LoadBalancerTypeLocationPricing{ - Location: &Location{Name: price.Location}, - Hourly: Price{ - Currency: s.Currency, - VATRate: s.VATRate, - Net: price.PriceHourly.Net, - Gross: price.PriceHourly.Gross, - }, - Monthly: Price{ - Currency: s.Currency, - VATRate: s.VATRate, - Net: price.PriceMonthly.Net, - Gross: price.PriceMonthly.Gross, - }, - }) - } - p.LoadBalancerTypes = append(p.LoadBalancerTypes, LoadBalancerTypePricing{ - LoadBalancerType: &LoadBalancerType{ - ID: loadBalancerType.ID, - Name: loadBalancerType.Name, - }, - Pricings: pricings, - }) - } - return p + return c.PricingFromSchema(s) +} + +// SchemaFromPricing converts a Pricing to a schema.Pricing. +func SchemaFromPricing(p Pricing) schema.Pricing { + return c.SchemaFromPricing(p) } // FirewallFromSchema converts a schema.Firewall to a Firewall. func FirewallFromSchema(s schema.Firewall) *Firewall { - f := &Firewall{ - ID: s.ID, - Name: s.Name, - Labels: map[string]string{}, - Created: s.Created, - } - for key, value := range s.Labels { - f.Labels[key] = value - } - for _, res := range s.AppliedTo { - r := FirewallResource{Type: FirewallResourceType(res.Type)} - switch r.Type { - case FirewallResourceTypeLabelSelector: - r.LabelSelector = &FirewallResourceLabelSelector{Selector: res.LabelSelector.Selector} - case FirewallResourceTypeServer: - r.Server = &FirewallResourceServer{ID: res.Server.ID} - } - f.AppliedTo = append(f.AppliedTo, r) - } - for _, rule := range s.Rules { - sourceIPs := []net.IPNet{} - for _, sourceIP := range rule.SourceIPs { - _, mask, err := net.ParseCIDR(sourceIP) - if err == nil && mask != nil { - sourceIPs = append(sourceIPs, *mask) - } - } - destinationIPs := []net.IPNet{} - for _, destinationIP := range rule.DestinationIPs { - _, mask, err := net.ParseCIDR(destinationIP) - if err == nil && mask != nil { - destinationIPs = append(destinationIPs, *mask) - } - } - f.Rules = append(f.Rules, FirewallRule{ - Direction: FirewallRuleDirection(rule.Direction), - SourceIPs: sourceIPs, - DestinationIPs: destinationIPs, - Protocol: FirewallRuleProtocol(rule.Protocol), - Port: rule.Port, - Description: rule.Description, - }) - } - return f + return c.FirewallFromSchema(s) +} + +// SchemaFromFirewall converts a Firewall to a schema.Firewall. +func SchemaFromFirewall(f *Firewall) schema.Firewall { + return c.SchemaFromFirewall(f) } // PlacementGroupFromSchema converts a schema.PlacementGroup to a PlacementGroup. func PlacementGroupFromSchema(s schema.PlacementGroup) *PlacementGroup { - g := &PlacementGroup{ - ID: s.ID, - Name: s.Name, - Labels: s.Labels, - Created: s.Created, - Servers: s.Servers, - Type: PlacementGroupType(s.Type), - } - return g + return c.PlacementGroupFromSchema(s) +} + +// SchemaFromPlacementGroup converts a PlacementGroup to a schema.PlacementGroup. +func SchemaFromPlacementGroup(p *PlacementGroup) schema.PlacementGroup { + return c.SchemaFromPlacementGroup(p) +} + +// DeprecationFromSchema converts a [schema.DeprecationInfo] to a [DeprecationInfo]. +func DeprecationFromSchema(s *schema.DeprecationInfo) *DeprecationInfo { + return c.DeprecationFromSchema(s) +} + +// SchemaFromDeprecation converts a [DeprecationInfo] to a [schema.DeprecationInfo]. +func SchemaFromDeprecation(d *DeprecationInfo) *schema.DeprecationInfo { + return c.SchemaFromDeprecation(d) } func placementGroupCreateOptsToSchema(opts PlacementGroupCreateOpts) schema.PlacementGroupCreateRequest { - req := schema.PlacementGroupCreateRequest{ - Name: opts.Name, - Type: string(opts.Type), - } - if opts.Labels != nil { - req.Labels = &opts.Labels - } - return req + return c.SchemaFromPlacementGroupCreateOpts(opts) } func loadBalancerCreateOptsToSchema(opts LoadBalancerCreateOpts) schema.LoadBalancerCreateRequest { - req := schema.LoadBalancerCreateRequest{ - Name: opts.Name, - PublicInterface: opts.PublicInterface, - } - if opts.Algorithm != nil { - req.Algorithm = &schema.LoadBalancerCreateRequestAlgorithm{ - Type: string(opts.Algorithm.Type), - } - } - if opts.LoadBalancerType.ID != 0 { - req.LoadBalancerType = opts.LoadBalancerType.ID - } else if opts.LoadBalancerType.Name != "" { - req.LoadBalancerType = opts.LoadBalancerType.Name - } - if opts.Location != nil { - if opts.Location.ID != 0 { - req.Location = Ptr(strconv.FormatInt(opts.Location.ID, 10)) - } else { - req.Location = Ptr(opts.Location.Name) - } - } - if opts.NetworkZone != "" { - req.NetworkZone = Ptr(string(opts.NetworkZone)) - } - if opts.Labels != nil { - req.Labels = &opts.Labels - } - if opts.Network != nil { - req.Network = Ptr(opts.Network.ID) - } - for _, target := range opts.Targets { - schemaTarget := schema.LoadBalancerCreateRequestTarget{ - UsePrivateIP: target.UsePrivateIP, - } - switch target.Type { - case LoadBalancerTargetTypeServer: - schemaTarget.Type = string(LoadBalancerTargetTypeServer) - schemaTarget.Server = &schema.LoadBalancerCreateRequestTargetServer{ID: target.Server.Server.ID} - case LoadBalancerTargetTypeLabelSelector: - schemaTarget.Type = string(LoadBalancerTargetTypeLabelSelector) - schemaTarget.LabelSelector = &schema.LoadBalancerCreateRequestTargetLabelSelector{Selector: target.LabelSelector.Selector} - case LoadBalancerTargetTypeIP: - schemaTarget.Type = string(LoadBalancerTargetTypeIP) - schemaTarget.IP = &schema.LoadBalancerCreateRequestTargetIP{IP: target.IP.IP} - } - req.Targets = append(req.Targets, schemaTarget) - } - for _, service := range opts.Services { - schemaService := schema.LoadBalancerCreateRequestService{ - Protocol: string(service.Protocol), - ListenPort: service.ListenPort, - DestinationPort: service.DestinationPort, - Proxyprotocol: service.Proxyprotocol, - } - if service.HTTP != nil { - schemaService.HTTP = &schema.LoadBalancerCreateRequestServiceHTTP{ - RedirectHTTP: service.HTTP.RedirectHTTP, - StickySessions: service.HTTP.StickySessions, - CookieName: service.HTTP.CookieName, - } - if service.HTTP.CookieLifetime != nil { - if sec := service.HTTP.CookieLifetime.Seconds(); sec != 0 { - schemaService.HTTP.CookieLifetime = Ptr(int(sec)) - } - } - if service.HTTP.Certificates != nil { - certificates := []int64{} - for _, certificate := range service.HTTP.Certificates { - certificates = append(certificates, certificate.ID) - } - schemaService.HTTP.Certificates = &certificates - } - } - if service.HealthCheck != nil { - schemaHealthCheck := &schema.LoadBalancerCreateRequestServiceHealthCheck{ - Protocol: string(service.HealthCheck.Protocol), - Port: service.HealthCheck.Port, - Retries: service.HealthCheck.Retries, - } - if service.HealthCheck.Interval != nil { - schemaHealthCheck.Interval = Ptr(int(service.HealthCheck.Interval.Seconds())) - } - if service.HealthCheck.Timeout != nil { - schemaHealthCheck.Timeout = Ptr(int(service.HealthCheck.Timeout.Seconds())) - } - if service.HealthCheck.HTTP != nil { - schemaHealthCheckHTTP := &schema.LoadBalancerCreateRequestServiceHealthCheckHTTP{ - Domain: service.HealthCheck.HTTP.Domain, - Path: service.HealthCheck.HTTP.Path, - Response: service.HealthCheck.HTTP.Response, - TLS: service.HealthCheck.HTTP.TLS, - } - if service.HealthCheck.HTTP.StatusCodes != nil { - schemaHealthCheckHTTP.StatusCodes = &service.HealthCheck.HTTP.StatusCodes //nolint:gosec // does not result in bug - } - schemaHealthCheck.HTTP = schemaHealthCheckHTTP - } - schemaService.HealthCheck = schemaHealthCheck - } - req.Services = append(req.Services, schemaService) - } - return req + return c.SchemaFromLoadBalancerCreateOpts(opts) } func loadBalancerAddServiceOptsToSchema(opts LoadBalancerAddServiceOpts) schema.LoadBalancerActionAddServiceRequest { - req := schema.LoadBalancerActionAddServiceRequest{ - Protocol: string(opts.Protocol), - ListenPort: opts.ListenPort, - DestinationPort: opts.DestinationPort, - Proxyprotocol: opts.Proxyprotocol, - } - if opts.HTTP != nil { - req.HTTP = &schema.LoadBalancerActionAddServiceRequestHTTP{ - CookieName: opts.HTTP.CookieName, - RedirectHTTP: opts.HTTP.RedirectHTTP, - StickySessions: opts.HTTP.StickySessions, - } - if opts.HTTP.CookieLifetime != nil { - req.HTTP.CookieLifetime = Ptr(int(opts.HTTP.CookieLifetime.Seconds())) - } - if opts.HTTP.Certificates != nil { - certificates := []int64{} - for _, certificate := range opts.HTTP.Certificates { - certificates = append(certificates, certificate.ID) - } - req.HTTP.Certificates = &certificates - } - } - if opts.HealthCheck != nil { - req.HealthCheck = &schema.LoadBalancerActionAddServiceRequestHealthCheck{ - Protocol: string(opts.HealthCheck.Protocol), - Port: opts.HealthCheck.Port, - Retries: opts.HealthCheck.Retries, - } - if opts.HealthCheck.Interval != nil { - req.HealthCheck.Interval = Ptr(int(opts.HealthCheck.Interval.Seconds())) - } - if opts.HealthCheck.Timeout != nil { - req.HealthCheck.Timeout = Ptr(int(opts.HealthCheck.Timeout.Seconds())) - } - if opts.HealthCheck.HTTP != nil { - req.HealthCheck.HTTP = &schema.LoadBalancerActionAddServiceRequestHealthCheckHTTP{ - Domain: opts.HealthCheck.HTTP.Domain, - Path: opts.HealthCheck.HTTP.Path, - Response: opts.HealthCheck.HTTP.Response, - TLS: opts.HealthCheck.HTTP.TLS, - } - if opts.HealthCheck.HTTP.StatusCodes != nil { - req.HealthCheck.HTTP.StatusCodes = &opts.HealthCheck.HTTP.StatusCodes - } - } - } - return req + return c.SchemaFromLoadBalancerAddServiceOpts(opts) } func loadBalancerUpdateServiceOptsToSchema(opts LoadBalancerUpdateServiceOpts) schema.LoadBalancerActionUpdateServiceRequest { - req := schema.LoadBalancerActionUpdateServiceRequest{ - DestinationPort: opts.DestinationPort, - Proxyprotocol: opts.Proxyprotocol, - } - if opts.Protocol != "" { - req.Protocol = Ptr(string(opts.Protocol)) - } - if opts.HTTP != nil { - req.HTTP = &schema.LoadBalancerActionUpdateServiceRequestHTTP{ - CookieName: opts.HTTP.CookieName, - RedirectHTTP: opts.HTTP.RedirectHTTP, - StickySessions: opts.HTTP.StickySessions, - } - if opts.HTTP.CookieLifetime != nil { - req.HTTP.CookieLifetime = Ptr(int(opts.HTTP.CookieLifetime.Seconds())) - } - if opts.HTTP.Certificates != nil { - certificates := []int64{} - for _, certificate := range opts.HTTP.Certificates { - certificates = append(certificates, certificate.ID) - } - req.HTTP.Certificates = &certificates - } - } - if opts.HealthCheck != nil { - req.HealthCheck = &schema.LoadBalancerActionUpdateServiceRequestHealthCheck{ - Port: opts.HealthCheck.Port, - Retries: opts.HealthCheck.Retries, - } - if opts.HealthCheck.Interval != nil { - req.HealthCheck.Interval = Ptr(int(opts.HealthCheck.Interval.Seconds())) - } - if opts.HealthCheck.Timeout != nil { - req.HealthCheck.Timeout = Ptr(int(opts.HealthCheck.Timeout.Seconds())) - } - if opts.HealthCheck.Protocol != "" { - req.HealthCheck.Protocol = Ptr(string(opts.HealthCheck.Protocol)) - } - if opts.HealthCheck.HTTP != nil { - req.HealthCheck.HTTP = &schema.LoadBalancerActionUpdateServiceRequestHealthCheckHTTP{ - Domain: opts.HealthCheck.HTTP.Domain, - Path: opts.HealthCheck.HTTP.Path, - Response: opts.HealthCheck.HTTP.Response, - TLS: opts.HealthCheck.HTTP.TLS, - } - if opts.HealthCheck.HTTP.StatusCodes != nil { - req.HealthCheck.HTTP.StatusCodes = &opts.HealthCheck.HTTP.StatusCodes - } - } - } - return req + return c.SchemaFromLoadBalancerUpdateServiceOpts(opts) } func firewallCreateOptsToSchema(opts FirewallCreateOpts) schema.FirewallCreateRequest { - req := schema.FirewallCreateRequest{ - Name: opts.Name, - } - if opts.Labels != nil { - req.Labels = &opts.Labels - } - for _, rule := range opts.Rules { - schemaRule := schema.FirewallRule{ - Direction: string(rule.Direction), - Protocol: string(rule.Protocol), - Port: rule.Port, - Description: rule.Description, - } - switch rule.Direction { - case FirewallRuleDirectionOut: - schemaRule.DestinationIPs = make([]string, len(rule.DestinationIPs)) - for i, destinationIP := range rule.DestinationIPs { - schemaRule.DestinationIPs[i] = destinationIP.String() - } - case FirewallRuleDirectionIn: - schemaRule.SourceIPs = make([]string, len(rule.SourceIPs)) - for i, sourceIP := range rule.SourceIPs { - schemaRule.SourceIPs[i] = sourceIP.String() - } - } - req.Rules = append(req.Rules, schemaRule) - } - for _, res := range opts.ApplyTo { - schemaFirewallResource := schema.FirewallResource{ - Type: string(res.Type), - } - switch res.Type { - case FirewallResourceTypeServer: - schemaFirewallResource.Server = &schema.FirewallResourceServer{ - ID: res.Server.ID, - } - case FirewallResourceTypeLabelSelector: - schemaFirewallResource.LabelSelector = &schema.FirewallResourceLabelSelector{Selector: res.LabelSelector.Selector} - } - - req.ApplyTo = append(req.ApplyTo, schemaFirewallResource) - } - return req + return c.SchemaFromFirewallCreateOpts(opts) } func firewallSetRulesOptsToSchema(opts FirewallSetRulesOpts) schema.FirewallActionSetRulesRequest { - req := schema.FirewallActionSetRulesRequest{Rules: []schema.FirewallRule{}} - for _, rule := range opts.Rules { - schemaRule := schema.FirewallRule{ - Direction: string(rule.Direction), - Protocol: string(rule.Protocol), - Port: rule.Port, - Description: rule.Description, - } - switch rule.Direction { - case FirewallRuleDirectionOut: - schemaRule.DestinationIPs = make([]string, len(rule.DestinationIPs)) - for i, destinationIP := range rule.DestinationIPs { - schemaRule.DestinationIPs[i] = destinationIP.String() - } - case FirewallRuleDirectionIn: - schemaRule.SourceIPs = make([]string, len(rule.SourceIPs)) - for i, sourceIP := range rule.SourceIPs { - schemaRule.SourceIPs[i] = sourceIP.String() - } - } - req.Rules = append(req.Rules, schemaRule) - } - return req + return c.SchemaFromFirewallSetRulesOpts(opts) } func firewallResourceToSchema(resource FirewallResource) schema.FirewallResource { - s := schema.FirewallResource{ - Type: string(resource.Type), - } - switch resource.Type { - case FirewallResourceTypeLabelSelector: - s.LabelSelector = &schema.FirewallResourceLabelSelector{Selector: resource.LabelSelector.Selector} - case FirewallResourceTypeServer: - s.Server = &schema.FirewallResourceServer{ID: resource.Server.ID} - } - return s + return c.SchemaFromFirewallResource(resource) } func serverMetricsFromSchema(s *schema.ServerGetMetricsResponse) (*ServerMetrics, error) { - ms := ServerMetrics{ - Start: s.Metrics.Start, - End: s.Metrics.End, - Step: s.Metrics.Step, - } - - timeSeries := make(map[string][]ServerMetricsValue) - for tsName, v := range s.Metrics.TimeSeries { - vals := make([]ServerMetricsValue, len(v.Values)) - - for i, rawVal := range v.Values { - var val ServerMetricsValue - - tup, ok := rawVal.([]interface{}) - if !ok { - return nil, fmt.Errorf("failed to convert value to tuple: %v", rawVal) - } - if len(tup) != 2 { - return nil, fmt.Errorf("invalid tuple size: %d: %v", len(tup), rawVal) - } - ts, ok := tup[0].(float64) - if !ok { - return nil, fmt.Errorf("convert to float64: %v", tup[0]) - } - val.Timestamp = ts - - v, ok := tup[1].(string) - if !ok { - return nil, fmt.Errorf("not a string: %v", tup[1]) - } - val.Value = v - vals[i] = val - } - - timeSeries[tsName] = vals - } - ms.TimeSeries = timeSeries - - return &ms, nil + return c.ServerMetricsFromSchema(s) } func loadBalancerMetricsFromSchema(s *schema.LoadBalancerGetMetricsResponse) (*LoadBalancerMetrics, error) { - ms := LoadBalancerMetrics{ - Start: s.Metrics.Start, - End: s.Metrics.End, - Step: s.Metrics.Step, - } - - timeSeries := make(map[string][]LoadBalancerMetricsValue) - for tsName, v := range s.Metrics.TimeSeries { - vals := make([]LoadBalancerMetricsValue, len(v.Values)) - - for i, rawVal := range v.Values { - var val LoadBalancerMetricsValue - - tup, ok := rawVal.([]interface{}) - if !ok { - return nil, fmt.Errorf("failed to convert value to tuple: %v", rawVal) - } - if len(tup) != 2 { - return nil, fmt.Errorf("invalid tuple size: %d: %v", len(tup), rawVal) - } - ts, ok := tup[0].(float64) - if !ok { - return nil, fmt.Errorf("convert to float64: %v", tup[0]) - } - val.Timestamp = ts - - v, ok := tup[1].(string) - if !ok { - return nil, fmt.Errorf("not a string: %v", tup[1]) - } - val.Value = v - vals[i] = val - } - - timeSeries[tsName] = vals - } - ms.TimeSeries = timeSeries - - return &ms, nil -} - -// DeprecationFromSchema converts a [schema.DeprecationInfo] to a [DeprecationInfo]. -func DeprecationFromSchema(s *schema.DeprecationInfo) *DeprecationInfo { - if s == nil { - return nil - } - - return &DeprecationInfo{ - Announced: s.Announced, - UnavailableAfter: s.UnavailableAfter, - } + return c.LoadBalancerMetricsFromSchema(s) } diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/datacenter.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/datacenter.go index eaa12429f834..54590d2a2a54 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/datacenter.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/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/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/firewall.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/firewall.go index 371e648f14e1..d393f1e0e0e7 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/firewall.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/firewall.go @@ -12,8 +12,18 @@ type Firewall struct { AppliedTo []FirewallResource `json:"applied_to"` } -// FirewallRule defines the schema of a Firewall rule. +// FirewallRule defines the schema of a Firewall rule in responses. type FirewallRule struct { + Direction string `json:"direction"` + SourceIPs []string `json:"source_ips"` + DestinationIPs []string `json:"destination_ips"` + Protocol string `json:"protocol"` + Port *string `json:"port"` + Description *string `json:"description"` +} + +// FirewallRuleRequest defines the schema of a Firewall rule in requests. +type FirewallRuleRequest struct { Direction string `json:"direction"` SourceIPs []string `json:"source_ips,omitempty"` DestinationIPs []string `json:"destination_ips,omitempty"` @@ -34,10 +44,10 @@ type FirewallGetResponse struct { // FirewallCreateRequest defines the schema of the request to create a Firewall. type FirewallCreateRequest struct { - Name string `json:"name"` - Labels *map[string]string `json:"labels,omitempty"` - Rules []FirewallRule `json:"rules,omitempty"` - ApplyTo []FirewallResource `json:"apply_to,omitempty"` + Name string `json:"name"` + Labels *map[string]string `json:"labels,omitempty"` + Rules []FirewallRuleRequest `json:"rules,omitempty"` + ApplyTo []FirewallResource `json:"apply_to,omitempty"` } // FirewallResource defines the schema of a resource to apply the new Firewall on. @@ -76,7 +86,7 @@ type FirewallUpdateResponse struct { // FirewallActionSetRulesRequest defines the schema of the request when setting Firewall rules. type FirewallActionSetRulesRequest struct { - Rules []FirewallRule `json:"rules"` + Rules []FirewallRuleRequest `json:"rules"` } // FirewallActionSetRulesResponse defines the schema of the response when setting Firewall rules. diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/image.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/image.go index 1520935ec7c5..eacc20f89621 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/image.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/image.go @@ -11,7 +11,7 @@ type Image struct { Description string `json:"description"` ImageSize *float32 `json:"image_size"` DiskSize float32 `json:"disk_size"` - Created time.Time `json:"created"` + Created *time.Time `json:"created"` CreatedFrom *ImageCreatedFrom `json:"created_from"` BoundTo *int64 `json:"bound_to"` OSFlavor string `json:"os_flavor"` @@ -19,8 +19,8 @@ type Image struct { Architecture string `json:"architecture"` RapidDeploy bool `json:"rapid_deploy"` Protection ImageProtection `json:"protection"` - Deprecated time.Time `json:"deprecated"` - Deleted time.Time `json:"deleted"` + Deprecated *time.Time `json:"deprecated"` + Deleted *time.Time `json:"deleted"` Labels map[string]string `json:"labels"` } diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/iso.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/iso.go index 0fcb1a6c9451..4cf48cc1aef7 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/iso.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/iso.go @@ -1,15 +1,12 @@ package schema -import "time" - // ISO defines the schema of an ISO image. type ISO struct { - ID int64 `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Type string `json:"type"` - Architecture *string `json:"architecture"` - Deprecated time.Time `json:"deprecated"` + ID int64 `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Type string `json:"type"` + Architecture *string `json:"architecture"` DeprecatableResource } diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/load_balancer_type.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/load_balancer_type.go index 09ac43d7a6ce..b0193d3a86f4 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/load_balancer_type.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/load_balancer_type.go @@ -10,6 +10,7 @@ type LoadBalancerType struct { MaxTargets int `json:"max_targets"` MaxAssignedCertificates int `json:"max_assigned_certificates"` Prices []PricingLoadBalancerTypePrice `json:"prices"` + Deprecated *string `json:"deprecated"` } // LoadBalancerTypeListResponse defines the schema of the response when diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/primary_ip.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/primary_ip.go index b685c386f9d2..1901ce800170 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/primary_ip.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/primary_ip.go @@ -11,7 +11,7 @@ type PrimaryIP struct { Type string `json:"type"` Protection PrimaryIPProtection `json:"protection"` DNSPtr []PrimaryIPDNSPTR `json:"dns_ptr"` - AssigneeID int64 `json:"assignee_id"` + AssigneeID *int64 `json:"assignee_id"` AssigneeType string `json:"assignee_type"` AutoDelete bool `json:"auto_delete"` Blocked bool `json:"blocked"` diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/server.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/server.go index 39a10b064831..068b3e81f945 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/server.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/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/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/server_type.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/server_type.go index 0920a5ee16d7..21a87da9a9b7 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/server_type.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/server_type.go @@ -13,6 +13,7 @@ type ServerType struct { Architecture string `json:"architecture"` IncludedTraffic int64 `json:"included_traffic"` Prices []PricingServerTypePrice `json:"prices"` + Deprecated bool `json:"deprecated"` DeprecatableResource } diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/volume.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/volume.go index 0dd391bccc85..1de6459550c2 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/volume.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema/volume.go @@ -10,6 +10,7 @@ type Volume struct { Status string `json:"status"` Location Location `json:"location"` Size int `json:"size"` + Format *string `json:"format"` Protection VolumeProtection `json:"protection"` Labels map[string]string `json:"labels"` LinuxDevice string `json:"linux_device"` diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema_assign.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema_assign.go new file mode 100644 index 000000000000..8894e3506916 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema_assign.go @@ -0,0 +1,15 @@ +//go:build !goverter + +package hcloud + +/* +This file is needed so that c is assigned to a converterImpl{}. +If we did this in schema.go, goverter would fail because of a +compiler error (converterImpl might not be defined). +Because this file is not compiled by goverter, we can safely +assign c here. +*/ + +func init() { + c = &converterImpl{} +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema_gen.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema_gen.go new file mode 100644 index 000000000000..7cc9df8d052e --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema_gen.go @@ -0,0 +1,957 @@ +package hcloud + +import ( + "encoding/json" + "fmt" + "net" + "time" + + "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema" +) + +//go:generate go run github.com/jmattheis/goverter/cmd/goverter gen ./... + +/* +This file generates conversions methods between the schema and the hcloud package. +Goverter (https://github.com/jmattheis/goverter) is used to generate these conversion +methods. Goverter is configured using comments in and on the [converter] interface. +A struct implementing the interface methods, [converterImpl], is generated in zz_schema.go. +The generated methods are then wrapped in schema.go to be exported. + +You can find a documentation of goverter here: https://goverter.jmattheis.de/ +*/ + +// goverter:converter +// +// Specify where and in which package to output the generated +// conversion methods. +// goverter:output:file zz_schema.go +// goverter:output:package k8s.io/autoscaler/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud +// +// In case of *T -> T conversion, use zero value if *T is nil. +// goverter:useZeroValueOnPointerInconsistency yes +// +// Do not deep copy in case of *T -> *T conversion. +// goverter:skipCopySameType yes +// +// Explicit conversion methods are needed for non-trivial cases +// where the target, source or both are of primitive types. Struct +// to struct conversions can be handled by goverter directly. +// goverter:extend ipFromString +// goverter:extend stringFromIP +// goverter:extend ipNetFromString +// goverter:extend stringFromIPNet +// goverter:extend timeToTimePtr +// goverter:extend serverFromInt64 +// goverter:extend int64FromServer +// goverter:extend networkFromInt64 +// goverter:extend int64FromNetwork +// goverter:extend loadBalancerFromInt64 +// goverter:extend int64FromLoadBalancer +// goverter:extend volumeFromInt64 +// goverter:extend int64FromVolume +// goverter:extend certificateFromInt64 +// goverter:extend int64FromCertificate +// goverter:extend locationFromString +// goverter:extend stringFromLocation +// goverter:extend serverTypeFromInt64 +// goverter:extend int64FromServerType +// goverter:extend floatingIPFromInt64 +// goverter:extend int64FromFloatingIP +// goverter:extend mapFromFloatingIPDNSPtrSchema +// goverter:extend floatingIPDNSPtrSchemaFromMap +// goverter:extend mapFromPrimaryIPDNSPtrSchema +// goverter:extend primaryIPDNSPtrSchemaFromMap +// goverter:extend mapFromServerPublicNetIPv6DNSPtrSchema +// goverter:extend serverPublicNetIPv6DNSPtrSchemaFromMap +// goverter:extend firewallStatusFromSchemaServerFirewall +// goverter:extend serverFirewallSchemaFromFirewallStatus +// goverter:extend durationFromIntSeconds +// goverter:extend intSecondsFromDuration +// goverter:extend serverFromImageCreatedFromSchema +// goverter:extend anyFromLoadBalancerType +// goverter:extend serverMetricsTimeSeriesFromSchema +// goverter:extend loadBalancerMetricsTimeSeriesFromSchema +// goverter:extend stringPtrFromLoadBalancerServiceProtocol +// goverter:extend stringPtrFromNetworkZone +// goverter:extend schemaFromLoadBalancerCreateOptsTargetLabelSelector +// goverter:extend schemaFromLoadBalancerCreateOptsTargetServer +// goverter:extend schemaFromLoadBalancerCreateOptsTargetIP +// goverter:extend stringMapToStringMapPtr +// goverter:extend int64SlicePtrFromCertificatePtrSlice +// goverter:extend stringSlicePtrFromStringSlice +type converter interface { + + // goverter:map Error.Code ErrorCode + // goverter:map Error.Message ErrorMessage + ActionFromSchema(schema.Action) *Action + + // goverter:map . Error | schemaActionErrorFromAction + SchemaFromAction(*Action) schema.Action + + ActionsFromSchema([]schema.Action) []*Action + + SchemaFromActions([]*Action) []schema.Action + + // goverter:map . IP | ipFromFloatingIPSchema + // goverter:map . Network | networkFromFloatingIPSchema + FloatingIPFromSchema(schema.FloatingIP) *FloatingIP + + // goverter:map . IP | floatingIPToIPString + SchemaFromFloatingIP(*FloatingIP) schema.FloatingIP + + // goverter:map . IP | ipFromPrimaryIPSchema + // goverter:map . Network | networkFromPrimaryIPSchema + PrimaryIPFromSchema(schema.PrimaryIP) *PrimaryIP + + // goverter:map . IP | primaryIPToIPString + // goverter:map AssigneeID | mapZeroInt64ToNil + SchemaFromPrimaryIP(*PrimaryIP) schema.PrimaryIP + + ISOFromSchema(schema.ISO) *ISO + + // We cannot use goverter settings when mapping a struct to a struct pointer + // See [converter.ISOFromSchema] + // See https://github.com/jmattheis/goverter/issues/114 + // goverter:map DeprecatableResource.Deprecation.UnavailableAfter Deprecated + intISOFromSchema(schema.ISO) ISO + + SchemaFromISO(*ISO) schema.ISO + + LocationFromSchema(schema.Location) *Location + + SchemaFromLocation(*Location) schema.Location + + DatacenterFromSchema(schema.Datacenter) *Datacenter + + SchemaFromDatacenter(*Datacenter) schema.Datacenter + + ServerFromSchema(schema.Server) *Server + + // goverter:map OutgoingTraffic | mapZeroUint64ToNil + // goverter:map IngoingTraffic | mapZeroUint64ToNil + // goverter:map BackupWindow | mapEmptyStringToNil + SchemaFromServer(*Server) schema.Server + + ServerPublicNetFromSchema(schema.ServerPublicNet) ServerPublicNet + + SchemaFromServerPublicNet(ServerPublicNet) schema.ServerPublicNet + + ServerPublicNetIPv4FromSchema(schema.ServerPublicNetIPv4) ServerPublicNetIPv4 + + SchemaFromServerPublicNetIPv4(ServerPublicNetIPv4) schema.ServerPublicNetIPv4 + + // goverter:map . IP | ipFromServerPublicNetIPv6Schema + // goverter:map . Network | ipNetFromServerPublicNetIPv6Schema + ServerPublicNetIPv6FromSchema(schema.ServerPublicNetIPv6) ServerPublicNetIPv6 + + // goverter:map Network IP + SchemaFromServerPublicNetIPv6(ServerPublicNetIPv6) schema.ServerPublicNetIPv6 + + // goverter:map AliasIPs Aliases + ServerPrivateNetFromSchema(schema.ServerPrivateNet) ServerPrivateNet + + // goverter:map Aliases AliasIPs + SchemaFromServerPrivateNet(ServerPrivateNet) schema.ServerPrivateNet + + // goverter:map Prices Pricings + ServerTypeFromSchema(schema.ServerType) *ServerType + + // goverter:map Pricings Prices + // goverter:map DeprecatableResource.Deprecation Deprecated | isDeprecationNotNil + SchemaFromServerType(*ServerType) schema.ServerType + + ImageFromSchema(schema.Image) *Image + + SchemaFromImage(*Image) schema.Image + + // Needed because of how goverter works internally, see https://github.com/jmattheis/goverter/issues/114 + // goverter:map ImageSize | mapZeroFloat32ToNil + intSchemaFromImage(Image) schema.Image + + // goverter:ignore Currency + // goverter:ignore VATRate + PriceFromSchema(schema.Price) Price + + SSHKeyFromSchema(schema.SSHKey) *SSHKey + + SchemaFromSSHKey(*SSHKey) schema.SSHKey + + VolumeFromSchema(schema.Volume) *Volume + + SchemaFromVolume(*Volume) schema.Volume + + NetworkFromSchema(schema.Network) *Network + + SchemaFromNetwork(*Network) schema.Network + + NetworkSubnetFromSchema(schema.NetworkSubnet) NetworkSubnet + + SchemaFromNetworkSubnet(NetworkSubnet) schema.NetworkSubnet + + NetworkRouteFromSchema(schema.NetworkRoute) NetworkRoute + + SchemaFromNetworkRoute(NetworkRoute) schema.NetworkRoute + + LoadBalancerFromSchema(schema.LoadBalancer) *LoadBalancer + + // goverter:map OutgoingTraffic | mapZeroUint64ToNil + // goverter:map IngoingTraffic | mapZeroUint64ToNil + SchemaFromLoadBalancer(*LoadBalancer) schema.LoadBalancer + + // goverter:map Prices Pricings + LoadBalancerTypeFromSchema(schema.LoadBalancerType) *LoadBalancerType + + // goverter:map Pricings Prices + SchemaFromLoadBalancerType(*LoadBalancerType) schema.LoadBalancerType + + // goverter:map PriceHourly Hourly + // goverter:map PriceMonthly Monthly + LoadBalancerTypeLocationPricingFromSchema(schema.PricingLoadBalancerTypePrice) LoadBalancerTypeLocationPricing + + // goverter:map Hourly PriceHourly + // goverter:map Monthly PriceMonthly + SchemaFromLoadBalancerTypeLocationPricing(LoadBalancerTypeLocationPricing) schema.PricingLoadBalancerTypePrice + + LoadBalancerServiceFromSchema(schema.LoadBalancerService) LoadBalancerService + + SchemaFromLoadBalancerService(LoadBalancerService) schema.LoadBalancerService + + LoadBalancerServiceHealthCheckFromSchema(*schema.LoadBalancerServiceHealthCheck) LoadBalancerServiceHealthCheck + + SchemaFromLoadBalancerServiceHealthCheck(LoadBalancerServiceHealthCheck) *schema.LoadBalancerServiceHealthCheck + + LoadBalancerTargetFromSchema(schema.LoadBalancerTarget) LoadBalancerTarget + + SchemaFromLoadBalancerTarget(LoadBalancerTarget) schema.LoadBalancerTarget + + // goverter:map ID Server + LoadBalancerTargetServerFromSchema(schema.LoadBalancerTargetServer) LoadBalancerTargetServer + + // goverter:map Server ID + SchemaFromLoadBalancerServerTarget(LoadBalancerTargetServer) schema.LoadBalancerTargetServer + + LoadBalancerTargetHealthStatusFromSchema(schema.LoadBalancerTargetHealthStatus) LoadBalancerTargetHealthStatus + + SchemaFromLoadBalancerTargetHealthStatus(LoadBalancerTargetHealthStatus) schema.LoadBalancerTargetHealthStatus + + CertificateFromSchema(schema.Certificate) *Certificate + + SchemaFromCertificate(*Certificate) schema.Certificate + + PaginationFromSchema(schema.MetaPagination) Pagination + + SchemaFromPagination(Pagination) schema.MetaPagination + + // goverter:ignore response + // goverter:map Details | errorDetailsFromSchema + ErrorFromSchema(schema.Error) Error + + // goverter:map Details | schemaFromErrorDetails + // goverter:map Details DetailsRaw | rawSchemaFromErrorDetails + SchemaFromError(Error) schema.Error + + // goverter:map . Image | imagePricingFromSchema + // goverter:map . FloatingIP | floatingIPPricingFromSchema + // goverter:map . FloatingIPs | floatingIPTypePricingFromSchema + // goverter:map . PrimaryIPs | primaryIPPricingFromSchema + // goverter:map . Traffic | trafficPricingFromSchema + // goverter:map . ServerTypes | serverTypePricingFromSchema + // goverter:map . LoadBalancerTypes | loadBalancerTypePricingFromSchema + // goverter:map . Volume | volumePricingFromSchema + PricingFromSchema(schema.Pricing) Pricing + + // goverter:map PriceHourly Hourly + // goverter:map PriceMonthly Monthly + serverTypePricingFromSchema(schema.PricingServerTypePrice) ServerTypeLocationPricing + + // goverter:map Image.PerGBMonth.Currency Currency + // goverter:map Image.PerGBMonth.VATRate VATRate + SchemaFromPricing(Pricing) schema.Pricing + + // goverter:map PerGBMonth PricePerGBMonth + schemaFromImagePricing(ImagePricing) schema.PricingImage + + // goverter:map Monthly PriceMonthly + schemaFromFloatingIPPricing(FloatingIPPricing) schema.PricingFloatingIP + + // goverter:map Pricings Prices + schemaFromFloatingIPTypePricing(FloatingIPTypePricing) schema.PricingFloatingIPType + + // goverter:map Monthly PriceMonthly + schemaFromFloatingIPTypeLocationPricing(FloatingIPTypeLocationPricing) schema.PricingFloatingIPTypePrice + + // goverter:map Pricings Prices + schemaFromPrimaryIPPricing(PrimaryIPPricing) schema.PricingPrimaryIP + + // goverter:map Monthly PriceMonthly + // goverter:map Hourly PriceHourly + schemaFromPrimaryIPTypePricing(PrimaryIPTypePricing) schema.PricingPrimaryIPTypePrice + + // goverter:map PerTB PricePerTB + schemaFromTrafficPricing(TrafficPricing) schema.PricingTraffic + + // goverter:map Pricings Prices + // goverter:map ServerType.ID ID + // goverter:map ServerType.Name Name + schemaFromServerTypePricing(ServerTypePricing) schema.PricingServerType + + // goverter:map Pricings Prices + // goverter:map LoadBalancerType.ID ID + // goverter:map LoadBalancerType.Name Name + schemaFromLoadBalancerTypePricing(LoadBalancerTypePricing) schema.PricingLoadBalancerType + + // goverter:map PerGBMonthly PricePerGBPerMonth + schemaFromVolumePricing(VolumePricing) schema.PricingVolume + + // goverter:map Monthly PriceMonthly + // goverter:map Hourly PriceHourly + schemaFromServerTypeLocationPricing(ServerTypeLocationPricing) schema.PricingServerTypePrice + + FirewallFromSchema(schema.Firewall) *Firewall + + SchemaFromFirewall(*Firewall) schema.Firewall + + PlacementGroupFromSchema(schema.PlacementGroup) *PlacementGroup + + SchemaFromPlacementGroup(*PlacementGroup) schema.PlacementGroup + + SchemaFromPlacementGroupCreateOpts(PlacementGroupCreateOpts) schema.PlacementGroupCreateRequest + + SchemaFromLoadBalancerCreateOpts(LoadBalancerCreateOpts) schema.LoadBalancerCreateRequest + + // goverter:map Server.ID ID + SchemaFromLoadBalancerCreateOptsTargetServer(LoadBalancerCreateOptsTargetServer) schema.LoadBalancerCreateRequestTargetServer + + SchemaFromLoadBalancerAddServiceOpts(LoadBalancerAddServiceOpts) schema.LoadBalancerActionAddServiceRequest + + // goverter:ignore ListenPort + SchemaFromLoadBalancerUpdateServiceOpts(LoadBalancerUpdateServiceOpts) schema.LoadBalancerActionUpdateServiceRequest + + SchemaFromFirewallCreateOpts(FirewallCreateOpts) schema.FirewallCreateRequest + + SchemaFromFirewallSetRulesOpts(FirewallSetRulesOpts) schema.FirewallActionSetRulesRequest + + SchemaFromFirewallResource(FirewallResource) schema.FirewallResource + + // goverter:autoMap Metrics + ServerMetricsFromSchema(*schema.ServerGetMetricsResponse) (*ServerMetrics, error) + + // goverter:autoMap Metrics + LoadBalancerMetricsFromSchema(*schema.LoadBalancerGetMetricsResponse) (*LoadBalancerMetrics, error) + + DeprecationFromSchema(*schema.DeprecationInfo) *DeprecationInfo + + SchemaFromDeprecation(*DeprecationInfo) *schema.DeprecationInfo +} + +func schemaActionErrorFromAction(a Action) *schema.ActionError { + if a.ErrorCode != "" && a.ErrorMessage != "" { + return &schema.ActionError{ + Code: a.ErrorCode, + Message: a.ErrorMessage, + } + } + return nil +} + +func ipFromFloatingIPSchema(s schema.FloatingIP) net.IP { + if s.Type == string(FloatingIPTypeIPv4) { + return net.ParseIP(s.IP) + } + ip, _, _ := net.ParseCIDR(s.IP) + return ip +} + +func networkFromFloatingIPSchema(s schema.FloatingIP) *net.IPNet { + if s.Type == string(FloatingIPTypeIPv4) { + return nil + } + _, n, _ := net.ParseCIDR(s.IP) + return n +} + +func ipFromPrimaryIPSchema(s schema.PrimaryIP) net.IP { + if s.Type == string(FloatingIPTypeIPv4) { + return net.ParseIP(s.IP) + } + ip, _, _ := net.ParseCIDR(s.IP) + return ip +} + +func networkFromPrimaryIPSchema(s schema.PrimaryIP) *net.IPNet { + if s.Type == string(FloatingIPTypeIPv4) { + return nil + } + _, n, _ := net.ParseCIDR(s.IP) + return n +} + +func serverFromInt64(id int64) Server { + return Server{ID: id} +} + +func int64FromServer(s Server) int64 { + return s.ID +} + +func networkFromInt64(id int64) Network { + return Network{ID: id} +} + +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} +} + +func int64FromVolume(volume *Volume) int64 { + if volume == nil { + return 0 + } + return volume.ID +} + +func serverTypeFromInt64(id int64) *ServerType { + return &ServerType{ID: id} +} + +func int64FromServerType(s *ServerType) int64 { + if s == nil { + return 0 + } + return s.ID +} + +func certificateFromInt64(id int64) *Certificate { + return &Certificate{ID: id} +} + +func int64FromCertificate(c *Certificate) int64 { + if c == nil { + return 0 + } + return c.ID +} + +func locationFromString(s string) Location { + return Location{Name: s} +} + +func stringFromLocation(l Location) string { + return l.Name +} + +func mapFromFloatingIPDNSPtrSchema(dnsPtr []schema.FloatingIPDNSPtr) map[string]string { + m := make(map[string]string, len(dnsPtr)) + for _, entry := range dnsPtr { + m[entry.IP] = entry.DNSPtr + } + return m +} + +func floatingIPDNSPtrSchemaFromMap(m map[string]string) []schema.FloatingIPDNSPtr { + dnsPtr := make([]schema.FloatingIPDNSPtr, 0, len(m)) + for ip, ptr := range m { + dnsPtr = append(dnsPtr, schema.FloatingIPDNSPtr{ + IP: ip, + DNSPtr: ptr, + }) + } + return dnsPtr +} + +func mapFromPrimaryIPDNSPtrSchema(dnsPtr []schema.PrimaryIPDNSPTR) map[string]string { + m := make(map[string]string, len(dnsPtr)) + for _, entry := range dnsPtr { + m[entry.IP] = entry.DNSPtr + } + return m +} + +func primaryIPDNSPtrSchemaFromMap(m map[string]string) []schema.PrimaryIPDNSPTR { + dnsPtr := make([]schema.PrimaryIPDNSPTR, 0, len(m)) + for ip, ptr := range m { + dnsPtr = append(dnsPtr, schema.PrimaryIPDNSPTR{ + IP: ip, + DNSPtr: ptr, + }) + } + return dnsPtr +} + +func mapFromServerPublicNetIPv6DNSPtrSchema(dnsPtr []schema.ServerPublicNetIPv6DNSPtr) map[string]string { + m := make(map[string]string, len(dnsPtr)) + for _, entry := range dnsPtr { + m[entry.IP] = entry.DNSPtr + } + return m +} + +func serverPublicNetIPv6DNSPtrSchemaFromMap(m map[string]string) []schema.ServerPublicNetIPv6DNSPtr { + dnsPtr := make([]schema.ServerPublicNetIPv6DNSPtr, 0, len(m)) + for ip, ptr := range m { + dnsPtr = append(dnsPtr, schema.ServerPublicNetIPv6DNSPtr{ + IP: ip, + DNSPtr: ptr, + }) + } + return dnsPtr +} + +func floatingIPToIPString(ip FloatingIP) string { + if ip.Type == FloatingIPTypeIPv4 { + return ip.IP.String() + } + return ip.Network.String() +} + +func primaryIPToIPString(ip PrimaryIP) string { + if ip.Type == PrimaryIPTypeIPv4 { + return ip.IP.String() + } + return ip.Network.String() +} + +func floatingIPFromInt64(id int64) *FloatingIP { + return &FloatingIP{ID: id} +} + +func int64FromFloatingIP(f *FloatingIP) int64 { + if f == nil { + return 0 + } + return f.ID +} + +func firewallStatusFromSchemaServerFirewall(fw schema.ServerFirewall) *ServerFirewallStatus { + return &ServerFirewallStatus{ + Firewall: Firewall{ID: fw.ID}, + Status: FirewallStatus(fw.Status), + } +} + +func serverFirewallSchemaFromFirewallStatus(s *ServerFirewallStatus) schema.ServerFirewall { + return schema.ServerFirewall{ + ID: s.Firewall.ID, + Status: string(s.Status), + } +} + +func ipFromServerPublicNetIPv6Schema(s schema.ServerPublicNetIPv6) net.IP { + ip, _, _ := net.ParseCIDR(s.IP) + return ip +} + +func ipNetFromServerPublicNetIPv6Schema(s schema.ServerPublicNetIPv6) *net.IPNet { + _, n, _ := net.ParseCIDR(s.IP) + return n +} + +func serverFromImageCreatedFromSchema(s schema.ImageCreatedFrom) Server { + return Server{ + ID: s.ID, + Name: s.Name, + } +} + +func ipFromString(s string) net.IP { + return net.ParseIP(s) +} + +func stringFromIP(ip net.IP) string { + if ip == nil { + return "" + } + return ip.String() +} + +func ipNetFromString(s string) net.IPNet { + _, n, _ := net.ParseCIDR(s) + if n == nil { + return net.IPNet{} + } + return *n +} + +func stringFromIPNet(ip net.IPNet) string { + return ip.String() +} + +func timeToTimePtr(t time.Time) *time.Time { + // Some hcloud structs don't use pointers for nullable times, so the zero value + // should be treated as nil. + if t == (time.Time{}) { + return nil + } + return &t +} + +func durationFromIntSeconds(s int) time.Duration { + return time.Duration(s) * time.Second +} + +func intSecondsFromDuration(d time.Duration) int { + return int(d.Seconds()) +} + +func errorDetailsFromSchema(d interface{}) interface{} { + if d, ok := d.(schema.ErrorDetailsInvalidInput); ok { + details := ErrorDetailsInvalidInput{ + Fields: make([]ErrorDetailsInvalidInputField, len(d.Fields)), + } + for i, field := range d.Fields { + details.Fields[i] = ErrorDetailsInvalidInputField{ + Name: field.Name, + Messages: field.Messages, + } + } + return details + } + return nil +} + +func schemaFromErrorDetails(d interface{}) interface{} { + if d, ok := d.(ErrorDetailsInvalidInput); ok { + details := schema.ErrorDetailsInvalidInput{ + Fields: make([]struct { + Name string `json:"name"` + Messages []string `json:"messages"` + }, len(d.Fields)), + } + for i, field := range d.Fields { + details.Fields[i] = struct { + Name string `json:"name"` + Messages []string `json:"messages"` + }{Name: field.Name, Messages: field.Messages} + } + return details + } + return nil +} + +func imagePricingFromSchema(s schema.Pricing) ImagePricing { + return ImagePricing{ + PerGBMonth: Price{ + Net: s.Image.PricePerGBMonth.Net, + Gross: s.Image.PricePerGBMonth.Gross, + Currency: s.Currency, + VATRate: s.VATRate, + }, + } +} + +func floatingIPPricingFromSchema(s schema.Pricing) FloatingIPPricing { + return FloatingIPPricing{ + Monthly: Price{ + Net: s.FloatingIP.PriceMonthly.Net, + Gross: s.FloatingIP.PriceMonthly.Gross, + Currency: s.Currency, + VATRate: s.VATRate, + }, + } +} + +func floatingIPTypePricingFromSchema(s schema.Pricing) []FloatingIPTypePricing { + p := make([]FloatingIPTypePricing, len(s.FloatingIPs)) + for i, floatingIPType := range s.FloatingIPs { + var pricings = make([]FloatingIPTypeLocationPricing, len(floatingIPType.Prices)) + for i, price := range floatingIPType.Prices { + pricings[i] = FloatingIPTypeLocationPricing{ + Location: &Location{Name: price.Location}, + Monthly: Price{ + Currency: s.Currency, + VATRate: s.VATRate, + Net: price.PriceMonthly.Net, + Gross: price.PriceMonthly.Gross, + }, + } + } + p[i] = FloatingIPTypePricing{Type: FloatingIPType(floatingIPType.Type), Pricings: pricings} + } + return p +} + +func primaryIPPricingFromSchema(s schema.Pricing) []PrimaryIPPricing { + p := make([]PrimaryIPPricing, len(s.FloatingIPs)) + for i, primaryIPType := range s.PrimaryIPs { + var pricings = make([]PrimaryIPTypePricing, len(primaryIPType.Prices)) + for i, price := range primaryIPType.Prices { + pricings[i] = PrimaryIPTypePricing{ + Location: price.Location, + Monthly: PrimaryIPPrice{ + Net: price.PriceMonthly.Net, + Gross: price.PriceMonthly.Gross, + }, + Hourly: PrimaryIPPrice{ + Net: price.PriceHourly.Net, + Gross: price.PriceHourly.Gross, + }, + } + } + p[i] = PrimaryIPPricing{Type: primaryIPType.Type, Pricings: pricings} + } + return p +} + +func trafficPricingFromSchema(s schema.Pricing) TrafficPricing { + return TrafficPricing{ + PerTB: Price{ + Net: s.Traffic.PricePerTB.Net, + Gross: s.Traffic.PricePerTB.Gross, + Currency: s.Currency, + VATRate: s.VATRate, + }, + } +} + +func serverTypePricingFromSchema(s schema.Pricing) []ServerTypePricing { + p := make([]ServerTypePricing, len(s.ServerTypes)) + for i, serverType := range s.ServerTypes { + var pricings = make([]ServerTypeLocationPricing, len(serverType.Prices)) + for i, price := range serverType.Prices { + pricings[i] = ServerTypeLocationPricing{ + Location: &Location{Name: price.Location}, + Hourly: Price{ + Currency: s.Currency, + VATRate: s.VATRate, + Net: price.PriceHourly.Net, + Gross: price.PriceHourly.Gross, + }, + Monthly: Price{ + Currency: s.Currency, + VATRate: s.VATRate, + Net: price.PriceMonthly.Net, + Gross: price.PriceMonthly.Gross, + }, + } + } + p[i] = ServerTypePricing{ + ServerType: &ServerType{ + ID: serverType.ID, + Name: serverType.Name, + }, + Pricings: pricings, + } + } + return p +} + +func loadBalancerTypePricingFromSchema(s schema.Pricing) []LoadBalancerTypePricing { + p := make([]LoadBalancerTypePricing, len(s.LoadBalancerTypes)) + for i, loadBalancerType := range s.LoadBalancerTypes { + var pricings = make([]LoadBalancerTypeLocationPricing, len(loadBalancerType.Prices)) + for i, price := range loadBalancerType.Prices { + pricings[i] = LoadBalancerTypeLocationPricing{ + Location: &Location{Name: price.Location}, + Hourly: Price{ + Currency: s.Currency, + VATRate: s.VATRate, + Net: price.PriceHourly.Net, + Gross: price.PriceHourly.Gross, + }, + Monthly: Price{ + Currency: s.Currency, + VATRate: s.VATRate, + Net: price.PriceMonthly.Net, + Gross: price.PriceMonthly.Gross, + }, + } + } + p[i] = LoadBalancerTypePricing{ + LoadBalancerType: &LoadBalancerType{ + ID: loadBalancerType.ID, + Name: loadBalancerType.Name, + }, + Pricings: pricings, + } + } + return p +} + +func volumePricingFromSchema(s schema.Pricing) VolumePricing { + return VolumePricing{ + PerGBMonthly: Price{ + Net: s.Volume.PricePerGBPerMonth.Net, + Gross: s.Volume.PricePerGBPerMonth.Gross, + Currency: s.Currency, + VATRate: s.VATRate, + }, + } +} + +func anyFromLoadBalancerType(t *LoadBalancerType) interface{} { + if t == nil { + return nil + } + if t.ID != 0 { + return t.ID + } + return t.Name +} + +func serverMetricsTimeSeriesFromSchema(s schema.ServerTimeSeriesVals) ([]ServerMetricsValue, error) { + vals := make([]ServerMetricsValue, len(s.Values)) + + for i, rawVal := range s.Values { + var val ServerMetricsValue + + tup, ok := rawVal.([]interface{}) + if !ok { + return nil, fmt.Errorf("failed to convert value to tuple: %v", rawVal) + } + if len(tup) != 2 { + return nil, fmt.Errorf("invalid tuple size: %d: %v", len(tup), rawVal) + } + ts, ok := tup[0].(float64) + if !ok { + return nil, fmt.Errorf("convert to float64: %v", tup[0]) + } + val.Timestamp = ts + + v, ok := tup[1].(string) + if !ok { + return nil, fmt.Errorf("not a string: %v", tup[1]) + } + val.Value = v + vals[i] = val + } + + return vals, nil +} + +func loadBalancerMetricsTimeSeriesFromSchema(s schema.LoadBalancerTimeSeriesVals) ([]LoadBalancerMetricsValue, error) { + vals := make([]LoadBalancerMetricsValue, len(s.Values)) + + for i, rawVal := range s.Values { + var val LoadBalancerMetricsValue + + tup, ok := rawVal.([]interface{}) + if !ok { + return nil, fmt.Errorf("failed to convert value to tuple: %v", rawVal) + } + if len(tup) != 2 { + return nil, fmt.Errorf("invalid tuple size: %d: %v", len(tup), rawVal) + } + ts, ok := tup[0].(float64) + if !ok { + return nil, fmt.Errorf("convert to float64: %v", tup[0]) + } + val.Timestamp = ts + + v, ok := tup[1].(string) + if !ok { + return nil, fmt.Errorf("not a string: %v", tup[1]) + } + val.Value = v + vals[i] = val + } + + return vals, nil +} + +func mapEmptyStringToNil(s string) *string { + if s == "" { + return nil + } + return &s +} + +func stringPtrFromLoadBalancerServiceProtocol(p LoadBalancerServiceProtocol) *string { + return mapEmptyStringToNil(string(p)) +} + +func stringPtrFromNetworkZone(z NetworkZone) *string { + return mapEmptyStringToNil(string(z)) +} + +func mapZeroInt64ToNil(i int64) *int64 { + if i == 0 { + return nil + } + return &i +} + +func mapZeroUint64ToNil(i uint64) *uint64 { + if i == 0 { + return nil + } + return &i +} + +func schemaFromLoadBalancerCreateOptsTargetLabelSelector(l LoadBalancerCreateOptsTargetLabelSelector) *schema.LoadBalancerCreateRequestTargetLabelSelector { + if l.Selector == "" { + return nil + } + return &schema.LoadBalancerCreateRequestTargetLabelSelector{Selector: l.Selector} +} + +func schemaFromLoadBalancerCreateOptsTargetIP(l LoadBalancerCreateOptsTargetIP) *schema.LoadBalancerCreateRequestTargetIP { + if l.IP == "" { + return nil + } + return &schema.LoadBalancerCreateRequestTargetIP{IP: l.IP} +} + +func schemaFromLoadBalancerCreateOptsTargetServer(l LoadBalancerCreateOptsTargetServer) *schema.LoadBalancerCreateRequestTargetServer { + if l.Server == nil { + return nil + } + return &schema.LoadBalancerCreateRequestTargetServer{ID: l.Server.ID} +} + +func stringMapToStringMapPtr(m map[string]string) *map[string]string { + if m == nil { + return nil + } + return &m +} + +func rawSchemaFromErrorDetails(v interface{}) json.RawMessage { + d := schemaFromErrorDetails(v) + if v == nil { + return nil + } + msg, _ := json.Marshal(d) + return msg +} + +func mapZeroFloat32ToNil(f float32) *float32 { + if f == 0 { + return nil + } + return &f +} + +func isDeprecationNotNil(d *DeprecationInfo) bool { + return d != nil +} + +// int64SlicePtrFromCertificatePtrSlice is needed so that a nil slice is mapped to nil instead of &nil. +func int64SlicePtrFromCertificatePtrSlice(s []*Certificate) *[]int64 { + if s == nil { + return nil + } + var ids = make([]int64, len(s)) + for i, cert := range s { + ids[i] = cert.ID + } + return &ids +} + +func stringSlicePtrFromStringSlice(s []string) *[]string { + if s == nil { + return nil + } + return &s +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/server.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/server.go index ff6e23444a33..8898456281ec 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/server.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/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. @@ -146,6 +147,7 @@ type ServerRescueType string // List of rescue types. const ( + // Deprecated: Use ServerRescueTypeLinux64 instead. ServerRescueTypeLinux32 ServerRescueType = "linux32" ServerRescueTypeLinux64 ServerRescueType = "linux64" ) diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/volume.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/volume.go index 754c89efb972..225a23a52033 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/volume.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/volume.go @@ -21,12 +21,18 @@ type Volume struct { Server *Server Location *Location Size int + Format *string Protection VolumeProtection Labels map[string]string LinuxDevice string Created time.Time } +const ( + VolumeFormatExt4 = "ext4" + VolumeFormatXFS = "xfs" +) + // VolumeProtection represents the protection level of a volume. type VolumeProtection struct { Delete bool diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_action_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_action_client_iface.go new file mode 100644 index 000000000000..13f8665dfd22 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_action_client_iface.go @@ -0,0 +1,79 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// IActionClient ... +type IActionClient interface { + // GetByID retrieves an action by its ID. If the action does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*Action, *Response, error) + // List returns a list of actions for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts ActionListOpts) ([]*Action, *Response, error) + // All returns all actions. + All(ctx context.Context) ([]*Action, error) + // AllWithOpts returns all actions for the given options. + AllWithOpts(ctx context.Context, opts ActionListOpts) ([]*Action, error) + // WatchOverallProgress watches several actions' progress until they complete + // with success or error. This watching happens in a goroutine and updates are + // provided through the two returned channels: + // + // - The first channel receives percentage updates of the progress, based on + // the number of completed versus total watched actions. The return value + // is an int between 0 and 100. + // - The second channel returned receives errors for actions that did not + // complete successfully, as well as any errors that happened while + // querying the API. + // + // By default, the method keeps watching until all actions have finished + // processing. If you want to be able to cancel the method or configure a + // timeout, use the [context.Context]. Once the method has stopped watching, + // both returned channels are closed. + // + // WatchOverallProgress uses the [WithPollBackoffFunc] of the [Client] to wait + // until sending the next request. + // + // Deprecated: WatchOverallProgress is deprecated, use [WaitForFunc] instead. + WatchOverallProgress(ctx context.Context, actions []*Action) (<-chan int, <-chan error) + // WatchProgress watches one action's progress until it completes with success + // or error. This watching happens in a goroutine and updates are provided + // through the two returned channels: + // + // - The first channel receives percentage updates of the progress, based on + // the progress percentage indicated by the API. The return value is an int + // between 0 and 100. + // - The second channel receives any errors that happened while querying the + // API, as well as the error of the action if it did not complete + // successfully, or nil if it did. + // + // By default, the method keeps watching until the action has finished + // processing. If you want to be able to cancel the method or configure a + // timeout, use the [context.Context]. Once the method has stopped watching, + // both returned channels are closed. + // + // WatchProgress uses the [WithPollBackoffFunc] of the [Client] to wait until + // sending the next request. + // + // Deprecated: WatchProgress is deprecated, use [WaitForFunc] instead. + WatchProgress(ctx context.Context, action *Action) (<-chan int, <-chan error) + // WaitForFunc waits until all actions are completed by polling the API at the interval + // defined by [WithPollBackoffFunc]. An action is considered as complete when its status is + // either [ActionStatusSuccess] or [ActionStatusError]. + // + // The handleUpdate callback is called every time an action is updated. + WaitForFunc(ctx context.Context, handleUpdate func(update *Action) error, actions ...*Action) error + // WaitFor waits until all actions succeed by polling the API at the interval defined by + // [WithPollBackoffFunc]. An action is considered as succeeded when its status is either + // [ActionStatusSuccess]. + // + // If a single action fails, the function will stop waiting and the error set in the + // action will be returned as an [ActionError]. + // + // For more flexibility, see the [ActionClient.WaitForFunc] function. + WaitFor(ctx context.Context, actions ...*Action) error +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_certificate_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_certificate_client_iface.go new file mode 100644 index 000000000000..94583925ff56 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_certificate_client_iface.go @@ -0,0 +1,40 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// ICertificateClient ... +type ICertificateClient interface { + // GetByID retrieves a Certificate by its ID. If the Certificate does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*Certificate, *Response, error) + // GetByName retrieves a Certificate by its name. If the Certificate does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*Certificate, *Response, error) + // Get retrieves a Certificate by its ID if the input can be parsed as an integer, otherwise it + // retrieves a Certificate by its name. If the Certificate does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*Certificate, *Response, error) + // List returns a list of Certificates for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts CertificateListOpts) ([]*Certificate, *Response, error) + // All returns all Certificates. + All(ctx context.Context) ([]*Certificate, error) + // AllWithOpts returns all Certificates for the given options. + AllWithOpts(ctx context.Context, opts CertificateListOpts) ([]*Certificate, error) + // Create creates a new uploaded certificate. + // + // Create returns an error for certificates of any other type. Use + // CreateCertificate to create such certificates. + Create(ctx context.Context, opts CertificateCreateOpts) (*Certificate, *Response, error) + // CreateCertificate creates a new certificate of any type. + CreateCertificate(ctx context.Context, opts CertificateCreateOpts) (CertificateCreateResult, *Response, error) + // Update updates a Certificate. + Update(ctx context.Context, certificate *Certificate, opts CertificateUpdateOpts) (*Certificate, *Response, error) + // Delete deletes a certificate. + Delete(ctx context.Context, certificate *Certificate) (*Response, error) + // RetryIssuance retries the issuance of a failed managed certificate. + RetryIssuance(ctx context.Context, certificate *Certificate) (*Action, *Response, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_datacenter_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_datacenter_client_iface.go new file mode 100644 index 000000000000..f93767567835 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_datacenter_client_iface.go @@ -0,0 +1,27 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// IDatacenterClient ... +type IDatacenterClient interface { + // GetByID retrieves a datacenter by its ID. If the datacenter does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*Datacenter, *Response, error) + // GetByName retrieves a datacenter by its name. If the datacenter does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*Datacenter, *Response, error) + // Get retrieves a datacenter by its ID if the input can be parsed as an integer, otherwise it + // retrieves a datacenter by its name. If the datacenter does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*Datacenter, *Response, error) + // List returns a list of datacenters for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts DatacenterListOpts) ([]*Datacenter, *Response, error) + // All returns all datacenters. + All(ctx context.Context) ([]*Datacenter, error) + // AllWithOpts returns all datacenters for the given options. + AllWithOpts(ctx context.Context, opts DatacenterListOpts) ([]*Datacenter, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_firewall_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_firewall_client_iface.go new file mode 100644 index 000000000000..ce6481158b51 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_firewall_client_iface.go @@ -0,0 +1,37 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// IFirewallClient ... +type IFirewallClient interface { + // GetByID retrieves a Firewall by its ID. If the Firewall does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*Firewall, *Response, error) + // GetByName retrieves a Firewall by its name. If the Firewall does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*Firewall, *Response, error) + // Get retrieves a Firewall by its ID if the input can be parsed as an integer, otherwise it + // retrieves a Firewall by its name. If the Firewall does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*Firewall, *Response, error) + // List returns a list of Firewalls for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts FirewallListOpts) ([]*Firewall, *Response, error) + // All returns all Firewalls. + All(ctx context.Context) ([]*Firewall, error) + // AllWithOpts returns all Firewalls for the given options. + AllWithOpts(ctx context.Context, opts FirewallListOpts) ([]*Firewall, error) + // Create creates a new Firewall. + Create(ctx context.Context, opts FirewallCreateOpts) (FirewallCreateResult, *Response, error) + // Update updates a Firewall. + Update(ctx context.Context, firewall *Firewall, opts FirewallUpdateOpts) (*Firewall, *Response, error) + // Delete deletes a Firewall. + Delete(ctx context.Context, firewall *Firewall) (*Response, error) + // SetRules sets the rules of a Firewall. + SetRules(ctx context.Context, firewall *Firewall, opts FirewallSetRulesOpts) ([]*Action, *Response, error) + ApplyResources(ctx context.Context, firewall *Firewall, resources []FirewallResource) ([]*Action, *Response, error) + RemoveResources(ctx context.Context, firewall *Firewall, resources []FirewallResource) ([]*Action, *Response, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_floating_ip_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_floating_ip_client_iface.go new file mode 100644 index 000000000000..4d71be269068 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_floating_ip_client_iface.go @@ -0,0 +1,43 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// IFloatingIPClient ... +type IFloatingIPClient interface { + // GetByID retrieves a Floating IP by its ID. If the Floating IP does not exist, + // nil is returned. + GetByID(ctx context.Context, id int64) (*FloatingIP, *Response, error) + // GetByName retrieves a Floating IP by its name. If the Floating IP does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*FloatingIP, *Response, error) + // Get retrieves a Floating IP by its ID if the input can be parsed as an integer, otherwise it + // retrieves a Floating IP by its name. If the Floating IP does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*FloatingIP, *Response, error) + // List returns a list of Floating IPs for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts FloatingIPListOpts) ([]*FloatingIP, *Response, error) + // All returns all Floating IPs. + All(ctx context.Context) ([]*FloatingIP, error) + // AllWithOpts returns all Floating IPs for the given options. + AllWithOpts(ctx context.Context, opts FloatingIPListOpts) ([]*FloatingIP, error) + // Create creates a Floating IP. + Create(ctx context.Context, opts FloatingIPCreateOpts) (FloatingIPCreateResult, *Response, error) + // Delete deletes a Floating IP. + Delete(ctx context.Context, floatingIP *FloatingIP) (*Response, error) + // Update updates a Floating IP. + Update(ctx context.Context, floatingIP *FloatingIP, opts FloatingIPUpdateOpts) (*FloatingIP, *Response, error) + // Assign assigns a Floating IP to a server. + Assign(ctx context.Context, floatingIP *FloatingIP, server *Server) (*Action, *Response, error) + // Unassign unassigns a Floating IP from the currently assigned server. + Unassign(ctx context.Context, floatingIP *FloatingIP) (*Action, *Response, error) + // ChangeDNSPtr changes or resets the reverse DNS pointer for a Floating IP address. + // Pass a nil ptr to reset the reverse DNS pointer to its default value. + ChangeDNSPtr(ctx context.Context, floatingIP *FloatingIP, ip string, ptr *string) (*Action, *Response, error) + // ChangeProtection changes the resource protection level of a Floating IP. + ChangeProtection(ctx context.Context, floatingIP *FloatingIP, opts FloatingIPChangeProtectionOpts) (*Action, *Response, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_image_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_image_client_iface.go new file mode 100644 index 000000000000..17fbcd929a01 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_image_client_iface.go @@ -0,0 +1,48 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// IImageClient ... +type IImageClient interface { + // GetByID retrieves an image by its ID. If the image does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*Image, *Response, error) + // GetByName retrieves an image by its name. If the image does not exist, nil is returned. + // + // Deprecated: Use [ImageClient.GetByNameAndArchitecture] instead. + GetByName(ctx context.Context, name string) (*Image, *Response, error) + // GetByNameAndArchitecture retrieves an image by its name and architecture. If the image does not exist, + // nil is returned. + // In contrast to [ImageClient.Get], this method also returns deprecated images. Depending on your needs you should + // check for this in your calling method. + GetByNameAndArchitecture(ctx context.Context, name string, architecture Architecture) (*Image, *Response, error) + // Get retrieves an image by its ID if the input can be parsed as an integer, otherwise it + // retrieves an image by its name. If the image does not exist, nil is returned. + // + // Deprecated: Use [ImageClient.GetForArchitecture] instead. + Get(ctx context.Context, idOrName string) (*Image, *Response, error) + // GetForArchitecture retrieves an image by its ID if the input can be parsed as an integer, otherwise it + // retrieves an image by its name and architecture. If the image does not exist, nil is returned. + // + // In contrast to [ImageClient.Get], this method also returns deprecated images. Depending on your needs you should + // check for this in your calling method. + GetForArchitecture(ctx context.Context, idOrName string, architecture Architecture) (*Image, *Response, error) + // List returns a list of images for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts ImageListOpts) ([]*Image, *Response, error) + // All returns all images. + All(ctx context.Context) ([]*Image, error) + // AllWithOpts returns all images for the given options. + AllWithOpts(ctx context.Context, opts ImageListOpts) ([]*Image, error) + // Delete deletes an image. + Delete(ctx context.Context, image *Image) (*Response, error) + // Update updates an image. + Update(ctx context.Context, image *Image, opts ImageUpdateOpts) (*Image, *Response, error) + // ChangeProtection changes the resource protection level of an image. + ChangeProtection(ctx context.Context, image *Image, opts ImageChangeProtectionOpts) (*Action, *Response, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_iso_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_iso_client_iface.go new file mode 100644 index 000000000000..aff450edffdb --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_iso_client_iface.go @@ -0,0 +1,26 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// IISOClient ... +type IISOClient interface { + // GetByID retrieves an ISO by its ID. + GetByID(ctx context.Context, id int64) (*ISO, *Response, error) + // GetByName retrieves an ISO by its name. + GetByName(ctx context.Context, name string) (*ISO, *Response, error) + // Get retrieves an ISO by its ID if the input can be parsed as an integer, otherwise it retrieves an ISO by its name. + Get(ctx context.Context, idOrName string) (*ISO, *Response, error) + // List returns a list of ISOs for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts ISOListOpts) ([]*ISO, *Response, error) + // All returns all ISOs. + All(ctx context.Context) ([]*ISO, error) + // AllWithOpts returns all ISOs for the given options. + AllWithOpts(ctx context.Context, opts ISOListOpts) ([]*ISO, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_load_balancer_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_load_balancer_client_iface.go new file mode 100644 index 000000000000..2665f22b02d0 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_load_balancer_client_iface.go @@ -0,0 +1,71 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" + "net" +) + +// ILoadBalancerClient ... +type ILoadBalancerClient interface { + // GetByID retrieves a Load Balancer by its ID. If the Load Balancer does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*LoadBalancer, *Response, error) + // GetByName retrieves a Load Balancer by its name. If the Load Balancer does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*LoadBalancer, *Response, error) + // Get retrieves a Load Balancer by its ID if the input can be parsed as an integer, otherwise it + // retrieves a Load Balancer by its name. If the Load Balancer does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*LoadBalancer, *Response, error) + // List returns a list of Load Balancers for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts LoadBalancerListOpts) ([]*LoadBalancer, *Response, error) + // All returns all Load Balancers. + All(ctx context.Context) ([]*LoadBalancer, error) + // AllWithOpts returns all Load Balancers for the given options. + AllWithOpts(ctx context.Context, opts LoadBalancerListOpts) ([]*LoadBalancer, error) + // Update updates a Load Balancer. + Update(ctx context.Context, loadBalancer *LoadBalancer, opts LoadBalancerUpdateOpts) (*LoadBalancer, *Response, error) + // Create creates a new Load Balancer. + Create(ctx context.Context, opts LoadBalancerCreateOpts) (LoadBalancerCreateResult, *Response, error) + // Delete deletes a Load Balancer. + Delete(ctx context.Context, loadBalancer *LoadBalancer) (*Response, error) + // AddServerTarget adds a server target to a Load Balancer. + AddServerTarget(ctx context.Context, loadBalancer *LoadBalancer, opts LoadBalancerAddServerTargetOpts) (*Action, *Response, error) + // RemoveServerTarget removes a server target from a Load Balancer. + RemoveServerTarget(ctx context.Context, loadBalancer *LoadBalancer, server *Server) (*Action, *Response, error) + // AddLabelSelectorTarget adds a label selector target to a Load Balancer. + AddLabelSelectorTarget(ctx context.Context, loadBalancer *LoadBalancer, opts LoadBalancerAddLabelSelectorTargetOpts) (*Action, *Response, error) + // RemoveLabelSelectorTarget removes a label selector target from a Load Balancer. + RemoveLabelSelectorTarget(ctx context.Context, loadBalancer *LoadBalancer, labelSelector string) (*Action, *Response, error) + // AddIPTarget adds an IP target to a Load Balancer. + AddIPTarget(ctx context.Context, loadBalancer *LoadBalancer, opts LoadBalancerAddIPTargetOpts) (*Action, *Response, error) + // RemoveIPTarget removes an IP target from a Load Balancer. + RemoveIPTarget(ctx context.Context, loadBalancer *LoadBalancer, ip net.IP) (*Action, *Response, error) + // AddService adds a service to a Load Balancer. + AddService(ctx context.Context, loadBalancer *LoadBalancer, opts LoadBalancerAddServiceOpts) (*Action, *Response, error) + // UpdateService updates a Load Balancer service. + UpdateService(ctx context.Context, loadBalancer *LoadBalancer, listenPort int, opts LoadBalancerUpdateServiceOpts) (*Action, *Response, error) + // DeleteService deletes a Load Balancer service. + DeleteService(ctx context.Context, loadBalancer *LoadBalancer, listenPort int) (*Action, *Response, error) + // ChangeProtection changes the resource protection level of a Load Balancer. + ChangeProtection(ctx context.Context, loadBalancer *LoadBalancer, opts LoadBalancerChangeProtectionOpts) (*Action, *Response, error) + // ChangeAlgorithm changes the algorithm of a Load Balancer. + ChangeAlgorithm(ctx context.Context, loadBalancer *LoadBalancer, opts LoadBalancerChangeAlgorithmOpts) (*Action, *Response, error) + // AttachToNetwork attaches a Load Balancer to a network. + AttachToNetwork(ctx context.Context, loadBalancer *LoadBalancer, opts LoadBalancerAttachToNetworkOpts) (*Action, *Response, error) + // DetachFromNetwork detaches a Load Balancer from a network. + DetachFromNetwork(ctx context.Context, loadBalancer *LoadBalancer, opts LoadBalancerDetachFromNetworkOpts) (*Action, *Response, error) + // EnablePublicInterface enables the Load Balancer's public network interface. + EnablePublicInterface(ctx context.Context, loadBalancer *LoadBalancer) (*Action, *Response, error) + // DisablePublicInterface disables the Load Balancer's public network interface. + DisablePublicInterface(ctx context.Context, loadBalancer *LoadBalancer) (*Action, *Response, error) + // ChangeType changes a Load Balancer's type. + ChangeType(ctx context.Context, loadBalancer *LoadBalancer, opts LoadBalancerChangeTypeOpts) (*Action, *Response, error) + // GetMetrics obtains metrics for a Load Balancer. + GetMetrics(ctx context.Context, lb *LoadBalancer, opts LoadBalancerGetMetricsOpts) (*LoadBalancerMetrics, *Response, error) + // ChangeDNSPtr changes or resets the reverse DNS pointer for a Load Balancer. + // Pass a nil ptr to reset the reverse DNS pointer to its default value. + ChangeDNSPtr(ctx context.Context, lb *LoadBalancer, ip string, ptr *string) (*Action, *Response, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_load_balancer_type_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_load_balancer_type_client_iface.go new file mode 100644 index 000000000000..fd3289d4df2e --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_load_balancer_type_client_iface.go @@ -0,0 +1,27 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// ILoadBalancerTypeClient ... +type ILoadBalancerTypeClient interface { + // GetByID retrieves a Load Balancer type by its ID. If the Load Balancer type does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*LoadBalancerType, *Response, error) + // GetByName retrieves a Load Balancer type by its name. If the Load Balancer type does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*LoadBalancerType, *Response, error) + // Get retrieves a Load Balancer type by its ID if the input can be parsed as an integer, otherwise it + // retrieves a Load Balancer type by its name. If the Load Balancer type does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*LoadBalancerType, *Response, error) + // List returns a list of Load Balancer types for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts LoadBalancerTypeListOpts) ([]*LoadBalancerType, *Response, error) + // All returns all Load Balancer types. + All(ctx context.Context) ([]*LoadBalancerType, error) + // AllWithOpts returns all Load Balancer types for the given options. + AllWithOpts(ctx context.Context, opts LoadBalancerTypeListOpts) ([]*LoadBalancerType, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_location_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_location_client_iface.go new file mode 100644 index 000000000000..9da4d5f6bd7c --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_location_client_iface.go @@ -0,0 +1,27 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// ILocationClient ... +type ILocationClient interface { + // GetByID retrieves a location by its ID. If the location does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*Location, *Response, error) + // GetByName retrieves an location by its name. If the location does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*Location, *Response, error) + // Get retrieves a location by its ID if the input can be parsed as an integer, otherwise it + // retrieves a location by its name. If the location does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*Location, *Response, error) + // List returns a list of locations for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts LocationListOpts) ([]*Location, *Response, error) + // All returns all locations. + All(ctx context.Context) ([]*Location, error) + // AllWithOpts returns all locations for the given options. + AllWithOpts(ctx context.Context, opts LocationListOpts) ([]*Location, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_network_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_network_client_iface.go new file mode 100644 index 000000000000..f8b752e34786 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_network_client_iface.go @@ -0,0 +1,45 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// INetworkClient ... +type INetworkClient interface { + // GetByID retrieves a network by its ID. If the network does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*Network, *Response, error) + // GetByName retrieves a network by its name. If the network does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*Network, *Response, error) + // Get retrieves a network by its ID if the input can be parsed as an integer, otherwise it + // retrieves a network by its name. If the network does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*Network, *Response, error) + // List returns a list of networks for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts NetworkListOpts) ([]*Network, *Response, error) + // All returns all networks. + All(ctx context.Context) ([]*Network, error) + // AllWithOpts returns all networks for the given options. + AllWithOpts(ctx context.Context, opts NetworkListOpts) ([]*Network, error) + // Delete deletes a network. + Delete(ctx context.Context, network *Network) (*Response, error) + // Update updates a network. + Update(ctx context.Context, network *Network, opts NetworkUpdateOpts) (*Network, *Response, error) + // Create creates a new network. + Create(ctx context.Context, opts NetworkCreateOpts) (*Network, *Response, error) + // ChangeIPRange changes the IP range of a network. + ChangeIPRange(ctx context.Context, network *Network, opts NetworkChangeIPRangeOpts) (*Action, *Response, error) + // AddSubnet adds a subnet to a network. + AddSubnet(ctx context.Context, network *Network, opts NetworkAddSubnetOpts) (*Action, *Response, error) + // DeleteSubnet deletes a subnet from a network. + DeleteSubnet(ctx context.Context, network *Network, opts NetworkDeleteSubnetOpts) (*Action, *Response, error) + // AddRoute adds a route to a network. + AddRoute(ctx context.Context, network *Network, opts NetworkAddRouteOpts) (*Action, *Response, error) + // DeleteRoute deletes a route from a network. + DeleteRoute(ctx context.Context, network *Network, opts NetworkDeleteRouteOpts) (*Action, *Response, error) + // ChangeProtection changes the resource protection level of a network. + ChangeProtection(ctx context.Context, network *Network, opts NetworkChangeProtectionOpts) (*Action, *Response, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_placement_group_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_placement_group_client_iface.go new file mode 100644 index 000000000000..9fadd4f2cba7 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_placement_group_client_iface.go @@ -0,0 +1,33 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// IPlacementGroupClient ... +type IPlacementGroupClient interface { + // GetByID retrieves a PlacementGroup by its ID. If the PlacementGroup does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*PlacementGroup, *Response, error) + // GetByName retrieves a PlacementGroup by its name. If the PlacementGroup does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*PlacementGroup, *Response, error) + // Get retrieves a PlacementGroup by its ID if the input can be parsed as an integer, otherwise it + // retrieves a PlacementGroup by its name. If the PlacementGroup does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*PlacementGroup, *Response, error) + // List returns a list of PlacementGroups for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts PlacementGroupListOpts) ([]*PlacementGroup, *Response, error) + // All returns all PlacementGroups. + All(ctx context.Context) ([]*PlacementGroup, error) + // AllWithOpts returns all PlacementGroups for the given options. + AllWithOpts(ctx context.Context, opts PlacementGroupListOpts) ([]*PlacementGroup, error) + // Create creates a new PlacementGroup. + Create(ctx context.Context, opts PlacementGroupCreateOpts) (PlacementGroupCreateResult, *Response, error) + // Update updates a PlacementGroup. + Update(ctx context.Context, placementGroup *PlacementGroup, opts PlacementGroupUpdateOpts) (*PlacementGroup, *Response, error) + // Delete deletes a PlacementGroup. + Delete(ctx context.Context, placementGroup *PlacementGroup) (*Response, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_pricing_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_pricing_client_iface.go new file mode 100644 index 000000000000..cd4068c6228d --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_pricing_client_iface.go @@ -0,0 +1,13 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// IPricingClient ... +type IPricingClient interface { + // Get retrieves pricing information. + Get(ctx context.Context) (Pricing, *Response, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_primary_ip_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_primary_ip_client_iface.go new file mode 100644 index 000000000000..6b8e617e233b --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_primary_ip_client_iface.go @@ -0,0 +1,43 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// IPrimaryIPClient ... +type IPrimaryIPClient interface { + // GetByID retrieves a Primary IP by its ID. If the Primary IP does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*PrimaryIP, *Response, error) + // GetByIP retrieves a Primary IP by its IP Address. If the Primary IP does not exist, nil is returned. + GetByIP(ctx context.Context, ip string) (*PrimaryIP, *Response, error) + // GetByName retrieves a Primary IP by its name. If the Primary IP does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*PrimaryIP, *Response, error) + // Get retrieves a Primary IP by its ID if the input can be parsed as an integer, otherwise it + // retrieves a Primary IP by its name. If the Primary IP does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*PrimaryIP, *Response, error) + // List returns a list of Primary IPs for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts PrimaryIPListOpts) ([]*PrimaryIP, *Response, error) + // All returns all Primary IPs. + All(ctx context.Context) ([]*PrimaryIP, error) + // AllWithOpts returns all Primary IPs for the given options. + AllWithOpts(ctx context.Context, opts PrimaryIPListOpts) ([]*PrimaryIP, error) + // Create creates a Primary IP. + Create(ctx context.Context, reqBody PrimaryIPCreateOpts) (*PrimaryIPCreateResult, *Response, error) + // Delete deletes a Primary IP. + Delete(ctx context.Context, primaryIP *PrimaryIP) (*Response, error) + // Update updates a Primary IP. + Update(ctx context.Context, primaryIP *PrimaryIP, reqBody PrimaryIPUpdateOpts) (*PrimaryIP, *Response, error) + // Assign a Primary IP to a resource. + Assign(ctx context.Context, opts PrimaryIPAssignOpts) (*Action, *Response, error) + // Unassign a Primary IP from a resource. + Unassign(ctx context.Context, id int64) (*Action, *Response, error) + // ChangeDNSPtr Change the reverse DNS from a Primary IP. + ChangeDNSPtr(ctx context.Context, opts PrimaryIPChangeDNSPtrOpts) (*Action, *Response, error) + // ChangeProtection Changes the protection configuration of a Primary IP. + ChangeProtection(ctx context.Context, opts PrimaryIPChangeProtectionOpts) (*Action, *Response, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_rdns_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_rdns_client_iface.go new file mode 100644 index 000000000000..f92f186779f4 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_rdns_client_iface.go @@ -0,0 +1,15 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" + "net" +) + +// IRDNSClient ... +type IRDNSClient interface { + // ChangeDNSPtr changes or resets the reverse DNS pointer for a IP address. + // Pass a nil ptr to reset the reverse DNS pointer to its default value. + ChangeDNSPtr(ctx context.Context, rdns RDNSSupporter, ip net.IP, ptr *string) (*Action, *Response, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_resource_action_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_resource_action_client_iface.go new file mode 100644 index 000000000000..67910ab223a8 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_resource_action_client_iface.go @@ -0,0 +1,20 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// IResourceActionClient ... +type IResourceActionClient interface { + // GetByID retrieves an action by its ID. If the action does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*Action, *Response, error) + // List returns a list of actions for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts ActionListOpts) ([]*Action, *Response, error) + // All returns all actions for the given options. + All(ctx context.Context, opts ActionListOpts) ([]*Action, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_schema.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_schema.go new file mode 100755 index 000000000000..66fe08d3a8e8 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_schema.go @@ -0,0 +1,2491 @@ +// Code generated by github.com/jmattheis/goverter, DO NOT EDIT. +//go:build !goverter + +package hcloud + +import ( + schema "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/schema" + "net" + "time" +) + +type converterImpl struct{} + +func (c *converterImpl) ActionFromSchema(source schema.Action) *Action { + var hcloudAction Action + hcloudAction.ID = source.ID + hcloudAction.Status = ActionStatus(source.Status) + hcloudAction.Command = source.Command + hcloudAction.Progress = source.Progress + hcloudAction.Started = source.Started + hcloudAction.Finished = c.pTimeTimeToTimeTime(source.Finished) + var pString *string + if source.Error != nil { + pString = &source.Error.Code + } + var xstring string + if pString != nil { + xstring = *pString + } + hcloudAction.ErrorCode = xstring + var pString2 *string + if source.Error != nil { + pString2 = &source.Error.Message + } + var xstring2 string + if pString2 != nil { + xstring2 = *pString2 + } + hcloudAction.ErrorMessage = xstring2 + var pHcloudActionResourceList []*ActionResource + if source.Resources != nil { + pHcloudActionResourceList = make([]*ActionResource, len(source.Resources)) + for i := 0; i < len(source.Resources); i++ { + pHcloudActionResourceList[i] = c.schemaActionResourceReferenceToPHcloudActionResource(source.Resources[i]) + } + } + hcloudAction.Resources = pHcloudActionResourceList + return &hcloudAction +} +func (c *converterImpl) ActionsFromSchema(source []schema.Action) []*Action { + var pHcloudActionList []*Action + if source != nil { + pHcloudActionList = make([]*Action, len(source)) + for i := 0; i < len(source); i++ { + pHcloudActionList[i] = c.ActionFromSchema(source[i]) + } + } + return pHcloudActionList +} +func (c *converterImpl) CertificateFromSchema(source schema.Certificate) *Certificate { + var hcloudCertificate Certificate + hcloudCertificate.ID = source.ID + hcloudCertificate.Name = source.Name + hcloudCertificate.Labels = source.Labels + hcloudCertificate.Type = CertificateType(source.Type) + hcloudCertificate.Certificate = source.Certificate + hcloudCertificate.Created = c.timeTimeToTimeTime(source.Created) + hcloudCertificate.NotValidBefore = c.timeTimeToTimeTime(source.NotValidBefore) + hcloudCertificate.NotValidAfter = c.timeTimeToTimeTime(source.NotValidAfter) + hcloudCertificate.DomainNames = source.DomainNames + hcloudCertificate.Fingerprint = source.Fingerprint + hcloudCertificate.Status = c.pSchemaCertificateStatusRefToPHcloudCertificateStatus(source.Status) + var hcloudCertificateUsedByRefList []CertificateUsedByRef + if source.UsedBy != nil { + hcloudCertificateUsedByRefList = make([]CertificateUsedByRef, len(source.UsedBy)) + for i := 0; i < len(source.UsedBy); i++ { + hcloudCertificateUsedByRefList[i] = c.schemaCertificateUsedByRefToHcloudCertificateUsedByRef(source.UsedBy[i]) + } + } + hcloudCertificate.UsedBy = hcloudCertificateUsedByRefList + return &hcloudCertificate +} +func (c *converterImpl) DatacenterFromSchema(source schema.Datacenter) *Datacenter { + var hcloudDatacenter Datacenter + hcloudDatacenter.ID = source.ID + hcloudDatacenter.Name = source.Name + hcloudDatacenter.Description = source.Description + hcloudDatacenter.Location = c.LocationFromSchema(source.Location) + hcloudDatacenter.ServerTypes = c.schemaDatacenterServerTypesToHcloudDatacenterServerTypes(source.ServerTypes) + return &hcloudDatacenter +} +func (c *converterImpl) DeprecationFromSchema(source *schema.DeprecationInfo) *DeprecationInfo { + var pHcloudDeprecationInfo *DeprecationInfo + if source != nil { + var hcloudDeprecationInfo DeprecationInfo + hcloudDeprecationInfo.Announced = c.timeTimeToTimeTime((*source).Announced) + hcloudDeprecationInfo.UnavailableAfter = c.timeTimeToTimeTime((*source).UnavailableAfter) + pHcloudDeprecationInfo = &hcloudDeprecationInfo + } + return pHcloudDeprecationInfo +} +func (c *converterImpl) ErrorFromSchema(source schema.Error) Error { + var hcloudError Error + hcloudError.Code = ErrorCode(source.Code) + hcloudError.Message = source.Message + hcloudError.Details = errorDetailsFromSchema(source.Details) + return hcloudError +} +func (c *converterImpl) FirewallFromSchema(source schema.Firewall) *Firewall { + var hcloudFirewall Firewall + hcloudFirewall.ID = source.ID + hcloudFirewall.Name = source.Name + hcloudFirewall.Labels = source.Labels + hcloudFirewall.Created = c.timeTimeToTimeTime(source.Created) + var hcloudFirewallRuleList []FirewallRule + if source.Rules != nil { + hcloudFirewallRuleList = make([]FirewallRule, len(source.Rules)) + for i := 0; i < len(source.Rules); i++ { + hcloudFirewallRuleList[i] = c.schemaFirewallRuleToHcloudFirewallRule(source.Rules[i]) + } + } + hcloudFirewall.Rules = hcloudFirewallRuleList + var hcloudFirewallResourceList []FirewallResource + if source.AppliedTo != nil { + hcloudFirewallResourceList = make([]FirewallResource, len(source.AppliedTo)) + for j := 0; j < len(source.AppliedTo); j++ { + hcloudFirewallResourceList[j] = c.schemaFirewallResourceToHcloudFirewallResource(source.AppliedTo[j]) + } + } + hcloudFirewall.AppliedTo = hcloudFirewallResourceList + return &hcloudFirewall +} +func (c *converterImpl) FloatingIPFromSchema(source schema.FloatingIP) *FloatingIP { + var hcloudFloatingIP FloatingIP + hcloudFloatingIP.ID = source.ID + var xstring string + if source.Description != nil { + xstring = *source.Description + } + hcloudFloatingIP.Description = xstring + hcloudFloatingIP.Created = c.timeTimeToTimeTime(source.Created) + hcloudFloatingIP.IP = ipFromFloatingIPSchema(source) + hcloudFloatingIP.Network = networkFromFloatingIPSchema(source) + hcloudFloatingIP.Type = FloatingIPType(source.Type) + var pHcloudServer *Server + if source.Server != nil { + hcloudServer := serverFromInt64(*source.Server) + pHcloudServer = &hcloudServer + } + hcloudFloatingIP.Server = pHcloudServer + hcloudFloatingIP.DNSPtr = mapFromFloatingIPDNSPtrSchema(source.DNSPtr) + hcloudFloatingIP.HomeLocation = c.LocationFromSchema(source.HomeLocation) + hcloudFloatingIP.Blocked = source.Blocked + hcloudFloatingIP.Protection = c.schemaFloatingIPProtectionToHcloudFloatingIPProtection(source.Protection) + hcloudFloatingIP.Labels = source.Labels + hcloudFloatingIP.Name = source.Name + return &hcloudFloatingIP +} +func (c *converterImpl) ISOFromSchema(source schema.ISO) *ISO { + hcloudISO := c.intISOFromSchema(source) + return &hcloudISO +} +func (c *converterImpl) ImageFromSchema(source schema.Image) *Image { + var hcloudImage Image + hcloudImage.ID = source.ID + var xstring string + if source.Name != nil { + xstring = *source.Name + } + hcloudImage.Name = xstring + hcloudImage.Type = ImageType(source.Type) + hcloudImage.Status = ImageStatus(source.Status) + hcloudImage.Description = source.Description + var xfloat32 float32 + if source.ImageSize != nil { + xfloat32 = *source.ImageSize + } + hcloudImage.ImageSize = xfloat32 + hcloudImage.DiskSize = source.DiskSize + hcloudImage.Created = c.pTimeTimeToTimeTime(source.Created) + hcloudImage.CreatedFrom = c.pSchemaImageCreatedFromToPHcloudServer(source.CreatedFrom) + var pHcloudServer *Server + if source.BoundTo != nil { + hcloudServer := serverFromInt64(*source.BoundTo) + pHcloudServer = &hcloudServer + } + hcloudImage.BoundTo = pHcloudServer + hcloudImage.RapidDeploy = source.RapidDeploy + hcloudImage.OSFlavor = source.OSFlavor + var xstring2 string + if source.OSVersion != nil { + xstring2 = *source.OSVersion + } + hcloudImage.OSVersion = xstring2 + hcloudImage.Architecture = Architecture(source.Architecture) + hcloudImage.Protection = c.schemaImageProtectionToHcloudImageProtection(source.Protection) + hcloudImage.Deprecated = c.pTimeTimeToTimeTime(source.Deprecated) + hcloudImage.Labels = source.Labels + hcloudImage.Deleted = c.pTimeTimeToTimeTime(source.Deleted) + return &hcloudImage +} +func (c *converterImpl) LoadBalancerFromSchema(source schema.LoadBalancer) *LoadBalancer { + var hcloudLoadBalancer LoadBalancer + hcloudLoadBalancer.ID = source.ID + hcloudLoadBalancer.Name = source.Name + hcloudLoadBalancer.PublicNet = c.schemaLoadBalancerPublicNetToHcloudLoadBalancerPublicNet(source.PublicNet) + var hcloudLoadBalancerPrivateNetList []LoadBalancerPrivateNet + if source.PrivateNet != nil { + hcloudLoadBalancerPrivateNetList = make([]LoadBalancerPrivateNet, len(source.PrivateNet)) + for i := 0; i < len(source.PrivateNet); i++ { + hcloudLoadBalancerPrivateNetList[i] = c.schemaLoadBalancerPrivateNetToHcloudLoadBalancerPrivateNet(source.PrivateNet[i]) + } + } + hcloudLoadBalancer.PrivateNet = hcloudLoadBalancerPrivateNetList + hcloudLoadBalancer.Location = c.LocationFromSchema(source.Location) + hcloudLoadBalancer.LoadBalancerType = c.LoadBalancerTypeFromSchema(source.LoadBalancerType) + hcloudLoadBalancer.Algorithm = c.schemaLoadBalancerAlgorithmToHcloudLoadBalancerAlgorithm(source.Algorithm) + var hcloudLoadBalancerServiceList []LoadBalancerService + if source.Services != nil { + hcloudLoadBalancerServiceList = make([]LoadBalancerService, len(source.Services)) + for j := 0; j < len(source.Services); j++ { + hcloudLoadBalancerServiceList[j] = c.LoadBalancerServiceFromSchema(source.Services[j]) + } + } + hcloudLoadBalancer.Services = hcloudLoadBalancerServiceList + var hcloudLoadBalancerTargetList []LoadBalancerTarget + if source.Targets != nil { + hcloudLoadBalancerTargetList = make([]LoadBalancerTarget, len(source.Targets)) + for k := 0; k < len(source.Targets); k++ { + hcloudLoadBalancerTargetList[k] = c.LoadBalancerTargetFromSchema(source.Targets[k]) + } + } + hcloudLoadBalancer.Targets = hcloudLoadBalancerTargetList + hcloudLoadBalancer.Protection = c.schemaLoadBalancerProtectionToHcloudLoadBalancerProtection(source.Protection) + hcloudLoadBalancer.Labels = source.Labels + hcloudLoadBalancer.Created = c.timeTimeToTimeTime(source.Created) + hcloudLoadBalancer.IncludedTraffic = source.IncludedTraffic + var xuint64 uint64 + if source.OutgoingTraffic != nil { + xuint64 = *source.OutgoingTraffic + } + hcloudLoadBalancer.OutgoingTraffic = xuint64 + var xuint642 uint64 + if source.IngoingTraffic != nil { + xuint642 = *source.IngoingTraffic + } + hcloudLoadBalancer.IngoingTraffic = xuint642 + return &hcloudLoadBalancer +} +func (c *converterImpl) LoadBalancerMetricsFromSchema(source *schema.LoadBalancerGetMetricsResponse) (*LoadBalancerMetrics, error) { + var pHcloudLoadBalancerMetrics *LoadBalancerMetrics + if source != nil { + var hcloudLoadBalancerMetrics LoadBalancerMetrics + hcloudLoadBalancerMetrics.Start = c.timeTimeToTimeTime((*source).Metrics.Start) + hcloudLoadBalancerMetrics.End = c.timeTimeToTimeTime((*source).Metrics.End) + hcloudLoadBalancerMetrics.Step = (*source).Metrics.Step + var mapStringHcloudLoadBalancerMetricsValueList map[string][]LoadBalancerMetricsValue + if (*source).Metrics.TimeSeries != nil { + mapStringHcloudLoadBalancerMetricsValueList = make(map[string][]LoadBalancerMetricsValue, len((*source).Metrics.TimeSeries)) + for key, value := range (*source).Metrics.TimeSeries { + hcloudLoadBalancerMetricsValueList, err := loadBalancerMetricsTimeSeriesFromSchema(value) + if err != nil { + return nil, err + } + mapStringHcloudLoadBalancerMetricsValueList[key] = hcloudLoadBalancerMetricsValueList + } + } + hcloudLoadBalancerMetrics.TimeSeries = mapStringHcloudLoadBalancerMetricsValueList + pHcloudLoadBalancerMetrics = &hcloudLoadBalancerMetrics + } + return pHcloudLoadBalancerMetrics, nil +} +func (c *converterImpl) LoadBalancerServiceFromSchema(source schema.LoadBalancerService) LoadBalancerService { + var hcloudLoadBalancerService LoadBalancerService + hcloudLoadBalancerService.Protocol = LoadBalancerServiceProtocol(source.Protocol) + hcloudLoadBalancerService.ListenPort = source.ListenPort + hcloudLoadBalancerService.DestinationPort = source.DestinationPort + hcloudLoadBalancerService.Proxyprotocol = source.Proxyprotocol + hcloudLoadBalancerService.HTTP = c.pSchemaLoadBalancerServiceHTTPToHcloudLoadBalancerServiceHTTP(source.HTTP) + hcloudLoadBalancerService.HealthCheck = c.LoadBalancerServiceHealthCheckFromSchema(source.HealthCheck) + return hcloudLoadBalancerService +} +func (c *converterImpl) LoadBalancerServiceHealthCheckFromSchema(source *schema.LoadBalancerServiceHealthCheck) LoadBalancerServiceHealthCheck { + var hcloudLoadBalancerServiceHealthCheck LoadBalancerServiceHealthCheck + if source != nil { + var hcloudLoadBalancerServiceHealthCheck2 LoadBalancerServiceHealthCheck + hcloudLoadBalancerServiceHealthCheck2.Protocol = LoadBalancerServiceProtocol((*source).Protocol) + hcloudLoadBalancerServiceHealthCheck2.Port = (*source).Port + hcloudLoadBalancerServiceHealthCheck2.Interval = durationFromIntSeconds((*source).Interval) + hcloudLoadBalancerServiceHealthCheck2.Timeout = durationFromIntSeconds((*source).Timeout) + hcloudLoadBalancerServiceHealthCheck2.Retries = (*source).Retries + hcloudLoadBalancerServiceHealthCheck2.HTTP = c.pSchemaLoadBalancerServiceHealthCheckHTTPToPHcloudLoadBalancerServiceHealthCheckHTTP((*source).HTTP) + hcloudLoadBalancerServiceHealthCheck = hcloudLoadBalancerServiceHealthCheck2 + } + return hcloudLoadBalancerServiceHealthCheck +} +func (c *converterImpl) LoadBalancerTargetFromSchema(source schema.LoadBalancerTarget) LoadBalancerTarget { + var hcloudLoadBalancerTarget LoadBalancerTarget + hcloudLoadBalancerTarget.Type = LoadBalancerTargetType(source.Type) + hcloudLoadBalancerTarget.Server = c.pSchemaLoadBalancerTargetServerToPHcloudLoadBalancerTargetServer(source.Server) + hcloudLoadBalancerTarget.LabelSelector = c.pSchemaLoadBalancerTargetLabelSelectorToPHcloudLoadBalancerTargetLabelSelector(source.LabelSelector) + hcloudLoadBalancerTarget.IP = c.pSchemaLoadBalancerTargetIPToPHcloudLoadBalancerTargetIP(source.IP) + var hcloudLoadBalancerTargetHealthStatusList []LoadBalancerTargetHealthStatus + if source.HealthStatus != nil { + hcloudLoadBalancerTargetHealthStatusList = make([]LoadBalancerTargetHealthStatus, len(source.HealthStatus)) + for i := 0; i < len(source.HealthStatus); i++ { + hcloudLoadBalancerTargetHealthStatusList[i] = c.LoadBalancerTargetHealthStatusFromSchema(source.HealthStatus[i]) + } + } + hcloudLoadBalancerTarget.HealthStatus = hcloudLoadBalancerTargetHealthStatusList + var hcloudLoadBalancerTargetList []LoadBalancerTarget + if source.Targets != nil { + hcloudLoadBalancerTargetList = make([]LoadBalancerTarget, len(source.Targets)) + for j := 0; j < len(source.Targets); j++ { + hcloudLoadBalancerTargetList[j] = c.LoadBalancerTargetFromSchema(source.Targets[j]) + } + } + hcloudLoadBalancerTarget.Targets = hcloudLoadBalancerTargetList + hcloudLoadBalancerTarget.UsePrivateIP = source.UsePrivateIP + return hcloudLoadBalancerTarget +} +func (c *converterImpl) LoadBalancerTargetHealthStatusFromSchema(source schema.LoadBalancerTargetHealthStatus) LoadBalancerTargetHealthStatus { + var hcloudLoadBalancerTargetHealthStatus LoadBalancerTargetHealthStatus + hcloudLoadBalancerTargetHealthStatus.ListenPort = source.ListenPort + hcloudLoadBalancerTargetHealthStatus.Status = LoadBalancerTargetHealthStatusStatus(source.Status) + return hcloudLoadBalancerTargetHealthStatus +} +func (c *converterImpl) LoadBalancerTargetServerFromSchema(source schema.LoadBalancerTargetServer) LoadBalancerTargetServer { + var hcloudLoadBalancerTargetServer LoadBalancerTargetServer + hcloudServer := serverFromInt64(source.ID) + hcloudLoadBalancerTargetServer.Server = &hcloudServer + return hcloudLoadBalancerTargetServer +} +func (c *converterImpl) LoadBalancerTypeFromSchema(source schema.LoadBalancerType) *LoadBalancerType { + var hcloudLoadBalancerType LoadBalancerType + hcloudLoadBalancerType.ID = source.ID + hcloudLoadBalancerType.Name = source.Name + hcloudLoadBalancerType.Description = source.Description + hcloudLoadBalancerType.MaxConnections = source.MaxConnections + hcloudLoadBalancerType.MaxServices = source.MaxServices + hcloudLoadBalancerType.MaxTargets = source.MaxTargets + hcloudLoadBalancerType.MaxAssignedCertificates = source.MaxAssignedCertificates + var hcloudLoadBalancerTypeLocationPricingList []LoadBalancerTypeLocationPricing + if source.Prices != nil { + hcloudLoadBalancerTypeLocationPricingList = make([]LoadBalancerTypeLocationPricing, len(source.Prices)) + for i := 0; i < len(source.Prices); i++ { + hcloudLoadBalancerTypeLocationPricingList[i] = c.LoadBalancerTypeLocationPricingFromSchema(source.Prices[i]) + } + } + hcloudLoadBalancerType.Pricings = hcloudLoadBalancerTypeLocationPricingList + hcloudLoadBalancerType.Deprecated = source.Deprecated + return &hcloudLoadBalancerType +} +func (c *converterImpl) LoadBalancerTypeLocationPricingFromSchema(source schema.PricingLoadBalancerTypePrice) LoadBalancerTypeLocationPricing { + var hcloudLoadBalancerTypeLocationPricing LoadBalancerTypeLocationPricing + hcloudLocation := locationFromString(source.Location) + hcloudLoadBalancerTypeLocationPricing.Location = &hcloudLocation + hcloudLoadBalancerTypeLocationPricing.Hourly = c.PriceFromSchema(source.PriceHourly) + hcloudLoadBalancerTypeLocationPricing.Monthly = c.PriceFromSchema(source.PriceMonthly) + return hcloudLoadBalancerTypeLocationPricing +} +func (c *converterImpl) LocationFromSchema(source schema.Location) *Location { + var hcloudLocation Location + hcloudLocation.ID = source.ID + hcloudLocation.Name = source.Name + hcloudLocation.Description = source.Description + hcloudLocation.Country = source.Country + hcloudLocation.City = source.City + hcloudLocation.Latitude = source.Latitude + hcloudLocation.Longitude = source.Longitude + hcloudLocation.NetworkZone = NetworkZone(source.NetworkZone) + return &hcloudLocation +} +func (c *converterImpl) NetworkFromSchema(source schema.Network) *Network { + var hcloudNetwork Network + hcloudNetwork.ID = source.ID + hcloudNetwork.Name = source.Name + hcloudNetwork.Created = c.timeTimeToTimeTime(source.Created) + netIPNet := ipNetFromString(source.IPRange) + hcloudNetwork.IPRange = &netIPNet + var hcloudNetworkSubnetList []NetworkSubnet + if source.Subnets != nil { + hcloudNetworkSubnetList = make([]NetworkSubnet, len(source.Subnets)) + for i := 0; i < len(source.Subnets); i++ { + hcloudNetworkSubnetList[i] = c.NetworkSubnetFromSchema(source.Subnets[i]) + } + } + hcloudNetwork.Subnets = hcloudNetworkSubnetList + var hcloudNetworkRouteList []NetworkRoute + if source.Routes != nil { + hcloudNetworkRouteList = make([]NetworkRoute, len(source.Routes)) + for j := 0; j < len(source.Routes); j++ { + hcloudNetworkRouteList[j] = c.NetworkRouteFromSchema(source.Routes[j]) + } + } + hcloudNetwork.Routes = hcloudNetworkRouteList + var pHcloudServerList []*Server + if source.Servers != nil { + pHcloudServerList = make([]*Server, len(source.Servers)) + for k := 0; k < len(source.Servers); k++ { + hcloudServer := serverFromInt64(source.Servers[k]) + pHcloudServerList[k] = &hcloudServer + } + } + hcloudNetwork.Servers = pHcloudServerList + hcloudNetwork.Protection = c.schemaNetworkProtectionToHcloudNetworkProtection(source.Protection) + hcloudNetwork.Labels = source.Labels + hcloudNetwork.ExposeRoutesToVSwitch = source.ExposeRoutesToVSwitch + return &hcloudNetwork +} +func (c *converterImpl) NetworkRouteFromSchema(source schema.NetworkRoute) NetworkRoute { + var hcloudNetworkRoute NetworkRoute + netIPNet := ipNetFromString(source.Destination) + hcloudNetworkRoute.Destination = &netIPNet + hcloudNetworkRoute.Gateway = ipFromString(source.Gateway) + return hcloudNetworkRoute +} +func (c *converterImpl) NetworkSubnetFromSchema(source schema.NetworkSubnet) NetworkSubnet { + var hcloudNetworkSubnet NetworkSubnet + hcloudNetworkSubnet.Type = NetworkSubnetType(source.Type) + netIPNet := ipNetFromString(source.IPRange) + hcloudNetworkSubnet.IPRange = &netIPNet + hcloudNetworkSubnet.NetworkZone = NetworkZone(source.NetworkZone) + hcloudNetworkSubnet.Gateway = ipFromString(source.Gateway) + hcloudNetworkSubnet.VSwitchID = source.VSwitchID + return hcloudNetworkSubnet +} +func (c *converterImpl) PaginationFromSchema(source schema.MetaPagination) Pagination { + var hcloudPagination Pagination + hcloudPagination.Page = source.Page + hcloudPagination.PerPage = source.PerPage + hcloudPagination.PreviousPage = source.PreviousPage + hcloudPagination.NextPage = source.NextPage + hcloudPagination.LastPage = source.LastPage + hcloudPagination.TotalEntries = source.TotalEntries + return hcloudPagination +} +func (c *converterImpl) PlacementGroupFromSchema(source schema.PlacementGroup) *PlacementGroup { + var hcloudPlacementGroup PlacementGroup + hcloudPlacementGroup.ID = source.ID + hcloudPlacementGroup.Name = source.Name + hcloudPlacementGroup.Labels = source.Labels + hcloudPlacementGroup.Created = c.timeTimeToTimeTime(source.Created) + hcloudPlacementGroup.Servers = source.Servers + hcloudPlacementGroup.Type = PlacementGroupType(source.Type) + return &hcloudPlacementGroup +} +func (c *converterImpl) PriceFromSchema(source schema.Price) Price { + var hcloudPrice Price + hcloudPrice.Net = source.Net + hcloudPrice.Gross = source.Gross + return hcloudPrice +} +func (c *converterImpl) PricingFromSchema(source schema.Pricing) Pricing { + var hcloudPricing Pricing + hcloudPricing.Image = imagePricingFromSchema(source) + hcloudPricing.FloatingIP = floatingIPPricingFromSchema(source) + hcloudPricing.FloatingIPs = floatingIPTypePricingFromSchema(source) + hcloudPricing.PrimaryIPs = primaryIPPricingFromSchema(source) + hcloudPricing.Traffic = trafficPricingFromSchema(source) + hcloudPricing.ServerBackup = c.schemaPricingServerBackupToHcloudServerBackupPricing(source.ServerBackup) + hcloudPricing.ServerTypes = serverTypePricingFromSchema(source) + hcloudPricing.LoadBalancerTypes = loadBalancerTypePricingFromSchema(source) + hcloudPricing.Volume = volumePricingFromSchema(source) + return hcloudPricing +} +func (c *converterImpl) PrimaryIPFromSchema(source schema.PrimaryIP) *PrimaryIP { + var hcloudPrimaryIP PrimaryIP + hcloudPrimaryIP.ID = source.ID + hcloudPrimaryIP.IP = ipFromPrimaryIPSchema(source) + hcloudPrimaryIP.Network = networkFromPrimaryIPSchema(source) + hcloudPrimaryIP.Labels = source.Labels + hcloudPrimaryIP.Name = source.Name + hcloudPrimaryIP.Type = PrimaryIPType(source.Type) + hcloudPrimaryIP.Protection = c.schemaPrimaryIPProtectionToHcloudPrimaryIPProtection(source.Protection) + hcloudPrimaryIP.DNSPtr = mapFromPrimaryIPDNSPtrSchema(source.DNSPtr) + var xint64 int64 + if source.AssigneeID != nil { + xint64 = *source.AssigneeID + } + hcloudPrimaryIP.AssigneeID = xint64 + hcloudPrimaryIP.AssigneeType = source.AssigneeType + hcloudPrimaryIP.AutoDelete = source.AutoDelete + hcloudPrimaryIP.Blocked = source.Blocked + hcloudPrimaryIP.Created = c.timeTimeToTimeTime(source.Created) + hcloudPrimaryIP.Datacenter = c.DatacenterFromSchema(source.Datacenter) + return &hcloudPrimaryIP +} +func (c *converterImpl) SSHKeyFromSchema(source schema.SSHKey) *SSHKey { + var hcloudSSHKey SSHKey + hcloudSSHKey.ID = source.ID + hcloudSSHKey.Name = source.Name + hcloudSSHKey.Fingerprint = source.Fingerprint + hcloudSSHKey.PublicKey = source.PublicKey + hcloudSSHKey.Labels = source.Labels + hcloudSSHKey.Created = c.timeTimeToTimeTime(source.Created) + return &hcloudSSHKey +} +func (c *converterImpl) SchemaFromAction(source *Action) schema.Action { + var schemaAction schema.Action + if source != nil { + var schemaAction2 schema.Action + schemaAction2.ID = (*source).ID + schemaAction2.Status = string((*source).Status) + schemaAction2.Command = (*source).Command + schemaAction2.Progress = (*source).Progress + schemaAction2.Started = c.timeTimeToTimeTime((*source).Started) + schemaAction2.Finished = timeToTimePtr((*source).Finished) + schemaAction2.Error = schemaActionErrorFromAction((*source)) + var schemaActionResourceReferenceList []schema.ActionResourceReference + if (*source).Resources != nil { + schemaActionResourceReferenceList = make([]schema.ActionResourceReference, len((*source).Resources)) + for i := 0; i < len((*source).Resources); i++ { + schemaActionResourceReferenceList[i] = c.pHcloudActionResourceToSchemaActionResourceReference((*source).Resources[i]) + } + } + schemaAction2.Resources = schemaActionResourceReferenceList + schemaAction = schemaAction2 + } + return schemaAction +} +func (c *converterImpl) SchemaFromActions(source []*Action) []schema.Action { + var schemaActionList []schema.Action + if source != nil { + schemaActionList = make([]schema.Action, len(source)) + for i := 0; i < len(source); i++ { + schemaActionList[i] = c.SchemaFromAction(source[i]) + } + } + return schemaActionList +} +func (c *converterImpl) SchemaFromCertificate(source *Certificate) schema.Certificate { + var schemaCertificate schema.Certificate + if source != nil { + var schemaCertificate2 schema.Certificate + schemaCertificate2.ID = (*source).ID + schemaCertificate2.Name = (*source).Name + schemaCertificate2.Labels = (*source).Labels + schemaCertificate2.Type = string((*source).Type) + schemaCertificate2.Certificate = (*source).Certificate + schemaCertificate2.Created = c.timeTimeToTimeTime((*source).Created) + schemaCertificate2.NotValidBefore = c.timeTimeToTimeTime((*source).NotValidBefore) + schemaCertificate2.NotValidAfter = c.timeTimeToTimeTime((*source).NotValidAfter) + schemaCertificate2.DomainNames = (*source).DomainNames + schemaCertificate2.Fingerprint = (*source).Fingerprint + schemaCertificate2.Status = c.pHcloudCertificateStatusToPSchemaCertificateStatusRef((*source).Status) + var schemaCertificateUsedByRefList []schema.CertificateUsedByRef + if (*source).UsedBy != nil { + schemaCertificateUsedByRefList = make([]schema.CertificateUsedByRef, len((*source).UsedBy)) + for i := 0; i < len((*source).UsedBy); i++ { + schemaCertificateUsedByRefList[i] = c.hcloudCertificateUsedByRefToSchemaCertificateUsedByRef((*source).UsedBy[i]) + } + } + schemaCertificate2.UsedBy = schemaCertificateUsedByRefList + schemaCertificate = schemaCertificate2 + } + return schemaCertificate +} +func (c *converterImpl) SchemaFromDatacenter(source *Datacenter) schema.Datacenter { + var schemaDatacenter schema.Datacenter + if source != nil { + var schemaDatacenter2 schema.Datacenter + schemaDatacenter2.ID = (*source).ID + schemaDatacenter2.Name = (*source).Name + schemaDatacenter2.Description = (*source).Description + schemaDatacenter2.Location = c.SchemaFromLocation((*source).Location) + schemaDatacenter2.ServerTypes = c.hcloudDatacenterServerTypesToSchemaDatacenterServerTypes((*source).ServerTypes) + schemaDatacenter = schemaDatacenter2 + } + return schemaDatacenter +} +func (c *converterImpl) SchemaFromDeprecation(source *DeprecationInfo) *schema.DeprecationInfo { + var pSchemaDeprecationInfo *schema.DeprecationInfo + if source != nil { + var schemaDeprecationInfo schema.DeprecationInfo + schemaDeprecationInfo.Announced = c.timeTimeToTimeTime((*source).Announced) + schemaDeprecationInfo.UnavailableAfter = c.timeTimeToTimeTime((*source).UnavailableAfter) + pSchemaDeprecationInfo = &schemaDeprecationInfo + } + return pSchemaDeprecationInfo +} +func (c *converterImpl) SchemaFromError(source Error) schema.Error { + var schemaError schema.Error + schemaError.Code = string(source.Code) + schemaError.Message = source.Message + schemaError.DetailsRaw = rawSchemaFromErrorDetails(source.Details) + schemaError.Details = schemaFromErrorDetails(source.Details) + return schemaError +} +func (c *converterImpl) SchemaFromFirewall(source *Firewall) schema.Firewall { + var schemaFirewall schema.Firewall + if source != nil { + var schemaFirewall2 schema.Firewall + schemaFirewall2.ID = (*source).ID + schemaFirewall2.Name = (*source).Name + schemaFirewall2.Labels = (*source).Labels + schemaFirewall2.Created = c.timeTimeToTimeTime((*source).Created) + var schemaFirewallRuleList []schema.FirewallRule + if (*source).Rules != nil { + schemaFirewallRuleList = make([]schema.FirewallRule, len((*source).Rules)) + for i := 0; i < len((*source).Rules); i++ { + schemaFirewallRuleList[i] = c.hcloudFirewallRuleToSchemaFirewallRule((*source).Rules[i]) + } + } + schemaFirewall2.Rules = schemaFirewallRuleList + var schemaFirewallResourceList []schema.FirewallResource + if (*source).AppliedTo != nil { + schemaFirewallResourceList = make([]schema.FirewallResource, len((*source).AppliedTo)) + for j := 0; j < len((*source).AppliedTo); j++ { + schemaFirewallResourceList[j] = c.SchemaFromFirewallResource((*source).AppliedTo[j]) + } + } + schemaFirewall2.AppliedTo = schemaFirewallResourceList + schemaFirewall = schemaFirewall2 + } + return schemaFirewall +} +func (c *converterImpl) SchemaFromFirewallCreateOpts(source FirewallCreateOpts) schema.FirewallCreateRequest { + var schemaFirewallCreateRequest schema.FirewallCreateRequest + schemaFirewallCreateRequest.Name = source.Name + schemaFirewallCreateRequest.Labels = stringMapToStringMapPtr(source.Labels) + var schemaFirewallRuleRequestList []schema.FirewallRuleRequest + if source.Rules != nil { + schemaFirewallRuleRequestList = make([]schema.FirewallRuleRequest, len(source.Rules)) + for i := 0; i < len(source.Rules); i++ { + schemaFirewallRuleRequestList[i] = c.hcloudFirewallRuleToSchemaFirewallRuleRequest(source.Rules[i]) + } + } + schemaFirewallCreateRequest.Rules = schemaFirewallRuleRequestList + var schemaFirewallResourceList []schema.FirewallResource + if source.ApplyTo != nil { + schemaFirewallResourceList = make([]schema.FirewallResource, len(source.ApplyTo)) + for j := 0; j < len(source.ApplyTo); j++ { + schemaFirewallResourceList[j] = c.SchemaFromFirewallResource(source.ApplyTo[j]) + } + } + schemaFirewallCreateRequest.ApplyTo = schemaFirewallResourceList + return schemaFirewallCreateRequest +} +func (c *converterImpl) SchemaFromFirewallResource(source FirewallResource) schema.FirewallResource { + var schemaFirewallResource schema.FirewallResource + schemaFirewallResource.Type = string(source.Type) + schemaFirewallResource.Server = c.pHcloudFirewallResourceServerToPSchemaFirewallResourceServer(source.Server) + schemaFirewallResource.LabelSelector = c.pHcloudFirewallResourceLabelSelectorToPSchemaFirewallResourceLabelSelector(source.LabelSelector) + return schemaFirewallResource +} +func (c *converterImpl) SchemaFromFirewallSetRulesOpts(source FirewallSetRulesOpts) schema.FirewallActionSetRulesRequest { + var schemaFirewallActionSetRulesRequest schema.FirewallActionSetRulesRequest + var schemaFirewallRuleRequestList []schema.FirewallRuleRequest + if source.Rules != nil { + schemaFirewallRuleRequestList = make([]schema.FirewallRuleRequest, len(source.Rules)) + for i := 0; i < len(source.Rules); i++ { + schemaFirewallRuleRequestList[i] = c.hcloudFirewallRuleToSchemaFirewallRuleRequest(source.Rules[i]) + } + } + schemaFirewallActionSetRulesRequest.Rules = schemaFirewallRuleRequestList + return schemaFirewallActionSetRulesRequest +} +func (c *converterImpl) SchemaFromFloatingIP(source *FloatingIP) schema.FloatingIP { + var schemaFloatingIP schema.FloatingIP + if source != nil { + var schemaFloatingIP2 schema.FloatingIP + schemaFloatingIP2.ID = (*source).ID + pString := (*source).Description + schemaFloatingIP2.Description = &pString + schemaFloatingIP2.Created = c.timeTimeToTimeTime((*source).Created) + schemaFloatingIP2.IP = floatingIPToIPString((*source)) + schemaFloatingIP2.Type = string((*source).Type) + schemaFloatingIP2.Server = c.pHcloudServerToPInt64((*source).Server) + schemaFloatingIP2.DNSPtr = floatingIPDNSPtrSchemaFromMap((*source).DNSPtr) + schemaFloatingIP2.HomeLocation = c.SchemaFromLocation((*source).HomeLocation) + schemaFloatingIP2.Blocked = (*source).Blocked + schemaFloatingIP2.Protection = c.hcloudFloatingIPProtectionToSchemaFloatingIPProtection((*source).Protection) + schemaFloatingIP2.Labels = (*source).Labels + schemaFloatingIP2.Name = (*source).Name + schemaFloatingIP = schemaFloatingIP2 + } + return schemaFloatingIP +} +func (c *converterImpl) SchemaFromISO(source *ISO) schema.ISO { + var schemaISO schema.ISO + if source != nil { + var schemaISO2 schema.ISO + schemaISO2.ID = (*source).ID + schemaISO2.Name = (*source).Name + schemaISO2.Description = (*source).Description + schemaISO2.Type = string((*source).Type) + var pString *string + if (*source).Architecture != nil { + xstring := string(*(*source).Architecture) + pString = &xstring + } + schemaISO2.Architecture = pString + schemaISO2.DeprecatableResource = c.hcloudDeprecatableResourceToSchemaDeprecatableResource((*source).DeprecatableResource) + schemaISO = schemaISO2 + } + return schemaISO +} +func (c *converterImpl) SchemaFromImage(source *Image) schema.Image { + var schemaImage schema.Image + if source != nil { + schemaImage = c.intSchemaFromImage((*source)) + } + return schemaImage +} +func (c *converterImpl) SchemaFromLoadBalancer(source *LoadBalancer) schema.LoadBalancer { + var schemaLoadBalancer schema.LoadBalancer + if source != nil { + var schemaLoadBalancer2 schema.LoadBalancer + schemaLoadBalancer2.ID = (*source).ID + schemaLoadBalancer2.Name = (*source).Name + schemaLoadBalancer2.PublicNet = c.hcloudLoadBalancerPublicNetToSchemaLoadBalancerPublicNet((*source).PublicNet) + var schemaLoadBalancerPrivateNetList []schema.LoadBalancerPrivateNet + if (*source).PrivateNet != nil { + schemaLoadBalancerPrivateNetList = make([]schema.LoadBalancerPrivateNet, len((*source).PrivateNet)) + for i := 0; i < len((*source).PrivateNet); i++ { + schemaLoadBalancerPrivateNetList[i] = c.hcloudLoadBalancerPrivateNetToSchemaLoadBalancerPrivateNet((*source).PrivateNet[i]) + } + } + schemaLoadBalancer2.PrivateNet = schemaLoadBalancerPrivateNetList + schemaLoadBalancer2.Location = c.SchemaFromLocation((*source).Location) + schemaLoadBalancer2.LoadBalancerType = c.SchemaFromLoadBalancerType((*source).LoadBalancerType) + schemaLoadBalancer2.Protection = c.hcloudLoadBalancerProtectionToSchemaLoadBalancerProtection((*source).Protection) + schemaLoadBalancer2.Labels = (*source).Labels + schemaLoadBalancer2.Created = c.timeTimeToTimeTime((*source).Created) + var schemaLoadBalancerServiceList []schema.LoadBalancerService + if (*source).Services != nil { + schemaLoadBalancerServiceList = make([]schema.LoadBalancerService, len((*source).Services)) + for j := 0; j < len((*source).Services); j++ { + schemaLoadBalancerServiceList[j] = c.SchemaFromLoadBalancerService((*source).Services[j]) + } + } + schemaLoadBalancer2.Services = schemaLoadBalancerServiceList + var schemaLoadBalancerTargetList []schema.LoadBalancerTarget + if (*source).Targets != nil { + schemaLoadBalancerTargetList = make([]schema.LoadBalancerTarget, len((*source).Targets)) + for k := 0; k < len((*source).Targets); k++ { + schemaLoadBalancerTargetList[k] = c.SchemaFromLoadBalancerTarget((*source).Targets[k]) + } + } + schemaLoadBalancer2.Targets = schemaLoadBalancerTargetList + schemaLoadBalancer2.Algorithm = c.hcloudLoadBalancerAlgorithmToSchemaLoadBalancerAlgorithm((*source).Algorithm) + schemaLoadBalancer2.IncludedTraffic = (*source).IncludedTraffic + schemaLoadBalancer2.OutgoingTraffic = mapZeroUint64ToNil((*source).OutgoingTraffic) + schemaLoadBalancer2.IngoingTraffic = mapZeroUint64ToNil((*source).IngoingTraffic) + schemaLoadBalancer = schemaLoadBalancer2 + } + return schemaLoadBalancer +} +func (c *converterImpl) SchemaFromLoadBalancerAddServiceOpts(source LoadBalancerAddServiceOpts) schema.LoadBalancerActionAddServiceRequest { + var schemaLoadBalancerActionAddServiceRequest schema.LoadBalancerActionAddServiceRequest + schemaLoadBalancerActionAddServiceRequest.Protocol = string(source.Protocol) + schemaLoadBalancerActionAddServiceRequest.ListenPort = source.ListenPort + schemaLoadBalancerActionAddServiceRequest.DestinationPort = source.DestinationPort + schemaLoadBalancerActionAddServiceRequest.Proxyprotocol = source.Proxyprotocol + schemaLoadBalancerActionAddServiceRequest.HTTP = c.pHcloudLoadBalancerAddServiceOptsHTTPToPSchemaLoadBalancerActionAddServiceRequestHTTP(source.HTTP) + schemaLoadBalancerActionAddServiceRequest.HealthCheck = c.pHcloudLoadBalancerAddServiceOptsHealthCheckToPSchemaLoadBalancerActionAddServiceRequestHealthCheck(source.HealthCheck) + return schemaLoadBalancerActionAddServiceRequest +} +func (c *converterImpl) SchemaFromLoadBalancerCreateOpts(source LoadBalancerCreateOpts) schema.LoadBalancerCreateRequest { + var schemaLoadBalancerCreateRequest schema.LoadBalancerCreateRequest + schemaLoadBalancerCreateRequest.Name = source.Name + schemaLoadBalancerCreateRequest.LoadBalancerType = anyFromLoadBalancerType(source.LoadBalancerType) + schemaLoadBalancerCreateRequest.Algorithm = c.pHcloudLoadBalancerAlgorithmToPSchemaLoadBalancerCreateRequestAlgorithm(source.Algorithm) + schemaLoadBalancerCreateRequest.Location = c.pHcloudLocationToPString(source.Location) + schemaLoadBalancerCreateRequest.NetworkZone = stringPtrFromNetworkZone(source.NetworkZone) + schemaLoadBalancerCreateRequest.Labels = stringMapToStringMapPtr(source.Labels) + var schemaLoadBalancerCreateRequestTargetList []schema.LoadBalancerCreateRequestTarget + if source.Targets != nil { + schemaLoadBalancerCreateRequestTargetList = make([]schema.LoadBalancerCreateRequestTarget, len(source.Targets)) + for i := 0; i < len(source.Targets); i++ { + schemaLoadBalancerCreateRequestTargetList[i] = c.hcloudLoadBalancerCreateOptsTargetToSchemaLoadBalancerCreateRequestTarget(source.Targets[i]) + } + } + schemaLoadBalancerCreateRequest.Targets = schemaLoadBalancerCreateRequestTargetList + var schemaLoadBalancerCreateRequestServiceList []schema.LoadBalancerCreateRequestService + if source.Services != nil { + schemaLoadBalancerCreateRequestServiceList = make([]schema.LoadBalancerCreateRequestService, len(source.Services)) + for j := 0; j < len(source.Services); j++ { + schemaLoadBalancerCreateRequestServiceList[j] = c.hcloudLoadBalancerCreateOptsServiceToSchemaLoadBalancerCreateRequestService(source.Services[j]) + } + } + schemaLoadBalancerCreateRequest.Services = schemaLoadBalancerCreateRequestServiceList + schemaLoadBalancerCreateRequest.PublicInterface = source.PublicInterface + schemaLoadBalancerCreateRequest.Network = c.pHcloudNetworkToPInt64(source.Network) + return schemaLoadBalancerCreateRequest +} +func (c *converterImpl) SchemaFromLoadBalancerCreateOptsTargetServer(source LoadBalancerCreateOptsTargetServer) schema.LoadBalancerCreateRequestTargetServer { + var schemaLoadBalancerCreateRequestTargetServer schema.LoadBalancerCreateRequestTargetServer + var pInt64 *int64 + if source.Server != nil { + pInt64 = &source.Server.ID + } + var xint64 int64 + if pInt64 != nil { + xint64 = *pInt64 + } + schemaLoadBalancerCreateRequestTargetServer.ID = xint64 + return schemaLoadBalancerCreateRequestTargetServer +} +func (c *converterImpl) SchemaFromLoadBalancerServerTarget(source LoadBalancerTargetServer) schema.LoadBalancerTargetServer { + var schemaLoadBalancerTargetServer schema.LoadBalancerTargetServer + schemaLoadBalancerTargetServer.ID = c.pHcloudServerToInt64(source.Server) + return schemaLoadBalancerTargetServer +} +func (c *converterImpl) SchemaFromLoadBalancerService(source LoadBalancerService) schema.LoadBalancerService { + var schemaLoadBalancerService schema.LoadBalancerService + schemaLoadBalancerService.Protocol = string(source.Protocol) + schemaLoadBalancerService.ListenPort = source.ListenPort + schemaLoadBalancerService.DestinationPort = source.DestinationPort + schemaLoadBalancerService.Proxyprotocol = source.Proxyprotocol + schemaLoadBalancerService.HTTP = c.hcloudLoadBalancerServiceHTTPToPSchemaLoadBalancerServiceHTTP(source.HTTP) + schemaLoadBalancerService.HealthCheck = c.SchemaFromLoadBalancerServiceHealthCheck(source.HealthCheck) + return schemaLoadBalancerService +} +func (c *converterImpl) SchemaFromLoadBalancerServiceHealthCheck(source LoadBalancerServiceHealthCheck) *schema.LoadBalancerServiceHealthCheck { + var schemaLoadBalancerServiceHealthCheck schema.LoadBalancerServiceHealthCheck + schemaLoadBalancerServiceHealthCheck.Protocol = string(source.Protocol) + schemaLoadBalancerServiceHealthCheck.Port = source.Port + schemaLoadBalancerServiceHealthCheck.Interval = intSecondsFromDuration(source.Interval) + schemaLoadBalancerServiceHealthCheck.Timeout = intSecondsFromDuration(source.Timeout) + schemaLoadBalancerServiceHealthCheck.Retries = source.Retries + schemaLoadBalancerServiceHealthCheck.HTTP = c.pHcloudLoadBalancerServiceHealthCheckHTTPToPSchemaLoadBalancerServiceHealthCheckHTTP(source.HTTP) + return &schemaLoadBalancerServiceHealthCheck +} +func (c *converterImpl) SchemaFromLoadBalancerTarget(source LoadBalancerTarget) schema.LoadBalancerTarget { + var schemaLoadBalancerTarget schema.LoadBalancerTarget + schemaLoadBalancerTarget.Type = string(source.Type) + schemaLoadBalancerTarget.Server = c.pHcloudLoadBalancerTargetServerToPSchemaLoadBalancerTargetServer(source.Server) + schemaLoadBalancerTarget.LabelSelector = c.pHcloudLoadBalancerTargetLabelSelectorToPSchemaLoadBalancerTargetLabelSelector(source.LabelSelector) + schemaLoadBalancerTarget.IP = c.pHcloudLoadBalancerTargetIPToPSchemaLoadBalancerTargetIP(source.IP) + var schemaLoadBalancerTargetHealthStatusList []schema.LoadBalancerTargetHealthStatus + if source.HealthStatus != nil { + schemaLoadBalancerTargetHealthStatusList = make([]schema.LoadBalancerTargetHealthStatus, len(source.HealthStatus)) + for i := 0; i < len(source.HealthStatus); i++ { + schemaLoadBalancerTargetHealthStatusList[i] = c.SchemaFromLoadBalancerTargetHealthStatus(source.HealthStatus[i]) + } + } + schemaLoadBalancerTarget.HealthStatus = schemaLoadBalancerTargetHealthStatusList + schemaLoadBalancerTarget.UsePrivateIP = source.UsePrivateIP + var schemaLoadBalancerTargetList []schema.LoadBalancerTarget + if source.Targets != nil { + schemaLoadBalancerTargetList = make([]schema.LoadBalancerTarget, len(source.Targets)) + for j := 0; j < len(source.Targets); j++ { + schemaLoadBalancerTargetList[j] = c.SchemaFromLoadBalancerTarget(source.Targets[j]) + } + } + schemaLoadBalancerTarget.Targets = schemaLoadBalancerTargetList + return schemaLoadBalancerTarget +} +func (c *converterImpl) SchemaFromLoadBalancerTargetHealthStatus(source LoadBalancerTargetHealthStatus) schema.LoadBalancerTargetHealthStatus { + var schemaLoadBalancerTargetHealthStatus schema.LoadBalancerTargetHealthStatus + schemaLoadBalancerTargetHealthStatus.ListenPort = source.ListenPort + schemaLoadBalancerTargetHealthStatus.Status = string(source.Status) + return schemaLoadBalancerTargetHealthStatus +} +func (c *converterImpl) SchemaFromLoadBalancerType(source *LoadBalancerType) schema.LoadBalancerType { + var schemaLoadBalancerType schema.LoadBalancerType + if source != nil { + var schemaLoadBalancerType2 schema.LoadBalancerType + schemaLoadBalancerType2.ID = (*source).ID + schemaLoadBalancerType2.Name = (*source).Name + schemaLoadBalancerType2.Description = (*source).Description + schemaLoadBalancerType2.MaxConnections = (*source).MaxConnections + schemaLoadBalancerType2.MaxServices = (*source).MaxServices + schemaLoadBalancerType2.MaxTargets = (*source).MaxTargets + schemaLoadBalancerType2.MaxAssignedCertificates = (*source).MaxAssignedCertificates + var schemaPricingLoadBalancerTypePriceList []schema.PricingLoadBalancerTypePrice + if (*source).Pricings != nil { + schemaPricingLoadBalancerTypePriceList = make([]schema.PricingLoadBalancerTypePrice, len((*source).Pricings)) + for i := 0; i < len((*source).Pricings); i++ { + schemaPricingLoadBalancerTypePriceList[i] = c.SchemaFromLoadBalancerTypeLocationPricing((*source).Pricings[i]) + } + } + schemaLoadBalancerType2.Prices = schemaPricingLoadBalancerTypePriceList + schemaLoadBalancerType2.Deprecated = (*source).Deprecated + schemaLoadBalancerType = schemaLoadBalancerType2 + } + return schemaLoadBalancerType +} +func (c *converterImpl) SchemaFromLoadBalancerTypeLocationPricing(source LoadBalancerTypeLocationPricing) schema.PricingLoadBalancerTypePrice { + var schemaPricingLoadBalancerTypePrice schema.PricingLoadBalancerTypePrice + schemaPricingLoadBalancerTypePrice.Location = c.pHcloudLocationToString(source.Location) + schemaPricingLoadBalancerTypePrice.PriceHourly = c.hcloudPriceToSchemaPrice(source.Hourly) + schemaPricingLoadBalancerTypePrice.PriceMonthly = c.hcloudPriceToSchemaPrice(source.Monthly) + return schemaPricingLoadBalancerTypePrice +} +func (c *converterImpl) SchemaFromLoadBalancerUpdateServiceOpts(source LoadBalancerUpdateServiceOpts) schema.LoadBalancerActionUpdateServiceRequest { + var schemaLoadBalancerActionUpdateServiceRequest schema.LoadBalancerActionUpdateServiceRequest + schemaLoadBalancerActionUpdateServiceRequest.Protocol = stringPtrFromLoadBalancerServiceProtocol(source.Protocol) + schemaLoadBalancerActionUpdateServiceRequest.DestinationPort = source.DestinationPort + schemaLoadBalancerActionUpdateServiceRequest.Proxyprotocol = source.Proxyprotocol + schemaLoadBalancerActionUpdateServiceRequest.HTTP = c.pHcloudLoadBalancerUpdateServiceOptsHTTPToPSchemaLoadBalancerActionUpdateServiceRequestHTTP(source.HTTP) + schemaLoadBalancerActionUpdateServiceRequest.HealthCheck = c.pHcloudLoadBalancerUpdateServiceOptsHealthCheckToPSchemaLoadBalancerActionUpdateServiceRequestHealthCheck(source.HealthCheck) + return schemaLoadBalancerActionUpdateServiceRequest +} +func (c *converterImpl) SchemaFromLocation(source *Location) schema.Location { + var schemaLocation schema.Location + if source != nil { + var schemaLocation2 schema.Location + schemaLocation2.ID = (*source).ID + schemaLocation2.Name = (*source).Name + schemaLocation2.Description = (*source).Description + schemaLocation2.Country = (*source).Country + schemaLocation2.City = (*source).City + schemaLocation2.Latitude = (*source).Latitude + schemaLocation2.Longitude = (*source).Longitude + schemaLocation2.NetworkZone = string((*source).NetworkZone) + schemaLocation = schemaLocation2 + } + return schemaLocation +} +func (c *converterImpl) SchemaFromNetwork(source *Network) schema.Network { + var schemaNetwork schema.Network + if source != nil { + var schemaNetwork2 schema.Network + schemaNetwork2.ID = (*source).ID + schemaNetwork2.Name = (*source).Name + schemaNetwork2.Created = c.timeTimeToTimeTime((*source).Created) + schemaNetwork2.IPRange = c.pNetIPNetToString((*source).IPRange) + var schemaNetworkSubnetList []schema.NetworkSubnet + if (*source).Subnets != nil { + schemaNetworkSubnetList = make([]schema.NetworkSubnet, len((*source).Subnets)) + for i := 0; i < len((*source).Subnets); i++ { + schemaNetworkSubnetList[i] = c.SchemaFromNetworkSubnet((*source).Subnets[i]) + } + } + schemaNetwork2.Subnets = schemaNetworkSubnetList + var schemaNetworkRouteList []schema.NetworkRoute + if (*source).Routes != nil { + schemaNetworkRouteList = make([]schema.NetworkRoute, len((*source).Routes)) + for j := 0; j < len((*source).Routes); j++ { + schemaNetworkRouteList[j] = c.SchemaFromNetworkRoute((*source).Routes[j]) + } + } + schemaNetwork2.Routes = schemaNetworkRouteList + var int64List []int64 + if (*source).Servers != nil { + int64List = make([]int64, len((*source).Servers)) + for k := 0; k < len((*source).Servers); k++ { + int64List[k] = c.pHcloudServerToInt64((*source).Servers[k]) + } + } + schemaNetwork2.Servers = int64List + schemaNetwork2.Protection = c.hcloudNetworkProtectionToSchemaNetworkProtection((*source).Protection) + schemaNetwork2.Labels = (*source).Labels + schemaNetwork2.ExposeRoutesToVSwitch = (*source).ExposeRoutesToVSwitch + schemaNetwork = schemaNetwork2 + } + return schemaNetwork +} +func (c *converterImpl) SchemaFromNetworkRoute(source NetworkRoute) schema.NetworkRoute { + var schemaNetworkRoute schema.NetworkRoute + schemaNetworkRoute.Destination = c.pNetIPNetToString(source.Destination) + schemaNetworkRoute.Gateway = stringFromIP(source.Gateway) + return schemaNetworkRoute +} +func (c *converterImpl) SchemaFromNetworkSubnet(source NetworkSubnet) schema.NetworkSubnet { + var schemaNetworkSubnet schema.NetworkSubnet + schemaNetworkSubnet.Type = string(source.Type) + schemaNetworkSubnet.IPRange = c.pNetIPNetToString(source.IPRange) + schemaNetworkSubnet.NetworkZone = string(source.NetworkZone) + schemaNetworkSubnet.Gateway = stringFromIP(source.Gateway) + schemaNetworkSubnet.VSwitchID = source.VSwitchID + return schemaNetworkSubnet +} +func (c *converterImpl) SchemaFromPagination(source Pagination) schema.MetaPagination { + var schemaMetaPagination schema.MetaPagination + schemaMetaPagination.Page = source.Page + schemaMetaPagination.PerPage = source.PerPage + schemaMetaPagination.PreviousPage = source.PreviousPage + schemaMetaPagination.NextPage = source.NextPage + schemaMetaPagination.LastPage = source.LastPage + schemaMetaPagination.TotalEntries = source.TotalEntries + return schemaMetaPagination +} +func (c *converterImpl) SchemaFromPlacementGroup(source *PlacementGroup) schema.PlacementGroup { + var schemaPlacementGroup schema.PlacementGroup + if source != nil { + var schemaPlacementGroup2 schema.PlacementGroup + schemaPlacementGroup2.ID = (*source).ID + schemaPlacementGroup2.Name = (*source).Name + schemaPlacementGroup2.Labels = (*source).Labels + schemaPlacementGroup2.Created = c.timeTimeToTimeTime((*source).Created) + schemaPlacementGroup2.Servers = (*source).Servers + schemaPlacementGroup2.Type = string((*source).Type) + schemaPlacementGroup = schemaPlacementGroup2 + } + return schemaPlacementGroup +} +func (c *converterImpl) SchemaFromPlacementGroupCreateOpts(source PlacementGroupCreateOpts) schema.PlacementGroupCreateRequest { + var schemaPlacementGroupCreateRequest schema.PlacementGroupCreateRequest + schemaPlacementGroupCreateRequest.Name = source.Name + schemaPlacementGroupCreateRequest.Labels = stringMapToStringMapPtr(source.Labels) + schemaPlacementGroupCreateRequest.Type = string(source.Type) + return schemaPlacementGroupCreateRequest +} +func (c *converterImpl) SchemaFromPricing(source Pricing) schema.Pricing { + var schemaPricing schema.Pricing + schemaPricing.Currency = source.Image.PerGBMonth.Currency + schemaPricing.VATRate = source.Image.PerGBMonth.VATRate + schemaPricing.Image = c.schemaFromImagePricing(source.Image) + schemaPricing.FloatingIP = c.schemaFromFloatingIPPricing(source.FloatingIP) + var schemaPricingFloatingIPTypeList []schema.PricingFloatingIPType + if source.FloatingIPs != nil { + schemaPricingFloatingIPTypeList = make([]schema.PricingFloatingIPType, len(source.FloatingIPs)) + for i := 0; i < len(source.FloatingIPs); i++ { + schemaPricingFloatingIPTypeList[i] = c.schemaFromFloatingIPTypePricing(source.FloatingIPs[i]) + } + } + schemaPricing.FloatingIPs = schemaPricingFloatingIPTypeList + var schemaPricingPrimaryIPList []schema.PricingPrimaryIP + if source.PrimaryIPs != nil { + schemaPricingPrimaryIPList = make([]schema.PricingPrimaryIP, len(source.PrimaryIPs)) + for j := 0; j < len(source.PrimaryIPs); j++ { + schemaPricingPrimaryIPList[j] = c.schemaFromPrimaryIPPricing(source.PrimaryIPs[j]) + } + } + schemaPricing.PrimaryIPs = schemaPricingPrimaryIPList + schemaPricing.Traffic = c.schemaFromTrafficPricing(source.Traffic) + schemaPricing.ServerBackup = c.hcloudServerBackupPricingToSchemaPricingServerBackup(source.ServerBackup) + var schemaPricingServerTypeList []schema.PricingServerType + if source.ServerTypes != nil { + schemaPricingServerTypeList = make([]schema.PricingServerType, len(source.ServerTypes)) + for k := 0; k < len(source.ServerTypes); k++ { + schemaPricingServerTypeList[k] = c.schemaFromServerTypePricing(source.ServerTypes[k]) + } + } + schemaPricing.ServerTypes = schemaPricingServerTypeList + var schemaPricingLoadBalancerTypeList []schema.PricingLoadBalancerType + if source.LoadBalancerTypes != nil { + schemaPricingLoadBalancerTypeList = make([]schema.PricingLoadBalancerType, len(source.LoadBalancerTypes)) + for l := 0; l < len(source.LoadBalancerTypes); l++ { + schemaPricingLoadBalancerTypeList[l] = c.schemaFromLoadBalancerTypePricing(source.LoadBalancerTypes[l]) + } + } + schemaPricing.LoadBalancerTypes = schemaPricingLoadBalancerTypeList + schemaPricing.Volume = c.schemaFromVolumePricing(source.Volume) + return schemaPricing +} +func (c *converterImpl) SchemaFromPrimaryIP(source *PrimaryIP) schema.PrimaryIP { + var schemaPrimaryIP schema.PrimaryIP + if source != nil { + var schemaPrimaryIP2 schema.PrimaryIP + schemaPrimaryIP2.ID = (*source).ID + schemaPrimaryIP2.IP = primaryIPToIPString((*source)) + schemaPrimaryIP2.Labels = (*source).Labels + schemaPrimaryIP2.Name = (*source).Name + schemaPrimaryIP2.Type = string((*source).Type) + schemaPrimaryIP2.Protection = c.hcloudPrimaryIPProtectionToSchemaPrimaryIPProtection((*source).Protection) + schemaPrimaryIP2.DNSPtr = primaryIPDNSPtrSchemaFromMap((*source).DNSPtr) + schemaPrimaryIP2.AssigneeID = mapZeroInt64ToNil((*source).AssigneeID) + schemaPrimaryIP2.AssigneeType = (*source).AssigneeType + schemaPrimaryIP2.AutoDelete = (*source).AutoDelete + schemaPrimaryIP2.Blocked = (*source).Blocked + schemaPrimaryIP2.Created = c.timeTimeToTimeTime((*source).Created) + schemaPrimaryIP2.Datacenter = c.SchemaFromDatacenter((*source).Datacenter) + schemaPrimaryIP = schemaPrimaryIP2 + } + return schemaPrimaryIP +} +func (c *converterImpl) SchemaFromSSHKey(source *SSHKey) schema.SSHKey { + var schemaSSHKey schema.SSHKey + if source != nil { + var schemaSSHKey2 schema.SSHKey + schemaSSHKey2.ID = (*source).ID + schemaSSHKey2.Name = (*source).Name + schemaSSHKey2.Fingerprint = (*source).Fingerprint + schemaSSHKey2.PublicKey = (*source).PublicKey + schemaSSHKey2.Labels = (*source).Labels + schemaSSHKey2.Created = c.timeTimeToTimeTime((*source).Created) + schemaSSHKey = schemaSSHKey2 + } + return schemaSSHKey +} +func (c *converterImpl) SchemaFromServer(source *Server) schema.Server { + var schemaServer schema.Server + if source != nil { + var schemaServer2 schema.Server + schemaServer2.ID = (*source).ID + schemaServer2.Name = (*source).Name + schemaServer2.Status = string((*source).Status) + schemaServer2.Created = c.timeTimeToTimeTime((*source).Created) + schemaServer2.PublicNet = c.SchemaFromServerPublicNet((*source).PublicNet) + var schemaServerPrivateNetList []schema.ServerPrivateNet + if (*source).PrivateNet != nil { + schemaServerPrivateNetList = make([]schema.ServerPrivateNet, len((*source).PrivateNet)) + for i := 0; i < len((*source).PrivateNet); i++ { + schemaServerPrivateNetList[i] = c.SchemaFromServerPrivateNet((*source).PrivateNet[i]) + } + } + schemaServer2.PrivateNet = schemaServerPrivateNetList + schemaServer2.ServerType = c.SchemaFromServerType((*source).ServerType) + schemaServer2.IncludedTraffic = (*source).IncludedTraffic + schemaServer2.OutgoingTraffic = mapZeroUint64ToNil((*source).OutgoingTraffic) + schemaServer2.IngoingTraffic = mapZeroUint64ToNil((*source).IngoingTraffic) + schemaServer2.BackupWindow = mapEmptyStringToNil((*source).BackupWindow) + schemaServer2.RescueEnabled = (*source).RescueEnabled + schemaServer2.ISO = c.pHcloudISOToPSchemaISO((*source).ISO) + schemaServer2.Locked = (*source).Locked + schemaServer2.Datacenter = c.SchemaFromDatacenter((*source).Datacenter) + schemaServer2.Image = c.pHcloudImageToPSchemaImage((*source).Image) + schemaServer2.Protection = c.hcloudServerProtectionToSchemaServerProtection((*source).Protection) + schemaServer2.Labels = (*source).Labels + var int64List []int64 + if (*source).Volumes != nil { + int64List = make([]int64, len((*source).Volumes)) + for j := 0; j < len((*source).Volumes); j++ { + int64List[j] = int64FromVolume((*source).Volumes[j]) + } + } + 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 +} +func (c *converterImpl) SchemaFromServerPrivateNet(source ServerPrivateNet) schema.ServerPrivateNet { + var schemaServerPrivateNet schema.ServerPrivateNet + schemaServerPrivateNet.Network = c.pHcloudNetworkToInt64(source.Network) + schemaServerPrivateNet.IP = stringFromIP(source.IP) + var stringList []string + if source.Aliases != nil { + stringList = make([]string, len(source.Aliases)) + for i := 0; i < len(source.Aliases); i++ { + stringList[i] = stringFromIP(source.Aliases[i]) + } + } + schemaServerPrivateNet.AliasIPs = stringList + schemaServerPrivateNet.MACAddress = source.MACAddress + return schemaServerPrivateNet +} +func (c *converterImpl) SchemaFromServerPublicNet(source ServerPublicNet) schema.ServerPublicNet { + var schemaServerPublicNet schema.ServerPublicNet + schemaServerPublicNet.IPv4 = c.SchemaFromServerPublicNetIPv4(source.IPv4) + schemaServerPublicNet.IPv6 = c.SchemaFromServerPublicNetIPv6(source.IPv6) + var int64List []int64 + if source.FloatingIPs != nil { + int64List = make([]int64, len(source.FloatingIPs)) + for i := 0; i < len(source.FloatingIPs); i++ { + int64List[i] = int64FromFloatingIP(source.FloatingIPs[i]) + } + } + schemaServerPublicNet.FloatingIPs = int64List + var schemaServerFirewallList []schema.ServerFirewall + if source.Firewalls != nil { + schemaServerFirewallList = make([]schema.ServerFirewall, len(source.Firewalls)) + for j := 0; j < len(source.Firewalls); j++ { + schemaServerFirewallList[j] = serverFirewallSchemaFromFirewallStatus(source.Firewalls[j]) + } + } + schemaServerPublicNet.Firewalls = schemaServerFirewallList + return schemaServerPublicNet +} +func (c *converterImpl) SchemaFromServerPublicNetIPv4(source ServerPublicNetIPv4) schema.ServerPublicNetIPv4 { + var schemaServerPublicNetIPv4 schema.ServerPublicNetIPv4 + schemaServerPublicNetIPv4.ID = source.ID + schemaServerPublicNetIPv4.IP = stringFromIP(source.IP) + schemaServerPublicNetIPv4.Blocked = source.Blocked + schemaServerPublicNetIPv4.DNSPtr = source.DNSPtr + return schemaServerPublicNetIPv4 +} +func (c *converterImpl) SchemaFromServerPublicNetIPv6(source ServerPublicNetIPv6) schema.ServerPublicNetIPv6 { + var schemaServerPublicNetIPv6 schema.ServerPublicNetIPv6 + schemaServerPublicNetIPv6.ID = source.ID + schemaServerPublicNetIPv6.IP = c.pNetIPNetToString(source.Network) + schemaServerPublicNetIPv6.Blocked = source.Blocked + schemaServerPublicNetIPv6.DNSPtr = serverPublicNetIPv6DNSPtrSchemaFromMap(source.DNSPtr) + return schemaServerPublicNetIPv6 +} +func (c *converterImpl) SchemaFromServerType(source *ServerType) schema.ServerType { + var schemaServerType schema.ServerType + if source != nil { + var schemaServerType2 schema.ServerType + schemaServerType2.ID = (*source).ID + schemaServerType2.Name = (*source).Name + schemaServerType2.Description = (*source).Description + schemaServerType2.Cores = (*source).Cores + schemaServerType2.Memory = (*source).Memory + schemaServerType2.Disk = (*source).Disk + schemaServerType2.StorageType = string((*source).StorageType) + schemaServerType2.CPUType = string((*source).CPUType) + schemaServerType2.Architecture = string((*source).Architecture) + schemaServerType2.IncludedTraffic = (*source).IncludedTraffic + var schemaPricingServerTypePriceList []schema.PricingServerTypePrice + if (*source).Pricings != nil { + schemaPricingServerTypePriceList = make([]schema.PricingServerTypePrice, len((*source).Pricings)) + for i := 0; i < len((*source).Pricings); i++ { + schemaPricingServerTypePriceList[i] = c.schemaFromServerTypeLocationPricing((*source).Pricings[i]) + } + } + schemaServerType2.Prices = schemaPricingServerTypePriceList + schemaServerType2.Deprecated = isDeprecationNotNil((*source).DeprecatableResource.Deprecation) + schemaServerType2.DeprecatableResource = c.hcloudDeprecatableResourceToSchemaDeprecatableResource((*source).DeprecatableResource) + schemaServerType = schemaServerType2 + } + return schemaServerType +} +func (c *converterImpl) SchemaFromVolume(source *Volume) schema.Volume { + var schemaVolume schema.Volume + if source != nil { + var schemaVolume2 schema.Volume + schemaVolume2.ID = (*source).ID + schemaVolume2.Name = (*source).Name + schemaVolume2.Server = c.pHcloudServerToPInt64((*source).Server) + schemaVolume2.Status = string((*source).Status) + schemaVolume2.Location = c.SchemaFromLocation((*source).Location) + schemaVolume2.Size = (*source).Size + schemaVolume2.Format = (*source).Format + schemaVolume2.Protection = c.hcloudVolumeProtectionToSchemaVolumeProtection((*source).Protection) + schemaVolume2.Labels = (*source).Labels + schemaVolume2.LinuxDevice = (*source).LinuxDevice + schemaVolume2.Created = c.timeTimeToTimeTime((*source).Created) + schemaVolume = schemaVolume2 + } + return schemaVolume +} +func (c *converterImpl) ServerFromSchema(source schema.Server) *Server { + var hcloudServer Server + hcloudServer.ID = source.ID + hcloudServer.Name = source.Name + hcloudServer.Status = ServerStatus(source.Status) + hcloudServer.Created = c.timeTimeToTimeTime(source.Created) + hcloudServer.PublicNet = c.ServerPublicNetFromSchema(source.PublicNet) + var hcloudServerPrivateNetList []ServerPrivateNet + if source.PrivateNet != nil { + hcloudServerPrivateNetList = make([]ServerPrivateNet, len(source.PrivateNet)) + for i := 0; i < len(source.PrivateNet); i++ { + hcloudServerPrivateNetList[i] = c.ServerPrivateNetFromSchema(source.PrivateNet[i]) + } + } + hcloudServer.PrivateNet = hcloudServerPrivateNetList + hcloudServer.ServerType = c.ServerTypeFromSchema(source.ServerType) + hcloudServer.Datacenter = c.DatacenterFromSchema(source.Datacenter) + hcloudServer.IncludedTraffic = source.IncludedTraffic + var xuint64 uint64 + if source.OutgoingTraffic != nil { + xuint64 = *source.OutgoingTraffic + } + hcloudServer.OutgoingTraffic = xuint64 + var xuint642 uint64 + if source.IngoingTraffic != nil { + xuint642 = *source.IngoingTraffic + } + hcloudServer.IngoingTraffic = xuint642 + var xstring string + if source.BackupWindow != nil { + xstring = *source.BackupWindow + } + hcloudServer.BackupWindow = xstring + hcloudServer.RescueEnabled = source.RescueEnabled + hcloudServer.Locked = source.Locked + hcloudServer.ISO = c.pSchemaISOToPHcloudISO(source.ISO) + hcloudServer.Image = c.pSchemaImageToPHcloudImage(source.Image) + hcloudServer.Protection = c.schemaServerProtectionToHcloudServerProtection(source.Protection) + hcloudServer.Labels = source.Labels + var pHcloudVolumeList []*Volume + if source.Volumes != nil { + pHcloudVolumeList = make([]*Volume, len(source.Volumes)) + for j := 0; j < len(source.Volumes); j++ { + pHcloudVolumeList[j] = volumeFromInt64(source.Volumes[j]) + } + } + 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) { + var pHcloudServerMetrics *ServerMetrics + if source != nil { + var hcloudServerMetrics ServerMetrics + hcloudServerMetrics.Start = c.timeTimeToTimeTime((*source).Metrics.Start) + hcloudServerMetrics.End = c.timeTimeToTimeTime((*source).Metrics.End) + hcloudServerMetrics.Step = (*source).Metrics.Step + var mapStringHcloudServerMetricsValueList map[string][]ServerMetricsValue + if (*source).Metrics.TimeSeries != nil { + mapStringHcloudServerMetricsValueList = make(map[string][]ServerMetricsValue, len((*source).Metrics.TimeSeries)) + for key, value := range (*source).Metrics.TimeSeries { + hcloudServerMetricsValueList, err := serverMetricsTimeSeriesFromSchema(value) + if err != nil { + return nil, err + } + mapStringHcloudServerMetricsValueList[key] = hcloudServerMetricsValueList + } + } + hcloudServerMetrics.TimeSeries = mapStringHcloudServerMetricsValueList + pHcloudServerMetrics = &hcloudServerMetrics + } + return pHcloudServerMetrics, nil +} +func (c *converterImpl) ServerPrivateNetFromSchema(source schema.ServerPrivateNet) ServerPrivateNet { + var hcloudServerPrivateNet ServerPrivateNet + hcloudNetwork := networkFromInt64(source.Network) + hcloudServerPrivateNet.Network = &hcloudNetwork + hcloudServerPrivateNet.IP = ipFromString(source.IP) + var netIPList []net.IP + if source.AliasIPs != nil { + netIPList = make([]net.IP, len(source.AliasIPs)) + for i := 0; i < len(source.AliasIPs); i++ { + netIPList[i] = ipFromString(source.AliasIPs[i]) + } + } + hcloudServerPrivateNet.Aliases = netIPList + hcloudServerPrivateNet.MACAddress = source.MACAddress + return hcloudServerPrivateNet +} +func (c *converterImpl) ServerPublicNetFromSchema(source schema.ServerPublicNet) ServerPublicNet { + var hcloudServerPublicNet ServerPublicNet + hcloudServerPublicNet.IPv4 = c.ServerPublicNetIPv4FromSchema(source.IPv4) + hcloudServerPublicNet.IPv6 = c.ServerPublicNetIPv6FromSchema(source.IPv6) + var pHcloudFloatingIPList []*FloatingIP + if source.FloatingIPs != nil { + pHcloudFloatingIPList = make([]*FloatingIP, len(source.FloatingIPs)) + for i := 0; i < len(source.FloatingIPs); i++ { + pHcloudFloatingIPList[i] = floatingIPFromInt64(source.FloatingIPs[i]) + } + } + hcloudServerPublicNet.FloatingIPs = pHcloudFloatingIPList + var pHcloudServerFirewallStatusList []*ServerFirewallStatus + if source.Firewalls != nil { + pHcloudServerFirewallStatusList = make([]*ServerFirewallStatus, len(source.Firewalls)) + for j := 0; j < len(source.Firewalls); j++ { + pHcloudServerFirewallStatusList[j] = firewallStatusFromSchemaServerFirewall(source.Firewalls[j]) + } + } + hcloudServerPublicNet.Firewalls = pHcloudServerFirewallStatusList + return hcloudServerPublicNet +} +func (c *converterImpl) ServerPublicNetIPv4FromSchema(source schema.ServerPublicNetIPv4) ServerPublicNetIPv4 { + var hcloudServerPublicNetIPv4 ServerPublicNetIPv4 + hcloudServerPublicNetIPv4.ID = source.ID + hcloudServerPublicNetIPv4.IP = ipFromString(source.IP) + hcloudServerPublicNetIPv4.Blocked = source.Blocked + hcloudServerPublicNetIPv4.DNSPtr = source.DNSPtr + return hcloudServerPublicNetIPv4 +} +func (c *converterImpl) ServerPublicNetIPv6FromSchema(source schema.ServerPublicNetIPv6) ServerPublicNetIPv6 { + var hcloudServerPublicNetIPv6 ServerPublicNetIPv6 + hcloudServerPublicNetIPv6.ID = source.ID + hcloudServerPublicNetIPv6.IP = ipFromServerPublicNetIPv6Schema(source) + hcloudServerPublicNetIPv6.Network = ipNetFromServerPublicNetIPv6Schema(source) + hcloudServerPublicNetIPv6.Blocked = source.Blocked + hcloudServerPublicNetIPv6.DNSPtr = mapFromServerPublicNetIPv6DNSPtrSchema(source.DNSPtr) + return hcloudServerPublicNetIPv6 +} +func (c *converterImpl) ServerTypeFromSchema(source schema.ServerType) *ServerType { + var hcloudServerType ServerType + hcloudServerType.ID = source.ID + hcloudServerType.Name = source.Name + hcloudServerType.Description = source.Description + hcloudServerType.Cores = source.Cores + hcloudServerType.Memory = source.Memory + hcloudServerType.Disk = source.Disk + hcloudServerType.StorageType = StorageType(source.StorageType) + hcloudServerType.CPUType = CPUType(source.CPUType) + hcloudServerType.Architecture = Architecture(source.Architecture) + hcloudServerType.IncludedTraffic = source.IncludedTraffic + var hcloudServerTypeLocationPricingList []ServerTypeLocationPricing + if source.Prices != nil { + hcloudServerTypeLocationPricingList = make([]ServerTypeLocationPricing, len(source.Prices)) + for i := 0; i < len(source.Prices); i++ { + hcloudServerTypeLocationPricingList[i] = c.serverTypePricingFromSchema(source.Prices[i]) + } + } + hcloudServerType.Pricings = hcloudServerTypeLocationPricingList + hcloudServerType.DeprecatableResource = c.schemaDeprecatableResourceToHcloudDeprecatableResource(source.DeprecatableResource) + return &hcloudServerType +} +func (c *converterImpl) VolumeFromSchema(source schema.Volume) *Volume { + var hcloudVolume Volume + hcloudVolume.ID = source.ID + hcloudVolume.Name = source.Name + hcloudVolume.Status = VolumeStatus(source.Status) + var pHcloudServer *Server + if source.Server != nil { + hcloudServer := serverFromInt64(*source.Server) + pHcloudServer = &hcloudServer + } + hcloudVolume.Server = pHcloudServer + hcloudVolume.Location = c.LocationFromSchema(source.Location) + hcloudVolume.Size = source.Size + hcloudVolume.Format = source.Format + hcloudVolume.Protection = c.schemaVolumeProtectionToHcloudVolumeProtection(source.Protection) + hcloudVolume.Labels = source.Labels + hcloudVolume.LinuxDevice = source.LinuxDevice + hcloudVolume.Created = c.timeTimeToTimeTime(source.Created) + return &hcloudVolume +} +func (c *converterImpl) hcloudCertificateStatusTypeToString(source CertificateStatusType) string { + return string(source) +} +func (c *converterImpl) hcloudCertificateUsedByRefToSchemaCertificateUsedByRef(source CertificateUsedByRef) schema.CertificateUsedByRef { + var schemaCertificateUsedByRef schema.CertificateUsedByRef + schemaCertificateUsedByRef.ID = source.ID + schemaCertificateUsedByRef.Type = string(source.Type) + return schemaCertificateUsedByRef +} +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)) + for i := 0; i < len(source.Supported); i++ { + int64List[i] = int64FromServerType(source.Supported[i]) + } + } + 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 { + int64List3 = make([]int64, len(source.Available)) + for k := 0; k < len(source.Available); k++ { + int64List3[k] = int64FromServerType(source.Available[k]) + } + } + schemaDatacenterServerTypes.Available = int64List3 + return schemaDatacenterServerTypes +} +func (c *converterImpl) hcloudDeprecatableResourceToSchemaDeprecatableResource(source DeprecatableResource) schema.DeprecatableResource { + var schemaDeprecatableResource schema.DeprecatableResource + schemaDeprecatableResource.Deprecation = c.SchemaFromDeprecation(source.Deprecation) + return schemaDeprecatableResource +} +func (c *converterImpl) hcloudFirewallRuleToSchemaFirewallRule(source FirewallRule) schema.FirewallRule { + var schemaFirewallRule schema.FirewallRule + schemaFirewallRule.Direction = string(source.Direction) + var stringList []string + if source.SourceIPs != nil { + stringList = make([]string, len(source.SourceIPs)) + for i := 0; i < len(source.SourceIPs); i++ { + stringList[i] = stringFromIPNet(source.SourceIPs[i]) + } + } + schemaFirewallRule.SourceIPs = stringList + var stringList2 []string + if source.DestinationIPs != nil { + stringList2 = make([]string, len(source.DestinationIPs)) + for j := 0; j < len(source.DestinationIPs); j++ { + stringList2[j] = stringFromIPNet(source.DestinationIPs[j]) + } + } + schemaFirewallRule.DestinationIPs = stringList2 + schemaFirewallRule.Protocol = string(source.Protocol) + schemaFirewallRule.Port = source.Port + schemaFirewallRule.Description = source.Description + return schemaFirewallRule +} +func (c *converterImpl) hcloudFirewallRuleToSchemaFirewallRuleRequest(source FirewallRule) schema.FirewallRuleRequest { + var schemaFirewallRuleRequest schema.FirewallRuleRequest + schemaFirewallRuleRequest.Direction = string(source.Direction) + var stringList []string + if source.SourceIPs != nil { + stringList = make([]string, len(source.SourceIPs)) + for i := 0; i < len(source.SourceIPs); i++ { + stringList[i] = stringFromIPNet(source.SourceIPs[i]) + } + } + schemaFirewallRuleRequest.SourceIPs = stringList + var stringList2 []string + if source.DestinationIPs != nil { + stringList2 = make([]string, len(source.DestinationIPs)) + for j := 0; j < len(source.DestinationIPs); j++ { + stringList2[j] = stringFromIPNet(source.DestinationIPs[j]) + } + } + schemaFirewallRuleRequest.DestinationIPs = stringList2 + schemaFirewallRuleRequest.Protocol = string(source.Protocol) + schemaFirewallRuleRequest.Port = source.Port + schemaFirewallRuleRequest.Description = source.Description + return schemaFirewallRuleRequest +} +func (c *converterImpl) hcloudFloatingIPProtectionToSchemaFloatingIPProtection(source FloatingIPProtection) schema.FloatingIPProtection { + var schemaFloatingIPProtection schema.FloatingIPProtection + schemaFloatingIPProtection.Delete = source.Delete + return schemaFloatingIPProtection +} +func (c *converterImpl) hcloudImageProtectionToSchemaImageProtection(source ImageProtection) schema.ImageProtection { + var schemaImageProtection schema.ImageProtection + schemaImageProtection.Delete = source.Delete + return schemaImageProtection +} +func (c *converterImpl) hcloudLoadBalancerAlgorithmToSchemaLoadBalancerAlgorithm(source LoadBalancerAlgorithm) schema.LoadBalancerAlgorithm { + var schemaLoadBalancerAlgorithm schema.LoadBalancerAlgorithm + schemaLoadBalancerAlgorithm.Type = string(source.Type) + return schemaLoadBalancerAlgorithm +} +func (c *converterImpl) hcloudLoadBalancerCreateOptsServiceToSchemaLoadBalancerCreateRequestService(source LoadBalancerCreateOptsService) schema.LoadBalancerCreateRequestService { + var schemaLoadBalancerCreateRequestService schema.LoadBalancerCreateRequestService + schemaLoadBalancerCreateRequestService.Protocol = string(source.Protocol) + schemaLoadBalancerCreateRequestService.ListenPort = source.ListenPort + schemaLoadBalancerCreateRequestService.DestinationPort = source.DestinationPort + schemaLoadBalancerCreateRequestService.Proxyprotocol = source.Proxyprotocol + schemaLoadBalancerCreateRequestService.HTTP = c.pHcloudLoadBalancerCreateOptsServiceHTTPToPSchemaLoadBalancerCreateRequestServiceHTTP(source.HTTP) + schemaLoadBalancerCreateRequestService.HealthCheck = c.pHcloudLoadBalancerCreateOptsServiceHealthCheckToPSchemaLoadBalancerCreateRequestServiceHealthCheck(source.HealthCheck) + return schemaLoadBalancerCreateRequestService +} +func (c *converterImpl) hcloudLoadBalancerCreateOptsTargetToSchemaLoadBalancerCreateRequestTarget(source LoadBalancerCreateOptsTarget) schema.LoadBalancerCreateRequestTarget { + var schemaLoadBalancerCreateRequestTarget schema.LoadBalancerCreateRequestTarget + schemaLoadBalancerCreateRequestTarget.Type = string(source.Type) + schemaLoadBalancerCreateRequestTarget.Server = schemaFromLoadBalancerCreateOptsTargetServer(source.Server) + schemaLoadBalancerCreateRequestTarget.LabelSelector = schemaFromLoadBalancerCreateOptsTargetLabelSelector(source.LabelSelector) + schemaLoadBalancerCreateRequestTarget.IP = schemaFromLoadBalancerCreateOptsTargetIP(source.IP) + schemaLoadBalancerCreateRequestTarget.UsePrivateIP = source.UsePrivateIP + return schemaLoadBalancerCreateRequestTarget +} +func (c *converterImpl) hcloudLoadBalancerPrivateNetToSchemaLoadBalancerPrivateNet(source LoadBalancerPrivateNet) schema.LoadBalancerPrivateNet { + var schemaLoadBalancerPrivateNet schema.LoadBalancerPrivateNet + schemaLoadBalancerPrivateNet.Network = c.pHcloudNetworkToInt64(source.Network) + schemaLoadBalancerPrivateNet.IP = stringFromIP(source.IP) + return schemaLoadBalancerPrivateNet +} +func (c *converterImpl) hcloudLoadBalancerProtectionToSchemaLoadBalancerProtection(source LoadBalancerProtection) schema.LoadBalancerProtection { + var schemaLoadBalancerProtection schema.LoadBalancerProtection + schemaLoadBalancerProtection.Delete = source.Delete + return schemaLoadBalancerProtection +} +func (c *converterImpl) hcloudLoadBalancerPublicNetIPv4ToSchemaLoadBalancerPublicNetIPv4(source LoadBalancerPublicNetIPv4) schema.LoadBalancerPublicNetIPv4 { + var schemaLoadBalancerPublicNetIPv4 schema.LoadBalancerPublicNetIPv4 + schemaLoadBalancerPublicNetIPv4.IP = stringFromIP(source.IP) + schemaLoadBalancerPublicNetIPv4.DNSPtr = source.DNSPtr + return schemaLoadBalancerPublicNetIPv4 +} +func (c *converterImpl) hcloudLoadBalancerPublicNetIPv6ToSchemaLoadBalancerPublicNetIPv6(source LoadBalancerPublicNetIPv6) schema.LoadBalancerPublicNetIPv6 { + var schemaLoadBalancerPublicNetIPv6 schema.LoadBalancerPublicNetIPv6 + schemaLoadBalancerPublicNetIPv6.IP = stringFromIP(source.IP) + schemaLoadBalancerPublicNetIPv6.DNSPtr = source.DNSPtr + return schemaLoadBalancerPublicNetIPv6 +} +func (c *converterImpl) hcloudLoadBalancerPublicNetToSchemaLoadBalancerPublicNet(source LoadBalancerPublicNet) schema.LoadBalancerPublicNet { + var schemaLoadBalancerPublicNet schema.LoadBalancerPublicNet + schemaLoadBalancerPublicNet.Enabled = source.Enabled + schemaLoadBalancerPublicNet.IPv4 = c.hcloudLoadBalancerPublicNetIPv4ToSchemaLoadBalancerPublicNetIPv4(source.IPv4) + schemaLoadBalancerPublicNet.IPv6 = c.hcloudLoadBalancerPublicNetIPv6ToSchemaLoadBalancerPublicNetIPv6(source.IPv6) + return schemaLoadBalancerPublicNet +} +func (c *converterImpl) hcloudLoadBalancerServiceHTTPToPSchemaLoadBalancerServiceHTTP(source LoadBalancerServiceHTTP) *schema.LoadBalancerServiceHTTP { + var schemaLoadBalancerServiceHTTP schema.LoadBalancerServiceHTTP + schemaLoadBalancerServiceHTTP.CookieName = source.CookieName + schemaLoadBalancerServiceHTTP.CookieLifetime = intSecondsFromDuration(source.CookieLifetime) + var int64List []int64 + if source.Certificates != nil { + int64List = make([]int64, len(source.Certificates)) + for i := 0; i < len(source.Certificates); i++ { + int64List[i] = int64FromCertificate(source.Certificates[i]) + } + } + schemaLoadBalancerServiceHTTP.Certificates = int64List + schemaLoadBalancerServiceHTTP.RedirectHTTP = source.RedirectHTTP + schemaLoadBalancerServiceHTTP.StickySessions = source.StickySessions + return &schemaLoadBalancerServiceHTTP +} +func (c *converterImpl) hcloudNetworkProtectionToSchemaNetworkProtection(source NetworkProtection) schema.NetworkProtection { + var schemaNetworkProtection schema.NetworkProtection + schemaNetworkProtection.Delete = source.Delete + return schemaNetworkProtection +} +func (c *converterImpl) hcloudPriceToSchemaPrice(source Price) schema.Price { + var schemaPrice schema.Price + schemaPrice.Net = source.Net + schemaPrice.Gross = source.Gross + return schemaPrice +} +func (c *converterImpl) hcloudPrimaryIPPriceToSchemaPrice(source PrimaryIPPrice) schema.Price { + var schemaPrice schema.Price + schemaPrice.Net = source.Net + schemaPrice.Gross = source.Gross + return schemaPrice +} +func (c *converterImpl) hcloudPrimaryIPProtectionToSchemaPrimaryIPProtection(source PrimaryIPProtection) schema.PrimaryIPProtection { + var schemaPrimaryIPProtection schema.PrimaryIPProtection + schemaPrimaryIPProtection.Delete = source.Delete + return schemaPrimaryIPProtection +} +func (c *converterImpl) hcloudServerBackupPricingToSchemaPricingServerBackup(source ServerBackupPricing) schema.PricingServerBackup { + var schemaPricingServerBackup schema.PricingServerBackup + schemaPricingServerBackup.Percentage = source.Percentage + return schemaPricingServerBackup +} +func (c *converterImpl) hcloudServerProtectionToSchemaServerProtection(source ServerProtection) schema.ServerProtection { + var schemaServerProtection schema.ServerProtection + schemaServerProtection.Delete = source.Delete + schemaServerProtection.Rebuild = source.Rebuild + return schemaServerProtection +} +func (c *converterImpl) hcloudVolumeProtectionToSchemaVolumeProtection(source VolumeProtection) schema.VolumeProtection { + var schemaVolumeProtection schema.VolumeProtection + schemaVolumeProtection.Delete = source.Delete + return schemaVolumeProtection +} +func (c *converterImpl) intISOFromSchema(source schema.ISO) ISO { + var hcloudISO ISO + hcloudISO.ID = source.ID + hcloudISO.Name = source.Name + hcloudISO.Description = source.Description + hcloudISO.Type = ISOType(source.Type) + var pHcloudArchitecture *Architecture + if source.Architecture != nil { + hcloudArchitecture := Architecture(*source.Architecture) + pHcloudArchitecture = &hcloudArchitecture + } + hcloudISO.Architecture = pHcloudArchitecture + var pTimeTime *time.Time + if source.DeprecatableResource.Deprecation != nil { + pTimeTime = &source.DeprecatableResource.Deprecation.UnavailableAfter + } + hcloudISO.Deprecated = c.pTimeTimeToTimeTime(pTimeTime) + hcloudISO.DeprecatableResource = c.schemaDeprecatableResourceToHcloudDeprecatableResource(source.DeprecatableResource) + return hcloudISO +} +func (c *converterImpl) intSchemaFromImage(source Image) schema.Image { + var schemaImage schema.Image + schemaImage.ID = source.ID + schemaImage.Status = string(source.Status) + schemaImage.Type = string(source.Type) + pString := source.Name + schemaImage.Name = &pString + schemaImage.Description = source.Description + schemaImage.ImageSize = mapZeroFloat32ToNil(source.ImageSize) + schemaImage.DiskSize = source.DiskSize + schemaImage.Created = timeToTimePtr(source.Created) + schemaImage.CreatedFrom = c.pHcloudServerToPSchemaImageCreatedFrom(source.CreatedFrom) + schemaImage.BoundTo = c.pHcloudServerToPInt64(source.BoundTo) + schemaImage.OSFlavor = source.OSFlavor + pString2 := source.OSVersion + schemaImage.OSVersion = &pString2 + schemaImage.Architecture = string(source.Architecture) + schemaImage.RapidDeploy = source.RapidDeploy + schemaImage.Protection = c.hcloudImageProtectionToSchemaImageProtection(source.Protection) + schemaImage.Deprecated = timeToTimePtr(source.Deprecated) + schemaImage.Deleted = timeToTimePtr(source.Deleted) + schemaImage.Labels = source.Labels + return schemaImage +} +func (c *converterImpl) pHcloudActionResourceToSchemaActionResourceReference(source *ActionResource) schema.ActionResourceReference { + var schemaActionResourceReference schema.ActionResourceReference + if source != nil { + var schemaActionResourceReference2 schema.ActionResourceReference + schemaActionResourceReference2.ID = (*source).ID + schemaActionResourceReference2.Type = string((*source).Type) + schemaActionResourceReference = schemaActionResourceReference2 + } + return schemaActionResourceReference +} +func (c *converterImpl) pHcloudCertificateStatusToPSchemaCertificateStatusRef(source *CertificateStatus) *schema.CertificateStatusRef { + var pSchemaCertificateStatusRef *schema.CertificateStatusRef + if source != nil { + var schemaCertificateStatusRef schema.CertificateStatusRef + schemaCertificateStatusRef.Issuance = c.hcloudCertificateStatusTypeToString((*source).Issuance) + schemaCertificateStatusRef.Renewal = c.hcloudCertificateStatusTypeToString((*source).Renewal) + schemaCertificateStatusRef.Error = c.pHcloudErrorToPSchemaError((*source).Error) + pSchemaCertificateStatusRef = &schemaCertificateStatusRef + } + return pSchemaCertificateStatusRef +} +func (c *converterImpl) pHcloudErrorToPSchemaError(source *Error) *schema.Error { + var pSchemaError *schema.Error + if source != nil { + schemaError := c.SchemaFromError((*source)) + pSchemaError = &schemaError + } + return pSchemaError +} +func (c *converterImpl) pHcloudFirewallResourceLabelSelectorToPSchemaFirewallResourceLabelSelector(source *FirewallResourceLabelSelector) *schema.FirewallResourceLabelSelector { + var pSchemaFirewallResourceLabelSelector *schema.FirewallResourceLabelSelector + if source != nil { + var schemaFirewallResourceLabelSelector schema.FirewallResourceLabelSelector + schemaFirewallResourceLabelSelector.Selector = (*source).Selector + pSchemaFirewallResourceLabelSelector = &schemaFirewallResourceLabelSelector + } + return pSchemaFirewallResourceLabelSelector +} +func (c *converterImpl) pHcloudFirewallResourceServerToPSchemaFirewallResourceServer(source *FirewallResourceServer) *schema.FirewallResourceServer { + var pSchemaFirewallResourceServer *schema.FirewallResourceServer + if source != nil { + var schemaFirewallResourceServer schema.FirewallResourceServer + schemaFirewallResourceServer.ID = (*source).ID + pSchemaFirewallResourceServer = &schemaFirewallResourceServer + } + return pSchemaFirewallResourceServer +} +func (c *converterImpl) pHcloudISOToPSchemaISO(source *ISO) *schema.ISO { + var pSchemaISO *schema.ISO + if source != nil { + var schemaISO schema.ISO + schemaISO.ID = (*source).ID + schemaISO.Name = (*source).Name + schemaISO.Description = (*source).Description + schemaISO.Type = string((*source).Type) + var pString *string + if (*source).Architecture != nil { + xstring := string(*(*source).Architecture) + pString = &xstring + } + schemaISO.Architecture = pString + schemaISO.DeprecatableResource = c.hcloudDeprecatableResourceToSchemaDeprecatableResource((*source).DeprecatableResource) + pSchemaISO = &schemaISO + } + return pSchemaISO +} +func (c *converterImpl) pHcloudImageToPSchemaImage(source *Image) *schema.Image { + var pSchemaImage *schema.Image + if source != nil { + schemaImage := c.intSchemaFromImage((*source)) + pSchemaImage = &schemaImage + } + return pSchemaImage +} +func (c *converterImpl) pHcloudLoadBalancerAddServiceOptsHTTPToPSchemaLoadBalancerActionAddServiceRequestHTTP(source *LoadBalancerAddServiceOptsHTTP) *schema.LoadBalancerActionAddServiceRequestHTTP { + var pSchemaLoadBalancerActionAddServiceRequestHTTP *schema.LoadBalancerActionAddServiceRequestHTTP + if source != nil { + var schemaLoadBalancerActionAddServiceRequestHTTP schema.LoadBalancerActionAddServiceRequestHTTP + schemaLoadBalancerActionAddServiceRequestHTTP.CookieName = (*source).CookieName + var pInt *int + if (*source).CookieLifetime != nil { + xint := intSecondsFromDuration(*(*source).CookieLifetime) + pInt = &xint + } + schemaLoadBalancerActionAddServiceRequestHTTP.CookieLifetime = pInt + schemaLoadBalancerActionAddServiceRequestHTTP.Certificates = int64SlicePtrFromCertificatePtrSlice((*source).Certificates) + schemaLoadBalancerActionAddServiceRequestHTTP.RedirectHTTP = (*source).RedirectHTTP + schemaLoadBalancerActionAddServiceRequestHTTP.StickySessions = (*source).StickySessions + pSchemaLoadBalancerActionAddServiceRequestHTTP = &schemaLoadBalancerActionAddServiceRequestHTTP + } + return pSchemaLoadBalancerActionAddServiceRequestHTTP +} +func (c *converterImpl) pHcloudLoadBalancerAddServiceOptsHealthCheckHTTPToPSchemaLoadBalancerActionAddServiceRequestHealthCheckHTTP(source *LoadBalancerAddServiceOptsHealthCheckHTTP) *schema.LoadBalancerActionAddServiceRequestHealthCheckHTTP { + var pSchemaLoadBalancerActionAddServiceRequestHealthCheckHTTP *schema.LoadBalancerActionAddServiceRequestHealthCheckHTTP + if source != nil { + var schemaLoadBalancerActionAddServiceRequestHealthCheckHTTP schema.LoadBalancerActionAddServiceRequestHealthCheckHTTP + schemaLoadBalancerActionAddServiceRequestHealthCheckHTTP.Domain = (*source).Domain + schemaLoadBalancerActionAddServiceRequestHealthCheckHTTP.Path = (*source).Path + schemaLoadBalancerActionAddServiceRequestHealthCheckHTTP.Response = (*source).Response + schemaLoadBalancerActionAddServiceRequestHealthCheckHTTP.StatusCodes = stringSlicePtrFromStringSlice((*source).StatusCodes) + schemaLoadBalancerActionAddServiceRequestHealthCheckHTTP.TLS = (*source).TLS + pSchemaLoadBalancerActionAddServiceRequestHealthCheckHTTP = &schemaLoadBalancerActionAddServiceRequestHealthCheckHTTP + } + return pSchemaLoadBalancerActionAddServiceRequestHealthCheckHTTP +} +func (c *converterImpl) pHcloudLoadBalancerAddServiceOptsHealthCheckToPSchemaLoadBalancerActionAddServiceRequestHealthCheck(source *LoadBalancerAddServiceOptsHealthCheck) *schema.LoadBalancerActionAddServiceRequestHealthCheck { + var pSchemaLoadBalancerActionAddServiceRequestHealthCheck *schema.LoadBalancerActionAddServiceRequestHealthCheck + if source != nil { + var schemaLoadBalancerActionAddServiceRequestHealthCheck schema.LoadBalancerActionAddServiceRequestHealthCheck + schemaLoadBalancerActionAddServiceRequestHealthCheck.Protocol = string((*source).Protocol) + schemaLoadBalancerActionAddServiceRequestHealthCheck.Port = (*source).Port + var pInt *int + if (*source).Interval != nil { + xint := intSecondsFromDuration(*(*source).Interval) + pInt = &xint + } + schemaLoadBalancerActionAddServiceRequestHealthCheck.Interval = pInt + var pInt2 *int + if (*source).Timeout != nil { + xint2 := intSecondsFromDuration(*(*source).Timeout) + pInt2 = &xint2 + } + schemaLoadBalancerActionAddServiceRequestHealthCheck.Timeout = pInt2 + schemaLoadBalancerActionAddServiceRequestHealthCheck.Retries = (*source).Retries + schemaLoadBalancerActionAddServiceRequestHealthCheck.HTTP = c.pHcloudLoadBalancerAddServiceOptsHealthCheckHTTPToPSchemaLoadBalancerActionAddServiceRequestHealthCheckHTTP((*source).HTTP) + pSchemaLoadBalancerActionAddServiceRequestHealthCheck = &schemaLoadBalancerActionAddServiceRequestHealthCheck + } + return pSchemaLoadBalancerActionAddServiceRequestHealthCheck +} +func (c *converterImpl) pHcloudLoadBalancerAlgorithmToPSchemaLoadBalancerCreateRequestAlgorithm(source *LoadBalancerAlgorithm) *schema.LoadBalancerCreateRequestAlgorithm { + var pSchemaLoadBalancerCreateRequestAlgorithm *schema.LoadBalancerCreateRequestAlgorithm + if source != nil { + var schemaLoadBalancerCreateRequestAlgorithm schema.LoadBalancerCreateRequestAlgorithm + schemaLoadBalancerCreateRequestAlgorithm.Type = string((*source).Type) + pSchemaLoadBalancerCreateRequestAlgorithm = &schemaLoadBalancerCreateRequestAlgorithm + } + return pSchemaLoadBalancerCreateRequestAlgorithm +} +func (c *converterImpl) pHcloudLoadBalancerCreateOptsServiceHTTPToPSchemaLoadBalancerCreateRequestServiceHTTP(source *LoadBalancerCreateOptsServiceHTTP) *schema.LoadBalancerCreateRequestServiceHTTP { + var pSchemaLoadBalancerCreateRequestServiceHTTP *schema.LoadBalancerCreateRequestServiceHTTP + if source != nil { + var schemaLoadBalancerCreateRequestServiceHTTP schema.LoadBalancerCreateRequestServiceHTTP + schemaLoadBalancerCreateRequestServiceHTTP.CookieName = (*source).CookieName + var pInt *int + if (*source).CookieLifetime != nil { + xint := intSecondsFromDuration(*(*source).CookieLifetime) + pInt = &xint + } + schemaLoadBalancerCreateRequestServiceHTTP.CookieLifetime = pInt + schemaLoadBalancerCreateRequestServiceHTTP.Certificates = int64SlicePtrFromCertificatePtrSlice((*source).Certificates) + schemaLoadBalancerCreateRequestServiceHTTP.RedirectHTTP = (*source).RedirectHTTP + schemaLoadBalancerCreateRequestServiceHTTP.StickySessions = (*source).StickySessions + pSchemaLoadBalancerCreateRequestServiceHTTP = &schemaLoadBalancerCreateRequestServiceHTTP + } + return pSchemaLoadBalancerCreateRequestServiceHTTP +} +func (c *converterImpl) pHcloudLoadBalancerCreateOptsServiceHealthCheckHTTPToPSchemaLoadBalancerCreateRequestServiceHealthCheckHTTP(source *LoadBalancerCreateOptsServiceHealthCheckHTTP) *schema.LoadBalancerCreateRequestServiceHealthCheckHTTP { + var pSchemaLoadBalancerCreateRequestServiceHealthCheckHTTP *schema.LoadBalancerCreateRequestServiceHealthCheckHTTP + if source != nil { + var schemaLoadBalancerCreateRequestServiceHealthCheckHTTP schema.LoadBalancerCreateRequestServiceHealthCheckHTTP + schemaLoadBalancerCreateRequestServiceHealthCheckHTTP.Domain = (*source).Domain + schemaLoadBalancerCreateRequestServiceHealthCheckHTTP.Path = (*source).Path + schemaLoadBalancerCreateRequestServiceHealthCheckHTTP.Response = (*source).Response + schemaLoadBalancerCreateRequestServiceHealthCheckHTTP.StatusCodes = stringSlicePtrFromStringSlice((*source).StatusCodes) + schemaLoadBalancerCreateRequestServiceHealthCheckHTTP.TLS = (*source).TLS + pSchemaLoadBalancerCreateRequestServiceHealthCheckHTTP = &schemaLoadBalancerCreateRequestServiceHealthCheckHTTP + } + return pSchemaLoadBalancerCreateRequestServiceHealthCheckHTTP +} +func (c *converterImpl) pHcloudLoadBalancerCreateOptsServiceHealthCheckToPSchemaLoadBalancerCreateRequestServiceHealthCheck(source *LoadBalancerCreateOptsServiceHealthCheck) *schema.LoadBalancerCreateRequestServiceHealthCheck { + var pSchemaLoadBalancerCreateRequestServiceHealthCheck *schema.LoadBalancerCreateRequestServiceHealthCheck + if source != nil { + var schemaLoadBalancerCreateRequestServiceHealthCheck schema.LoadBalancerCreateRequestServiceHealthCheck + schemaLoadBalancerCreateRequestServiceHealthCheck.Protocol = string((*source).Protocol) + schemaLoadBalancerCreateRequestServiceHealthCheck.Port = (*source).Port + var pInt *int + if (*source).Interval != nil { + xint := intSecondsFromDuration(*(*source).Interval) + pInt = &xint + } + schemaLoadBalancerCreateRequestServiceHealthCheck.Interval = pInt + var pInt2 *int + if (*source).Timeout != nil { + xint2 := intSecondsFromDuration(*(*source).Timeout) + pInt2 = &xint2 + } + schemaLoadBalancerCreateRequestServiceHealthCheck.Timeout = pInt2 + schemaLoadBalancerCreateRequestServiceHealthCheck.Retries = (*source).Retries + schemaLoadBalancerCreateRequestServiceHealthCheck.HTTP = c.pHcloudLoadBalancerCreateOptsServiceHealthCheckHTTPToPSchemaLoadBalancerCreateRequestServiceHealthCheckHTTP((*source).HTTP) + pSchemaLoadBalancerCreateRequestServiceHealthCheck = &schemaLoadBalancerCreateRequestServiceHealthCheck + } + return pSchemaLoadBalancerCreateRequestServiceHealthCheck +} +func (c *converterImpl) pHcloudLoadBalancerServiceHealthCheckHTTPToPSchemaLoadBalancerServiceHealthCheckHTTP(source *LoadBalancerServiceHealthCheckHTTP) *schema.LoadBalancerServiceHealthCheckHTTP { + var pSchemaLoadBalancerServiceHealthCheckHTTP *schema.LoadBalancerServiceHealthCheckHTTP + if source != nil { + var schemaLoadBalancerServiceHealthCheckHTTP schema.LoadBalancerServiceHealthCheckHTTP + schemaLoadBalancerServiceHealthCheckHTTP.Domain = (*source).Domain + schemaLoadBalancerServiceHealthCheckHTTP.Path = (*source).Path + schemaLoadBalancerServiceHealthCheckHTTP.Response = (*source).Response + schemaLoadBalancerServiceHealthCheckHTTP.StatusCodes = (*source).StatusCodes + schemaLoadBalancerServiceHealthCheckHTTP.TLS = (*source).TLS + pSchemaLoadBalancerServiceHealthCheckHTTP = &schemaLoadBalancerServiceHealthCheckHTTP + } + return pSchemaLoadBalancerServiceHealthCheckHTTP +} +func (c *converterImpl) pHcloudLoadBalancerTargetIPToPSchemaLoadBalancerTargetIP(source *LoadBalancerTargetIP) *schema.LoadBalancerTargetIP { + var pSchemaLoadBalancerTargetIP *schema.LoadBalancerTargetIP + if source != nil { + var schemaLoadBalancerTargetIP schema.LoadBalancerTargetIP + schemaLoadBalancerTargetIP.IP = (*source).IP + pSchemaLoadBalancerTargetIP = &schemaLoadBalancerTargetIP + } + return pSchemaLoadBalancerTargetIP +} +func (c *converterImpl) pHcloudLoadBalancerTargetLabelSelectorToPSchemaLoadBalancerTargetLabelSelector(source *LoadBalancerTargetLabelSelector) *schema.LoadBalancerTargetLabelSelector { + var pSchemaLoadBalancerTargetLabelSelector *schema.LoadBalancerTargetLabelSelector + if source != nil { + var schemaLoadBalancerTargetLabelSelector schema.LoadBalancerTargetLabelSelector + schemaLoadBalancerTargetLabelSelector.Selector = (*source).Selector + pSchemaLoadBalancerTargetLabelSelector = &schemaLoadBalancerTargetLabelSelector + } + return pSchemaLoadBalancerTargetLabelSelector +} +func (c *converterImpl) pHcloudLoadBalancerTargetServerToPSchemaLoadBalancerTargetServer(source *LoadBalancerTargetServer) *schema.LoadBalancerTargetServer { + var pSchemaLoadBalancerTargetServer *schema.LoadBalancerTargetServer + if source != nil { + schemaLoadBalancerTargetServer := c.SchemaFromLoadBalancerServerTarget((*source)) + pSchemaLoadBalancerTargetServer = &schemaLoadBalancerTargetServer + } + 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 { + var schemaLoadBalancerActionUpdateServiceRequestHTTP schema.LoadBalancerActionUpdateServiceRequestHTTP + schemaLoadBalancerActionUpdateServiceRequestHTTP.CookieName = (*source).CookieName + var pInt *int + if (*source).CookieLifetime != nil { + xint := intSecondsFromDuration(*(*source).CookieLifetime) + pInt = &xint + } + schemaLoadBalancerActionUpdateServiceRequestHTTP.CookieLifetime = pInt + schemaLoadBalancerActionUpdateServiceRequestHTTP.Certificates = int64SlicePtrFromCertificatePtrSlice((*source).Certificates) + schemaLoadBalancerActionUpdateServiceRequestHTTP.RedirectHTTP = (*source).RedirectHTTP + schemaLoadBalancerActionUpdateServiceRequestHTTP.StickySessions = (*source).StickySessions + pSchemaLoadBalancerActionUpdateServiceRequestHTTP = &schemaLoadBalancerActionUpdateServiceRequestHTTP + } + return pSchemaLoadBalancerActionUpdateServiceRequestHTTP +} +func (c *converterImpl) pHcloudLoadBalancerUpdateServiceOptsHealthCheckHTTPToPSchemaLoadBalancerActionUpdateServiceRequestHealthCheckHTTP(source *LoadBalancerUpdateServiceOptsHealthCheckHTTP) *schema.LoadBalancerActionUpdateServiceRequestHealthCheckHTTP { + var pSchemaLoadBalancerActionUpdateServiceRequestHealthCheckHTTP *schema.LoadBalancerActionUpdateServiceRequestHealthCheckHTTP + if source != nil { + var schemaLoadBalancerActionUpdateServiceRequestHealthCheckHTTP schema.LoadBalancerActionUpdateServiceRequestHealthCheckHTTP + schemaLoadBalancerActionUpdateServiceRequestHealthCheckHTTP.Domain = (*source).Domain + schemaLoadBalancerActionUpdateServiceRequestHealthCheckHTTP.Path = (*source).Path + schemaLoadBalancerActionUpdateServiceRequestHealthCheckHTTP.Response = (*source).Response + schemaLoadBalancerActionUpdateServiceRequestHealthCheckHTTP.StatusCodes = stringSlicePtrFromStringSlice((*source).StatusCodes) + schemaLoadBalancerActionUpdateServiceRequestHealthCheckHTTP.TLS = (*source).TLS + pSchemaLoadBalancerActionUpdateServiceRequestHealthCheckHTTP = &schemaLoadBalancerActionUpdateServiceRequestHealthCheckHTTP + } + return pSchemaLoadBalancerActionUpdateServiceRequestHealthCheckHTTP +} +func (c *converterImpl) pHcloudLoadBalancerUpdateServiceOptsHealthCheckToPSchemaLoadBalancerActionUpdateServiceRequestHealthCheck(source *LoadBalancerUpdateServiceOptsHealthCheck) *schema.LoadBalancerActionUpdateServiceRequestHealthCheck { + var pSchemaLoadBalancerActionUpdateServiceRequestHealthCheck *schema.LoadBalancerActionUpdateServiceRequestHealthCheck + if source != nil { + var schemaLoadBalancerActionUpdateServiceRequestHealthCheck schema.LoadBalancerActionUpdateServiceRequestHealthCheck + schemaLoadBalancerActionUpdateServiceRequestHealthCheck.Protocol = stringPtrFromLoadBalancerServiceProtocol((*source).Protocol) + schemaLoadBalancerActionUpdateServiceRequestHealthCheck.Port = (*source).Port + var pInt *int + if (*source).Interval != nil { + xint := intSecondsFromDuration(*(*source).Interval) + pInt = &xint + } + schemaLoadBalancerActionUpdateServiceRequestHealthCheck.Interval = pInt + var pInt2 *int + if (*source).Timeout != nil { + xint2 := intSecondsFromDuration(*(*source).Timeout) + pInt2 = &xint2 + } + schemaLoadBalancerActionUpdateServiceRequestHealthCheck.Timeout = pInt2 + schemaLoadBalancerActionUpdateServiceRequestHealthCheck.Retries = (*source).Retries + schemaLoadBalancerActionUpdateServiceRequestHealthCheck.HTTP = c.pHcloudLoadBalancerUpdateServiceOptsHealthCheckHTTPToPSchemaLoadBalancerActionUpdateServiceRequestHealthCheckHTTP((*source).HTTP) + pSchemaLoadBalancerActionUpdateServiceRequestHealthCheck = &schemaLoadBalancerActionUpdateServiceRequestHealthCheck + } + return pSchemaLoadBalancerActionUpdateServiceRequestHealthCheck +} +func (c *converterImpl) pHcloudLocationToPString(source *Location) *string { + var pString *string + if source != nil { + xstring := stringFromLocation((*source)) + pString = &xstring + } + return pString +} +func (c *converterImpl) pHcloudLocationToString(source *Location) string { + var xstring string + if source != nil { + xstring = stringFromLocation((*source)) + } + return xstring +} +func (c *converterImpl) pHcloudNetworkToInt64(source *Network) int64 { + var xint64 int64 + if source != nil { + xint64 = int64FromNetwork((*source)) + } + return xint64 +} +func (c *converterImpl) pHcloudNetworkToPInt64(source *Network) *int64 { + var pInt64 *int64 + if source != nil { + xint64 := int64FromNetwork((*source)) + pInt64 = &xint64 + } + return pInt64 +} +func (c *converterImpl) pHcloudPlacementGroupToPSchemaPlacementGroup(source *PlacementGroup) *schema.PlacementGroup { + var pSchemaPlacementGroup *schema.PlacementGroup + if source != nil { + var schemaPlacementGroup schema.PlacementGroup + schemaPlacementGroup.ID = (*source).ID + schemaPlacementGroup.Name = (*source).Name + schemaPlacementGroup.Labels = (*source).Labels + schemaPlacementGroup.Created = c.timeTimeToTimeTime((*source).Created) + schemaPlacementGroup.Servers = (*source).Servers + schemaPlacementGroup.Type = string((*source).Type) + pSchemaPlacementGroup = &schemaPlacementGroup + } + return pSchemaPlacementGroup +} +func (c *converterImpl) pHcloudServerToInt64(source *Server) int64 { + var xint64 int64 + if source != nil { + xint64 = int64FromServer((*source)) + } + return xint64 +} +func (c *converterImpl) pHcloudServerToPInt64(source *Server) *int64 { + var pInt64 *int64 + if source != nil { + xint64 := int64FromServer((*source)) + pInt64 = &xint64 + } + return pInt64 +} +func (c *converterImpl) pHcloudServerToPSchemaImageCreatedFrom(source *Server) *schema.ImageCreatedFrom { + var pSchemaImageCreatedFrom *schema.ImageCreatedFrom + if source != nil { + var schemaImageCreatedFrom schema.ImageCreatedFrom + schemaImageCreatedFrom.ID = (*source).ID + schemaImageCreatedFrom.Name = (*source).Name + pSchemaImageCreatedFrom = &schemaImageCreatedFrom + } + return pSchemaImageCreatedFrom +} +func (c *converterImpl) pNetIPNetToString(source *net.IPNet) string { + var xstring string + if source != nil { + xstring = stringFromIPNet((*source)) + } + return xstring +} +func (c *converterImpl) pSchemaCertificateStatusRefToPHcloudCertificateStatus(source *schema.CertificateStatusRef) *CertificateStatus { + var pHcloudCertificateStatus *CertificateStatus + if source != nil { + var hcloudCertificateStatus CertificateStatus + hcloudCertificateStatus.Issuance = CertificateStatusType((*source).Issuance) + hcloudCertificateStatus.Renewal = CertificateStatusType((*source).Renewal) + hcloudCertificateStatus.Error = c.pSchemaErrorToPHcloudError((*source).Error) + pHcloudCertificateStatus = &hcloudCertificateStatus + } + return pHcloudCertificateStatus +} +func (c *converterImpl) pSchemaErrorToPHcloudError(source *schema.Error) *Error { + var pHcloudError *Error + if source != nil { + hcloudError := c.ErrorFromSchema((*source)) + pHcloudError = &hcloudError + } + return pHcloudError +} +func (c *converterImpl) pSchemaFirewallResourceLabelSelectorToPHcloudFirewallResourceLabelSelector(source *schema.FirewallResourceLabelSelector) *FirewallResourceLabelSelector { + var pHcloudFirewallResourceLabelSelector *FirewallResourceLabelSelector + if source != nil { + var hcloudFirewallResourceLabelSelector FirewallResourceLabelSelector + hcloudFirewallResourceLabelSelector.Selector = (*source).Selector + pHcloudFirewallResourceLabelSelector = &hcloudFirewallResourceLabelSelector + } + return pHcloudFirewallResourceLabelSelector +} +func (c *converterImpl) pSchemaFirewallResourceServerToPHcloudFirewallResourceServer(source *schema.FirewallResourceServer) *FirewallResourceServer { + var pHcloudFirewallResourceServer *FirewallResourceServer + if source != nil { + var hcloudFirewallResourceServer FirewallResourceServer + hcloudFirewallResourceServer.ID = (*source).ID + pHcloudFirewallResourceServer = &hcloudFirewallResourceServer + } + return pHcloudFirewallResourceServer +} +func (c *converterImpl) pSchemaISOToPHcloudISO(source *schema.ISO) *ISO { + var pHcloudISO *ISO + if source != nil { + hcloudISO := c.intISOFromSchema((*source)) + pHcloudISO = &hcloudISO + } + return pHcloudISO +} +func (c *converterImpl) pSchemaImageCreatedFromToPHcloudServer(source *schema.ImageCreatedFrom) *Server { + var pHcloudServer *Server + if source != nil { + hcloudServer := serverFromImageCreatedFromSchema((*source)) + pHcloudServer = &hcloudServer + } + return pHcloudServer +} +func (c *converterImpl) pSchemaImageToPHcloudImage(source *schema.Image) *Image { + var pHcloudImage *Image + if source != nil { + var hcloudImage Image + hcloudImage.ID = (*source).ID + var xstring string + if (*source).Name != nil { + xstring = *(*source).Name + } + hcloudImage.Name = xstring + hcloudImage.Type = ImageType((*source).Type) + hcloudImage.Status = ImageStatus((*source).Status) + hcloudImage.Description = (*source).Description + var xfloat32 float32 + if (*source).ImageSize != nil { + xfloat32 = *(*source).ImageSize + } + hcloudImage.ImageSize = xfloat32 + hcloudImage.DiskSize = (*source).DiskSize + hcloudImage.Created = c.pTimeTimeToTimeTime((*source).Created) + hcloudImage.CreatedFrom = c.pSchemaImageCreatedFromToPHcloudServer((*source).CreatedFrom) + var pHcloudServer *Server + if (*source).BoundTo != nil { + hcloudServer := serverFromInt64(*(*source).BoundTo) + pHcloudServer = &hcloudServer + } + hcloudImage.BoundTo = pHcloudServer + hcloudImage.RapidDeploy = (*source).RapidDeploy + hcloudImage.OSFlavor = (*source).OSFlavor + var xstring2 string + if (*source).OSVersion != nil { + xstring2 = *(*source).OSVersion + } + hcloudImage.OSVersion = xstring2 + hcloudImage.Architecture = Architecture((*source).Architecture) + hcloudImage.Protection = c.schemaImageProtectionToHcloudImageProtection((*source).Protection) + hcloudImage.Deprecated = c.pTimeTimeToTimeTime((*source).Deprecated) + hcloudImage.Labels = (*source).Labels + hcloudImage.Deleted = c.pTimeTimeToTimeTime((*source).Deleted) + pHcloudImage = &hcloudImage + } + return pHcloudImage +} +func (c *converterImpl) pSchemaLoadBalancerServiceHTTPToHcloudLoadBalancerServiceHTTP(source *schema.LoadBalancerServiceHTTP) LoadBalancerServiceHTTP { + var hcloudLoadBalancerServiceHTTP LoadBalancerServiceHTTP + if source != nil { + var hcloudLoadBalancerServiceHTTP2 LoadBalancerServiceHTTP + hcloudLoadBalancerServiceHTTP2.CookieName = (*source).CookieName + hcloudLoadBalancerServiceHTTP2.CookieLifetime = durationFromIntSeconds((*source).CookieLifetime) + var pHcloudCertificateList []*Certificate + if (*source).Certificates != nil { + pHcloudCertificateList = make([]*Certificate, len((*source).Certificates)) + for i := 0; i < len((*source).Certificates); i++ { + pHcloudCertificateList[i] = certificateFromInt64((*source).Certificates[i]) + } + } + hcloudLoadBalancerServiceHTTP2.Certificates = pHcloudCertificateList + hcloudLoadBalancerServiceHTTP2.RedirectHTTP = (*source).RedirectHTTP + hcloudLoadBalancerServiceHTTP2.StickySessions = (*source).StickySessions + hcloudLoadBalancerServiceHTTP = hcloudLoadBalancerServiceHTTP2 + } + return hcloudLoadBalancerServiceHTTP +} +func (c *converterImpl) pSchemaLoadBalancerServiceHealthCheckHTTPToPHcloudLoadBalancerServiceHealthCheckHTTP(source *schema.LoadBalancerServiceHealthCheckHTTP) *LoadBalancerServiceHealthCheckHTTP { + var pHcloudLoadBalancerServiceHealthCheckHTTP *LoadBalancerServiceHealthCheckHTTP + if source != nil { + var hcloudLoadBalancerServiceHealthCheckHTTP LoadBalancerServiceHealthCheckHTTP + hcloudLoadBalancerServiceHealthCheckHTTP.Domain = (*source).Domain + hcloudLoadBalancerServiceHealthCheckHTTP.Path = (*source).Path + hcloudLoadBalancerServiceHealthCheckHTTP.Response = (*source).Response + hcloudLoadBalancerServiceHealthCheckHTTP.StatusCodes = (*source).StatusCodes + hcloudLoadBalancerServiceHealthCheckHTTP.TLS = (*source).TLS + pHcloudLoadBalancerServiceHealthCheckHTTP = &hcloudLoadBalancerServiceHealthCheckHTTP + } + return pHcloudLoadBalancerServiceHealthCheckHTTP +} +func (c *converterImpl) pSchemaLoadBalancerTargetIPToPHcloudLoadBalancerTargetIP(source *schema.LoadBalancerTargetIP) *LoadBalancerTargetIP { + var pHcloudLoadBalancerTargetIP *LoadBalancerTargetIP + if source != nil { + var hcloudLoadBalancerTargetIP LoadBalancerTargetIP + hcloudLoadBalancerTargetIP.IP = (*source).IP + pHcloudLoadBalancerTargetIP = &hcloudLoadBalancerTargetIP + } + return pHcloudLoadBalancerTargetIP +} +func (c *converterImpl) pSchemaLoadBalancerTargetLabelSelectorToPHcloudLoadBalancerTargetLabelSelector(source *schema.LoadBalancerTargetLabelSelector) *LoadBalancerTargetLabelSelector { + var pHcloudLoadBalancerTargetLabelSelector *LoadBalancerTargetLabelSelector + if source != nil { + var hcloudLoadBalancerTargetLabelSelector LoadBalancerTargetLabelSelector + hcloudLoadBalancerTargetLabelSelector.Selector = (*source).Selector + pHcloudLoadBalancerTargetLabelSelector = &hcloudLoadBalancerTargetLabelSelector + } + return pHcloudLoadBalancerTargetLabelSelector +} +func (c *converterImpl) pSchemaLoadBalancerTargetServerToPHcloudLoadBalancerTargetServer(source *schema.LoadBalancerTargetServer) *LoadBalancerTargetServer { + var pHcloudLoadBalancerTargetServer *LoadBalancerTargetServer + if source != nil { + hcloudLoadBalancerTargetServer := c.LoadBalancerTargetServerFromSchema((*source)) + pHcloudLoadBalancerTargetServer = &hcloudLoadBalancerTargetServer + } + return pHcloudLoadBalancerTargetServer +} +func (c *converterImpl) pSchemaPlacementGroupToPHcloudPlacementGroup(source *schema.PlacementGroup) *PlacementGroup { + var pHcloudPlacementGroup *PlacementGroup + if source != nil { + var hcloudPlacementGroup PlacementGroup + hcloudPlacementGroup.ID = (*source).ID + hcloudPlacementGroup.Name = (*source).Name + hcloudPlacementGroup.Labels = (*source).Labels + hcloudPlacementGroup.Created = c.timeTimeToTimeTime((*source).Created) + hcloudPlacementGroup.Servers = (*source).Servers + hcloudPlacementGroup.Type = PlacementGroupType((*source).Type) + pHcloudPlacementGroup = &hcloudPlacementGroup + } + return pHcloudPlacementGroup +} +func (c *converterImpl) pTimeTimeToTimeTime(source *time.Time) time.Time { + var timeTime time.Time + if source != nil { + timeTime = (*source) + } + return timeTime +} +func (c *converterImpl) schemaActionResourceReferenceToPHcloudActionResource(source schema.ActionResourceReference) *ActionResource { + var hcloudActionResource ActionResource + hcloudActionResource.ID = source.ID + hcloudActionResource.Type = ActionResourceType(source.Type) + return &hcloudActionResource +} +func (c *converterImpl) schemaCertificateUsedByRefToHcloudCertificateUsedByRef(source schema.CertificateUsedByRef) CertificateUsedByRef { + var hcloudCertificateUsedByRef CertificateUsedByRef + hcloudCertificateUsedByRef.ID = source.ID + 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) + return hcloudDeprecatableResource +} +func (c *converterImpl) schemaFirewallResourceToHcloudFirewallResource(source schema.FirewallResource) FirewallResource { + var hcloudFirewallResource FirewallResource + hcloudFirewallResource.Type = FirewallResourceType(source.Type) + hcloudFirewallResource.Server = c.pSchemaFirewallResourceServerToPHcloudFirewallResourceServer(source.Server) + hcloudFirewallResource.LabelSelector = c.pSchemaFirewallResourceLabelSelectorToPHcloudFirewallResourceLabelSelector(source.LabelSelector) + return hcloudFirewallResource +} +func (c *converterImpl) schemaFirewallRuleToHcloudFirewallRule(source schema.FirewallRule) FirewallRule { + var hcloudFirewallRule FirewallRule + hcloudFirewallRule.Direction = FirewallRuleDirection(source.Direction) + var netIPNetList []net.IPNet + if source.SourceIPs != nil { + netIPNetList = make([]net.IPNet, len(source.SourceIPs)) + for i := 0; i < len(source.SourceIPs); i++ { + netIPNetList[i] = ipNetFromString(source.SourceIPs[i]) + } + } + hcloudFirewallRule.SourceIPs = netIPNetList + var netIPNetList2 []net.IPNet + if source.DestinationIPs != nil { + netIPNetList2 = make([]net.IPNet, len(source.DestinationIPs)) + for j := 0; j < len(source.DestinationIPs); j++ { + netIPNetList2[j] = ipNetFromString(source.DestinationIPs[j]) + } + } + hcloudFirewallRule.DestinationIPs = netIPNetList2 + hcloudFirewallRule.Protocol = FirewallRuleProtocol(source.Protocol) + hcloudFirewallRule.Port = source.Port + hcloudFirewallRule.Description = source.Description + return hcloudFirewallRule +} +func (c *converterImpl) schemaFloatingIPProtectionToHcloudFloatingIPProtection(source schema.FloatingIPProtection) FloatingIPProtection { + var hcloudFloatingIPProtection FloatingIPProtection + hcloudFloatingIPProtection.Delete = source.Delete + return hcloudFloatingIPProtection +} +func (c *converterImpl) schemaFromFloatingIPPricing(source FloatingIPPricing) schema.PricingFloatingIP { + var schemaPricingFloatingIP schema.PricingFloatingIP + schemaPricingFloatingIP.PriceMonthly = c.hcloudPriceToSchemaPrice(source.Monthly) + return schemaPricingFloatingIP +} +func (c *converterImpl) schemaFromFloatingIPTypeLocationPricing(source FloatingIPTypeLocationPricing) schema.PricingFloatingIPTypePrice { + var schemaPricingFloatingIPTypePrice schema.PricingFloatingIPTypePrice + schemaPricingFloatingIPTypePrice.Location = c.pHcloudLocationToString(source.Location) + schemaPricingFloatingIPTypePrice.PriceMonthly = c.hcloudPriceToSchemaPrice(source.Monthly) + return schemaPricingFloatingIPTypePrice +} +func (c *converterImpl) schemaFromFloatingIPTypePricing(source FloatingIPTypePricing) schema.PricingFloatingIPType { + var schemaPricingFloatingIPType schema.PricingFloatingIPType + schemaPricingFloatingIPType.Type = string(source.Type) + var schemaPricingFloatingIPTypePriceList []schema.PricingFloatingIPTypePrice + if source.Pricings != nil { + schemaPricingFloatingIPTypePriceList = make([]schema.PricingFloatingIPTypePrice, len(source.Pricings)) + for i := 0; i < len(source.Pricings); i++ { + schemaPricingFloatingIPTypePriceList[i] = c.schemaFromFloatingIPTypeLocationPricing(source.Pricings[i]) + } + } + schemaPricingFloatingIPType.Prices = schemaPricingFloatingIPTypePriceList + return schemaPricingFloatingIPType +} +func (c *converterImpl) schemaFromImagePricing(source ImagePricing) schema.PricingImage { + var schemaPricingImage schema.PricingImage + schemaPricingImage.PricePerGBMonth = c.hcloudPriceToSchemaPrice(source.PerGBMonth) + return schemaPricingImage +} +func (c *converterImpl) schemaFromLoadBalancerTypePricing(source LoadBalancerTypePricing) schema.PricingLoadBalancerType { + var schemaPricingLoadBalancerType schema.PricingLoadBalancerType + var pInt64 *int64 + if source.LoadBalancerType != nil { + pInt64 = &source.LoadBalancerType.ID + } + var xint64 int64 + if pInt64 != nil { + xint64 = *pInt64 + } + schemaPricingLoadBalancerType.ID = xint64 + var pString *string + if source.LoadBalancerType != nil { + pString = &source.LoadBalancerType.Name + } + var xstring string + if pString != nil { + xstring = *pString + } + schemaPricingLoadBalancerType.Name = xstring + var schemaPricingLoadBalancerTypePriceList []schema.PricingLoadBalancerTypePrice + if source.Pricings != nil { + schemaPricingLoadBalancerTypePriceList = make([]schema.PricingLoadBalancerTypePrice, len(source.Pricings)) + for i := 0; i < len(source.Pricings); i++ { + schemaPricingLoadBalancerTypePriceList[i] = c.SchemaFromLoadBalancerTypeLocationPricing(source.Pricings[i]) + } + } + schemaPricingLoadBalancerType.Prices = schemaPricingLoadBalancerTypePriceList + return schemaPricingLoadBalancerType +} +func (c *converterImpl) schemaFromPrimaryIPPricing(source PrimaryIPPricing) schema.PricingPrimaryIP { + var schemaPricingPrimaryIP schema.PricingPrimaryIP + schemaPricingPrimaryIP.Type = source.Type + var schemaPricingPrimaryIPTypePriceList []schema.PricingPrimaryIPTypePrice + if source.Pricings != nil { + schemaPricingPrimaryIPTypePriceList = make([]schema.PricingPrimaryIPTypePrice, len(source.Pricings)) + for i := 0; i < len(source.Pricings); i++ { + schemaPricingPrimaryIPTypePriceList[i] = c.schemaFromPrimaryIPTypePricing(source.Pricings[i]) + } + } + schemaPricingPrimaryIP.Prices = schemaPricingPrimaryIPTypePriceList + return schemaPricingPrimaryIP +} +func (c *converterImpl) schemaFromPrimaryIPTypePricing(source PrimaryIPTypePricing) schema.PricingPrimaryIPTypePrice { + var schemaPricingPrimaryIPTypePrice schema.PricingPrimaryIPTypePrice + schemaPricingPrimaryIPTypePrice.Datacenter = source.Datacenter + schemaPricingPrimaryIPTypePrice.Location = source.Location + schemaPricingPrimaryIPTypePrice.PriceHourly = c.hcloudPrimaryIPPriceToSchemaPrice(source.Hourly) + schemaPricingPrimaryIPTypePrice.PriceMonthly = c.hcloudPrimaryIPPriceToSchemaPrice(source.Monthly) + return schemaPricingPrimaryIPTypePrice +} +func (c *converterImpl) schemaFromServerTypeLocationPricing(source ServerTypeLocationPricing) schema.PricingServerTypePrice { + var schemaPricingServerTypePrice schema.PricingServerTypePrice + schemaPricingServerTypePrice.Location = c.pHcloudLocationToString(source.Location) + schemaPricingServerTypePrice.PriceHourly = c.hcloudPriceToSchemaPrice(source.Hourly) + schemaPricingServerTypePrice.PriceMonthly = c.hcloudPriceToSchemaPrice(source.Monthly) + return schemaPricingServerTypePrice +} +func (c *converterImpl) schemaFromServerTypePricing(source ServerTypePricing) schema.PricingServerType { + var schemaPricingServerType schema.PricingServerType + var pInt64 *int64 + if source.ServerType != nil { + pInt64 = &source.ServerType.ID + } + var xint64 int64 + if pInt64 != nil { + xint64 = *pInt64 + } + schemaPricingServerType.ID = xint64 + var pString *string + if source.ServerType != nil { + pString = &source.ServerType.Name + } + var xstring string + if pString != nil { + xstring = *pString + } + schemaPricingServerType.Name = xstring + var schemaPricingServerTypePriceList []schema.PricingServerTypePrice + if source.Pricings != nil { + schemaPricingServerTypePriceList = make([]schema.PricingServerTypePrice, len(source.Pricings)) + for i := 0; i < len(source.Pricings); i++ { + schemaPricingServerTypePriceList[i] = c.schemaFromServerTypeLocationPricing(source.Pricings[i]) + } + } + schemaPricingServerType.Prices = schemaPricingServerTypePriceList + return schemaPricingServerType +} +func (c *converterImpl) schemaFromTrafficPricing(source TrafficPricing) schema.PricingTraffic { + var schemaPricingTraffic schema.PricingTraffic + schemaPricingTraffic.PricePerTB = c.hcloudPriceToSchemaPrice(source.PerTB) + return schemaPricingTraffic +} +func (c *converterImpl) schemaFromVolumePricing(source VolumePricing) schema.PricingVolume { + var schemaPricingVolume schema.PricingVolume + schemaPricingVolume.PricePerGBPerMonth = c.hcloudPriceToSchemaPrice(source.PerGBMonthly) + return schemaPricingVolume +} +func (c *converterImpl) schemaImageProtectionToHcloudImageProtection(source schema.ImageProtection) ImageProtection { + var hcloudImageProtection ImageProtection + hcloudImageProtection.Delete = source.Delete + return hcloudImageProtection +} +func (c *converterImpl) schemaLoadBalancerAlgorithmToHcloudLoadBalancerAlgorithm(source schema.LoadBalancerAlgorithm) LoadBalancerAlgorithm { + var hcloudLoadBalancerAlgorithm LoadBalancerAlgorithm + hcloudLoadBalancerAlgorithm.Type = LoadBalancerAlgorithmType(source.Type) + return hcloudLoadBalancerAlgorithm +} +func (c *converterImpl) schemaLoadBalancerPrivateNetToHcloudLoadBalancerPrivateNet(source schema.LoadBalancerPrivateNet) LoadBalancerPrivateNet { + var hcloudLoadBalancerPrivateNet LoadBalancerPrivateNet + hcloudNetwork := networkFromInt64(source.Network) + hcloudLoadBalancerPrivateNet.Network = &hcloudNetwork + hcloudLoadBalancerPrivateNet.IP = ipFromString(source.IP) + return hcloudLoadBalancerPrivateNet +} +func (c *converterImpl) schemaLoadBalancerProtectionToHcloudLoadBalancerProtection(source schema.LoadBalancerProtection) LoadBalancerProtection { + var hcloudLoadBalancerProtection LoadBalancerProtection + hcloudLoadBalancerProtection.Delete = source.Delete + return hcloudLoadBalancerProtection +} +func (c *converterImpl) schemaLoadBalancerPublicNetIPv4ToHcloudLoadBalancerPublicNetIPv4(source schema.LoadBalancerPublicNetIPv4) LoadBalancerPublicNetIPv4 { + var hcloudLoadBalancerPublicNetIPv4 LoadBalancerPublicNetIPv4 + hcloudLoadBalancerPublicNetIPv4.IP = ipFromString(source.IP) + hcloudLoadBalancerPublicNetIPv4.DNSPtr = source.DNSPtr + return hcloudLoadBalancerPublicNetIPv4 +} +func (c *converterImpl) schemaLoadBalancerPublicNetIPv6ToHcloudLoadBalancerPublicNetIPv6(source schema.LoadBalancerPublicNetIPv6) LoadBalancerPublicNetIPv6 { + var hcloudLoadBalancerPublicNetIPv6 LoadBalancerPublicNetIPv6 + hcloudLoadBalancerPublicNetIPv6.IP = ipFromString(source.IP) + hcloudLoadBalancerPublicNetIPv6.DNSPtr = source.DNSPtr + return hcloudLoadBalancerPublicNetIPv6 +} +func (c *converterImpl) schemaLoadBalancerPublicNetToHcloudLoadBalancerPublicNet(source schema.LoadBalancerPublicNet) LoadBalancerPublicNet { + var hcloudLoadBalancerPublicNet LoadBalancerPublicNet + hcloudLoadBalancerPublicNet.Enabled = source.Enabled + hcloudLoadBalancerPublicNet.IPv4 = c.schemaLoadBalancerPublicNetIPv4ToHcloudLoadBalancerPublicNetIPv4(source.IPv4) + hcloudLoadBalancerPublicNet.IPv6 = c.schemaLoadBalancerPublicNetIPv6ToHcloudLoadBalancerPublicNetIPv6(source.IPv6) + return hcloudLoadBalancerPublicNet +} +func (c *converterImpl) schemaNetworkProtectionToHcloudNetworkProtection(source schema.NetworkProtection) NetworkProtection { + var hcloudNetworkProtection NetworkProtection + hcloudNetworkProtection.Delete = source.Delete + return hcloudNetworkProtection +} +func (c *converterImpl) schemaPricingServerBackupToHcloudServerBackupPricing(source schema.PricingServerBackup) ServerBackupPricing { + var hcloudServerBackupPricing ServerBackupPricing + hcloudServerBackupPricing.Percentage = source.Percentage + return hcloudServerBackupPricing +} +func (c *converterImpl) schemaPrimaryIPProtectionToHcloudPrimaryIPProtection(source schema.PrimaryIPProtection) PrimaryIPProtection { + var hcloudPrimaryIPProtection PrimaryIPProtection + hcloudPrimaryIPProtection.Delete = source.Delete + return hcloudPrimaryIPProtection +} +func (c *converterImpl) schemaServerProtectionToHcloudServerProtection(source schema.ServerProtection) ServerProtection { + var hcloudServerProtection ServerProtection + hcloudServerProtection.Delete = source.Delete + hcloudServerProtection.Rebuild = source.Rebuild + return hcloudServerProtection +} +func (c *converterImpl) schemaVolumeProtectionToHcloudVolumeProtection(source schema.VolumeProtection) VolumeProtection { + var hcloudVolumeProtection VolumeProtection + hcloudVolumeProtection.Delete = source.Delete + return hcloudVolumeProtection +} +func (c *converterImpl) serverTypePricingFromSchema(source schema.PricingServerTypePrice) ServerTypeLocationPricing { + var hcloudServerTypeLocationPricing ServerTypeLocationPricing + hcloudLocation := locationFromString(source.Location) + hcloudServerTypeLocationPricing.Location = &hcloudLocation + hcloudServerTypeLocationPricing.Hourly = c.PriceFromSchema(source.PriceHourly) + hcloudServerTypeLocationPricing.Monthly = c.PriceFromSchema(source.PriceMonthly) + return hcloudServerTypeLocationPricing +} +func (c *converterImpl) timeTimeToTimeTime(source time.Time) time.Time { + return source +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_server_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_server_client_iface.go new file mode 100644 index 000000000000..82038a30cbac --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_server_client_iface.go @@ -0,0 +1,90 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// IServerClient ... +type IServerClient interface { + // GetByID retrieves a server by its ID. If the server does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*Server, *Response, error) + // GetByName retrieves a server by its name. If the server does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*Server, *Response, error) + // Get retrieves a server by its ID if the input can be parsed as an integer, otherwise it + // retrieves a server by its name. If the server does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*Server, *Response, error) + // List returns a list of servers for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts ServerListOpts) ([]*Server, *Response, error) + // All returns all servers. + All(ctx context.Context) ([]*Server, error) + // AllWithOpts returns all servers for the given options. + AllWithOpts(ctx context.Context, opts ServerListOpts) ([]*Server, error) + // Create creates a new server. + Create(ctx context.Context, opts ServerCreateOpts) (ServerCreateResult, *Response, error) + // Delete deletes a server. + // + // Deprecated: Use [ServerClient.DeleteWithResult] instead. + Delete(ctx context.Context, server *Server) (*Response, error) + // DeleteWithResult deletes a server and returns the parsed response containing the action. + DeleteWithResult(ctx context.Context, server *Server) (*ServerDeleteResult, *Response, error) + // Update updates a server. + Update(ctx context.Context, server *Server, opts ServerUpdateOpts) (*Server, *Response, error) + // Poweron starts a server. + Poweron(ctx context.Context, server *Server) (*Action, *Response, error) + // Reboot reboots a server. + Reboot(ctx context.Context, server *Server) (*Action, *Response, error) + // Reset resets a server. + Reset(ctx context.Context, server *Server) (*Action, *Response, error) + // Shutdown shuts down a server. + Shutdown(ctx context.Context, server *Server) (*Action, *Response, error) + // Poweroff stops a server. + Poweroff(ctx context.Context, server *Server) (*Action, *Response, error) + // ResetPassword resets a server's password. + ResetPassword(ctx context.Context, server *Server) (ServerResetPasswordResult, *Response, error) + // CreateImage creates an image from a server. + CreateImage(ctx context.Context, server *Server, opts *ServerCreateImageOpts) (ServerCreateImageResult, *Response, error) + // EnableRescue enables rescue mode for a server. + EnableRescue(ctx context.Context, server *Server, opts ServerEnableRescueOpts) (ServerEnableRescueResult, *Response, error) + // DisableRescue disables rescue mode for a server. + DisableRescue(ctx context.Context, server *Server) (*Action, *Response, error) + // Rebuild rebuilds a server. + // + // Deprecated: Use [ServerClient.RebuildWithResult] instead. + Rebuild(ctx context.Context, server *Server, opts ServerRebuildOpts) (*Action, *Response, error) + // RebuildWithResult rebuilds a server. + RebuildWithResult(ctx context.Context, server *Server, opts ServerRebuildOpts) (ServerRebuildResult, *Response, error) + // AttachISO attaches an ISO to a server. + AttachISO(ctx context.Context, server *Server, iso *ISO) (*Action, *Response, error) + // DetachISO detaches the currently attached ISO from a server. + DetachISO(ctx context.Context, server *Server) (*Action, *Response, error) + // EnableBackup enables backup for a server. Pass in an empty backup window to let the + // API pick a window for you. See the API documentation at docs.hetzner.cloud for a list + // of valid backup windows. + EnableBackup(ctx context.Context, server *Server, window string) (*Action, *Response, error) + // DisableBackup disables backup for a server. + DisableBackup(ctx context.Context, server *Server) (*Action, *Response, error) + // ChangeType changes a server's type. + ChangeType(ctx context.Context, server *Server, opts ServerChangeTypeOpts) (*Action, *Response, error) + // ChangeDNSPtr changes or resets the reverse DNS pointer for a server IP address. + // Pass a nil ptr to reset the reverse DNS pointer to its default value. + ChangeDNSPtr(ctx context.Context, server *Server, ip string, ptr *string) (*Action, *Response, error) + // ChangeProtection changes the resource protection level of a server. + ChangeProtection(ctx context.Context, server *Server, opts ServerChangeProtectionOpts) (*Action, *Response, error) + // RequestConsole requests a WebSocket VNC console. + RequestConsole(ctx context.Context, server *Server) (ServerRequestConsoleResult, *Response, error) + // AttachToNetwork attaches a server to a network. + AttachToNetwork(ctx context.Context, server *Server, opts ServerAttachToNetworkOpts) (*Action, *Response, error) + // DetachFromNetwork detaches a server from a network. + DetachFromNetwork(ctx context.Context, server *Server, opts ServerDetachFromNetworkOpts) (*Action, *Response, error) + // ChangeAliasIPs changes a server's alias IPs in a network. + ChangeAliasIPs(ctx context.Context, server *Server, opts ServerChangeAliasIPsOpts) (*Action, *Response, error) + // GetMetrics obtains metrics for Server. + GetMetrics(ctx context.Context, server *Server, opts ServerGetMetricsOpts) (*ServerMetrics, *Response, error) + AddToPlacementGroup(ctx context.Context, server *Server, placementGroup *PlacementGroup) (*Action, *Response, error) + RemoveFromPlacementGroup(ctx context.Context, server *Server) (*Action, *Response, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_server_type_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_server_type_client_iface.go new file mode 100644 index 000000000000..57c57afa0603 --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_server_type_client_iface.go @@ -0,0 +1,27 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// IServerTypeClient ... +type IServerTypeClient interface { + // GetByID retrieves a server type by its ID. If the server type does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*ServerType, *Response, error) + // GetByName retrieves a server type by its name. If the server type does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*ServerType, *Response, error) + // Get retrieves a server type by its ID if the input can be parsed as an integer, otherwise it + // retrieves a server type by its name. If the server type does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*ServerType, *Response, error) + // List returns a list of server types for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts ServerTypeListOpts) ([]*ServerType, *Response, error) + // All returns all server types. + All(ctx context.Context) ([]*ServerType, error) + // AllWithOpts returns all server types for the given options. + AllWithOpts(ctx context.Context, opts ServerTypeListOpts) ([]*ServerType, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_ssh_key_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_ssh_key_client_iface.go new file mode 100644 index 000000000000..d2c6988d9c3d --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_ssh_key_client_iface.go @@ -0,0 +1,35 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// ISSHKeyClient ... +type ISSHKeyClient interface { + // GetByID retrieves a SSH key by its ID. If the SSH key does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*SSHKey, *Response, error) + // GetByName retrieves a SSH key by its name. If the SSH key does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*SSHKey, *Response, error) + // GetByFingerprint retreives a SSH key by its fingerprint. If the SSH key does not exist, nil is returned. + GetByFingerprint(ctx context.Context, fingerprint string) (*SSHKey, *Response, error) + // Get retrieves a SSH key by its ID if the input can be parsed as an integer, otherwise it + // retrieves a SSH key by its name. If the SSH key does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*SSHKey, *Response, error) + // List returns a list of SSH keys for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts SSHKeyListOpts) ([]*SSHKey, *Response, error) + // All returns all SSH keys. + All(ctx context.Context) ([]*SSHKey, error) + // AllWithOpts returns all SSH keys with the given options. + AllWithOpts(ctx context.Context, opts SSHKeyListOpts) ([]*SSHKey, error) + // Create creates a new SSH key with the given options. + Create(ctx context.Context, opts SSHKeyCreateOpts) (*SSHKey, *Response, error) + // Delete deletes a SSH key. + Delete(ctx context.Context, sshKey *SSHKey) (*Response, error) + // Update updates a SSH key. + Update(ctx context.Context, sshKey *SSHKey, opts SSHKeyUpdateOpts) (*SSHKey, *Response, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_volume_client_iface.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_volume_client_iface.go new file mode 100644 index 000000000000..28edb7a270ee --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/hcloud/zz_volume_client_iface.go @@ -0,0 +1,43 @@ +// Code generated by ifacemaker; DO NOT EDIT. + +package hcloud + +import ( + "context" +) + +// IVolumeClient ... +type IVolumeClient interface { + // GetByID retrieves a volume by its ID. If the volume does not exist, nil is returned. + GetByID(ctx context.Context, id int64) (*Volume, *Response, error) + // GetByName retrieves a volume by its name. If the volume does not exist, nil is returned. + GetByName(ctx context.Context, name string) (*Volume, *Response, error) + // Get retrieves a volume by its ID if the input can be parsed as an integer, otherwise it + // retrieves a volume by its name. If the volume does not exist, nil is returned. + Get(ctx context.Context, idOrName string) (*Volume, *Response, error) + // List returns a list of volumes for a specific page. + // + // Please note that filters specified in opts are not taken into account + // when their value corresponds to their zero value or when they are empty. + List(ctx context.Context, opts VolumeListOpts) ([]*Volume, *Response, error) + // All returns all volumes. + All(ctx context.Context) ([]*Volume, error) + // AllWithOpts returns all volumes with the given options. + AllWithOpts(ctx context.Context, opts VolumeListOpts) ([]*Volume, error) + // Create creates a new volume with the given options. + Create(ctx context.Context, opts VolumeCreateOpts) (VolumeCreateResult, *Response, error) + // Delete deletes a volume. + Delete(ctx context.Context, volume *Volume) (*Response, error) + // Update updates a volume. + Update(ctx context.Context, volume *Volume, opts VolumeUpdateOpts) (*Volume, *Response, error) + // AttachWithOpts attaches a volume to a server. + AttachWithOpts(ctx context.Context, volume *Volume, opts VolumeAttachOpts) (*Action, *Response, error) + // Attach attaches a volume to a server. + Attach(ctx context.Context, volume *Volume, server *Server) (*Action, *Response, error) + // Detach detaches a volume from a server. + Detach(ctx context.Context, volume *Volume) (*Action, *Response, error) + // ChangeProtection changes the resource protection level of a volume. + ChangeProtection(ctx context.Context, volume *Volume, opts VolumeChangeProtectionOpts) (*Action, *Response, error) + // Resize changes the size of a volume. + Resize(ctx context.Context, volume *Volume, size int) (*Action, *Response, error) +} diff --git a/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/tools.go b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/tools.go new file mode 100644 index 000000000000..4ca84ddc737b --- /dev/null +++ b/cluster-autoscaler/cloudprovider/hetzner/hcloud-go/tools.go @@ -0,0 +1,9 @@ +//go:build tools +// +build tools + +package tools + +import ( + _ "github.com/jmattheis/goverter/cmd/goverter" + _ "github.com/vburenin/ifacemaker" +) diff --git a/cluster-autoscaler/cloudprovider/hetzner/hetzner_node_group.go b/cluster-autoscaler/cloudprovider/hetzner/hetzner_node_group.go index b010dfbadc3e..6fef8f37c5fd 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hetzner_node_group.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hetzner_node_group.go @@ -23,7 +23,6 @@ import ( "math/rand" "strings" "sync" - "time" apiv1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -411,6 +410,9 @@ func instanceTypeArch(manager *hetznerManager, instanceType string) (string, err } func createServer(n *hetznerNodeGroup) error { + ctx, cancel := context.WithTimeout(n.manager.apiCallContext, n.manager.createTimeout) + defer cancel() + serverType, err := n.manager.cachedServerType.getServerType(n.instanceType) if err != nil { return err @@ -454,23 +456,20 @@ func createServer(n *hetznerNodeGroup) error { opts.Firewalls = []*hcloud.ServerCreateFirewall{serverCreateFirewall} } - serverCreateResult, _, err := n.manager.client.Server.Create(n.manager.apiCallContext, opts) + serverCreateResult, _, err := n.manager.client.Server.Create(ctx, opts) if err != nil { return fmt.Errorf("could not create server type %s in region %s: %v", n.instanceType, n.region, err) } server := serverCreateResult.Server - actions := []*hcloud.Action{serverCreateResult.Action} - actions = append(actions, serverCreateResult.NextActions...) + actions := append(serverCreateResult.NextActions, serverCreateResult.Action) // Delete the server if any action (most importantly create_server & start_server) fails - for _, action := range actions { - err = waitForServerAction(n.manager, server.Name, action) - if err != nil { - _ = n.manager.deleteServer(server) - return fmt.Errorf("failed to start server %s error: %v", server.Name, err) - } + err = n.manager.client.Action.WaitFor(ctx, actions...) + if err != nil { + _ = n.manager.deleteServer(server) + return fmt.Errorf("failed to start server %s error: %v", server.Name, err) } return nil @@ -525,39 +524,6 @@ func findImage(n *hetznerNodeGroup, serverType *hcloud.ServerType) (*hcloud.Imag return images[0], nil } -func waitForServerAction(m *hetznerManager, serverName string, action *hcloud.Action) error { - // The implementation of the Hetzner Cloud action client's WatchProgress - // method may be a little puzzling. The following comment thus explains how - // waitForServerAction works. - // - // WatchProgress returns two channels. The first channel is used to send a - // ballpark estimate for the action progress, the second to send any error - // that may occur. - // - // WatchProgress is implemented in such a way, that the first channel can - // be ignored. It is not necessary to consume it to avoid a deadlock in - // WatchProgress. Any write to this channel is wrapped in a select. - // Progress updates are simply not sent if nothing reads from the other - // side. - // - // Once the action completes successfully nil is send through the second - // channel. Then both channels are closed. - // - // The following code therefore only watches the second channel. If it - // reads an error from the channel the action is failed. Otherwise the - // action is successful. - _, errChan := m.client.Action.WatchProgress(m.apiCallContext, action) - select { - case err := <-errChan: - if err != nil { - return fmt.Errorf("error while waiting for server action: %s: %v", serverName, err) - } - return nil - case <-time.After(m.createTimeout): - return fmt.Errorf("timeout waiting for server %s", serverName) - } -} - func (n *hetznerNodeGroup) resetTargetSize(expectedDelta int) { servers, err := n.manager.allServers(n.id) if err != nil {