github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/dds/v3/instances/results.go (about)

     1  package instances
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  type commonResult struct {
     9  	golangsdk.Result
    10  }
    11  
    12  type CreateResult struct {
    13  	commonResult
    14  }
    15  
    16  type Instance struct {
    17  	Id                  string            `json:"id"`
    18  	Name                string            `json:"name"`
    19  	DataStore           DataStore         `json:"datastore"`
    20  	Status              string            `json:"status"`
    21  	Region              string            `json:"region"`
    22  	AvailabilityZone    string            `json:"availability_zone"`
    23  	VpcId               string            `json:"vpc_id"`
    24  	SubnetId            string            `json:"subnet_id"`
    25  	SecurityGroupId     string            `json:"security_group_id"`
    26  	DiskEncryptionId    string            `json:"disk_encryption_id"`
    27  	Ssl                 string            `json:"ssl_option"`
    28  	Mode                string            `json:"mode"`
    29  	Flavor              []FlavorOpt       `json:"flavor"`
    30  	BackupStrategy      BackupStrategyOpt `json:"backup_strategy"`
    31  	EnterpriseProjectID string            `json:"enterprise_project_id"`
    32  }
    33  
    34  type FlavorOpt struct {
    35  	Type     string `json:"type" required:"true"`
    36  	Num      string `json:"num" required:"true"`
    37  	Storage  string `json:"storage,omitempty"`
    38  	Size     string `json:"size,omitempty"`
    39  	SpecCode string `json:"spec_code" required:"true"`
    40  }
    41  
    42  type BackupStrategyOpt struct {
    43  	StartTime string `json:"start_time" required:"true"`
    44  	KeepDays  string `json:"keep_days,omitempty"`
    45  }
    46  
    47  func (r CreateResult) Extract() (*Instance, error) {
    48  	var response Instance
    49  	err := r.ExtractInto(&response)
    50  	return &response, err
    51  }
    52  
    53  type UpdateInstanceResult struct {
    54  	commonResult
    55  }
    56  
    57  type DeleteInstanceResult struct {
    58  	commonResult
    59  }
    60  
    61  type DeleteInstanceResponse struct {
    62  	JobId string `json:"job_id"`
    63  }
    64  
    65  func (r DeleteInstanceResult) Extract() (*DeleteInstanceResponse, error) {
    66  	var response DeleteInstanceResponse
    67  	err := r.ExtractInto(&response)
    68  	return &response, err
    69  }
    70  
    71  type ListInstanceResult struct {
    72  	commonResult
    73  }
    74  
    75  type ListInstanceResponse struct {
    76  	Instances  []InstanceResponse `json:"instances"`
    77  	TotalCount int                `json:"total_count"`
    78  }
    79  
    80  type InstanceResponse struct {
    81  	Id                  string         `json:"id"`
    82  	Name                string         `json:"name"`
    83  	Status              string         `json:"status"`
    84  	Port                string         `json:"port"`
    85  	Mode                string         `json:"mode"`
    86  	Region              string         `json:"region"`
    87  	DataStore           DataStore      `json:"datastore"`
    88  	Engine              string         `json:"engine"`
    89  	Created             string         `json:"created"`
    90  	Updated             string         `json:"updated"`
    91  	DbUserName          string         `json:"db_user_name"`
    92  	Ssl                 int            `json:"ssl"`
    93  	VpcId               string         `json:"vpc_id"`
    94  	SubnetId            string         `json:"subnet_id"`
    95  	SecurityGroupId     string         `json:"security_group_id"`
    96  	BackupStrategy      BackupStrategy `json:"backup_strategy"`
    97  	MaintenanceWindow   string         `json:"maintenance_window"`
    98  	Groups              []Group        `json:"groups"`
    99  	DiskEncryptionId    string         `json:"disk_encryption_id"`
   100  	TimeZone            string         `json:"time_zone"`
   101  	Actions             []string       `json:"actions"`
   102  	EnterpriseProjectID string         `json:"enterprise_project_id"`
   103  }
   104  
   105  type Group struct {
   106  	Type   string  `json:"type"`
   107  	Id     string  `json:"id"`
   108  	Name   string  `json:"name"`
   109  	Status string  `json:"status"`
   110  	Volume Volume  `json:"volume"`
   111  	Nodes  []Nodes `json:"nodes"`
   112  }
   113  
   114  type Volume struct {
   115  	Size string `json:"size"`
   116  	Used string `json:"used"`
   117  }
   118  
   119  type Nodes struct {
   120  	Id               string `json:"id"`
   121  	Name             string `json:"name"`
   122  	Status           string `json:"status"`
   123  	Role             string `json:"role"`
   124  	PrivateIP        string `json:"private_ip"`
   125  	PublicIP         string `json:"public_ip"`
   126  	SpecCode         string `json:"spec_code"`
   127  	AvailabilityZone string `json:"availability_zone"`
   128  }
   129  
   130  type InstancePage struct {
   131  	pagination.SinglePageBase
   132  }
   133  
   134  func (r InstancePage) IsEmpty() (bool, error) {
   135  	data, err := ExtractInstances(r)
   136  	if err != nil {
   137  		return false, err
   138  	}
   139  	return len(data.Instances) == 0, err
   140  }
   141  
   142  func ExtractInstances(r pagination.Page) (ListInstanceResponse, error) {
   143  	var s ListInstanceResponse
   144  	err := (r.(InstancePage)).ExtractInto(&s)
   145  	return s, err
   146  }