blob: 7e10c6d299bf0e5175c7bd8ddcb7fdd1a99156da [file] [log] [blame]
Jamie Hannaford9823bb62014-09-26 17:06:36 +02001package external
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
5 "github.com/gophercloud/gophercloud/pagination"
Jamie Hannaford9823bb62014-09-26 17:06:36 +02006)
7
8// NetworkExternal represents a decorated form of a Network with based on the
9// "external-net" extension.
10type NetworkExternal struct {
11 // UUID for the network
Jon Perritt3c166472016-02-25 03:07:41 -060012 ID string `json:"id"`
Jamie Hannaford9823bb62014-09-26 17:06:36 +020013
14 // Human-readable name for the network. Might not be unique.
Jon Perritt3c166472016-02-25 03:07:41 -060015 Name string `json:"name"`
Jamie Hannaford9823bb62014-09-26 17:06:36 +020016
17 // The administrative state of network. If false (down), the network does not forward packets.
Jon Perritt3c166472016-02-25 03:07:41 -060018 AdminStateUp bool `json:"admin_state_up"`
Jamie Hannaford9823bb62014-09-26 17:06:36 +020019
20 // Indicates whether network is currently operational. Possible values include
21 // `ACTIVE', `DOWN', `BUILD', or `ERROR'. Plug-ins might define additional values.
Jon Perritt3c166472016-02-25 03:07:41 -060022 Status string `json:"status"`
Jamie Hannaford9823bb62014-09-26 17:06:36 +020023
24 // Subnets associated with this network.
Jon Perritt3c166472016-02-25 03:07:41 -060025 Subnets []string `json:"subnets"`
Jamie Hannaford9823bb62014-09-26 17:06:36 +020026
27 // Owner of network. Only admin users can specify a tenant_id other than its own.
Jon Perritt3c166472016-02-25 03:07:41 -060028 TenantID string `json:"tenant_id"`
Jamie Hannaford9823bb62014-09-26 17:06:36 +020029
30 // Specifies whether the network resource can be accessed by any tenant or not.
Jon Perritt3c166472016-02-25 03:07:41 -060031 Shared bool `json:"shared"`
Jamie Hannaford9823bb62014-09-26 17:06:36 +020032
33 // Specifies whether the network is an external network or not.
Jon Perritt3c166472016-02-25 03:07:41 -060034 External bool `json:"router:external"`
Jamie Hannaford9823bb62014-09-26 17:06:36 +020035}
36
Jamie Hannaford91cd64e2014-10-08 13:08:52 +020037// ExtractGet decorates a GetResult struct returned from a networks.Get()
38// function with extended attributes.
39func ExtractGet(r networks.GetResult) (*NetworkExternal, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060040 var s struct {
41 Network *NetworkExternal `json:"network"`
42 }
43 err := r.ExtractInto(&s)
44 return s.Network, err
Jamie Hannaford91cd64e2014-10-08 13:08:52 +020045}
46
Jamie Hannaford9823bb62014-09-26 17:06:36 +020047// ExtractCreate decorates a CreateResult struct returned from a networks.Create()
48// function with extended attributes.
49func ExtractCreate(r networks.CreateResult) (*NetworkExternal, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060050 var s struct {
51 Network *NetworkExternal `json:"network"`
52 }
53 err := r.ExtractInto(&s)
54 return s.Network, err
Jamie Hannaford9823bb62014-09-26 17:06:36 +020055}
56
57// ExtractUpdate decorates a UpdateResult struct returned from a
58// networks.Update() function with extended attributes.
59func ExtractUpdate(r networks.UpdateResult) (*NetworkExternal, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060060 var s struct {
61 Network *NetworkExternal `json:"network"`
62 }
63 err := r.ExtractInto(&s)
64 return s.Network, err
Jamie Hannaford9823bb62014-09-26 17:06:36 +020065}
66
67// ExtractList accepts a Page struct, specifically a NetworkPage struct, and
Jon Perrittb0b9c0d2015-03-10 17:24:08 -060068// extracts the elements into a slice of NetworkExternal structs. In other
Jamie Hannaford9823bb62014-09-26 17:06:36 +020069// words, a generic collection is mapped into a relevant slice.
Jon Perritt31b66462016-02-25 22:25:30 -060070func ExtractList(r pagination.Page) ([]NetworkExternal, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060071 var s struct {
72 Networks []NetworkExternal `json:"networks" json:"networks"`
Jamie Hannaford9823bb62014-09-26 17:06:36 +020073 }
Jon Perritt31b66462016-02-25 22:25:30 -060074 err := (r.(networks.NetworkPage)).ExtractInto(&s)
Jon Perritt3c166472016-02-25 03:07:41 -060075 return s.Networks, err
Jamie Hannaford9823bb62014-09-26 17:06:36 +020076}