forked from hashicorp/nomad-driver-podman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Honor podman shortnames behavior and allow non-docker transports
Closes hashicorp#97 Closes hashicorp#69
- Loading branch information
1 parent
30d4a24
commit ea06b5a
Showing
9 changed files
with
600 additions
and
105 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
// This is terribly simplified but should be enough | ||
type inspectImageResponse struct { | ||
Id string `json:"Id"` | ||
} | ||
|
||
func (c *API) ImageInspectID(ctx context.Context, image string) (string, error) { | ||
var inspectData inspectImageResponse | ||
|
||
res, err := c.Get(ctx, fmt.Sprintf("/v1.0.0/libpod/images/%s/json", image)) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
defer res.Body.Close() | ||
body, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if res.StatusCode != http.StatusOK { | ||
return "", fmt.Errorf("unknown error, status code: %d: %s", res.StatusCode, body) | ||
} | ||
err = json.Unmarshal(body, &inspectData) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return inspectData.Id, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
// ImageLoad uploads a tar archive as an image | ||
func (c *API) ImageLoad(ctx context.Context, path string) (string, error) { | ||
archive, err := os.Open(path) | ||
defer archive.Close() | ||
names := []string{} | ||
|
||
res, err := c.Post(ctx, "/v1.0.0/libpod/images/load", archive) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
defer res.Body.Close() | ||
body, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
return "", err | ||
} | ||
if res.StatusCode != http.StatusOK { | ||
return "", fmt.Errorf("unknown error, status code: %d: %s", res.StatusCode, body) | ||
} | ||
err = json.Unmarshal(body, &names) | ||
if err != nil { | ||
return "", err | ||
} | ||
return names[0], nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.