本文整理匯總了Golang中hyper/engine.Engine類的典型用法代碼示例。如果您正苦於以下問題:Golang Engine類的具體用法?Golang Engine怎麽用?Golang Engine使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Engine類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: postVmCreate
func postVmCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
job := eng.Job("vmCreate", r.Form.Get("cpu"), r.Form.Get("mem"))
stdoutBuf := bytes.NewBuffer(nil)
job.Stdout.Add(stdoutBuf)
if err := job.Run(); err != nil {
return err
}
var (
env engine.Env
dat map[string]interface{}
returnedJSONstr string
)
returnedJSONstr = engine.Tail(stdoutBuf, 1)
if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil {
return err
}
env.Set("ID", dat["ID"].(string))
env.SetInt("Code", (int)(dat["Code"].(float64)))
env.Set("Cause", dat["Cause"].(string))
return writeJSONEnv(w, http.StatusOK, env)
}
示例2: Install
// Install installs daemon capabilities to eng.
func (daemon *Daemon) Install(eng *engine.Engine) error {
// Now, we just install a command 'info' to set/get the information of the docker and Hyper daemon
for name, method := range map[string]engine.Handler{
"info": daemon.CmdInfo,
"version": daemon.CmdVersion,
"create": daemon.CmdCreate,
"pull": daemon.CmdPull,
"podCreate": daemon.CmdPodCreate,
"podStart": daemon.CmdPodStart,
"podInfo": daemon.CmdPodInfo,
"podRm": daemon.CmdPodRm,
"podRun": daemon.CmdPodRun,
"podStop": daemon.CmdPodStop,
"vmCreate": daemon.CmdVmCreate,
"vmKill": daemon.CmdVmKill,
"list": daemon.CmdList,
"exec": daemon.CmdExec,
"attach": daemon.CmdAttach,
"tty": daemon.CmdTty,
"serveapi": apiserver.ServeApi,
"acceptconnections": apiserver.AcceptConnections,
} {
glog.V(3).Infof("Engine Register: name= %s\n", name)
if err := eng.Register(name, method); err != nil {
return err
}
}
return nil
}
示例3: postPodRemove
func postPodRemove(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
glog.V(1).Infof("Pod(%s) is process to be removed", r.Form.Get("podId"))
job := eng.Job("podRm", r.Form.Get("podId"))
stdoutBuf := bytes.NewBuffer(nil)
job.Stdout.Add(stdoutBuf)
if err := job.Run(); err != nil {
return err
}
var (
env engine.Env
dat map[string]interface{}
returnedJSONstr string
)
returnedJSONstr = engine.Tail(stdoutBuf, 1)
if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil {
return err
}
env.Set("ID", dat["ID"].(string))
env.SetInt("Code", (int)(dat["Code"].(float64)))
env.Set("Cause", dat["Cause"].(string))
return writeJSONEnv(w, http.StatusOK, env)
}
示例4: postContainerCreate
func postContainerCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
glog.V(1).Infof("Image name is %s\n", r.Form.Get("imageName"))
job := eng.Job("create", r.Form.Get("imageName"))
stdoutBuf := bytes.NewBuffer(nil)
stderrBuf := bytes.NewBuffer(nil)
job.Stdout.Add(stdoutBuf)
job.Stderr.Add(stderrBuf)
if err := job.Run(); err != nil {
return err
}
var (
env engine.Env
dat map[string]interface{}
returnedJSONstr string
)
returnedJSONstr = engine.Tail(stdoutBuf, 1)
if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil {
return err
}
env.Set("ContainerID", dat["ContainerID"].(string))
return writeJSONEnv(w, http.StatusCreated, env)
}
示例5: postAttach
func postAttach(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
var (
job = eng.Job("attach", r.Form.Get("type"), r.Form.Get("value"), r.Form.Get("tag"))
errOut io.Writer = os.Stderr
errStream io.Writer
)
// Setting up the streaming http interface.
inStream, outStream, err := hijackServer(w)
if err != nil {
return err
}
defer closeStreams(inStream, outStream)
fmt.Fprintf(outStream, "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\r\n")
errStream = outStream
job.Stdin.Add(inStream)
job.Stdout.Add(outStream)
job.Stderr.Set(errStream)
// Now run the user process in container.
job.SetCloseIO(false)
if err := job.Run(); err != nil {
fmt.Fprintf(errOut, "Error starting attach to POD %s: %s\n", r.Form.Get("podname"), err.Error())
return err
}
w.WriteHeader(http.StatusNoContent)
return nil
}
示例6: getPodInfo
func getPodInfo(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
job := eng.Job("podInfo", r.Form.Get("podName"))
stdoutBuf := bytes.NewBuffer(nil)
job.Stdout.Add(stdoutBuf)
if err := job.Run(); err != nil {
return err
}
var (
env engine.Env
dat map[string]interface{}
returnedJSONstr string
)
returnedJSONstr = engine.Tail(stdoutBuf, 1)
if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil {
return err
}
env.Set("hostname", dat["hostname"].(string))
return writeJSONEnv(w, http.StatusCreated, env)
}
示例7: postTtyResize
func postTtyResize(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
job := eng.Job("tty", r.Form.Get("id"), r.Form.Get("tag"), r.Form.Get("h"), r.Form.Get("w"))
if err := job.Run(); err != nil {
return err
}
return nil
}
示例8: postImageCreate
func postImageCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
glog.V(1).Infof("Image name is %s\n", r.Form.Get("imageName"))
job := eng.Job("pull", r.Form.Get("imageName"))
stdoutBuf := bytes.NewBuffer(nil)
job.Stdout.Add(stdoutBuf)
if err := job.Run(); err != nil {
return err
}
return nil
}
示例9: getList
func getList(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
glog.V(1).Infof("List type is %s\n", r.Form.Get("item"))
job := eng.Job("list", r.Form.Get("item"))
stdoutBuf := bytes.NewBuffer(nil)
job.Stdout.Add(stdoutBuf)
if err := job.Run(); err != nil {
return err
}
str := engine.Tail(stdoutBuf, 1)
type listResponse struct {
Item string `json:"item"`
PodData []string `json:"podData"`
VmData []string `json:"vmData"`
CData []string `json:"cData"`
}
var res listResponse
if err := json.Unmarshal([]byte(str), &res); err != nil {
return err
}
var env engine.Env
env.Set("Item", res.Item)
if res.Item == "pod" {
env.SetList("podData", res.PodData)
}
if res.Item == "vm" {
env.SetList("vmData", res.VmData)
}
if res.Item == "container" {
env.SetList("cData", res.CData)
}
return writeJSONEnv(w, http.StatusOK, env)
}
示例10: NewDaemonFromDirectory
func NewDaemonFromDirectory(eng *engine.Engine) (*Daemon, error) {
// register portallocator release on shutdown
eng.OnShutdown(func() {
if err := portallocator.ReleaseAll(); err != nil {
glog.Errorf("portallocator.ReleaseAll(): %s", err.Error())
}
})
// Check that the system is supported and we have sufficient privileges
if runtime.GOOS != "linux" {
return nil, fmt.Errorf("The Docker daemon is only supported on linux")
}
if os.Geteuid() != 0 {
return nil, fmt.Errorf("The Docker daemon needs to be run as root")
}
if err := checkKernel(); err != nil {
return nil, err
}
cfg, err := goconfig.LoadConfigFile(eng.Config)
if err != nil {
glog.Errorf("Read config file (%s) failed, %s", eng.Config, err.Error())
return nil, err
}
kernel, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Kernel")
initrd, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Initrd")
glog.V(0).Infof("The config: kernel=%s, initrd=%s", kernel, initrd)
biface, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Bridge")
bridgeip, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "BridgeIP")
glog.V(0).Infof("The config: bridge=%s, ip=%s", biface, bridgeip)
bios, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Bios")
cbfs, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Cbfs")
glog.V(0).Infof("The config: bios=%s, cbfs=%s", bios, cbfs)
host, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Host")
var tempdir = "/var/run/hyper/"
os.Setenv("TMPDIR", tempdir)
if err := os.MkdirAll(tempdir, 0755); err != nil && !os.IsExist(err) {
return nil, err
}
var realRoot = "/var/lib/hyper/"
// Create the root directory if it doesn't exists
if err := os.MkdirAll(realRoot, 0755); err != nil && !os.IsExist(err) {
return nil, err
}
if err := network.InitNetwork(biface, bridgeip); err != nil {
glog.Errorf("InitNetwork failed, %s\n", err.Error())
return nil, err
}
var (
proto = "unix"
addr = "/var/run/docker.sock"
db_file = fmt.Sprintf("%s/hyper.db", realRoot)
)
db, err := leveldb.OpenFile(db_file, nil)
if err != nil {
glog.Errorf("open leveldb file failed, %s\n", err.Error())
return nil, err
}
dockerCli := docker.NewDockerCli("", proto, addr, nil)
qemuchan := map[string]interface{}{}
qemuclient := map[string]interface{}{}
subQemuClient := map[string]interface{}{}
cList := []*Container{}
pList := map[string]*Pod{}
vList := map[string]*Vm{}
daemon := &Daemon{
ID: fmt.Sprintf("%d", os.Getpid()),
db: db,
eng: eng,
kernel: kernel,
initrd: initrd,
bios: bios,
cbfs: cbfs,
dockerCli: dockerCli,
containerList: cList,
podList: pList,
vmList: vList,
qemuChan: qemuchan,
qemuClientChan: qemuclient,
subQemuClientChan: subQemuClient,
Host: host,
}
stor := &Storage{}
// Get the docker daemon info
body, _, err := dockerCli.SendCmdInfo()
if err != nil {
return nil, err
}
outInfo := engine.NewOutput()
remoteInfo, err := outInfo.AddEnv()
if err != nil {
return nil, err
}
if _, err := outInfo.Write(body); err != nil {
return nil, fmt.Errorf("Error while reading remote info!\n")
}
//.........這裏部分代碼省略.........
示例11: getInfo
func getInfo(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
w.Header().Set("Content-Type", "application/json")
eng.ServeHTTP(w, r)
return nil
}