Skip to content

Commit 96fe9f8

Browse files
committed
Networking V2: add QoS DSCP rule Get call
Implement QoS DSCP marking rule Get call.
1 parent 5d7c57d commit 96fe9f8

6 files changed

Lines changed: 59 additions & 0 deletions

File tree

openstack/networking/v2/extensions/qos/rules/doc.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ Example of Listing DSCP marking rules
101101
fmt.Printf("%+v\n", dscpMarkingRule)
102102
}
103103
104+
Example of Getting a single DSCPMarkingRule
105+
106+
policyID := "501005fa-3b56-4061-aaca-3f24995112e1"
107+
ruleID := "30a57f4a-336b-4382-8275-d708babd2241"
108+
109+
rule, err := rules.GetDSCPMarkingRule(networkClient, policyID, ruleID).ExtractDSCPMarkingRule()
110+
if err != nil {
111+
panic(err)
112+
}
113+
114+
fmt.Printf("Rule: %+v\n", rule)
115+
104116
Example of Creating a single DSCPMarkingRule
105117
106118
opts := rules.CreateDSCPMarkingRuleOpts{

openstack/networking/v2/extensions/qos/rules/requests.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ func ListDSCPMarkingRules(c *gophercloud.ServiceClient, policyID string, opts DS
191191
})
192192
}
193193

194+
// GetDSCPMarkingRule retrieves a specific DSCPMarkingRule based on its ID.
195+
func GetDSCPMarkingRule(c *gophercloud.ServiceClient, policyID, ruleID string) (r GetDSCPMarkingRuleResult) {
196+
_, r.Err = c.Get(getDSCPMarkingRuleURL(c, policyID, ruleID), &r.Body, nil)
197+
return
198+
}
199+
194200
// CreateDSCPMarkingRuleOptsBuilder allows to add additional parameters to the
195201
// CreateDSCPMarkingRule request.
196202
type CreateDSCPMarkingRuleOptsBuilder interface {

openstack/networking/v2/extensions/qos/rules/results.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ func (r commonResult) ExtractDSCPMarkingRule() (*DSCPMarkingRule, error) {
9696
return s.DSCPMarkingRule, err
9797
}
9898

99+
// GetDSCPMarkingRuleResult represents the result of a Get operation. Call its Extract
100+
// method to interpret it as a DSCPMarkingRule.
101+
type GetDSCPMarkingRuleResult struct {
102+
commonResult
103+
}
104+
99105
// CreateDSCPMarkingRuleResult represents the result of a Create operation. Call its Extract
100106
// method to interpret it as a DSCPMarkingRule.
101107
type CreateDSCPMarkingRuleResult struct {

openstack/networking/v2/extensions/qos/rules/testing/fixtures.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ const DSCPMarkingRulesListResult = `
8080
}
8181
`
8282

83+
// DSCPMarkingRuleGetResult represents a raw result of a Get DSCPMarkingRule call.
84+
const DSCPMarkingRuleGetResult = `
85+
{
86+
"dscp_marking_rule": {
87+
"id": "30a57f4a-336b-4382-8275-d708babd2241",
88+
"dscp_mark": 26
89+
}
90+
}
91+
`
92+
8393
// DSCPMarkingRuleCreateRequest represents a raw body of a Create DSCPMarkingRule call.
8494
const DSCPMarkingRuleCreateRequest = `
8595
{

openstack/networking/v2/extensions/qos/rules/testing/requests_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,27 @@ func TestListDSCPMarkingRule(t *testing.T) {
200200
}
201201
}
202202

203+
func TestGetDSCPMarkingRule(t *testing.T) {
204+
th.SetupHTTP()
205+
defer th.TeardownHTTP()
206+
207+
th.Mux.HandleFunc("/v2.0/qos/policies/501005fa-3b56-4061-aaca-3f24995112e1/dscp_marking_rules/30a57f4a-336b-4382-8275-d708babd2241", func(w http.ResponseWriter, r *http.Request) {
208+
th.TestMethod(t, r, "GET")
209+
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
210+
211+
w.Header().Add("Content-Type", "application/json")
212+
w.WriteHeader(http.StatusOK)
213+
214+
fmt.Fprintf(w, DSCPMarkingRuleGetResult)
215+
})
216+
217+
r, err := rules.GetDSCPMarkingRule(fake.ServiceClient(), "501005fa-3b56-4061-aaca-3f24995112e1", "30a57f4a-336b-4382-8275-d708babd2241").ExtractDSCPMarkingRule()
218+
th.AssertNoErr(t, err)
219+
220+
th.AssertEquals(t, r.ID, "30a57f4a-336b-4382-8275-d708babd2241")
221+
th.AssertEquals(t, 26, r.DSCPMark)
222+
}
223+
203224
func TestCreateDSCPMarkingRule(t *testing.T) {
204225
th.SetupHTTP()
205226
defer th.TeardownHTTP()

openstack/networking/v2/extensions/qos/rules/urls.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func listDSCPMarkingRulesURL(c *gophercloud.ServiceClient, policyID string) stri
4949
return dscpMarkingRulesRootURL(c, policyID)
5050
}
5151

52+
func getDSCPMarkingRuleURL(c *gophercloud.ServiceClient, policyID, ruleID string) string {
53+
return dscpMarkingRulesResourceURL(c, policyID, ruleID)
54+
}
55+
5256
func createDSCPMarkingRuleURL(c *gophercloud.ServiceClient, policyID string) string {
5357
return dscpMarkingRulesRootURL(c, policyID)
5458
}

0 commit comments

Comments
 (0)