Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions openstack/dns/v2/zones/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,44 @@ func Delete(client *golangsdk.ServiceClient, zoneID string) (r DeleteResult) {
})
return
}

// RouterOptsBuilder allows to add parameters to the associate/disassociate Zone request.
type RouterOptsBuilder interface {
ToRouterMap() (map[string]interface{}, error)
}

// RouterOpts specifies the required information to associate/disassociate a Router with a Zone.
type RouterOpts struct {
// Router ID
RouterID string `json:"router_id" required:"true"`

// Router Region
RouterRegion string `json:"router_region,omitempty"`
}

// ToRouterMap constructs a request body from RouterOpts.
func (opts RouterOpts) ToRouterMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "router")
}

// AssociateZone associate a Router with a Zone.
func AssociateZone(client *golangsdk.ServiceClient, zoneID string, opts RouterOptsBuilder) (r AssociateResult) {
b, err := opts.ToRouterMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(associateURL(client, zoneID), b, nil, nil)
return
}

// DisassociateZone disassociate a Router with a Zone.
func DisassociateZone(client *golangsdk.ServiceClient, zoneID string, opts RouterOptsBuilder) (r DisassociateResult) {
b, err := opts.ToRouterMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(disassociateURL(client, zoneID), b, nil, nil)
return
}
19 changes: 19 additions & 0 deletions openstack/dns/v2/zones/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ type Zone struct {
// Links includes HTTP references to the itself, useful for passing along
// to other APIs that might want a server reference.
Links map[string]interface{} `json:"links"`

// Routers associate with the Zone
Routers []RouterResult `json:"routers"`
}

type RouterResult struct {
RouterID string `json:"router_id"`
RouterRegion string `json:"router_region"`
Status string `json:"status"`
}

func (r *Zone) UnmarshalJSON(b []byte) error {
Expand Down Expand Up @@ -165,3 +174,13 @@ func (r *Zone) UnmarshalJSON(b []byte) error {

return err
}

// AssociateResult is the response from AssociateZone
type AssociateResult struct {
commonResult
}

// DisassociateResult is the response from DisassociateZone
type DisassociateResult struct {
commonResult
}
8 changes: 8 additions & 0 deletions openstack/dns/v2/zones/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ func baseURL(c *golangsdk.ServiceClient) string {
func zoneURL(c *golangsdk.ServiceClient, zoneID string) string {
return c.ServiceURL("zones", zoneID)
}

func associateURL(client *golangsdk.ServiceClient, zoneID string) string {
return client.ServiceURL("zones", zoneID, "associaterouter")
}

func disassociateURL(client *golangsdk.ServiceClient, zoneID string) string {
return client.ServiceURL("zones", zoneID, "disassociaterouter")
}