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

     1  package shares
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	"github.com/huaweicloud/golangsdk"
     8  	"github.com/huaweicloud/golangsdk/pagination"
     9  )
    10  
    11  // TurboResponse contains the information of creating response
    12  type TurboResponse struct {
    13  	ID     string `json:"id"`
    14  	Name   string `json:"name"`
    15  	Status string `json:"status"`
    16  }
    17  
    18  // Turbo contains all information associated with an SFS Turbo file system
    19  type Turbo struct {
    20  	// The UUID of the SFS Turbo file system
    21  	ID string `json:"id"`
    22  	// The name of the SFS Turbo file system
    23  	Name string `json:"name"`
    24  	// Size of the share in GB
    25  	Size string `json:"size"`
    26  	// The statue of the SFS Turbo file system
    27  	Status string `json:"status"`
    28  	// The sub-statue of the SFS Turbo file system
    29  	SubStatus string `json:"sub_status"`
    30  	// The version ID of the SFS Turbo file system
    31  	Version string `json:"version"`
    32  	// The mount location
    33  	ExportLocation string `json:"export_location"`
    34  	// The creation progress of the SFS Turbo file system
    35  	Actions []string `json:"actions"`
    36  	// The protocol type of the SFS Turbo file system
    37  	ShareProto string `json:"share_proto"`
    38  	// The type of the SFS Turbo file system, STANDARD or PERFORMANCE.
    39  	ShareType string `json:"share_type"`
    40  	// The region of the SFS Turbo file system
    41  	Region string `json:"region"`
    42  	// The code of the availability zone
    43  	AvailabilityZone string `json:"availability_zone"`
    44  	// The name of the availability zone
    45  	AZName string `json:"az_name"`
    46  	// The VPC ID
    47  	VpcID string `json:"vpc_id"`
    48  	// The subnet ID
    49  	SubnetID string `json:"subnet_id"`
    50  	// The security group ID
    51  	SecurityGroupID string `json:"security_group_id"`
    52  	// The avaliable capacity if the SFS Turbo file system
    53  	AvailCapacity string `json:"avail_capacity"`
    54  	// bandwidth is returned for an enhanced file system
    55  	ExpandType string `json:"expand_type"`
    56  	// The ID of the encryption key
    57  	CryptKeyID string `json:"crypt_key_id"`
    58  	// The billing mode, 0 indicates pay-per-use, 1 indicates yearly/monthly subscription
    59  	PayModel string `json:"pay_model"`
    60  	// Timestamp when the share was created
    61  	CreatedAt time.Time `json:"-"`
    62  	// The enterprise project ID
    63  	EnterpriseProjectId string `json:"enterprise_project_id"`
    64  }
    65  
    66  func (r *Turbo) UnmarshalJSON(b []byte) error {
    67  	type tmp Turbo
    68  	var s struct {
    69  		tmp
    70  		CreatedAt golangsdk.JSONRFC3339MilliNoZ `json:"created_at"`
    71  	}
    72  	err := json.Unmarshal(b, &s)
    73  	if err != nil {
    74  		return err
    75  	}
    76  	*r = Turbo(s.tmp)
    77  
    78  	r.CreatedAt = time.Time(s.CreatedAt)
    79  
    80  	return nil
    81  }
    82  
    83  type commonResult struct {
    84  	golangsdk.Result
    85  }
    86  
    87  // CreateResult contains the response body and error from a Create request.
    88  type CreateResult struct {
    89  	commonResult
    90  }
    91  
    92  // GetResult contains the response body and error from a Get request.
    93  type GetResult struct {
    94  	commonResult
    95  }
    96  
    97  // DeleteResult contains the response body and error from a Delete request.
    98  type DeleteResult struct {
    99  	golangsdk.ErrResult
   100  }
   101  
   102  // ExpandResult contains the response body and error from a Expand request.
   103  type ExpandResult struct {
   104  	golangsdk.ErrResult
   105  }
   106  
   107  // Extract will get the Turbo response object from the CreateResult
   108  func (r CreateResult) Extract() (*TurboResponse, error) {
   109  	var resp TurboResponse
   110  	err := r.ExtractInto(&resp)
   111  	return &resp, err
   112  }
   113  
   114  // Extract will get the Turbo object from the GetResult
   115  func (r GetResult) Extract() (*Turbo, error) {
   116  	var object Turbo
   117  	err := r.ExtractInto(&object)
   118  	return &object, err
   119  }
   120  
   121  // TurboPage is the page returned by a pager when traversing over a
   122  // collection of Shares.
   123  type TurboPage struct {
   124  	pagination.LinkedPageBase
   125  }
   126  
   127  // ExtractTurbos accepts a Page struct, specifically a TurboPage struct,
   128  // and extracts the elements into a slice of share structs. In other words,
   129  // a generic collection is mapped into a relevant slice.
   130  func ExtractTurbos(r pagination.Page) ([]Turbo, error) {
   131  	var s struct {
   132  		ListedShares []Turbo `json:"shares"`
   133  	}
   134  	err := (r.(TurboPage)).ExtractInto(&s)
   135  	return s.ListedShares, err
   136  }
   137  
   138  // IsEmpty returns true if a ListResult contains no Shares.
   139  func (r TurboPage) IsEmpty() (bool, error) {
   140  	shares, err := ExtractTurbos(r)
   141  	return len(shares) == 0, err
   142  }
   143  
   144  // NextPageURL is invoked when a paginated collection of shares has reached
   145  // the end of a page and the pager seeks to traverse over a new one. In order
   146  // to do this, it needs to construct the next page's URL.
   147  func (r TurboPage) NextPageURL() (string, error) {
   148  	var s struct {
   149  		Links []golangsdk.Link `json:"shares_links"`
   150  	}
   151  	err := r.ExtractInto(&s)
   152  	if err != nil {
   153  		return "", err
   154  	}
   155  	return golangsdk.ExtractNextURL(s.Links)
   156  }