Skip to content

Commit

Permalink
fix: limit source vm to 15 char
Browse files Browse the repository at this point in the history
- Updates `DefaultSourceNamePrefix` to "source".
- Limits the name of the source virtual machine to 15 characters to support Windows. This was causing issues for deploying Windows VMs as they require a shorter hostname.

#455

Signed-off-by: Ryan Johnson <ryan.johnson@broadcom.com>
  • Loading branch information
tenthirtyam committed Sep 30, 2024
1 parent 3b382d2 commit 910387b
Show file tree
Hide file tree
Showing 5 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 @@ -1344,7 +1344,7 @@ boot time.
**NOTE**: Guests using Windows with Win32-OpenSSH v9.1.0.0p1-Beta, scp
(the default protocol for copying data) returns a a non-zero error code since the MOTW
cannot be set, which cause any file transfer to fail. As a workaround you can override the transfer protocol
with SFTP instead `ssh_file_transfer_method = "sftp"`.
with SFTP instead `ssh_file_transfer_protocol = "sftp"`.

- `ssh_proxy_host` (string) - A SOCKS proxy host to use for SSH connection

Expand Down
2 changes: 1 addition & 1 deletion .web-docs/components/builder/vsphere-iso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ JSON Example:
**NOTE**: Guests using Windows with Win32-OpenSSH v9.1.0.0p1-Beta, scp
(the default protocol for copying data) returns a a non-zero error code since the MOTW
cannot be set, which cause any file transfer to fail. As a workaround you can override the transfer protocol
with SFTP instead `ssh_file_transfer_method = "sftp"`.
with SFTP instead `ssh_file_transfer_protocol = "sftp"`.

- `ssh_proxy_host` (string) - A SOCKS proxy host to use for SSH connection

Expand Down
4 changes: 2 additions & 2 deletions .web-docs/components/builder/vsphere-supervisor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ items are listed below as well as the _optional_ configurations.
- `image_name` (string) - Name of the source virtual machine (VM) image. If it is specified, the image with the name will be used for the
source VM, otherwise the image name from imported image will be used.

- `source_name` (string) - Name of the source VM. Defaults to `packer-vsphere-supervisor-<random-suffix>`.
- `source_name` (string) - Name of the source VM. Limited to 15 characters. Defaults to `source-<random-5-digit-suffix>`.

- `network_type` (string) - Name of the network type to attach to the source VM's network interface. Defaults to empty.

Expand Down Expand Up @@ -296,7 +296,7 @@ items are listed below as well as the _optional_ configurations.
**NOTE**: Guests using Windows with Win32-OpenSSH v9.1.0.0p1-Beta, scp
(the default protocol for copying data) returns a a non-zero error code since the MOTW
cannot be set, which cause any file transfer to fail. As a workaround you can override the transfer protocol
with SFTP instead `ssh_file_transfer_method = "sftp"`.
with SFTP instead `ssh_file_transfer_protocol = "sftp"`.

- `ssh_proxy_host` (string) - A SOCKS proxy host to use for SSH connection

Expand Down
9 changes: 6 additions & 3 deletions builder/vsphere/supervisor/step_create_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

const (
DefaultSourceNamePrefix = "packer-vsphere-supervisor"
DefaultSourceNamePrefix = "source"
VMSelectorLabelKey = DefaultSourceNamePrefix + "-selector"

StateKeySourceName = "source_name"
Expand All @@ -42,11 +42,10 @@ type CreateSourceConfig struct {
ClassName string `mapstructure:"class_name" required:"true"`
// Name of the storage class that configures storage-related attributes.
StorageClass string `mapstructure:"storage_class" required:"true"`

// Name of the source virtual machine (VM) image. If it is specified, the image with the name will be used for the
// source VM, otherwise the image name from imported image will be used.
ImageName string `mapstructure:"image_name"`
// Name of the source VM. Defaults to `packer-vsphere-supervisor-<random-suffix>`.
// Name of the source VM. Limited to 15 characters. Defaults to `source-<random-5-digit-suffix>`.
SourceName string `mapstructure:"source_name"`
// Name of the network type to attach to the source VM's network interface. Defaults to empty.
NetworkType string `mapstructure:"network_type"`
Expand Down Expand Up @@ -86,6 +85,10 @@ func (c *CreateSourceConfig) Prepare() []error {
c.SourceName = fmt.Sprintf("%s-%s", DefaultSourceNamePrefix, rand.String(5))
}

if len(c.SourceName) > 15 {
errs = append(errs, fmt.Errorf("'source_name' must not exceed 15 characters (length: %d): %s", len(c.SourceName), c.SourceName))
}

return errs
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- `image_name` (string) - Name of the source virtual machine (VM) image. If it is specified, the image with the name will be used for the
source VM, otherwise the image name from imported image will be used.

- `source_name` (string) - Name of the source VM. Defaults to `packer-vsphere-supervisor-<random-suffix>`.
- `source_name` (string) - Name of the source VM. Limited to 15 characters. Defaults to `source-<random-5-digit-suffix>`.

- `network_type` (string) - Name of the network type to attach to the source VM's network interface. Defaults to empty.

Expand Down

0 comments on commit 910387b

Please sign in to comment.