-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgo_import
44 lines (32 loc) · 1.48 KB
/
go_import
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
func (c *Cluster) Import(source string, repository string, tar string, imageReader io.Reader, callback func(what, status string)) {
// call engine load image
err := nn.Import(source, repository, tar, reader)
if callback != nil {
if err != nil {
callback(nn.Name, err.Error())
} else {
callback(nn.Name, "Import success")
}
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
callback := func(what, status string) {
fmt.Fprintf(wf, "{%q:%q,%q:\"%s\"}", "id", what, "status", status)
}
source := r.Form.Get("fromSrc")
repo := r.Form.Get("repo")
tag := r.Form.Get("tag")
c.cluster.Import(source, repo, tag, r.Body, callback )
// Import image
// `callback` can be called multiple time
// `what` is what is being loaded
// `status` is the current status, like "", "in progress" or "loaded"
Import(source string, repository string, tar string, imageReader io.Reader, callback func(what, status string))
func (e *Engine) Import(source string, repository string, tar string, imageReader io.Reader) error {
if _, err := e.client.ImportImage(source, repository, tar, imageReader); err != nil {
return err
}
// force fresh images
e.RefreshImages()
return nil
}