github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v1/vpcs/results.go (about)

     1  package vpcs
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/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  	//Specifies the range of available subnets in the VPC.
    31  	CIDR string `json:"cidr"`
    32  
    33  	//Enterprise Project ID.
    34  	EnterpriseProjectID string `json:"enterprise_project_id"`
    35  
    36  	// Status indicates whether or not 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 informaion 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 struct {
    77  		Vpcs []Vpc `json:"vpcs"`
    78  	}
    79  	err := (r.(VpcPage)).ExtractInto(&s)
    80  	return s.Vpcs, err
    81  }
    82  
    83  type commonResult struct {
    84  	golangsdk.Result
    85  }
    86  
    87  // Extract is a function that accepts a result and extracts a vpc.
    88  func (r commonResult) Extract() (*Vpc, error) {
    89  	var s struct {
    90  		Vpc *Vpc `json:"vpc"`
    91  	}
    92  	err := r.ExtractInto(&s)
    93  	return s.Vpc, err
    94  }
    95  
    96  // CreateResult represents the result of a create operation. Call its Extract
    97  // method to interpret it as a Vpc.
    98  type CreateResult struct {
    99  	commonResult
   100  }
   101  
   102  // GetResult represents the result of a get operation. Call its Extract
   103  // method to interpret it as a Vpc.
   104  type GetResult struct {
   105  	commonResult
   106  }
   107  
   108  // UpdateResult represents the result of an update operation. Call its Extract
   109  // method to interpret it as a Vpc.
   110  type UpdateResult struct {
   111  	commonResult
   112  }
   113  
   114  // DeleteResult represents the result of a delete operation. Call its ExtractErr
   115  // method to determine if the request succeeded or failed.
   116  type DeleteResult struct {
   117  	golangsdk.ErrResult
   118  }