blob: 229013b4f780acc77a02b77edc909d83a2bdebdf [file] [log] [blame]
Jamie Hannafordb0d99122014-09-25 10:49:14 +02001package provider
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 Hannafordb0d99122014-09-25 10:49:14 +02006)
7
8// NetworkExtAttrs represents an extended form of a Network with additional fields.
9type NetworkExtAttrs struct {
10 // UUID for the network
Jon Perritt3c166472016-02-25 03:07:41 -060011 ID string `json:"id"`
Jamie Hannafordb0d99122014-09-25 10:49:14 +020012
13 // Human-readable name for the network. Might not be unique.
Jon Perritt3c166472016-02-25 03:07:41 -060014 Name string `json:"name"`
Jamie Hannafordb0d99122014-09-25 10:49:14 +020015
16 // The administrative state of network. If false (down), the network does not forward packets.
Jon Perritt3c166472016-02-25 03:07:41 -060017 AdminStateUp bool `json:"admin_state_up"`
Jamie Hannafordb0d99122014-09-25 10:49:14 +020018
19 // Indicates whether network is currently operational. Possible values include
20 // `ACTIVE', `DOWN', `BUILD', or `ERROR'. Plug-ins might define additional values.
Jon Perritt3c166472016-02-25 03:07:41 -060021 Status string `json:"status"`
Jamie Hannafordb0d99122014-09-25 10:49:14 +020022
23 // Subnets associated with this network.
Jon Perritt3c166472016-02-25 03:07:41 -060024 Subnets []string `json:"subnets"`
Jamie Hannafordb0d99122014-09-25 10:49:14 +020025
26 // Owner of network. Only admin users can specify a tenant_id other than its own.
Jon Perritt3c166472016-02-25 03:07:41 -060027 TenantID string `json:"tenant_id"`
Jamie Hannafordb0d99122014-09-25 10:49:14 +020028
29 // Specifies whether the network resource can be accessed by any tenant or not.
Jon Perritt3c166472016-02-25 03:07:41 -060030 Shared bool `json:"shared"`
Jamie Hannafordb0d99122014-09-25 10:49:14 +020031
32 // Specifies the nature of the physical network mapped to this network
33 // resource. Examples are flat, vlan, or gre.
Jon Perritt3c166472016-02-25 03:07:41 -060034 NetworkType string `json:"provider:network_type"`
Jamie Hannafordb0d99122014-09-25 10:49:14 +020035
36 // Identifies the physical network on top of which this network object is
37 // being implemented. The OpenStack Networking API does not expose any facility
38 // for retrieving the list of available physical networks. As an example, in
39 // the Open vSwitch plug-in this is a symbolic name which is then mapped to
40 // specific bridges on each compute host through the Open vSwitch plug-in
41 // configuration file.
Jon Perritt3c166472016-02-25 03:07:41 -060042 PhysicalNetwork string `json:"provider:physical_network"`
Jamie Hannafordb0d99122014-09-25 10:49:14 +020043
44 // Identifies an isolated segment on the physical network; the nature of the
45 // segment depends on the segmentation model defined by network_type. For
46 // instance, if network_type is vlan, then this is a vlan identifier;
47 // otherwise, if network_type is gre, then this will be a gre key.
Jon Perritt3c166472016-02-25 03:07:41 -060048 SegmentationID string `json:"provider:segmentation_id"`
Jamie Hannafordb0d99122014-09-25 10:49:14 +020049}
50
Jamie Hannaford5a531902014-09-26 15:03:31 +020051// ExtractGet decorates a GetResult struct returned from a networks.Get()
52// function with extended attributes.
Jamie Hannafordb0d99122014-09-25 10:49:14 +020053func ExtractGet(r networks.GetResult) (*NetworkExtAttrs, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060054 var s struct {
Jamie Hannafordb0d99122014-09-25 10:49:14 +020055 Network *NetworkExtAttrs `json:"network"`
56 }
Jon Perritt3c166472016-02-25 03:07:41 -060057 err := r.ExtractInto(&s)
58 return s.Network, err
Jamie Hannafordb0d99122014-09-25 10:49:14 +020059}
60
Jamie Hannafordc7c49a72014-10-06 15:49:53 +020061// ExtractCreate decorates a CreateResult struct returned from a networks.Create()
Jamie Hannaford5a531902014-09-26 15:03:31 +020062// function with extended attributes.
Jamie Hannafordb0d99122014-09-25 10:49:14 +020063func ExtractCreate(r networks.CreateResult) (*NetworkExtAttrs, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060064 var s struct {
Jamie Hannafordb0d99122014-09-25 10:49:14 +020065 Network *NetworkExtAttrs `json:"network"`
66 }
Jon Perritt3c166472016-02-25 03:07:41 -060067 err := r.ExtractInto(&s)
68 return s.Network, err
Jamie Hannafordb0d99122014-09-25 10:49:14 +020069}
70
Jamie Hannaford5a531902014-09-26 15:03:31 +020071// ExtractUpdate decorates a UpdateResult struct returned from a
72// networks.Update() function with extended attributes.
Jamie Hannafordb0d99122014-09-25 10:49:14 +020073func ExtractUpdate(r networks.UpdateResult) (*NetworkExtAttrs, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060074 var s struct {
Jamie Hannafordb0d99122014-09-25 10:49:14 +020075 Network *NetworkExtAttrs `json:"network"`
76 }
Jon Perritt3c166472016-02-25 03:07:41 -060077 err := r.ExtractInto(&s)
78 return s.Network, err
Jamie Hannafordb0d99122014-09-25 10:49:14 +020079}
80
81// ExtractList accepts a Page struct, specifically a NetworkPage struct, and
82// extracts the elements into a slice of NetworkExtAttrs structs. In other
83// words, a generic collection is mapped into a relevant slice.
Jon Perritt31b66462016-02-25 22:25:30 -060084func ExtractList(r pagination.Page) ([]NetworkExtAttrs, error) {
Jon Perritt3c166472016-02-25 03:07:41 -060085 var s struct {
86 Networks []NetworkExtAttrs `json:"networks" json:"networks"`
Jamie Hannafordb0d99122014-09-25 10:49:14 +020087 }
Jon Perritt31b66462016-02-25 22:25:30 -060088 err := (r.(networks.NetworkPage)).ExtractInto(&s)
Jon Perritt3c166472016-02-25 03:07:41 -060089 return s.Networks, err
Jamie Hannafordb0d99122014-09-25 10:49:14 +020090}