-
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.
Implement docker volume with standalone client lib.
Signed-off-by: David Calavera <[email protected]>
- Loading branch information
Showing
2 changed files
with
68 additions
and
40 deletions.
There are no files selected for viewing
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,62 @@ | ||
package lib | ||
|
||
import ( | ||
"encoding/json" | ||
"net/url" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/pkg/parsers/filters" | ||
) | ||
|
||
// VolumeList returns the volumes configured in the docker host. | ||
func (cli *Client) VolumeList(filter filters.Args) (types.VolumesListResponse, error) { | ||
var volumes types.VolumesListResponse | ||
var query url.Values | ||
|
||
if filter.Len() > 0 { | ||
filterJSON, err := filters.ToParam(filter) | ||
if err != nil { | ||
return volumes, err | ||
} | ||
query.Set("filters", filterJSON) | ||
} | ||
resp, err := cli.GET("/volumes", query, nil) | ||
if err != nil { | ||
return volumes, err | ||
} | ||
defer ensureReaderClosed(resp) | ||
|
||
err = json.NewDecoder(resp.body).Decode(&volumes) | ||
return volumes, err | ||
} | ||
|
||
// VolumeInspect returns the information about a specific volume in the docker host. | ||
func (cli *Client) VolumeInspect(volumeID string) (types.Volume, error) { | ||
var volume types.Volume | ||
resp, err := cli.GET("/volumes"+volumeID, nil, nil) | ||
if err != nil { | ||
return volume, err | ||
} | ||
defer ensureReaderClosed(resp) | ||
err = json.NewDecoder(resp.body).Decode(&volume) | ||
return volume, err | ||
} | ||
|
||
// VolumeCreate creates a volume in the docker host. | ||
func (cli *Client) VolumeCreate(options types.VolumeCreateRequest) (types.Volume, error) { | ||
var volume types.Volume | ||
resp, err := cli.POST("/volumes/create", nil, options, nil) | ||
if err != nil { | ||
return volume, err | ||
} | ||
defer ensureReaderClosed(resp) | ||
err = json.NewDecoder(resp.body).Decode(&volume) | ||
return volume, err | ||
} | ||
|
||
// VolumeRemove removes a volume from the docker host. | ||
func (cli *Client) VolumeRemove(volumeID string) error { | ||
resp, err := cli.DELETE("/volumes"+volumeID, nil, nil) | ||
ensureReaderClosed(resp) | ||
return err | ||
} |
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