Skip to content

Commit

Permalink
Merge pull request #323 from adamwg/awg/volume-formats
Browse files Browse the repository at this point in the history
volumes: Add support for formatted volumes
  • Loading branch information
adamwg authored Jun 12, 2018
2 parents 1564717 + 03cbc62 commit 0b2fac0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All changes to `doctl` will be documented in this file.

## [1.8.2] - 2018-06-12

- #323 Add support for formatted volumes - @adamwg

## [1.8.1] - 2018-05-09

### Added
Expand Down
4 changes: 4 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ const (
ArgVolumeDesc = "desc"
// ArgVolumeRegion is the region of a volume.
ArgVolumeRegion = "region"
// ArgVolumeFilesystemType is the filesystem type for a volume.
ArgVolumeFilesystemType = "fs-type"
// ArgVolumeFilesystemLabel is the filesystem label for a volume.
ArgVolumeFilesystemLabel = "fs-label"
// ArgVolumeList is the IDs of many volumes.
ArgVolumeList = "volumes"

Expand Down
21 changes: 14 additions & 7 deletions commands/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,19 @@ func (a *volume) JSON(out io.Writer) error {

func (a *volume) Cols() []string {
return []string{
"ID", "Name", "Size", "Region", "DropletIDs",
"ID", "Name", "Size", "Region", "Filesystem Type", "Filesystem Label", "Droplet IDs",
}

}

func (a *volume) ColMap() map[string]string {
return map[string]string{
"ID": "ID", "Name": "Name", "Size": "Size", "Region": "Region", "DropletIDs": "Droplet IDs",
"ID": "ID",
"Name": "Name",
"Size": "Size",
"Region": "Region",
"Filesystem Type": "Filesystem Type",
"Filesystem Label": "Filesystem Label",
"Droplet IDs": "Droplet IDs",
}

}
Expand All @@ -609,10 +614,12 @@ func (a *volume) KV() []map[string]interface{} {
for _, volume := range a.volumes {

m := map[string]interface{}{
"ID": volume.ID,
"Name": volume.Name,
"Size": strconv.FormatInt(volume.SizeGigaBytes, 10) + " GiB",
"Region": volume.Region.Slug,
"ID": volume.ID,
"Name": volume.Name,
"Size": strconv.FormatInt(volume.SizeGigaBytes, 10) + " GiB",
"Region": volume.Region.Slug,
"Filesystem Type": volume.FilesystemType,
"Filesystem Label": volume.FilesystemLabel,
}
m["DropletIDs"] = ""
if len(volume.DropletIDs) != 0 {
Expand Down
13 changes: 13 additions & 0 deletions commands/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func Volume() *Command {
AddStringFlag(cmdVolumeCreate, doctl.ArgVolumeDesc, "", "", "Volume description")
AddStringFlag(cmdVolumeCreate, doctl.ArgVolumeRegion, "", "", "Volume region",
requiredOpt())
AddStringFlag(cmdVolumeCreate, doctl.ArgVolumeFilesystemType, "", "", "Volume filesystem type (ext4 or xfs)")
AddStringFlag(cmdVolumeCreate, doctl.ArgVolumeFilesystemLabel, "", "", "Volume filesystem label")

cmdRunVolumeDelete := CmdBuilder(cmd, RunVolumeDelete, "delete <volume-id>", "delete a volume", Writer,
aliasOpt("rm"))
Expand Down Expand Up @@ -145,12 +147,23 @@ func RunVolumeCreate(c *CmdConfig) error {

}

fsType, err := c.Doit.GetString(c.NS, doctl.ArgVolumeFilesystemType)
if err != nil {
return err
}
fsLabel, err := c.Doit.GetString(c.NS, doctl.ArgVolumeFilesystemLabel)
if err != nil {
return err
}

var createVolume godo.VolumeCreateRequest

createVolume.Name = name
createVolume.SizeGigaBytes = int64(size / (1 << 30))
createVolume.Description = desc
createVolume.Region = region
createVolume.FilesystemType = fsType
createVolume.FilesystemLabel = fsLabel

al := c.Volumes()

Expand Down

0 comments on commit 0b2fac0

Please sign in to comment.