github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v1/vpcs/results.go (about)

     1  package vpcs
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     6  )
     7  
     8  // Route is a possible route in a vpc.
     9  type Route struct {
    10  	NextHop         string `json:"nexthop"`
    11  	DestinationCIDR string `json:"destination"`
    12  }
    13  
    14  // Vpc represents a Neutron vpc. A vpc is a logical entity that
    15  // forwards packets across internal subnets and NATs (network address
    16  // translation) them on external networks through an appropriate gateway.
    17  //
    18  // A vpc has an interface for each subnet with which it is associated. By
    19  // default, the IP address of such interface is the subnet's gateway IP. Also,
    20  // whenever a vpc is associated with a subnet, a port for that vpc
    21  // interface is added to the subnet's network.
    22  type Vpc struct {
    23  	// ID is the unique identifier for the vpc.
    24  	ID string `json:"id"`
    25  
    26  	// Name is the human-readable name for the vpc. It does not have to be
    27  	// unique.
    28  	Name string `json:"name"`
    29  
    30  	// Specifies the range of available subnets in the VPC.
    31  	CIDR string `json:"cidr"`
    32  
    33  	// Provides supplementary information about the VPC.
    34  	Description string `json:"description"`
    35  
    36  	// Status indicates whether a vpc is currently operational.
    37  	Status string `json:"status"`
    38  
    39  	// Routes are a collection of static routes that the vpc will host.
    40  	Routes []Route `json:"routes"`
    41  
    42  	// Provides information about shared snat
    43  	EnableSharedSnat bool `json:"enable_shared_snat"`
    44  }
    45  
    46  // VpcPage is the page returned by a pager when traversing over a
    47  // collection of vpcs.
    48  type VpcPage struct {
    49  	pagination.LinkedPageBase
    50  }
    51  
    52  // NextPageURL is invoked when a paginated collection of vpcs has reached
    53  // the end of a page and the pager seeks to traverse over a new one. In order
    54  // to do this, it needs to construct the next page's URL.
    55  func (r VpcPage) NextPageURL() (string, error) {
    56  	var s struct {
    57  		Links []golangsdk.Link `json:"vpcs_links"`
    58  	}
    59  	err := r.ExtractInto(&s)
    60  	if err != nil {
    61  		return "", err
    62  	}
    63  	return golangsdk.ExtractNextURL(s.Links)
    64  }
    65  
    66  // IsEmpty checks whether a VpcPage struct is empty.
    67  func (r VpcPage) IsEmpty() (bool, error) {
    68  	is, err := ExtractVpcs(r)
    69  	return len(is) == 0, err
    70  }
    71  
    72  // ExtractVpcs accepts a Page struct, specifically a VpcPage struct,
    73  // and extracts the elements into a slice of Vpc structs. In other words,
    74  // a generic collection is mapped into a relevant slice.
    75  func ExtractVpcs(r pagination.Page) ([]Vpc, error) {
    76  	var s []Vpc
    77  	err := (r.(VpcPage)).ExtractIntoSlicePtr(&s, "vpcs")
    78  	if err != nil {
    79  		return nil, err
    80  	}
    81  	return s, nil
    82  }
    83  
    84  type commonResult struct {
    85  	golangsdk.Result
    86  }
    87  
    88  // Extract is a function that accepts a result and extracts a vpc.
    89  func (r commonResult) Extract() (*Vpc, error) {
    90  	s := new(Vpc)
    91  	err := r.ExtractIntoStructPtr(s, "vpc")
    92  	if err != nil {
    93  		return nil, err
    94  	}
    95  	return s, nil
    96  }
    97  
    98  // CreateResult represents the result of a create operation. Call its Extract
    99  // method to interpret it as a Vpc.
   100  type CreateResult struct {
   101  	commonResult
   102  }
   103  
   104  // GetResult represents the result of a get operation. Call its Extract
   105  // method to interpret it as a Vpc.
   106  type GetResult struct {
   107  	commonResult
   108  }
   109  
   110  // UpdateResult represents the result of an update operation. Call its Extract
   111  // method to interpret it as a Vpc.
   112  type UpdateResult struct {
   113  	commonResult
   114  }
   115  
   116  // DeleteResult represents the result of a delete operation. Call its ExtractErr
   117  // method to determine if the request succeeded or failed.
   118  type DeleteResult struct {
   119  	golangsdk.ErrResult
   120  }