github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/er/v3/vpcattachments/results.go (about)

     1  package vpcattachments
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk/openstack/common/tags"
     5  	"github.com/chnsz/golangsdk/pagination"
     6  )
     7  
     8  // SingleResp is the structure that represents the VPC attachment detail and the request information of the API request.
     9  type SingleResp struct {
    10  	// The response detail of the VPC attachment.
    11  	Attachment Attachment `json:"vpc_attachment"`
    12  	// The request ID.
    13  	RequestId string `json:"request_id"`
    14  }
    15  
    16  // Attachment is the structure that represents the details of the VPC attachment for ER service.
    17  type Attachment struct {
    18  	// The project ID.
    19  	ProjectId string `json:"project_id"`
    20  	// The ID of the project where the VPC is located.
    21  	VpcProjectId string `json:"vpc_project_id"`
    22  	// The ID of the VPC attachment.
    23  	ID string `json:"id"`
    24  	// The name of the VPC attachment.
    25  	Name string `json:"name"`
    26  	// The description of the VPC attachment.
    27  	Description string `json:"description"`
    28  	// The VPC ID corresponding to the VPC attachment.
    29  	VpcId string `json:"vpc_id"`
    30  	// The VPC subnet ID corresponding to the VPC attachment.
    31  	SubnetId string `json:"virsubnet_id"`
    32  	// Whether automatically configure a route pointing to the ER instance for the VPC.
    33  	AutoCreateVpcRoutes bool `json:"auto_create_vpc_routes"`
    34  	// The current status of the VPC attachment.
    35  	Status string `json:"state"`
    36  	// The creation time of the VPC attachment.
    37  	CreatedAt string `json:"created_at"`
    38  	// The last update time of the VPC attachment.
    39  	UpdatedAt string `json:"updated_at"`
    40  	// The key/value pairs to associate with the VPC attachment.
    41  	Tags []tags.ResourceTag `json:"tags"`
    42  }
    43  
    44  // MultipleResp is the structure that represents the VPC attachment list, page detail and the request information.
    45  type MultipleResp struct {
    46  	// The list of the VPC attachment.
    47  	Attachments []Attachment `json:"vpc_attachments"`
    48  	// The request ID.
    49  	RequestId string `json:"request_id"`
    50  	// The page information.
    51  	PageInfo PageInfo `json:"page_info"`
    52  }
    53  
    54  // PageInfo is the structure that represents the page information.
    55  type PageInfo struct {
    56  	// The next marker information.
    57  	NextMarker string `json:"next_marker"`
    58  	// The number of the VPC attahcment in current page.
    59  	CurrentCount int `json:"current_count"`
    60  }
    61  
    62  // AttachmentPage represents the response pages of the List method.
    63  type AttachmentPage struct {
    64  	pagination.MarkerPageBase
    65  }
    66  
    67  // IsEmpty returns true if current page no VPC attachment.
    68  func (r AttachmentPage) IsEmpty() (bool, error) {
    69  	resp, err := ExtractAttachments(r)
    70  	return len(resp) == 0, err
    71  }
    72  
    73  // LastMarker returns the last marker index during current page.
    74  func (r AttachmentPage) LastMarker() (string, error) {
    75  	resp, err := ExtractPageInfo(r)
    76  	if err != nil {
    77  		return "", err
    78  	}
    79  	if resp.NextMarker != "" {
    80  		return "", nil
    81  	}
    82  	return resp.NextMarker, nil
    83  }
    84  
    85  // NextPageURL generates the URL for the page of results after this one.
    86  func (r AttachmentPage) NextPageURL() (string, error) {
    87  	currentURL := r.URL
    88  
    89  	mark, err := r.Owner.LastMarker()
    90  	if err != nil {
    91  		return "", err
    92  	}
    93  	if mark == "" {
    94  		return "", nil
    95  	}
    96  
    97  	q := currentURL.Query()
    98  	q.Set("marker", mark)
    99  	currentURL.RawQuery = q.Encode()
   100  
   101  	return currentURL.String(), nil
   102  }
   103  
   104  // ExtractPageInfo is a method which to extract the response of the page information.
   105  func ExtractPageInfo(r pagination.Page) (*PageInfo, error) {
   106  	var s MultipleResp
   107  	err := r.(AttachmentPage).Result.ExtractInto(&s)
   108  	return &s.PageInfo, err
   109  }
   110  
   111  // ExtractAttachments is a method which to extract the response to an attachment list.
   112  func ExtractAttachments(r pagination.Page) ([]Attachment, error) {
   113  	var s MultipleResp
   114  	err := r.(AttachmentPage).Result.ExtractInto(&s)
   115  	return s.Attachments, err
   116  }