dsl struct tags; wip
diff --git a/openstack/compute/v2/extensions/defsecrules/requests.go b/openstack/compute/v2/extensions/defsecrules/requests.go
index 5e2d686..62c112e 100644
--- a/openstack/compute/v2/extensions/defsecrules/requests.go
+++ b/openstack/compute/v2/extensions/defsecrules/requests.go
@@ -7,24 +7,19 @@
// List will return a collection of default rules.
func List(client *gophercloud.ServiceClient) pagination.Pager {
- createPage := func(r pagination.PageResult) pagination.Page {
+ return pagination.NewPager(client, rootURL(client), func(r pagination.PageResult) pagination.Page {
return DefaultRulePage{pagination.SinglePageBase(r)}
- }
-
- return pagination.NewPager(client, rootURL(client), createPage)
+ })
}
// CreateOpts represents the configuration for adding a new default rule.
type CreateOpts struct {
- // Required - the lower bound of the port range that will be opened.
- FromPort int `json:"from_port"`
-
- // Required - the upper bound of the port range that will be opened.
- ToPort int `json:"to_port"`
-
- // Required - the protocol type that will be allowed, e.g. TCP.
- IPProtocol string `json:"ip_protocol"`
-
+ // The lower bound of the port range that will be opened.
+ FromPort int `json:"from_port" required:"true"`
+ // The upper bound of the port range that will be opened.
+ ToPort int `json:"to_port" required:"true"`
+ // The protocol type that will be allowed, e.g. TCP.
+ IPProtocol string `json:"ip_protocol" required:"true"`
// ONLY required if FromGroupID is blank. This represents the IP range that
// will be the source of network traffic to your security group. Use
// 0.0.0.0/0 to allow all IP addresses.
@@ -38,68 +33,33 @@
// ToRuleCreateMap builds the create rule options into a serializable format.
func (opts CreateOpts) ToRuleCreateMap() (map[string]interface{}, error) {
- if opts.FromPort == 0 {
- err := gophercloud.ErrMissingInput{}
- err.Function = "defsecrules.ToRuleCreateMap"
- err.Argument = "defsecrules.CreateOpts.FromPort"
- return nil, err
- }
- if opts.ToPort == 0 {
- err := gophercloud.ErrMissingInput{}
- err.Function = "defsecrules.ToRuleCreateMap"
- err.Argument = "defsecrules.CreateOpts.ToPort"
- return nil, err
- }
- if opts.IPProtocol == "" {
- err := gophercloud.ErrMissingInput{}
- err.Function = "defsecrules.ToRuleCreateMap"
- err.Argument = "defsecrules.CreateOpts.IPProtocol"
- return nil, err
- }
- if opts.CIDR == "" {
- err := gophercloud.ErrMissingInput{}
- err.Function = "defsecrules.ToRuleCreateMap"
- err.Argument = "defsecrules.CreateOpts.CIDR"
- return nil, err
- }
-
- rule := make(map[string]interface{})
-
- rule["from_port"] = opts.FromPort
- rule["to_port"] = opts.ToPort
- rule["ip_protocol"] = opts.IPProtocol
- rule["cidr"] = opts.CIDR
-
- return map[string]interface{}{"security_group_default_rule": rule}, nil
+ return gophercloud.BuildRequestBody(opts, "security_group_default_rule")
}
// Create is the operation responsible for creating a new default rule.
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
- var result CreateResult
-
- reqBody, err := opts.ToRuleCreateMap()
+ var r CreateResult
+ b, err := opts.ToRuleCreateMap()
if err != nil {
- result.Err = err
- return result
+ r.Err = err
+ return r
}
-
- _, result.Err = client.Post(rootURL(client), reqBody, &result.Body, &gophercloud.RequestOpts{
+ _, r.Err = client.Post(rootURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
-
- return result
+ return r
}
// Get will return details for a particular default rule.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
- var result GetResult
- _, result.Err = client.Get(resourceURL(client, id), &result.Body, nil)
- return result
+ var r GetResult
+ _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil)
+ return r
}
// Delete will permanently delete a default rule from the project.
func Delete(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
- var result gophercloud.ErrResult
- _, result.Err = client.Delete(resourceURL(client, id), nil)
- return result
+ var r gophercloud.ErrResult
+ _, r.Err = client.Delete(resourceURL(client, id), nil)
+ return r
}