restore server rewrite
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
22d434c1e6
commit
b053e63995
1 changed files with 39 additions and 41 deletions
|
@ -28,36 +28,23 @@ type Server struct {
|
||||||
netPlugin ocicni.CNIPlugin
|
netPlugin ocicni.CNIPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) loadSandboxes() error {
|
func (s *Server) loadSandbox(id string) error {
|
||||||
err := filepath.Walk(s.sandboxDir, func(path string, info os.FileInfo, err error) error {
|
metaJSON, err := ioutil.ReadFile(filepath.Join(s.sandboxDir, id, "metadata.json"))
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !info.IsDir() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if path == s.sandboxDir {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
metaJSON, err := ioutil.ReadFile(filepath.Join(path, "metadata.json"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var m metadata
|
var m metadata
|
||||||
if err2 := json.Unmarshal(metaJSON, &m); err2 != nil {
|
if err = json.Unmarshal(metaJSON, &m); err != nil {
|
||||||
return err2
|
|
||||||
}
|
|
||||||
sname, err := filepath.Rel(s.sandboxDir, path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.addSandbox(&sandbox{
|
s.addSandbox(&sandbox{
|
||||||
name: sname,
|
name: id,
|
||||||
logDir: m.LogDir,
|
logDir: m.LogDir,
|
||||||
labels: m.Labels,
|
labels: m.Labels,
|
||||||
containers: oci.NewMemoryStore(),
|
containers: oci.NewMemoryStore(),
|
||||||
})
|
})
|
||||||
scontainer, err := oci.NewContainer(m.ContainerName, path, path, m.Labels, sname, false)
|
sandboxPath := filepath.Join(s.sandboxDir, id)
|
||||||
|
scontainer, err := oci.NewContainer(m.ContainerName, sandboxPath, sandboxPath, m.Labels, id, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -66,9 +53,20 @@ func (s *Server) loadSandboxes() error {
|
||||||
logrus.Warnf("error updating status for container %s: %v", scontainer, err)
|
logrus.Warnf("error updating status for container %s: %v", scontainer, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
}
|
||||||
|
|
||||||
|
func (s *Server) restore() error {
|
||||||
|
dir, err := ioutil.ReadDir(s.sandboxDir)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
for _, v := range dir {
|
||||||
|
if err := s.loadSandbox(v.Name()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// New creates a new Server with options provided
|
// New creates a new Server with options provided
|
||||||
func New(runtimePath, sandboxDir, containerDir string) (*Server, error) {
|
func New(runtimePath, sandboxDir, containerDir string) (*Server, error) {
|
||||||
|
@ -107,8 +105,8 @@ func New(runtimePath, sandboxDir, containerDir string) (*Server, error) {
|
||||||
containers: containers,
|
containers: containers,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := s.loadSandboxes(); err != nil {
|
if err := s.restore(); err != nil {
|
||||||
logrus.Warnf("couldn't get sandboxes: %v", err)
|
logrus.Warnf("couldn't restore: %v", err)
|
||||||
}
|
}
|
||||||
logrus.Debugf("sandboxes: %v", s.state.sandboxes)
|
logrus.Debugf("sandboxes: %v", s.state.sandboxes)
|
||||||
logrus.Debugf("containers: %v", s.state.containers)
|
logrus.Debugf("containers: %v", s.state.containers)
|
||||||
|
|
Loading…
Reference in a new issue