func (opts CreateRuleOpts) ToRuleCreateMap() (map[string]interface{}, error) {
	rule := make(map[string]interface{})
	if opts.ParentGroupID == "" {
		return rule, errors.New("A ParentGroupID must be set")
	}
	if opts.FromPort == 0 {
		return rule, errors.New("A FromPort must be set")
	}
	if opts.ToPort == 0 {
		return rule, errors.New("A ToPort must be set")
	}
	if opts.IPProtocol == "" {
		return rule, errors.New("A IPProtocol must be set")
	}
	if opts.CIDR == "" && opts.FromGroupID == "" {
		return rule, errors.New("A CIDR or FromGroupID must be set")
	}
	rule["parent_group_id"] = opts.ParentGroupID
	rule["from_port"] = opts.FromPort
	rule["to_port"] = opts.ToPort
	rule["ip_protocol"] = opts.IPProtocol
	if opts.CIDR != "" {
		rule["cidr"] = opts.CIDR
	}
	if opts.FromGroupID != "" {
		rule["group_id"] = opts.FromGroupID
	}
	return map[string]interface{}{"security_group_rule": rule}, nil
}
ToRuleCreateMap builds the create rule options into a serializable format.
package secgroups
import (
	"errors"
	"github.com/rackspace/gophercloud"
	"github.com/rackspace/gophercloud/pagination"
)
func commonList(client *gophercloud.ServiceClient, url string) pagination.Pager {
	createPage := func(r pagination.PageResult) pagination.Page {
		return SecurityGroupPage{pagination.SinglePageBase(r)}
	}
	return pagination.NewPager(client, url, createPage)
}
func List(client *gophercloud.ServiceClient) pagination.Pager {
	return commonList(client, rootURL(client))
}
func ListByServer(client *gophercloud.ServiceClient, serverID string) pagination.Pager {
	return commonList(client, listByServerURL(client, serverID))
}
type GroupOpts struct {
	Name string `json:"name"`
	Description string `json:"description"`
}
type CreateOpts GroupOpts
type CreateOptsBuilder interface {
	ToSecGroupCreateMap() (map[string]interface{}, error)
}
var (
	errName = errors.New("Name is a required field")
	errDesc = errors.New("Description is a required field")
)
func (opts CreateOpts) ToSecGroupCreateMap() (map[string]interface{}, error) {
	sg := make(map[string]interface{})
	if opts.Name == "" {
		return sg, errName
	}
	if opts.Description == "" {
		return sg, errDesc
	}
	sg["name"] = opts.Name
	sg["description"] = opts.Description
	return map[string]interface{}{"security_group": sg}, nil
}
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
	var result CreateResult
	reqBody, err := opts.ToSecGroupCreateMap()
	if err != nil {
		result.Err = err
		return result
	}
	_, result.Err = client.Request("POST", rootURL(client), gophercloud.RequestOpts{
		JSONResponse: &result.Body,
		JSONBody:     &reqBody,
		OkCodes:      []int{200},
	})
	return result
}
type UpdateOpts GroupOpts
type UpdateOptsBuilder interface {
	ToSecGroupUpdateMap() (map[string]interface{}, error)
}
func (opts UpdateOpts) ToSecGroupUpdateMap() (map[string]interface{}, error) {
	sg := make(map[string]interface{})
	if opts.Name == "" {
		return sg, errName
	}
	if opts.Description == "" {
		return sg, errDesc
	}
	sg["name"] = opts.Name
	sg["description"] = opts.Description
	return map[string]interface{}{"security_group": sg}, nil
}
func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) UpdateResult {
	var result UpdateResult
	reqBody, err := opts.ToSecGroupUpdateMap()
	if err != nil {
		result.Err = err
		return result
	}
	_, result.Err = client.Request("PUT", resourceURL(client, id), gophercloud.RequestOpts{
		JSONResponse: &result.Body,
		JSONBody:     &reqBody,
		OkCodes:      []int{200},
	})
	return result
}
func Get(client *gophercloud.ServiceClient, id string) GetResult {
	var result GetResult
	_, result.Err = client.Request("GET", resourceURL(client, id), gophercloud.RequestOpts{
		JSONResponse: &result.Body,
		OkCodes:      []int{200},
	})
	return result
}
func Delete(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
	var result gophercloud.ErrResult
	_, result.Err = client.Request("DELETE", resourceURL(client, id), gophercloud.RequestOpts{
		OkCodes: []int{202},
	})
	return result
}
type CreateRuleOpts struct {
	ParentGroupID string `json:"parent_group_id"`
	FromPort int `json:"from_port"`
	ToPort int `json:"to_port"`
	IPProtocol string `json:"ip_protocol"`
	CIDR string `json:"cidr,omitempty"`
	FromGroupID string `json:"group_id,omitempty"`
}
type CreateRuleOptsBuilder interface {
	ToRuleCreateMap() (map[string]interface{}, error)
}