Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions openstack/networking/v2/extensions/layer3/routers/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,48 @@ type Router struct {
RevisionNumber int `json:"revision_number"`

// Timestamp when the router was created
CreatedAt time.Time `json:"created_at"`
CreatedAt time.Time `json:"-"`

// Timestamp when the router was last updated
UpdatedAt time.Time `json:"updated_at"`
UpdatedAt time.Time `json:"-"`
}

func (r *Router) UnmarshalJSON(b []byte) error {
type tmp Router

// Support for older neutron time format
var s1 struct {
tmp
CreatedAt gophercloud.JSONRFC3339NoZ `json:"created_at"`
UpdatedAt gophercloud.JSONRFC3339NoZ `json:"updated_at"`
}

err := json.Unmarshal(b, &s1)
if err == nil {
*r = Router(s1.tmp)
r.CreatedAt = time.Time(s1.CreatedAt)
r.UpdatedAt = time.Time(s1.UpdatedAt)

return nil
}

// Support for newer neutron time format
var s2 struct {
tmp
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

err = json.Unmarshal(b, &s2)
if err != nil {
return err
}

*r = Router(s2.tmp)
r.CreatedAt = time.Time(s2.CreatedAt)
r.UpdatedAt = time.Time(s2.UpdatedAt)

return nil
}

// RouterPage is the page returned by a pager when traversing over a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func TestList(t *testing.T) {
"admin_state_up": true,
"tenant_id": "6b96ff0cb17a4b859e1e575d221683d3",
"distributed": false,
"created_at": "2017-12-28T07:21:40Z",
"updated_at": "2017-12-28T07:21:40Z",
"id": "7177abc4-5ae9-4bb7-b0d4-89e94a4abf3b"
},
{
Expand All @@ -45,6 +47,8 @@ func TestList(t *testing.T) {
"admin_state_up": true,
"tenant_id": "33a40233088643acb66ff6eb0ebea679",
"distributed": false,
"created_at": "2017-12-28T07:21:40",
"updated_at": "2017-12-28T07:21:40",
"id": "a9254bdb-2613-4a13-ac4c-adc581fba50d"
},
{
Expand Down Expand Up @@ -86,6 +90,8 @@ func TestList(t *testing.T) {
Distributed: false,
Name: "second_routers",
ID: "7177abc4-5ae9-4bb7-b0d4-89e94a4abf3b",
CreatedAt: time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC),
UpdatedAt: time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC),
TenantID: "6b96ff0cb17a4b859e1e575d221683d3",
},
{
Expand All @@ -95,6 +101,8 @@ func TestList(t *testing.T) {
Distributed: false,
Name: "router1",
ID: "a9254bdb-2613-4a13-ac4c-adc581fba50d",
CreatedAt: time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC),
UpdatedAt: time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC),
TenantID: "33a40233088643acb66ff6eb0ebea679",
},
{
Expand Down
43 changes: 41 additions & 2 deletions openstack/networking/v2/extensions/security/rules/results.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rules

import (
"encoding/json"
"time"

"github.com/gophercloud/gophercloud/v2"
Expand Down Expand Up @@ -67,10 +68,48 @@ type SecGroupRule struct {
RevisionNumber int `json:"revision_number"`

// Timestamp when the rule was created
CreatedAt time.Time `json:"created_at"`
CreatedAt time.Time `json:"-"`

// Timestamp when the rule was last updated
UpdatedAt time.Time `json:"updated_at"`
UpdatedAt time.Time `json:"-"`
}

func (r *SecGroupRule) UnmarshalJSON(b []byte) error {
type tmp SecGroupRule

// Support for older neutron time format
var s1 struct {
tmp
CreatedAt gophercloud.JSONRFC3339NoZ `json:"created_at"`
UpdatedAt gophercloud.JSONRFC3339NoZ `json:"updated_at"`
}

err := json.Unmarshal(b, &s1)
if err == nil {
*r = SecGroupRule(s1.tmp)
r.CreatedAt = time.Time(s1.CreatedAt)
r.UpdatedAt = time.Time(s1.UpdatedAt)

return nil
}

// Support for newer neutron time format
var s2 struct {
tmp
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

err = json.Unmarshal(b, &s2)
if err != nil {
return err
}

*r = SecGroupRule(s2.tmp)
r.CreatedAt = time.Time(s2.CreatedAt)
r.UpdatedAt = time.Time(s2.UpdatedAt)

return nil
}

// SecGroupRulePage is the page returned by a pager when traversing over a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"testing"
"time"

fake "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/common"
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/extensions/security/rules"
Expand Down Expand Up @@ -35,6 +36,8 @@ func TestList(t *testing.T) {
"protocol": null,
"remote_group_id": null,
"remote_ip_prefix": null,
"created_at": "2017-12-28T07:21:40Z",
"updated_at": "2017-12-28T07:21:40Z",
"security_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5",
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
},
Expand All @@ -47,6 +50,8 @@ func TestList(t *testing.T) {
"protocol": null,
"remote_group_id": null,
"remote_ip_prefix": null,
"created_at": "2017-12-28T07:21:40",
"updated_at": "2017-12-28T07:21:40",
"security_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5",
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
}
Expand Down Expand Up @@ -76,6 +81,8 @@ func TestList(t *testing.T) {
Protocol: "",
RemoteGroupID: "",
RemoteIPPrefix: "",
CreatedAt: time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC),
UpdatedAt: time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC),
SecGroupID: "85cc3048-abc3-43cc-89b3-377341426ac5",
TenantID: "e4f50856753b4dc6afee5fa6b9b6c550",
},
Expand All @@ -88,6 +95,8 @@ func TestList(t *testing.T) {
Protocol: "",
RemoteGroupID: "",
RemoteIPPrefix: "",
CreatedAt: time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC),
UpdatedAt: time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC),
SecGroupID: "85cc3048-abc3-43cc-89b3-377341426ac5",
TenantID: "e4f50856753b4dc6afee5fa6b9b6c550",
},
Expand Down Expand Up @@ -372,6 +381,8 @@ func TestGet(t *testing.T) {
"protocol": null,
"remote_group_id": null,
"remote_ip_prefix": null,
"created_at": "2017-12-28T07:21:40Z",
"updated_at": "2017-12-28T07:21:40Z",
"security_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5",
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
}
Expand All @@ -390,6 +401,8 @@ func TestGet(t *testing.T) {
th.AssertEquals(t, "", sr.Protocol)
th.AssertEquals(t, "", sr.RemoteGroupID)
th.AssertEquals(t, "", sr.RemoteIPPrefix)
th.AssertEquals(t, time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC), sr.UpdatedAt)
th.AssertEquals(t, time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC), sr.CreatedAt)
th.AssertEquals(t, "85cc3048-abc3-43cc-89b3-377341426ac5", sr.SecGroupID)
th.AssertEquals(t, "e4f50856753b4dc6afee5fa6b9b6c550", sr.TenantID)
}
Expand Down
43 changes: 41 additions & 2 deletions openstack/networking/v2/subnets/results.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package subnets

