This repository has been archived by the owner on Feb 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 194
/
run.go
96 lines (73 loc) · 2.07 KB
/
run.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package daemon
import (
"fmt"
"github.com/golang/glog"
"github.com/hyperhq/hyperd/daemon/pod"
apitypes "github.com/hyperhq/hyperd/types"
"github.com/hyperhq/hyperd/utils"
)
func (daemon *Daemon) CreatePod(podId string, podSpec *apitypes.UserPod) (*pod.XPod, error) {
//FIXME: why restrict to 1024
if daemon.PodList.CountRunning() >= 1024 {
return nil, fmt.Errorf("There have already been %d running Pods", 1024)
}
if podId == "" {
podId = fmt.Sprintf("pod-%s", utils.RandStr(10, "alpha"))
}
if podSpec.Id == "" {
podSpec.Id = podId
}
if _, ok := daemon.PodList.Get(podSpec.Id); ok {
return nil, fmt.Errorf("pod %s already exist", podSpec.Id)
}
if err := podSpec.Validate(); err != nil {
return nil, err
}
factory := pod.NewPodFactory(daemon.Factory, daemon.PodList, daemon.db, daemon.Storage, daemon.Daemon, daemon.DefaultLog)
p, err := pod.CreateXPod(factory, podSpec)
if err != nil {
glog.Errorf("%s: failed to add pod: %v", podSpec.Id, err)
return nil, err
}
return p, nil
}
func (daemon *Daemon) StartPod(podId string) error {
p, ok := daemon.PodList.Get(podId)
if !ok {
return fmt.Errorf("The pod(%s) can not be found, please create it first", podId)
}
glog.Infof("Starting pod %q in vm: %q", podId, p.SandboxName())
err := p.Start()
if err != nil {
glog.Infof("failed to start pod %s: %v", p.Id(), err)
return err
}
return err
}
func (daemon *Daemon) WaitContainer(cid string, second int) (int, error) {
p, id, ok := daemon.PodList.GetByContainerIdOrName(cid)
if !ok {
return -1, fmt.Errorf("can not find container %s", cid)
}
return p.WaitContainer(id, second)
}
func (daemon *Daemon) SetPodLabels(pn string, override bool, labels map[string]string) error {
p, ok := daemon.PodList.Get(pn)
if !ok {
return fmt.Errorf("Can not get Pod %s info", pn)
}
err := p.SetLabel(labels, override)
if err != nil {
return err
}
// TODO update the persisit info
//spec, err := json.Marshal(p.spec)
//if err != nil {
// return err
//}
//
//if err := daemon.db.UpdatePod(p.name, spec); err != nil {
// return err
//}
return nil
}