Skip to content

Commit

Permalink
Add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik-K-N committed Apr 24, 2024
1 parent 25099f6 commit bbee8b9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
6 changes: 6 additions & 0 deletions builder/powervs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
return nil, err
}

dhcpClient, err := b.config.DHCPClient(ctx, b.config.ServiceInstanceID)
if err != nil {
return nil, err
}

var steps []multistep.Step

steps = append(steps,
Expand Down Expand Up @@ -120,6 +125,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
state.Put("jobClient", jobClient)
state.Put("instanceClient", instanceClient)
state.Put("networkClient", networkClient)
state.Put("dhcpClient", dhcpClient)

// Run!
b.runner = commonsteps.NewRunner(steps, b.config.PackerConfig, ui)
Expand Down
24 changes: 15 additions & 9 deletions builder/powervs/common/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var (
// for determining the SSH address of the instance.
func SSHHost() func(multistep.StateBag) (string, error) {
return func(state multistep.StateBag) (string, error) {
ui := state.Get("ui").(packersdk.Ui)
ui.Message("Fetching IP for machine")
instanceClient := state.Get("instanceClient").(*instance.IBMPIInstanceClient)
host := ""
const tries = 25
Expand All @@ -38,10 +40,15 @@ func SSHHost() func(multistep.StateBag) (string, error) {
return host, nil
}

ui := state.Get("ui").(packersdk.Ui)
ui.Say("Get Instance IP from DHCP server")

dhcpServerID, ok := state.GetOk("dhcpServerID")
if !ok {
// if the dhcpServerID is not set, dont try to fetch IP from DHCP server, instead wait for address to get populated.
ui.Message("Machine IP is not yet found, Trying again")
time.Sleep(sshHostSleepDuration)
continue
}
dhcpClient := state.Get("dhcpClient").(*instance.IBMPIDhcpClient)
ui.Message("Getting Instance IP from DHCP server")

net := state.Get("network").(*models.Network)
networkID := net.NetworkID
Expand All @@ -55,13 +62,12 @@ func SSHHost() func(multistep.StateBag) (string, error) {
}

if pvmNetwork == nil {
ui.Error("Failed to get network attached to VM")
return "", err
ui.Message("Failed to get network attached to VM, Trying again")
time.Sleep(sshHostSleepDuration)
continue
}

dhcpServerID := state.Get("dhcpServerID").(string)

dhcpServerDetails, err := dhcpClient.Get(dhcpServerID)
dhcpServerDetails, err := dhcpClient.Get(dhcpServerID.(string))
if err != nil {
ui.Error(fmt.Sprintf("Failed to get DHCP server details: %v", err))
return "", err
Expand All @@ -84,7 +90,7 @@ func SSHHost() func(multistep.StateBag) (string, error) {
return internalIP, nil
}

ui.Message("Machine IP is not yet found")
ui.Message("Machine IP is not yet found from DHCP server lease, Trying again")
time.Sleep(sshHostSleepDuration)
}
return "", errors.New("couldn't determine address for instance")
Expand Down
12 changes: 4 additions & 8 deletions builder/powervs/step_create_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (s *StepCreateNetwork) Run(_ context.Context, state multistep.StateBag) mul
DNSServers: []string{"8.8.8.8", "9.9.9.9"},
Type: core.StringPtr("pub-vlan"),
}
ui.Message("Creating Network")
net, err := networkClient.Create(netBody)
if err != nil {
ui.Error(fmt.Sprintf("failed to create network: %v", err))
Expand Down Expand Up @@ -73,7 +72,7 @@ func (s *StepCreateNetwork) Cleanup(state multistep.StateBag) {
dhcpClient := state.Get("dhcpClient").(*instance.IBMPIDhcpClient)

if err := dhcpClient.Delete(dhcpServerID); err != nil {
ui.Error(fmt.Sprintf("Error cleaning up DHCP server. Please delete the DHCP server manually: %s", dhcpServerID))
ui.Error(fmt.Sprintf("Error cleaning up DHCP server. Please delete the DHCP server manually: %s error: %v", dhcpServerID, err.Error()))
}
return
}
Expand All @@ -90,11 +89,7 @@ func (s *StepCreateNetwork) createDHCPNetwork(state multistep.StateBag) error {
ui := state.Get("ui").(packersdk.Ui)
dhcpClient := state.Get("dhcpClient").(*instance.IBMPIDhcpClient)

dhcpServerCreateParams := models.DHCPServerCreate{
Name: core.StringPtr("packerdhcpnetwork"),
}

dhcpServer, err := dhcpClient.Create(&dhcpServerCreateParams)
dhcpServer, err := dhcpClient.Create(&models.DHCPServerCreate{})
if err != nil {
return fmt.Errorf("error failed to create DHCP server: %v", err)
}
Expand All @@ -113,12 +108,13 @@ func (s *StepCreateNetwork) createDHCPNetwork(state multistep.StateBag) error {
}
if dhcpServerDetails.Network != nil && dhcpServerDetails.Network.ID != nil {
networkID = *dhcpServerDetails.Network.ID
ui.Message("DHCP server in active state")
break
}
if time.Since(startTime) > DHCPServerActiveTimeOut {
return fmt.Errorf("error DHCP server did not become active even after %f min", DHCPServerActiveTimeOut.Minutes())
}
ui.Say("Wating for DHCP server to become active")
ui.Message("Wating for DHCP server to become active")
time.Sleep(DHCPServerInterval)
}
ui.Say("Fetching network details")
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,5 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/zclconf/go-cty => github.com/nywilken/go-cty v1.13.3 // added by packer-sdc fix as noted in github.com/hashicorp/packer-plugin-sdk/issues/187
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nywilken/go-cty v1.13.3 h1:03U99oXf3j3g9xgqAE3YGpixCjM8Mg09KZ0Ji9LzX0o=
github.com/nywilken/go-cty v1.13.3/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0=
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
Expand Down Expand Up @@ -370,8 +372,6 @@ github.com/ugorji/go/codec v1.2.6 h1:7kbGefxLoDBuYXOms4yD7223OpNMMPNPZxXk5TvFcyQ
github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw=
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/zclconf/go-cty v1.13.3 h1:m+b9q3YDbg6Bec5rr+KGy1MzEVzY/jC2X+YX4yqKtHI=
github.com/zclconf/go-cty v1.13.3/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
Expand Down

0 comments on commit bbee8b9

Please sign in to comment.