Skip to content

Commit

Permalink
platform/machine/packet: use API to delete device
Browse files Browse the repository at this point in the history
since the mach.Destroy only adds devices to the pool, we don't need to
rely on it to actually remove a device.

Signed-off-by: Mathieu Tortuyaux <[email protected]>
  • Loading branch information
tormath1 committed Dec 15, 2021
1 parent 8aa6c8e commit 99f59e6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions platform/machine/packet/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,37 +98,37 @@ func (pc *cluster) NewMachine(userdata *conf.UserData) (platform.Machine, error)
mach.publicIP = pc.flight.api.GetDeviceAddress(device, 4, true)
mach.privateIP = pc.flight.api.GetDeviceAddress(device, 4, false)
if mach.publicIP == "" || mach.privateIP == "" {
mach.Destroy()
pc.flight.api.DeleteDevice(mach.ID())
err = fmt.Errorf("couldn't find IP addresses for device")
continue // provisioning error
}

dir := filepath.Join(pc.RuntimeConf().OutputDir, mach.ID())
if err = os.Mkdir(dir, 0777); err != nil {
mach.Destroy()
pc.flight.api.DeleteDevice(mach.ID())
return nil, err
}

if cons != nil {
if err = os.Rename(consolePath, filepath.Join(dir, "console.txt")); err != nil {
mach.Destroy()
pc.flight.api.DeleteDevice(mach.ID())
return nil, err
}
}

confPath := filepath.Join(dir, "user-data")
if err = conf.WriteFile(confPath); err != nil {
mach.Destroy()
pc.flight.api.DeleteDevice(mach.ID())
return nil, err
}

if mach.journal, err = platform.NewJournal(dir); err != nil {
mach.Destroy()
pc.flight.api.DeleteDevice(mach.ID())
return nil, err
}

if err = platform.StartMachine(mach, mach.journal); err != nil {
mach.Destroy()
pc.flight.api.DeleteDevice(mach.ID())
continue // provisioning error
}

Expand Down

0 comments on commit 99f59e6

Please sign in to comment.