Skip to content

Commit

Permalink
Using Os.Type to detect Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Naumov committed Mar 28, 2022
1 parent a15daec commit 328d9f1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
24 changes: 2 additions & 22 deletions builder/yandex/driver_yc.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,7 @@ func (d *driverYC) GetImage(imageID string) (*Image, error) {
return nil, err
}

return &Image{
ID: image.Id,
Labels: image.Labels,
Licenses: image.ProductIds,
Name: image.Name,
Family: image.Family,
Description: image.Description,
FolderID: image.FolderId,
MinDiskSizeGb: toGigabytes(image.MinDiskSize),
SizeGb: toGigabytes(image.StorageSize),
}, nil
return convert(image), nil
}

func (d *driverYC) GetImageFromFolder(ctx context.Context, folderID string, family string) (*Image, error) {
Expand All @@ -133,17 +123,7 @@ func (d *driverYC) GetImageFromFolder(ctx context.Context, folderID string, fami
return nil, err
}

return &Image{
ID: image.Id,
Labels: image.Labels,
Licenses: image.ProductIds,
Name: image.Name,
Description: image.Description,
FolderID: image.FolderId,
Family: image.Family,
MinDiskSizeGb: toGigabytes(image.MinDiskSize),
SizeGb: toGigabytes(image.StorageSize),
}, nil
return convert(image), nil
}

func (d *driverYC) GetImageFromFolderByName(ctx context.Context, folderID string, imageName string) (*Image, error) {
Expand Down
20 changes: 20 additions & 0 deletions builder/yandex/image.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package yandex

import (
"github.com/yandex-cloud/go-genproto/yandex/cloud/compute/v1"
)

type Image struct {
ID string
FolderID string
Expand All @@ -10,4 +14,20 @@ type Image struct {
Description string
Family string
SizeGb int
Os *compute.Os
}

func convert(image *compute.Image) *Image {
return &Image{
ID: image.Id,
Labels: image.Labels,
Licenses: image.ProductIds,
Name: image.Name,
Family: image.Family,
Description: image.Description,
FolderID: image.FolderId,
MinDiskSizeGb: toGigabytes(image.MinDiskSize),
SizeGb: toGigabytes(image.StorageSize),
Os: image.Os,
}
}
4 changes: 1 addition & 3 deletions builder/yandex/step_create_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io/ioutil"
"strings"

"github.com/c2h5oh/datasize"
"github.com/hashicorp/packer-plugin-sdk/multistep"
Expand Down Expand Up @@ -218,8 +217,7 @@ func (s *StepCreateInstance) Run(ctx context.Context, state multistep.StateBag)
if config.UseIPv6 {
ui.Say("Prepare user-data...")

osWindows := strings.Contains(strings.ToLower(sourceImage.Family), "windows")
if osWindows {
if sourceImage.Os.Type == compute.Os_WINDOWS {
ui.Say("Windows OS detected, no additional IPv6 configuration required")
} else {
oldUserData, ok := instanceMetadata["user-data"]
Expand Down

0 comments on commit 328d9f1

Please sign in to comment.