// Creates an image from Pull or from Import func postImagesCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if err := parseForm(r); err != nil { return err } var ( image = r.Form.Get("fromImage") repo = r.Form.Get("repo") tag = r.Form.Get("tag") job *engine.Job ) authEncoded := r.Header.Get("X-Registry-Auth") authConfig := ®istry.AuthConfig{} if authEncoded != "" { authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) if err := json.NewDecoder(authJson).Decode(authConfig); err != nil { // for a pull it is not an error if no auth was given // to increase compatibility with the existing api it is defaulting to be empty authConfig = ®istry.AuthConfig{} } } if image != "" { //pull if tag == "" { image, tag = parsers.ParseRepositoryTag(image) } metaHeaders := map[string][]string{} for k, v := range r.Header { if strings.HasPrefix(k, "X-Meta-") { metaHeaders[k] = v } } job = eng.Job("pull", image, tag) job.SetenvBool("parallel", version.GreaterThan("1.3")) job.SetenvJson("metaHeaders", metaHeaders) job.SetenvJson("authConfig", authConfig) } else { //import if tag == "" { repo, tag = parsers.ParseRepositoryTag(repo) } job = eng.Job("import", r.Form.Get("fromSrc"), repo, tag) job.Stdin.Add(r.Body) job.SetenvList("changes", r.Form["changes"]) } if version.GreaterThan("1.0") { job.SetenvBool("json", true) streamJSON(job, w, true) } else { job.Stdout.Add(utils.NewWriteFlusher(w)) } if err := job.Run(); err != nil { if !job.Stdout.Used() { return err } sf := utils.NewStreamFormatter(version.GreaterThan("1.0")) w.Write(sf.FormatError(err)) } return nil }
func ContainerStart(job *engine.Job) engine.Status { hostConfig := runconfig.ContainerHostConfigFromJob(job) if len(job.Args) != 1 { return job.Errorf("Usage: %s CONTAINER\n", job.Name) } var ( name = job.Args[0] ) v := url.Values{} if job.EnvExists("t") { v.Set("t", strconv.Itoa(job.GetenvInt("t"))) } job.SetenvBool("all", true) ship := shipWithContainerId(job, name) cli := client.NewKraneClientApi(*ship, false, job) if ship != nil { body, statusCode, err := cli.Call("POST", "/containers/"+name+"/start?"+v.Encode(), hostConfig, false) if statusCode == 304 { return job.Errorf("Container already started") } else if statusCode == 404 { return job.Errorf("No such container: %s\n", name) } else if statusCode == 404 { return job.Errorf("Cannot start container %s: %s\n", name, err) } else if (statusCode >= 200) && (statusCode < 300) { fmt.Printf("%s", body) } else { return job.Errorf("Cannot start container %s: %s\n", name, err) } } else { return job.Errorf("No such container: %s\n", name) } return engine.StatusOK }