mirror of
https://github.com/apricote/hcloud-upload-image.git
synced 2026-01-13 21:31:03 +00:00
feat: add --location flag to specify datacenter region (#141)
Allow users to specify which Hetzner datacenter location to use for the temporary server during image upload. Defaults to fsn1 for backward compatibility. Available locations: fsn1, nbg1, hel1, ash, hil, sin Implements: #142
This commit is contained in:
parent
a9b16cf07c
commit
fcbc14aab6
5 changed files with 28 additions and 3 deletions
|
|
@ -94,6 +94,10 @@ type UploadOptions struct {
|
|||
// We also always add a label `apricote.de/created-by=hcloud-image-upload` ([CreatedByLabel], [CreatedByValue]).
|
||||
Labels map[string]string
|
||||
|
||||
// Location is the datacenter location for the temporary server.
|
||||
// Defaults to fsn1 if not specified.
|
||||
Location *hcloud.Location
|
||||
|
||||
// DebugSkipResourceCleanup will skip the cleanup of the temporary SSH Key and Server.
|
||||
DebugSkipResourceCleanup bool
|
||||
}
|
||||
|
|
@ -214,9 +218,14 @@ func (s *Client) Upload(ctx context.Context, options UploadOptions) (*hcloud.Ima
|
|||
}
|
||||
}
|
||||
|
||||
location := defaultLocation
|
||||
if options.Location != nil {
|
||||
location = options.Location
|
||||
}
|
||||
|
||||
logger.DebugContext(ctx, "creating server with config",
|
||||
"image", defaultImage.Name,
|
||||
"location", defaultLocation.Name,
|
||||
"location", location.Name,
|
||||
"serverType", serverType.Name,
|
||||
)
|
||||
serverCreateResult, _, err := s.c.Server.Create(ctx, hcloud.ServerCreateOpts{
|
||||
|
|
@ -230,7 +239,7 @@ func (s *Client) Upload(ctx context.Context, options UploadOptions) (*hcloud.Ima
|
|||
StartAfterCreate: hcloud.Ptr(false),
|
||||
// Image will never be booted, we only boot into rescue system
|
||||
Image: defaultImage,
|
||||
Location: defaultLocation,
|
||||
Location: location,
|
||||
Labels: labels,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ func ExampleClient_Upload() {
|
|||
ImageURL: imageURL,
|
||||
ImageCompression: hcloudimages.CompressionBZ2,
|
||||
Architecture: hcloud.ArchitectureX86,
|
||||
Location: &hcloud.Location{Name: "nbg1"}, // Optional: defaults to fsn1
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue