github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/provider/results.go (about)

     1  package provider
     2  
     3  import (
     4  	"encoding/json"
     5  	"strconv"
     6  )
     7  
     8  // NetworkProviderExt represents an extended form of a Network with additional
     9  // fields.
    10  type NetworkProviderExt struct {
    11  	// Specifies the nature of the physical network mapped to this network
    12  	// resource. Examples are flat, vlan, or gre.
    13  	NetworkType string `json:"provider:network_type"`
    14  
    15  	// Identifies the physical network on top of which this network object is
    16  	// being implemented. The OpenStack Networking API does not expose any
    17  	// facility for retrieving the list of available physical networks. As an
    18  	// example, in the Open vSwitch plug-in this is a symbolic name which is
    19  	// then mapped to specific bridges on each compute host through the Open
    20  	// vSwitch plug-in configuration file.
    21  	PhysicalNetwork string `json:"provider:physical_network"`
    22  
    23  	// Identifies an isolated segment on the physical network; the nature of the
    24  	// segment depends on the segmentation model defined by network_type. For
    25  	// instance, if network_type is vlan, then this is a vlan identifier;
    26  	// otherwise, if network_type is gre, then this will be a gre key.
    27  	SegmentationID string `json:"-"`
    28  
    29  	// Segments is an array of Segment which defines multiple physical bindings
    30  	// to logical networks.
    31  	Segments []Segment `json:"segments"`
    32  }
    33  
    34  // Segment defines a physical binding to a logical network.
    35  type Segment struct {
    36  	PhysicalNetwork string `json:"provider:physical_network"`
    37  	NetworkType     string `json:"provider:network_type"`
    38  	SegmentationID  int    `json:"provider:segmentation_id"`
    39  }
    40  
    41  func (r *NetworkProviderExt) UnmarshalJSON(b []byte) error {
    42  	type tmp NetworkProviderExt
    43  	var networkProviderExt struct {
    44  		tmp
    45  		SegmentationID interface{} `json:"provider:segmentation_id"`
    46  	}
    47  
    48  	if err := json.Unmarshal(b, &networkProviderExt); err != nil {
    49  		return err
    50  	}
    51  
    52  	*r = NetworkProviderExt(networkProviderExt.tmp)
    53  
    54  	switch t := networkProviderExt.SegmentationID.(type) {
    55  	case float64:
    56  		r.SegmentationID = strconv.FormatFloat(t, 'f', -1, 64)
    57  	case string:
    58  		r.SegmentationID = string(t)
    59  	}
    60  
    61  	return nil
    62  }