github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/networking/v1/vpcs/results.go (about)

     1  package vpcs
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/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  	// Description provides supplementary information about the VPC
    31  	Description string `json:"description"`
    32  
    33  	//Specifies the range of available subnets in the VPC.
    34  	CIDR string `json:"cidr"`
    35  
    36  	//Enterprise Project ID.
    37  	EnterpriseProjectID string `json:"enterprise_project_id"`
    38  
    39  	// Status indicates whether or not a vpc is currently operational.
    40  	Status string `json:"status"`
    41  
    42  	// Routes are a collection of static routes that the vpc will host.
    43  	Routes []Route `json:"routes"`
    44  
    45  	//Provides informaion about shared snat
    46  	EnableSharedSnat bool `json:"enable_shared_snat"`
    47  }
    48  
    49  // VpcPage is the page returned by a pager when traversing over a
    50  // collection of vpcs.
    51  type VpcPage struct {
    52  	pagination.LinkedPageBase
    53  }
    54  
    55  // NextPageURL is invoked when a paginated collection of vpcs has reached
    56  // the end of a page and the pager seeks to traverse over a new one. In order
    57  // to do this, it needs to construct the next page's URL.
    58  func (r VpcPage) NextPageURL() (string, error) {
    59  	var s struct {
    60  		Links []golangsdk.Link `json:"vpcs_links"`
    61  	}
    62  	err := r.ExtractInto(&s)
    63  	if err != nil {
    64  		return "", err
    65  	}
    66  	return golangsdk.ExtractNextURL(s.Links)
    67  }
    68  
    69  // IsEmpty checks whether a VpcPage struct is empty.
    70  func (r VpcPage) IsEmpty() (bool, error) {
    71  	is, err := ExtractVpcs(r)
    72  	return len(is) == 0, err
    73  }
    74  
    75  // ExtractVpcs accepts a Page struct, specifically a VpcPage struct,
    76  // and extracts the elements into a slice of Vpc structs. In other words,
    77  // a generic collection is mapped into a relevant slice.
    78  func ExtractVpcs(r pagination.Page) ([]Vpc, error) {
    79  	var s struct {
    80  		Vpcs []Vpc `json:"vpcs"`
    81  	}
    82  	err := (r.(VpcPage)).ExtractInto(&s)
    83  	return s.Vpcs, err
    84  }
    85  
    86  type commonResult struct {
    87  	golangsdk.Result
    88  }
    89  
    90  // Extract is a function that accepts a result and extracts a vpc.
    91  func (r commonResult) Extract() (*Vpc, error) {
    92  	var s struct {
    93  		Vpc *Vpc `json:"vpc"`
    94  	}
    95  	err := r.ExtractInto(&s)
    96  	return s.Vpc, err
    97  }
    98  
    99  // CreateResult represents the result of a create operation. Call its Extract
   100  // method to interpret it as a Vpc.
   101  type CreateResult struct {
   102  	commonResult
   103  }
   104  
   105  // GetResult represents the result of a get operation. Call its Extract
   106  // method to interpret it as a Vpc.
   107  type GetResult struct {
   108  	commonResult
   109  }
   110  
   111  // UpdateResult represents the result of an update operation. Call its Extract
   112  // method to interpret it as a Vpc.
   113  type UpdateResult struct {
   114  	commonResult
   115  }
   116  
   117  // DeleteResult represents the result of a delete operation. Call its ExtractErr
   118  // method to determine if the request succeeded or failed.
   119  type DeleteResult struct {
   120  	golangsdk.ErrResult
   121  }