rackspace/gophercloud — pull request #210 by jamiehannaford (2014-09-29 13:08:30+00:00)
Title: [wip] Neutron v2 extensions

This PR introduces a possible idea for how we can structure and deal with vendor extensions. Everything is placed in the `extensions` directory, and each sub-resource mirrors the structure of normal resources as much as possible for consistency. For minor things like extended attributes, you do not need to duplicate or redefine the existing CRUD operations for a resource; but rather introduce different `ExtractXXX` functions to extract new structures out of the HTTP response returned from the API:

```go
// Original operation
res := networks.Get(client, "foo-id")

// Extension extracts what it needs to in a new way
extNetwork := ext.ExtractGet(res)
```

If you need to modify create and update operations (if you're introducing extended attributes for example), you will need to have a base interface which both the common opts struct satisfies, and the extension opts struct:

```go
// All options, whether common or extension based, need to satisfy this
type CreateOptsInt interface {
ToMap() map[string]map[string]interface{}
IsCreateOpts() bool
}

type CreateOpts struct {
Name string
}

func (o CreateOpts) IsCreateOpts() bool { return true }

func (o CreateOpts) ToMap() map[string]map[string]interface{} {
inner := make(map[string]interface{})
if o.Name != "" {
inner["name"] = o.Name
}

outer := make(map[string]map[string]interface{})
outer["network"] = inner
return outer
}

// Extension
type CreateOpts struct {
Parent networks.CreateOpts
NewAttr bool
}

func (o CreateOpts) ToMap() map[string]map[string]interface{} {
outer := o.Parent.ToMap()
outer["network"]["new_field"] = o.NewAttr
return outer
}

func (o CreateOpts) IsCreateOpts() bool { return true }

```

**External networks ([`external-net`](http://docs.openstack.org/api/openstack-network/2.0/content/external_net.html))**

- [x] Extended attributes

**Provider networks ([`provider`](http://docs.openstack.org/api/openstack-network/2.0/content/provider_ext.html))**

- [x] Extended attributes

**Layer-3 networking ([`router`](http://docs.openstack.org/api/openstack-network/2.0/content/router_ext.html))**

- [x] Routers
- [x] Floating IPs

**Security groups and rules ([`security-groups`](http://docs.openstack.org/api/openstack-network/2.0/content/security_groups.html))**

- [ ] Security groups
- [ ] Security group rules

**Load balancers ([`LBaaS`](http://docs.openstack.org/api/openstack-network/2.0/content/lbaas_ext.html))**

- [ ] Load balancers
- [ ] Listeners
- [ ] Pools
- [ ] Members
- [ ] Health monitors