github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/sdrs/v1/protectedinstances/results.go (about)

     1  package protectedinstances
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     6  )
     7  
     8  type Instance struct {
     9  	// Instance ID
    10  	ID string `json:"id"`
    11  	// Instance Name
    12  	Name string `json:"name"`
    13  	// Instance Description
    14  	Description string `json:"description"`
    15  	// Protection Group ID
    16  	GroupID string `json:"server_group_id"`
    17  	// Instance Status
    18  	Status string `json:"status"`
    19  	// Instance Progress
    20  	Progress int `json:"progress"`
    21  	// Source Server
    22  	SourceServer string `json:"source_server"`
    23  	// Target Server
    24  	TargetServer string `json:"target_server"`
    25  	// Instance CreatedAt time
    26  	CreatedAt string `json:"created_at"`
    27  	// Instance UpdatedAt time
    28  	UpdatedAt string `json:"updated_at"`
    29  	// Production site AZ of the protection group containing the protected instance.
    30  	PriorityStation string `json:"priority_station"`
    31  	// Attachment
    32  	Attachment []Attachment `json:"attachment"`
    33  	// Tags list
    34  	Tags []Tags `json:"tags"`
    35  	// Metadata
    36  	Metadata map[string]string `json:"metadata"`
    37  }
    38  
    39  type Attachment struct {
    40  	// Replication ID
    41  	Replication string `json:"replication"`
    42  	// Device Name
    43  	Device string `json:"device"`
    44  }
    45  
    46  type commonResult struct {
    47  	golangsdk.Result
    48  }
    49  
    50  // UpdateResult represents the result of a update operation. Call its Extract
    51  // method to interpret it as a Instance.
    52  type UpdateResult struct {
    53  	commonResult
    54  }
    55  
    56  // Extract is a function that accepts a result and extracts a instance.
    57  func (r commonResult) Extract() (*Instance, error) {
    58  	response := new(Instance)
    59  	err := r.ExtractIntoStructPtr(response, "protected_instance")
    60  	return response, err
    61  }
    62  
    63  // GetResult represents the result of a get operation. Call its Extract
    64  // method to interpret it as a Instance.
    65  type GetResult struct {
    66  	commonResult
    67  }
    68  
    69  // InstancePage is a struct which can do the page function
    70  type InstancePage struct {
    71  	pagination.SinglePageBase
    72  }
    73  
    74  // IsEmpty determines whether or not a InstancePage is empty.
    75  func (r InstancePage) IsEmpty() (bool, error) {
    76  	instances, err := ExtractInstances(r)
    77  	return len(instances) == 0, err
    78  }
    79  
    80  // ExtractInstances interprets the results of a single page from
    81  // a List() API call, producing a slice of []Instance structures.
    82  func ExtractInstances(r pagination.Page) ([]Instance, error) {
    83  	var s []Instance
    84  	err := (r.(InstancePage)).ExtractIntoSlicePtr(&s, "protected_instances")
    85  	return s, err
    86  }