import (
"encoding/json"
"time"

"github.com/gophercloud/gophercloud/v2"
Expand Down Expand Up @@ -129,10 +130,48 @@ type Subnet struct {
SegmentID string `json:"segment_id"`

// Timestamp when the subnet was created
CreatedAt time.Time `json:"created_at"`
CreatedAt time.Time `json:"-"`

// Timestamp when the subnet was last updated
UpdatedAt time.Time `json:"updated_at"`
UpdatedAt time.Time `json:"-"`
}

func (r *Subnet) UnmarshalJSON(b []byte) error {
type tmp Subnet

// Support for older neutron time format
var s1 struct {
tmp
CreatedAt gophercloud.JSONRFC3339NoZ `json:"created_at"`
UpdatedAt gophercloud.JSONRFC3339NoZ `json:"updated_at"`
}

err := json.Unmarshal(b, &s1)
if err == nil {
*r = Subnet(s1.tmp)
r.CreatedAt = time.Time(s1.CreatedAt)
r.UpdatedAt = time.Time(s1.UpdatedAt)

return nil
}

// Support for newer neutron time format
var s2 struct {
tmp
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

err = json.Unmarshal(b, &s2)
if err != nil {
return err
}

*r = Subnet(s2.tmp)
r.CreatedAt = time.Time(s2.CreatedAt)
r.UpdatedAt = time.Time(s2.UpdatedAt)

return nil
}

// SubnetPage is the page returned by a pager when traversing over a collection
Expand Down
10 changes: 10 additions & 0 deletions openstack/networking/v2/subnets/testing/fixtures_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package testing

import (
"time"

"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/subnets"
)

Expand All @@ -24,6 +26,8 @@ const SubnetListResult = `
"ip_version": 4,
"gateway_ip": "10.0.0.1",
"cidr": "10.0.0.0/24",
"created_at": "2017-12-28T07:21:40Z",
"updated_at": "2017-12-28T07:21:40Z",
"id": "08eae331-0402-425a-923c-34f7cfe39c1b"
},
{
Expand All @@ -43,6 +47,8 @@ const SubnetListResult = `
"ip_version": 4,
"gateway_ip": "192.0.0.1",
"cidr": "192.0.0.0/8",
"created_at": "2017-12-28T07:21:40",
"updated_at": "2017-12-28T07:21:40",
"id": "54d6f61d-db07-451c-9ab3-b9609b6b6f0b"
},
{
Expand Down Expand Up @@ -104,6 +110,8 @@ var Subnet1 = subnets.Subnet{
IPVersion: 4,
GatewayIP: "10.0.0.1",
CIDR: "10.0.0.0/24",
CreatedAt: time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC),
UpdatedAt: time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC),
ID: "08eae331-0402-425a-923c-34f7cfe39c1b",
}

Expand All @@ -125,6 +133,8 @@ var Subnet2 = subnets.Subnet{
IPVersion: 4,
GatewayIP: "192.0.0.1",
CIDR: "192.0.0.0/8",
CreatedAt: time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC),
UpdatedAt: time.Date(2017, 12, 28, 07, 21, 40, 0, time.UTC),
ID: "54d6f61d-db07-451c-9ab3-b9609b6b6f0b",
}

Expand Down
Loading