Skip to content

Commit

Permalink
fix: set mac address to lowercase
Browse files Browse the repository at this point in the history
- Sets the MAC address to lowercase.
- Update "Mac address" to "MAC address".

Ref: #324
Ref: https://kb.vmware.com/s/article/82139

Signed-off-by: Ryan Johnson <[email protected]>
  • Loading branch information
tenthirtyam authored and lbajolet-hashicorp committed Dec 6, 2023
1 parent b636f73 commit 3a13918
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .web-docs/components/builder/vsphere-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ necessary for this build to succeed and can be found further down the page.
available network. If the network is inside a network folder in vSphere inventory,
you need to provide the full path to the network.

- `mac_address` (string) - Sets a custom Mac Address to the network adapter. If set, the [network](#network) must be also specified.
- `mac_address` (string) - Sets a custom MAC address to the network adapter. If set, the [network](#network) must be also specified.

- `notes` (string) - VM notes.

Expand Down
5 changes: 3 additions & 2 deletions builder/vsphere/clone/step_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"fmt"
"path"
"strings"

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
Expand Down Expand Up @@ -41,7 +42,7 @@ type CloneConfig struct {
// available network. If the network is inside a network folder in vSphere inventory,
// you need to provide the full path to the network.
Network string `mapstructure:"network"`
// Sets a custom Mac Address to the network adapter. If set, the [network](#network) must be also specified.
// Sets a custom MAC address to the network adapter. If set, the [network](#network) must be also specified.
MacAddress string `mapstructure:"mac_address"`
// VM notes.
Notes string `mapstructure:"notes"`
Expand Down Expand Up @@ -117,7 +118,7 @@ func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multist
Datastore: s.Location.Datastore,
LinkedClone: s.Config.LinkedClone,
Network: s.Config.Network,
MacAddress: s.Config.MacAddress,
MacAddress: strings.ToLower(s.Config.MacAddress),
Annotation: s.Config.Notes,
VAppProperties: s.Config.VAppConfig.Properties,
PrimaryDiskSize: s.Config.DiskSize,
Expand Down
3 changes: 2 additions & 1 deletion builder/vsphere/clone/step_clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bytes"
"context"
"path"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -247,7 +248,7 @@ func driverCreateConfig(config *CloneConfig, location *common.LocationConfig) *d
Datastore: location.Datastore,
LinkedClone: config.LinkedClone,
Network: config.Network,
MacAddress: config.MacAddress,
MacAddress: strings.ToLower(config.MacAddress),
VAppProperties: config.VAppConfig.Properties,
PrimaryDiskSize: config.DiskSize,
}
Expand Down
2 changes: 1 addition & 1 deletion builder/vsphere/driver/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestVirtualMachineDriver_CloneWithMacAddress(t *testing.T) {
network := adapter.GetVirtualEthernetCard()
oldMacAddress := network.MacAddress

newMacAddress := "D4:B4:D4:96:70:26"
newMacAddress := "d4:b4:d4:96:70:26"
config := &CloneConfig{
Name: "mock name",
Host: "DC0_H0",
Expand Down
3 changes: 2 additions & 1 deletion builder/vsphere/iso/step_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"fmt"
"path"
"strings"

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
Expand Down Expand Up @@ -153,7 +154,7 @@ func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multiste
networkCards = append(networkCards, driver.NIC{
Network: nic.Network,
NetworkCard: nic.NetworkCard,
MacAddress: nic.MacAddress,
MacAddress: strings.ToLower(nic.MacAddress),
Passthrough: nic.Passthrough,
})
}
Expand Down
2 changes: 1 addition & 1 deletion builder/vsphere/iso/step_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func driverCreateConfig(config *CreateConfig, location *common.LocationConfig) *
networkCards = append(networkCards, driver.NIC{
Network: nic.Network,
NetworkCard: nic.NetworkCard,
MacAddress: nic.MacAddress,
MacAddress: strings.ToLower(nic.MacAddress),
Passthrough: nic.Passthrough,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
available network. If the network is inside a network folder in vSphere inventory,
you need to provide the full path to the network.

- `mac_address` (string) - Sets a custom Mac Address to the network adapter. If set, the [network](#network) must be also specified.
- `mac_address` (string) - Sets a custom MAC address to the network adapter. If set, the [network](#network) must be also specified.

- `notes` (string) - VM notes.

Expand Down

0 comments on commit 3a13918

Please sign in to comment.