This repository was archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Support for GuestOS ID / Family #97
Open
akutz
wants to merge
1
commit into
vmware-archive:master
Choose a base branch
from
akutz:feature/vmguestdescriptor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Copyright (c) 2022 VMware, Inc. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //go:generate go run ./internal/generate_guestosidentifiers.go | ||
|
|
||
| package v1alpha1 | ||
|
|
||
| // VirtualMachineGuestOSDescriptor is used to specify information about the | ||
| // | ||
| type VirtualMachineGuestOSDescriptor struct { | ||
| // VirtualMachineGuestOSIdentifier is the guest OS identifier. | ||
| // | ||
| // If ommited the Family field is used to determine a default | ||
| // VirtualMachineGuestOSIdentifier value. | ||
| // | ||
| // +optional | ||
| ID VirtualMachineGuestOSIdentifier `json:"id,omitempty"` | ||
|
|
||
| // VirtualMachineGuestOSFamily specifies the family of the guest OS. | ||
| // | ||
| // If omitted the VirtualMachineImage is used to attempt to determine | ||
| // the guest's family and/or ID. | ||
| // | ||
| // +optional | ||
| Family VirtualMachineGuestOSFamily `json:"family,omitempty"` | ||
| } | ||
|
|
||
| // VirtualMachineGuestOSFamily specifies the family of the guest OS. | ||
| type VirtualMachineGuestOSFamily string | ||
|
|
||
| const ( | ||
| VirtualMachineGuestOSFamilyWindows VirtualMachineGuestOSFamily = "windowsGuest" | ||
| VirtualMachineGuestOSFamilyLinux VirtualMachineGuestOSFamily = "linuxGuest" | ||
| VirtualMachineGuestOSFamilyNovellNetware VirtualMachineGuestOSFamily = "netwareGuest" | ||
| VirtualMachineGuestOSFamilySolaris VirtualMachineGuestOSFamily = "solarisGuest" | ||
| VirtualMachineGuestOSFamilyDarwin VirtualMachineGuestOSFamily = "darwinGuestFamily" | ||
| VirtualMachineGuestOSFamilyOther VirtualMachineGuestOSFamily = "otherGuestFamily" | ||
| ) | ||
|
|
||
| // VirtualMachineGuestOSIdentifier is the guest operating system identifier. | ||
| type VirtualMachineGuestOSIdentifier string | ||
|
|
||
| // validVirtualMachineGuestOSIdentifiers is a map used to determine if a | ||
| // VirtualMachineGuestOSIdentifier value is valid. | ||
| var validVirtualMachineGuestOSIdentifiers map[VirtualMachineGuestOSIdentifier]struct{} | ||
|
|
||
| // IsValidVirtualMachineGuestOSIdentifier returns true if the provided value is | ||
| // valid. | ||
| func IsValidVirtualMachineGuestOSIdentifier(s string) bool { | ||
| return VirtualMachineGuestOSIdentifier(s).IsValid() | ||
| } | ||
|
|
||
| // IsValidVirtualMachineGuestOSIdentifier returns true if the identifier is | ||
| // valid. | ||
| func (e VirtualMachineGuestOSIdentifier) IsValid() bool { | ||
| _, ok := validVirtualMachineGuestOSIdentifiers[e] | ||
| return ok | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright (c) 2020 VMware, Inc. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package v1alpha1_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/vmware-tanzu/vm-operator-api/api/v1alpha1" | ||
| ) | ||
|
|
||
| func TestIsValidVirtualMachineGuestOSIdentifier(t *testing.T) { | ||
|
|
||
| t.Run("valid", func(t *testing.T) { | ||
| testCases := []struct { | ||
| name string | ||
| id string | ||
| }{ | ||
| { | ||
| name: "otherLinuxGuest", | ||
| id: "otherLinuxGuest", | ||
| }, | ||
| { | ||
| name: "genericLinuxGuest", | ||
| id: "genericLinuxGuest", | ||
| }, | ||
| } | ||
| for i := range testCases { | ||
| tc := testCases[i] | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| if !v1alpha1.IsValidVirtualMachineGuestOSIdentifier(tc.id) { | ||
| t.Errorf("%s is invalid & should be valid", tc.id) | ||
| } | ||
|
|
||
| }) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("invalid", func(t *testing.T) { | ||
| testCases := []struct { | ||
| name string | ||
| id string | ||
| }{ | ||
| { | ||
| name: "windows", | ||
| id: "windows", | ||
| }, | ||
| { | ||
| name: "windowsGuest", | ||
| id: "windowsGuest", | ||
| }, | ||
| } | ||
| for i := range testCases { | ||
| tc := testCases[i] | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| if v1alpha1.IsValidVirtualMachineGuestOSIdentifier(tc.id) { | ||
| t.Errorf("%s is valid & should be invalid", tc.id) | ||
| } | ||
|
|
||
| }) | ||
| } | ||
| }) | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidental deletion of text?