add-support-images-save

Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
This commit is contained in:
Xian Chaobo
2015-05-06 04:14:36 +08:00
committed by Andrea Luzzardi
parent 5b3a03b852
commit 3962f6ffdf
3 changed files with 82 additions and 1 deletions

View File

@@ -62,6 +62,59 @@ func getVersion(c *context, w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(version)
}
// GET /images/get
func getImages(c *context, w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
names := r.Form["names"]
// find an engine which has all images
// Engine.Addr : [found names]
dict := make(map[string][]string)
bFoundEngine := false
var foundEngineAddr string
for _, image := range c.cluster.Images() {
for _, name := range names {
if image.Match(name) {
// check if engine addr already exists
value, exists := dict[image.Engine.Addr]
if exists {
// check if name already exists
found := false
for _, tempName := range value {
if tempName == name {
found = true
}
}
if found == false {
dict[image.Engine.Addr] = append(value, name)
if len(names) == len(dict[image.Engine.Addr]) {
bFoundEngine = true
foundEngineAddr = image.Engine.Addr
}
}
} else {
dict[image.Engine.Addr] = []string{name}
}
}
if bFoundEngine {
break
}
}
if bFoundEngine {
break
}
}
if bFoundEngine {
proxy(c.tlsConfig, foundEngineAddr, w, r)
} else {
httpError(w, fmt.Sprintf("Not found an engine which has all images: %s", names), http.StatusNotFound)
}
}
// GET /images/json
func getImagesJSON(c *context, w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {

View File

@@ -28,7 +28,7 @@ var routes = map[string]map[string]handler{
"/images/json": getImagesJSON,
"/images/viz": notImplementedHandler,
"/images/search": proxyRandom,
"/images/get": notImplementedHandler,
"/images/get": getImages,
"/images/{name:.*}/get": proxyImage,
"/images/{name:.*}/history": proxyImage,
"/images/{name:.*}/json": proxyImage,

View File

@@ -42,3 +42,31 @@ function teardown() {
rm -f $temp_file_name
rm -f $temp_file_name_o
}
@test "docker save muti-images" {
start_docker_with_busybox 1
start_docker 1
swarm_manage
# tag busybox
run docker_swarm tag busybox testimage
[ "$status" -eq 0 ]
# make sure image exists
run docker_swarm images
[ "$status" -eq 0 ]
[[ "${output}" == *"busybox"* ]]
[[ "${output}" == *"testimage"* ]]
temp_file_name=$(mktemp)
docker_swarm save busybox testimage > $temp_file_name
# saved image file exists, not empty and is tar file
[ -s $temp_file_name ]
run file $temp_file_name
[ "$status" -eq 0 ]
[[ "${output}" == *"tar archive"* ]]
rm -f $temp_file_name
}