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

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