move containerState to/from disk to libkpod

Signed-off-by: Ryan Cole <rcyoalne@gmail.com>
This commit is contained in:
Ryan Cole 2017-07-20 13:05:12 -04:00
parent 1aa0d5da86
commit d625e0e468
9 changed files with 40 additions and 35 deletions

View file

@ -1,6 +1,7 @@
package libkpod
import (
"encoding/json"
"sync"
"github.com/containers/image/types"
@ -9,6 +10,7 @@ import (
"github.com/docker/docker/pkg/truncindex"
"github.com/kubernetes-incubator/cri-o/oci"
"github.com/kubernetes-incubator/cri-o/pkg/storage"
"github.com/moby/moby/pkg/ioutils"
)
// ContainerServer implements the ImageServer
@ -70,6 +72,35 @@ func New(runtime *oci.Runtime, store cstorage.Store, storageImageServer storage.
}
}
// ContainerStateFromDisk retrieves information on the state of a running container
// from the disk
func (c *ContainerServer) ContainerStateFromDisk(ctr *oci.Container) error {
if err := ctr.FromDisk(); err != nil {
return err
}
// ignore errors, this is a best effort to have up-to-date info about
// a given container before its state gets stored
c.runtime.UpdateStatus(ctr)
return nil
}
// ContainerStateToDisk writes the container's state information to a JSON file
// on disk
func (c *ContainerServer) ContainerStateToDisk(ctr *oci.Container) error {
// ignore errors, this is a best effort to have up-to-date info about
// a given container before its state gets stored
c.Runtime().UpdateStatus(ctr)
jsonSource, err := ioutils.NewAtomicFileWriter(ctr.StatePath(), 0644)
if err != nil {
return err
}
defer jsonSource.Close()
enc := json.NewEncoder(jsonSource)
return enc.Encode(c.runtime.ContainerStatus(ctr))
}
type containerServerState struct {
containers oci.ContainerStorer
}