Skip to content

Commit

Permalink
Add support for volume tags (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
twhiteman authored Apr 27, 2020
1 parent e28519c commit 54ab761
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## Unreleased

## 1.7.1 (April 24 2020)

- Add support for volume tags [#175]

## 1.7.0 (June 26 2019)

- Expected instance to have Tags

## 1.6.1 (June 26 2019)

- compute/networks: support network objects for AddNIC [#169]
Expand Down
26 changes: 16 additions & 10 deletions compute/volumes.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2018, Joyent, Inc. All rights reserved.
// Copyright 2020 Joyent Inc.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -24,15 +24,16 @@ type VolumesClient struct {
}

type Volume struct {
ID string `json:"id"`
Name string `json:"name"`
Owner string `json:"owner_uuid"`
Type string `json:"type"`
FileSystemPath string `json:"filesystem_path"`
Size int64 `json:"size"`
State string `json:"state"`
Networks []string `json:"networks"`
Refs []string `json:"refs"`
ID string `json:"id"`
Name string `json:"name"`
Owner string `json:"owner_uuid"`
Type string `json:"type"`
FileSystemPath string `json:"filesystem_path"`
Size int64 `json:"size"`
State string `json:"state"`
Networks []string `json:"networks"`
Refs []string `json:"refs"`
Tags map[string]string `json:"tags"`
}

type ListVolumesInput struct {
Expand Down Expand Up @@ -86,6 +87,7 @@ type CreateVolumeInput struct {
Size int64
Networks []string
Type string
Tags map[string]string `json:"tags"`
}

func (input *CreateVolumeInput) toAPI() map[string]interface{} {
Expand All @@ -107,6 +109,10 @@ func (input *CreateVolumeInput) toAPI() map[string]interface{} {
result["networks"] = input.Networks
}

if input.Tags != nil {
result["tags"] = input.Tags
}

return result
}

Expand Down
23 changes: 21 additions & 2 deletions compute/volumes_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2018, Joyent, Inc. All rights reserved.
// Copyright 2020 Joyent Inc.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,6 +10,7 @@ package compute_test

import (
"context"
"fmt"
"io/ioutil"
"net/http"
"path"
Expand Down Expand Up @@ -138,6 +139,9 @@ func TestCreateVolume(t *testing.T) {
Name: "my-test-volume-1",
Type: "tritonnfs",
Networks: []string{"d251d640-a02e-47b5-8ae6-8b45d859528e"},
Tags: map[string]string{
"tag1": "value1",
},
})
if err != nil {
return nil, err
Expand All @@ -148,10 +152,22 @@ func TestCreateVolume(t *testing.T) {
t.Run("successful", func(t *testing.T) {
testutils.RegisterResponder("POST", path.Join("/", accountURL, "volumes"), createVolumeSuccess)

_, err := do(context.Background(), computeClient)
volume, err := do(context.Background(), computeClient)
if err != nil {
t.Fatal(err)
}

tagVal, tagOk := volume.Tags["tag1"]
if !tagOk {
t.Fatal(fmt.Errorf("Expected instance to have Tags: found \"%v\"",
volume.Tags))
}
if tagVal != "value1" {
t.Fatal(fmt.Errorf(
"Expected instance Tag \"tag1\" to equal \"value1\": found \"%s\"",
tagVal))
}

})

t.Run("error", func(t *testing.T) {
Expand Down Expand Up @@ -360,6 +376,9 @@ func createVolumeSuccess(req *http.Request) (*http.Response, error) {
"create_timestamp": "2018-01-12T21:09:09.788Z",
"state": "creating",
"networks": ["d251d640-a02e-47b5-8ae6-8b45d859528e"],
"tags": {
"tag1": "value1"
},
"id": "1edcc6ad-7987-4372-b13a-d21e678ba1e9"
}
`)
Expand Down
4 changes: 2 additions & 2 deletions version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2018, Joyent, Inc. All rights reserved.
// Copyright 2020 Joyent, Inc.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -15,7 +15,7 @@ import (

// Version represents main version number of the current release
// of the Triton-go SDK.
const Version = "1.7.0"
const Version = "1.7.1"

// Prerelease adds a pre-release marker to the version.
//
Expand Down

0 comments on commit 54ab761

Please sign in to comment.