Skip to content

Commit 5e216a2

Browse files
Merge pull request #20193 from ashley-cui/lastupnever
New machines should show Never as LastUp
2 parents 744e09d + bcfd9f3 commit 5e216a2

File tree

5 files changed

+12
-23
lines changed

5 files changed

+12
-23
lines changed

cmd/podman/machine/list.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ func toHumanFormat(vms []*machine.ListResponse) ([]*entities.ListReporter, error
206206
case vm.Running:
207207
response.LastUp = "Currently running"
208208
response.Running = true
209+
case vm.LastUp.IsZero():
210+
response.LastUp = "Never"
209211
default:
210212
response.LastUp = units.HumanDuration(time.Since(vm.LastUp)) + " ago"
211213
}

pkg/machine/applehv/machine.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -787,16 +787,7 @@ func getVMInfos() ([]*machine.ListResponse, error) {
787787
return err
788788
}
789789
listEntry.Running = vmState == machine.Running
790-
791-
if !vm.LastUp.IsZero() { // this means we have already written a time to the config
792-
listEntry.LastUp = vm.LastUp
793-
} else { // else we just created the machine AKA last up = created time
794-
listEntry.LastUp = vm.Created
795-
vm.LastUp = listEntry.LastUp
796-
if err := vm.writeConfig(); err != nil {
797-
return err
798-
}
799-
}
790+
listEntry.LastUp = vm.LastUp
800791

801792
listed = append(listed, listEntry)
802793
}

pkg/machine/e2e/list_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,16 @@ var _ = Describe("podman machine list", func() {
8484
session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
8585
Expect(err).ToNot(HaveOccurred())
8686
Expect(session).To(Exit(0))
87+
88+
l := new(listMachine)
89+
listSession, err := mb.setCmd(l.withFormat("{{.LastUp}}")).run()
90+
Expect(err).NotTo(HaveOccurred())
91+
Expect(listSession).To(Exit(0))
92+
Expect(listSession.outputToString()).To(Equal("Never"))
93+
8794
s := new(startMachine)
8895
startSession, err := mb.setCmd(s).runWithoutWait()
8996
Expect(err).ToNot(HaveOccurred())
90-
l := new(listMachine)
9197
for i := 0; i < 30; i++ {
9298
listSession, err := mb.setCmd(l).run()
9399
Expect(listSession).To(Exit(0))
@@ -100,7 +106,7 @@ var _ = Describe("podman machine list", func() {
100106
time.Sleep(3 * time.Second)
101107
}
102108
Expect(startSession).To(Exit(0))
103-
listSession, err := mb.setCmd(l).run()
109+
listSession, err = mb.setCmd(l).run()
104110
Expect(listSession).To(Exit(0))
105111
Expect(err).ToNot(HaveOccurred())
106112
Expect(listSession.outputToString()).To(ContainSubstring("Currently running"))

pkg/machine/qemu/config.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,7 @@ func getVMInfos() ([]*machine.ListResponse, error) {
204204
return err
205205
}
206206
listEntry.Running = state == machine.Running
207-
208-
if !vm.LastUp.IsZero() { // this means we have already written a time to the config
209-
listEntry.LastUp = vm.LastUp
210-
} else { // else we just created the machine AKA last up = created time
211-
listEntry.LastUp = vm.Created
212-
vm.LastUp = listEntry.LastUp
213-
if err := vm.writeConfig(); err != nil {
214-
return err
215-
}
216-
}
207+
listEntry.LastUp = vm.LastUp
217208

218209
listed = append(listed, listEntry)
219210
}

pkg/machine/wsl/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func (p *WSLVirtualization) NewMachine(opts machine.InitOptions) (machine.VM, er
4646
}
4747

4848
vm.Created = time.Now()
49-
vm.LastUp = vm.Created
5049

5150
// Default is false
5251
if opts.UserModeNetworking != nil {

0 commit comments

Comments
 (0)