Don't use Packer context as vSphere driver context (#9576)

This commit is contained in:
Sylvia Moss 2020-07-14 11:45:19 +02:00 committed by GitHub
parent eb5c3c3efb
commit 5a006f226a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 9 deletions

View File

@ -44,8 +44,8 @@ type StepConnect struct {
Config *ConnectConfig
}
func (s *StepConnect) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
d, err := driver.NewDriver(ctx, &driver.ConnectConfig{
func (s *StepConnect) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
d, err := driver.NewDriver(&driver.ConnectConfig{
VCenterServer: s.Config.VCenterServer,
Username: s.Config.Username,
Password: s.Config.Password,

View File

@ -1,7 +1,6 @@
package testing
import (
"context"
"encoding/json"
"fmt"
"math/rand"
@ -45,7 +44,7 @@ func TestConn(t *testing.T) *driver.Driver {
password = "jetbrains"
}
d, err := driver.NewDriver(context.TODO(), &driver.ConnectConfig{
d, err := driver.NewDriver(&driver.ConnectConfig{
VCenterServer: "vcenter.vsphere65.test",
Username: username,
Password: password,

View File

@ -16,6 +16,7 @@ import (
)
type Driver struct {
// context that controls the authenticated sessions used to run the VM commands
ctx context.Context
client *govmomi.Client
restClient *rest.Client
@ -31,7 +32,9 @@ type ConnectConfig struct {
Datacenter string
}
func NewDriver(ctx context.Context, config *ConnectConfig) (*Driver, error) {
func NewDriver(config *ConnectConfig) (*Driver, error) {
ctx := context.TODO()
vcenterUrl, err := url.Parse(fmt.Sprintf("https://%v/sdk", config.VCenterServer))
if err != nil {
return nil, err

View File

@ -1,7 +1,6 @@
package driver
import (
"context"
"fmt"
"math/rand"
"os"
@ -22,7 +21,7 @@ func newTestDriver(t *testing.T) *Driver {
password = "jetbrains"
}
d, err := NewDriver(context.TODO(), &ConnectConfig{
d, err := NewDriver(&ConnectConfig{
VCenterServer: "vcenter.vsphere65.test",
Username: username,
Password: password,

View File

@ -1,14 +1,13 @@
package main
import (
"context"
"fmt"
"github.com/hashicorp/packer/builder/vsphere/driver"
)
func main() {
d, err := driver.NewDriver(context.TODO(), &driver.ConnectConfig{
d, err := driver.NewDriver(&driver.ConnectConfig{
VCenterServer: "vcenter.vsphere65.test",
Username: "root",
Password: "jetbrains",