Skip to content

Commit fc58ed3

Browse files
committed
[Neutron][SecurityGroup] updated_at/created_at fields
for: #1648 * time.Time object * mapped to existing json fields General API reference: https://developer.openstack.org/api-ref/network/v2/?expanded=show-security-group-detail#show-security-group that fields defined in standard_attr.py , that means that it should be applied to all neutron-resources though decorator: https://github.com/openstack/neutron/blob/041203f1bb1a9cb814ab58c6088d0229cfe9d9bb/neutron/db/standard_attr.py#L181 https://github.com/openstack/neutron/blob/041203f1bb1a9cb814ab58c6088d0229cfe9d9bb/neutron/db/models/securitygroup.py#L26
1 parent 73bf16e commit fc58ed3

3 files changed

Lines changed: 40 additions & 11 deletions

File tree

openstack/networking/v2/extensions/security/groups/results.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package groups
22

33
import (
4+
"time"
5+
46
"github.com/gophercloud/gophercloud"
57
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules"
68
"github.com/gophercloud/gophercloud/pagination"
@@ -25,6 +27,11 @@ type SecGroup struct {
2527
// TenantID is the project owner of the security group.
2628
TenantID string `json:"tenant_id"`
2729

30+
// UpdatedAt and CreatedAt contain ISO-8601 timestamps of when the state of the
31+
// security group last changed, and when it was created.
32+
UpdatedAt time.Time `json:"updated_at"`
33+
CreatedAt time.Time `json:"created_at"`
34+
2835
// ProjectID is the project owner of the security group.
2936
ProjectID string `json:"project_id"`
3037

openstack/networking/v2/extensions/security/groups/testing/fixtures.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package testing
22

33
import (
4+
"time"
5+
46
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups"
57
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules"
68
)
@@ -13,19 +15,28 @@ const SecurityGroupListResponse = `
1315
"id": "85cc3048-abc3-43cc-89b3-377341426ac5",
1416
"name": "default",
1517
"security_group_rules": [],
16-
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
18+
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550",
19+
"created_at": "2019-06-30T04:15:37Z",
20+
"updated_at": "2019-06-30T05:18:49Z"
1721
}
1822
]
1923
}
2024
`
2125

22-
var SecurityGroup1 = groups.SecGroup{
23-
Description: "default",
24-
ID: "85cc3048-abc3-43cc-89b3-377341426ac5",
25-
Name: "default",
26-
Rules: []rules.SecGroupRule{},
27-
TenantID: "e4f50856753b4dc6afee5fa6b9b6c550",
28-
}
26+
var (
27+
createdTime, _ = time.Parse(time.RFC3339, "2019-06-30T04:15:37Z")
28+
updatedTime, _ = time.Parse(time.RFC3339, "2019-06-30T05:18:49Z")
29+
30+
SecurityGroup1 = groups.SecGroup{
31+
Description: "default",
32+
ID: "85cc3048-abc3-43cc-89b3-377341426ac5",
33+
Name: "default",
34+
Rules: []rules.SecGroupRule{},
35+
TenantID: "e4f50856753b4dc6afee5fa6b9b6c550",
36+
CreatedAt: createdTime,
37+
UpdatedAt: updatedTime,
38+
}
39+
)
2940

3041
const SecurityGroupCreateRequest = `
3142
{
@@ -68,7 +79,9 @@ const SecurityGroupCreateResponse = `
6879
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
6980
}
7081
],
71-
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
82+
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550",
83+
"created_at": "2019-06-30T04:15:37Z",
84+
"updated_at": "2019-06-30T05:18:49Z"
7285
}
7386
}
7487
`
@@ -113,7 +126,9 @@ const SecurityGroupUpdateResponse = `
113126
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
114127
}
115128
],
116-
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
129+
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550",
130+
"created_at": "2019-06-30T04:15:37Z",
131+
"updated_at": "2019-06-30T05:18:49Z"
117132
}
118133
}
119134
`
@@ -150,7 +165,9 @@ const SecurityGroupGetResponse = `
150165
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
151166
}
152167
],
153-
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
168+
"tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550",
169+
"created_at": "2019-06-30T04:15:37Z",
170+
"updated_at": "2019-06-30T05:18:49Z"
154171
}
155172
}
156173
`

openstack/networking/v2/extensions/security/groups/testing/requests_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"net/http"
66
"testing"
7+
"time"
78

89
fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common"
910
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups"
@@ -93,6 +94,8 @@ func TestUpdate(t *testing.T) {
9394
th.AssertEquals(t, "newer-webservers", sg.Name)
9495
th.AssertEquals(t, "security group for webservers", sg.Description)
9596
th.AssertEquals(t, "2076db17-a522-4506-91de-c6dd8e837028", sg.ID)
97+
th.AssertEquals(t, "2019-06-30T04:15:37Z", sg.CreatedAt.Format(time.RFC3339))
98+
th.AssertEquals(t, "2019-06-30T05:18:49Z", sg.UpdatedAt.Format(time.RFC3339))
9699
}
97100

98101
func TestGet(t *testing.T) {
@@ -117,6 +120,8 @@ func TestGet(t *testing.T) {
117120
th.AssertEquals(t, "default", sg.Name)
118121
th.AssertEquals(t, 2, len(sg.Rules))
119122
th.AssertEquals(t, "e4f50856753b4dc6afee5fa6b9b6c550", sg.TenantID)
123+
th.AssertEquals(t, "2019-06-30T04:15:37Z", sg.CreatedAt.Format(time.RFC3339))
124+
th.AssertEquals(t, "2019-06-30T05:18:49Z", sg.UpdatedAt.Format(time.RFC3339))
120125
}
121126

122127
func TestDelete(t *testing.T) {

0 commit comments

Comments
 (0)