[lxc-devel] [lxd/master] Record power state for VMs too
stgraber on Github
lxc-bot at linuxcontainers.org
Thu Dec 5 19:11:04 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191205/c21d5a36/attachment.bin>
-------------- next part --------------
From 5f83b94ce53c43a98be9d4862e50a837b5d4d010 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 5 Dec 2019 14:03:02 -0500
Subject: [PATCH 1/2] lxd/vm: Update comment
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/vm_qemu.go | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxd/vm_qemu.go b/lxd/vm_qemu.go
index 973483ac2c..923c8d3709 100644
--- a/lxd/vm_qemu.go
+++ b/lxd/vm_qemu.go
@@ -54,7 +54,7 @@ var vmConsole = map[int]bool{}
var vmConsoleLock sync.Mutex
func vmQemuLoad(s *state.State, args db.InstanceArgs, profiles []api.Profile) (instance.Instance, error) {
- // Create the container struct.
+ // Create the instance struct.
vm := vmQemuInstantiate(s, args)
// Expand config and devices.
@@ -2867,7 +2867,7 @@ func (vm *vmQemu) ExpiryDate() time.Time {
return vm.expiryDate
}
- // Return zero time if the container is not a snapshot.
+ // Return zero time if the instance is not a snapshot.
return time.Time{}
}
@@ -2938,10 +2938,10 @@ func (vm *vmQemu) DeferTemplateApply(trigger string) error {
}
func (vm *vmQemu) DaemonState() *state.State {
- // FIXME: This function should go away, since the abstract container
+ // FIXME: This function should go away, since the abstract instance
// interface should not be coupled with internal state details.
// However this is not currently possible, because many
- // higher-level APIs use container variables as "implicit
+ // higher-level APIs use instance variables as "implicit
// handles" to database/OS state and then need a way to get a
// reference to it.
return vm.state
From 4ce9ab9f530b37d5250dbeaafe8410985e4b33cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 5 Dec 2019 14:03:17 -0500
Subject: [PATCH 2/2] lxd/vm: Record power state
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #6469
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/vm_qemu.go | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/lxd/vm_qemu.go b/lxd/vm_qemu.go
index 923c8d3709..daf2aecf33 100644
--- a/lxd/vm_qemu.go
+++ b/lxd/vm_qemu.go
@@ -451,6 +451,12 @@ func (vm *vmQemu) OnStop(target string) error {
os.Remove(vm.getMonitorPath())
vm.unmount()
+ // Record power state
+ err := vm.state.Cluster.ContainerSetState(vm.id, "STOPPED")
+ if err != nil {
+ return err
+ }
+
if target == "reboot" {
return vm.Start(false)
}
@@ -638,6 +644,26 @@ func (vm *vmQemu) Start(stateful bool) error {
return err
}
+ // Database updates
+ err = vm.state.Cluster.Transaction(func(tx *db.ClusterTx) error {
+ // Record current state
+ err = tx.ContainerSetState(vm.id, "RUNNING")
+ if err != nil {
+ return errors.Wrap(err, "Error updating instance state")
+ }
+
+ // Update time instance last started time
+ err = tx.ContainerLastUsedUpdate(vm.id, time.Now().UTC())
+ if err != nil {
+ return errors.Wrap(err, "Error updating instance last used")
+ }
+
+ return nil
+ })
+ if err != nil {
+ return err
+ }
+
return nil
}
More information about the lxc-devel
mailing list