generated from hashicorp/packer-plugin-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ryan Johnson <[email protected]>
- Loading branch information
1 parent
623ba0a
commit 1956617
Showing
17 changed files
with
142 additions
and
131 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -13,17 +13,21 @@ import ( | |
"github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/driver" | ||
) | ||
|
||
const ( | ||
testDefaultUsername = "[email protected]" | ||
testDefaultPassword = "VMw@re1!" | ||
testDefaultApiEndpoint = "vcenter.example.com" | ||
) | ||
|
||
func NewVMName() string { | ||
rand.Seed(time.Now().UnixNano()) | ||
return fmt.Sprintf("test-%v", rand.Intn(1000)) | ||
r := rand.New(rand.NewSource(time.Now().UnixNano())) | ||
return fmt.Sprintf("test-%v", r.Intn(1000)) | ||
} | ||
|
||
func RenderConfig(builderType string, config map[string]interface{}) string { | ||
t := map[string][]map[string]interface{}{ | ||
"builders": { | ||
map[string]interface{}{ | ||
"type": builderType, | ||
}, | ||
{"type": builderType}, | ||
}, | ||
} | ||
for k, v := range config { | ||
|
@@ -37,21 +41,27 @@ func RenderConfig(builderType string, config map[string]interface{}) string { | |
func TestConn() (driver.Driver, error) { | ||
username := os.Getenv("VSPHERE_USERNAME") | ||
if username == "" { | ||
username = "root" | ||
username = testDefaultUsername | ||
} | ||
|
||
password := os.Getenv("VSPHERE_PASSWORD") | ||
if password == "" { | ||
password = "jetbrains" | ||
password = testDefaultPassword | ||
} | ||
|
||
vcenter := os.Getenv("VSPHERE_VCENTER_SERVER") | ||
if vcenter == "" { | ||
vcenter = testDefaultApiEndpoint | ||
} | ||
|
||
d, err := driver.NewDriver(&driver.ConnectConfig{ | ||
VCenterServer: "vcenter.example.com", | ||
VCenterServer: vcenter, | ||
Username: username, | ||
Password: password, | ||
InsecureConnection: true, | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("error connecting to vCenter Server instance: %v", err) | ||
return nil, fmt.Errorf("error connecting to endpoint: %v", err) | ||
} | ||
return d, nil | ||
} | ||
|
@@ -61,7 +71,6 @@ func GetVM(d driver.Driver, name string) (driver.VirtualMachine, error) { | |
if err != nil { | ||
return nil, fmt.Errorf("error finding virtual machine: %v", err) | ||
} | ||
|
||
return vm, nil | ||
} | ||
|
||
|
This file contains 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 |
---|---|---|
|
@@ -23,21 +23,27 @@ import ( | |
"github.com/vmware/govmomi/vim25/soap" | ||
) | ||
|
||
// Defines whether acceptance tests should be run | ||
const TestHostName = "esxi-01.example.com" | ||
const ( | ||
testDefaultUsername = "[email protected]" | ||
testDefaultPassword = "VMw@re1!" | ||
testDefaultApiEndpoint = "vcenter.example.com" | ||
testDefaultHost = "esxi-01.example.com" | ||
) | ||
|
||
func newTestDriver(t *testing.T) Driver { | ||
username := os.Getenv("VSPHERE_USERNAME") | ||
if username == "" { | ||
username = "root" | ||
} | ||
password := os.Getenv("VSPHERE_PASSWORD") | ||
if password == "" { | ||
password = "jetbrains" | ||
func getEnv(key, fallback string) string { | ||
if value := os.Getenv(key); value != "" { | ||
return value | ||
} | ||
return fallback | ||
} | ||
|
||
func newTestDriver(t *testing.T) Driver { | ||
username := getEnv("VSPHERE_USERNAME", testDefaultUsername) | ||
password := getEnv("VSPHERE_PASSWORD", testDefaultPassword) | ||
vcenter := getEnv("VSPHERE_VCENTER_SERVER", testDefaultApiEndpoint) | ||
|
||
d, err := NewDriver(&ConnectConfig{ | ||
VCenterServer: "vcenter.example.com", | ||
VCenterServer: vcenter, | ||
Username: username, | ||
Password: password, | ||
InsecureConnection: true, | ||
|
@@ -49,8 +55,8 @@ func newTestDriver(t *testing.T) Driver { | |
} | ||
|
||
func newVMName() string { | ||
rand.Seed(time.Now().UTC().UnixNano()) | ||
return fmt.Sprintf("test-%v", rand.Intn(1000)) | ||
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano())) | ||
return fmt.Sprintf("test-%v", r.Intn(1000)) | ||
} | ||
|
||
type VCenterSimulator struct { | ||
|
@@ -94,23 +100,23 @@ func (s *VCenterSimulator) Close() { | |
} | ||
} | ||
|
||
// Simulator shortcut to choose any pre created VM. | ||
// Simulator shortcut to choose any pre-created virtual machine. | ||
func (s *VCenterSimulator) ChooseSimulatorPreCreatedVM() (VirtualMachine, *simulator.VirtualMachine) { | ||
machine := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine) | ||
ref := machine.Reference() | ||
vm := s.driver.NewVM(&ref) | ||
return vm, machine | ||
} | ||
|
||
// Simulator shortcut to choose any pre created Datastore. | ||
// Simulator shortcut to choose any pre-created datastore. | ||
func (s *VCenterSimulator) ChooseSimulatorPreCreatedDatastore() (Datastore, *simulator.Datastore) { | ||
ds := simulator.Map.Any("Datastore").(*simulator.Datastore) | ||
ref := ds.Reference() | ||
datastore := s.driver.NewDatastore(&ref) | ||
return datastore, ds | ||
} | ||
|
||
// Simulator shortcut to choose any pre created Host. | ||
// Simulator shortcut to choose any pre-created EXSi host. | ||
func (s *VCenterSimulator) ChooseSimulatorPreCreatedHost() (*Host, *simulator.HostSystem) { | ||
h := simulator.Map.Any("HostSystem").(*simulator.HostSystem) | ||
ref := h.Reference() | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -14,6 +14,13 @@ import ( | |
"github.com/vmware/govmomi/vim25/types" | ||
) | ||
|
||
const ( | ||
defaultUsername = "[email protected]" | ||
defaultPassword = "VMw@re1!" | ||
defaultApiEndpoint = "vcenter.example.com" | ||
defaultHost = "esxi-01.example.com" | ||
) | ||
|
||
func TestAccISOBuilderAcc_default(t *testing.T) { | ||
config := defaultConfig() | ||
testCase := &acctest.PluginTestCase{ | ||
|
@@ -38,25 +45,18 @@ func TestAccISOBuilderAcc_default(t *testing.T) { | |
acctest.TestPlugin(t, testCase) | ||
} | ||
|
||
func defaultConfig() map[string]interface{} { | ||
username := os.Getenv("VSPHERE_USERNAME") | ||
if username == "" { | ||
username = "root" | ||
} | ||
password := os.Getenv("VSPHERE_PASSWORD") | ||
if password == "" { | ||
password = "jetbrains" | ||
} | ||
|
||
vcenter := os.Getenv("VSPHERE_VCENTER_SERVER") | ||
if vcenter == "" { | ||
vcenter = "vcenter.example.com" | ||
func getEnv(key, fallback string) string { | ||
if value := os.Getenv(key); value != "" { | ||
return value | ||
} | ||
return fallback | ||
} | ||
|
||
host := os.Getenv("VSPHERE_HOST") | ||
if host == "" { | ||
host = "esxi-01.example.com" | ||
} | ||
func defaultConfig() map[string]interface{} { | ||
username := getEnv("VSPHERE_USERNAME", defaultUsername) | ||
password := getEnv("VSPHERE_PASSWORD", defaultPassword) | ||
vcenter := getEnv("VSPHERE_VCENTER_SERVER", defaultApiEndpoint) | ||
host := getEnv("VSPHERE_HOST", defaultHost) | ||
|
||
config := map[string]interface{}{ | ||
"vcenter_server": vcenter, | ||
|
@@ -65,8 +65,8 @@ func defaultConfig() map[string]interface{} { | |
"host": host, | ||
"insecure_connection": true, | ||
|
||
"ssh_username": "root", | ||
"ssh_password": "jetbrains", | ||
"ssh_username": "packer", | ||
"ssh_password": "VMw@re1!", | ||
|
||
"vm_name": commonT.NewVMName(), | ||
"storage": map[string]interface{}{ | ||
|
@@ -546,21 +546,32 @@ func TestAccISOBuilderAcc_full(t *testing.T) { | |
func fullConfig() map[string]interface{} { | ||
username := os.Getenv("VSPHERE_USERNAME") | ||
if username == "" { | ||
username = "root" | ||
username = "[email protected]" | ||
} | ||
|
||
password := os.Getenv("VSPHERE_PASSWORD") | ||
if password == "" { | ||
password = "jetbrains" | ||
password = "VMw@re1!" | ||
} | ||
|
||
vcenter := os.Getenv("VSPHERE_VCENTER_SERVER") | ||
if vcenter == "" { | ||
vcenter = "vcenter.example.com" | ||
} | ||
|
||
host := os.Getenv("VSPHERE_HOST") | ||
if host == "" { | ||
host = "esxi-01.example.com" | ||
} | ||
|
||
config := map[string]interface{}{ | ||
"vcenter_server": "vcenter.example.com", | ||
"vcenter_server": vcenter, | ||
"username": username, | ||
"password": password, | ||
"host": host, | ||
"insecure_connection": true, | ||
|
||
"vm_name": commonT.NewVMName(), | ||
"host": "esxi-01.example.com", | ||
|
||
"RAM": 512, | ||
"disk_controller_type": []string{ | ||
|
@@ -602,8 +613,8 @@ func fullConfig() map[string]interface{} { | |
"/media/floppy/SETUP.SH<enter>", | ||
}, | ||
|
||
"ssh_username": "root", | ||
"ssh_password": "jetbrains", | ||
"ssh_username": "packer", | ||
"ssh_password": "VMw@re1!", | ||
} | ||
|
||
return config | ||
|
This file contains 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 |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
"type": "vsphere-clone", | ||
|
||
"vcenter_server": "vcenter.example.com", | ||
"username": "root", | ||
"password": "jetbrains", | ||
"username": "[email protected]", | ||
"password": "VMw@re1!", | ||
"insecure_connection": "true", | ||
|
||
"template": "alpine", | ||
|
This file contains 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 |
---|---|---|
|
@@ -12,9 +12,9 @@ source "vsphere-clone" "example_clone" { | |
communicator = "none" | ||
host = "esxi-01.example.com" | ||
insecure_connection = "true" | ||
password = "jetbrains" | ||
password = "VMw@re1!" | ||
template = "alpine" | ||
username = "root" | ||
username = "[email protected]" | ||
vcenter_server = "vcenter.example.com" | ||
vm_name = "alpine-clone-${local.timestamp}" | ||
} | ||
|
This file contains 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 |
---|---|---|
|
@@ -39,16 +39,16 @@ | |
"network_card": "vmxnet3" | ||
} | ||
], | ||
"password": "jetbrains", | ||
"ssh_password": "jetbrains", | ||
"ssh_username": "root", | ||
"password": "VMw@re1!", | ||
"ssh_password": "VMw@re1!", | ||
"ssh_username": "packer", | ||
"storage": [ | ||
{ | ||
"disk_size": 1024, | ||
"disk_thin_provisioned": true | ||
} | ||
], | ||
"username": "root", | ||
"username": "[email protected]", | ||
"vcenter_server": "vcenter.example.com", | ||
"vm_name": "alpine-{{timestamp}}" | ||
} | ||
|
Oops, something went wrong.