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

     1  package instances
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/openstack/common/tags"
     6  	"github.com/chnsz/golangsdk/pagination"
     7  )
     8  
     9  type commonResult struct {
    10  	golangsdk.Result
    11  }
    12  
    13  type CreateResult struct {
    14  	commonResult
    15  }
    16  
    17  type RenameResult struct {
    18  	commonResult
    19  }
    20  
    21  type ModifyAliasResult struct {
    22  	commonResult
    23  }
    24  
    25  type ModifyMaintainWindowResult struct {
    26  	commonResult
    27  }
    28  
    29  type ModifyReplicationModeResult struct {
    30  	commonResult
    31  }
    32  
    33  type ModifyBinlogRetentionHoursResult struct {
    34  	commonResult
    35  }
    36  
    37  type ModifySwitchStrategyResult struct {
    38  	commonResult
    39  }
    40  
    41  type ResizeFlavorResult struct {
    42  	commonResult
    43  }
    44  
    45  type EnlargeVolumeResult struct {
    46  	commonResult
    47  }
    48  
    49  type ApplyConfigurationOptsResult struct {
    50  	commonResult
    51  }
    52  
    53  type ModifyConfigurationResult struct {
    54  	commonResult
    55  }
    56  
    57  type ModifySecondLevelMonitoringResult struct {
    58  	commonResult
    59  }
    60  
    61  type GetConfigurationResult struct {
    62  	commonResult
    63  }
    64  
    65  type GetBinlogRetentionHoursResult struct {
    66  	commonResult
    67  }
    68  
    69  type GetTdeStatusResult struct {
    70  	commonResult
    71  }
    72  
    73  type GetSecondLevelMonitoringResult struct {
    74  	commonResult
    75  }
    76  
    77  type JobResult struct {
    78  	commonResult
    79  }
    80  
    81  type Instance struct {
    82  	Id                  string         `json:"id"`
    83  	Name                string         `json:"name"`
    84  	Status              string         `json:"status"`
    85  	Datastore           Datastore      `json:"datastore"`
    86  	Ha                  Ha             `json:"ha"`
    87  	ConfigurationId     string         `json:"configuration_id"`
    88  	Port                string         `json:"port"`
    89  	BackupStrategy      BackupStrategy `json:"backup_strategy"`
    90  	EnterpriseProjectId string         `json:"enterprise_project_id"`
    91  	DiskEncryptionId    string         `json:"disk_encryption_id"`
    92  	FlavorRef           string         `json:"flavor_ref"`
    93  	Volume              Volume         `json:"volume"`
    94  	Region              string         `json:"region"`
    95  	AvailabilityZone    string         `json:"availability_zone"`
    96  	VpcId               string         `json:"vpc_id"`
    97  	SubnetId            string         `json:"subnet_id"`
    98  	SecurityGroupId     string         `json:"security_group_id"`
    99  	ChargeInfo          ChargeResponse `json:"charge_info"`
   100  }
   101  
   102  type ChargeResponse struct {
   103  	ChargeMode string `json:"charge_mode"`
   104  }
   105  
   106  type CreateResponse struct {
   107  	Instance Instance `json:"instance"`
   108  	JobId    string   `json:"job_id"`
   109  	OrderId  string   `json:"order_id"`
   110  }
   111  
   112  func (r CreateResult) Extract() (*CreateResponse, error) {
   113  	var response CreateResponse
   114  	err := r.ExtractInto(&response)
   115  	return &response, err
   116  }
   117  
   118  type JobResponse struct {
   119  	JobId     string `json:"job_id"`
   120  	HumpJobId string `json:"jobId"`
   121  }
   122  
   123  func (r JobResult) Extract() (*JobResponse, error) {
   124  	var response JobResponse
   125  	err := r.ExtractInto(&response)
   126  	return &response, err
   127  }
   128  
   129  func (job JobResponse) GetJobId() string {
   130  	if job.JobId != "" {
   131  		return job.JobId
   132  	}
   133  	return job.HumpJobId
   134  }
   135  
   136  type ResizeFlavor struct {
   137  	JobId   string `json:"job_id"`
   138  	OrderId string `json:"order_id"`
   139  }
   140  
   141  func (r ResizeFlavorResult) Extract() (*ResizeFlavor, error) {
   142  	var response ResizeFlavor
   143  	err := r.ExtractInto(&response)
   144  	return &response, err
   145  }
   146  
   147  type EnlargeVolumeResp struct {
   148  	JobId   string `json:"job_id"`
   149  	OrderId string `json:"order_id"`
   150  }
   151  
   152  func (r EnlargeVolumeResult) Extract() (*EnlargeVolumeResp, error) {
   153  	var response EnlargeVolumeResp
   154  	err := r.ExtractInto(&response)
   155  	return &response, err
   156  }
   157  
   158  type ApplyConfigurationResp struct {
   159  	ConfigurationId   string `json:"configuration_id"`
   160  	ConfigurationName string `json:"configuration_name"`
   161  	Success           bool   `json:"success"`
   162  	JobId             string `json:"job_id"`
   163  }
   164  
   165  func (r ApplyConfigurationOptsResult) Extract() (*ApplyConfigurationResp, error) {
   166  	var response ApplyConfigurationResp
   167  	err := r.ExtractInto(&response)
   168  	return &response, err
   169  }
   170  
   171  type ModifyConfigurationResp struct {
   172  	JobId   string `json:"job_id"`
   173  	Restart bool   `json:"restart_required"`
   174  }
   175  
   176  func (r ModifyConfigurationResult) Extract() (*ModifyConfigurationResp, error) {
   177  	var response ModifyConfigurationResp
   178  	err := r.ExtractInto(&response)
   179  	return &response, err
   180  }
   181  
   182  type ConfigParams struct {
   183  	Name        string `json:"name"`
   184  	Value       string `json:"value"`
   185  	Restart     bool   `json:"restart_required"`
   186  	ReadOnly    bool   `json:"readonly"`
   187  	ValueRange  string `json:"value_range"`
   188  	Type        string `json:"type"`
   189  	Description string `json:"description"`
   190  }
   191  
   192  type GetConfigurationResp struct {
   193  	DatastoreVersion string         `json:"datastore_version_name"`
   194  	DatastoreName    string         `json:"datastore_name"`
   195  	Parameters       []ConfigParams `json:"configuration_parameters"`
   196  }
   197  
   198  func (r GetConfigurationResult) Extract() (*GetConfigurationResp, error) {
   199  	var response GetConfigurationResp
   200  	err := r.ExtractInto(&response)
   201  	return &response, err
   202  }
   203  
   204  type GetTdeStatusResp struct {
   205  	InstanceId string `json:"instance_id"`
   206  	TdeStatus  string `json:"tde_status"`
   207  }
   208  
   209  func (r GetTdeStatusResult) Extract() (*GetTdeStatusResp, error) {
   210  	var response GetTdeStatusResp
   211  	err := r.ExtractInto(&response)
   212  	return &response, err
   213  }
   214  
   215  type GetSecondLevelMonitoringResp struct {
   216  	SwitchOption bool `json:"switch_option"`
   217  	Interval     int  `json:"interval"`
   218  }
   219  
   220  func (r GetSecondLevelMonitoringResult) Extract() (*GetSecondLevelMonitoringResp, error) {
   221  	var response GetSecondLevelMonitoringResp
   222  	err := r.ExtractInto(&response)
   223  	return &response, err
   224  }
   225  
   226  type GetBinlogRetentionHoursResp struct {
   227  	BinlogRetentionHours int    `json:"binlog_retention_hours"`
   228  	BinlogClearType      string `json:"binlog_clear_type"`
   229  }
   230  
   231  func (r GetBinlogRetentionHoursResult) Extract() (*GetBinlogRetentionHoursResp, error) {
   232  	var response GetBinlogRetentionHoursResp
   233  	err := r.ExtractInto(&response)
   234  	return &response, err
   235  }
   236  
   237  type ListMsdtcHostsResponse struct {
   238  	Hosts      []RdsMsdtcHosts `json:"hosts"`
   239  	TotalCount int             `json:"total_count"`
   240  }
   241  
   242  type RdsMsdtcHosts struct {
   243  	Id       string `json:"id"`
   244  	Host     string `json:"host"`
   245  	HostName string `json:"host_name"`
   246  }
   247  
   248  type MsdtcHostsPage struct {
   249  	pagination.OffsetPageBase
   250  }
   251  
   252  func (r MsdtcHostsPage) IsEmpty() (bool, error) {
   253  	data, err := ExtractRdsMsdtcHosts(r)
   254  	if err != nil {
   255  		return false, err
   256  	}
   257  	return len(data.Hosts) == 0, err
   258  }
   259  
   260  // ExtractRdsMsdtcHosts is a function that takes a ListResult and returns the msdct hosts' information.
   261  func ExtractRdsMsdtcHosts(r pagination.Page) (ListMsdtcHostsResponse, error) {
   262  	var s ListMsdtcHostsResponse
   263  	err := (r.(MsdtcHostsPage)).ExtractInto(&s)
   264  	return s, err
   265  }
   266  
   267  type ReplicationMode struct {
   268  	WorkflowId      string `json:"workflowId"`
   269  	InstanceId      string `json:"instanceId"`
   270  	ReplicationMode string `json:"replicationMode"`
   271  }
   272  
   273  func (r ModifyReplicationModeResult) Extract() (*ReplicationMode, error) {
   274  	var response ReplicationMode
   275  	err := r.ExtractInto(&response)
   276  	return &response, err
   277  }
   278  
   279  type BinlogRetentionHoursResp struct {
   280  	Resp string `json:"resp"`
   281  }
   282  
   283  func (r ModifyBinlogRetentionHoursResult) Extract() (*BinlogRetentionHoursResp, error) {
   284  	var response BinlogRetentionHoursResp
   285  	err := r.ExtractInto(&response)
   286  	return &response, err
   287  }
   288  
   289  type ListRdsResult struct {
   290  	commonResult
   291  }
   292  
   293  type ListRdsResponse struct {
   294  	Instances  []RdsInstanceResponse `json:"instances"`
   295  	TotalCount int                   `json:"total_count"`
   296  }
   297  
   298  type RdsInstanceResponse struct {
   299  	Id                  string             `json:"id"`
   300  	Name                string             `json:"name"`
   301  	Status              string             `json:"status"`
   302  	PrivateIps          []string           `json:"private_ips"`
   303  	PublicIps           []string           `json:"public_ips"`
   304  	Port                int                `json:"port"`
   305  	Type                string             `json:"type"`
   306  	Ha                  Ha                 `json:"ha"`
   307  	Region              string             `json:"region"`
   308  	DataStore           Datastore          `json:"datastore"`
   309  	Created             string             `json:"created"`
   310  	Updated             string             `json:"updated"`
   311  	DbUserName          string             `json:"db_user_name"`
   312  	VpcId               string             `json:"vpc_id"`
   313  	SubnetId            string             `json:"subnet_id"`
   314  	SecurityGroupId     string             `json:"security_group_id"`
   315  	FlavorRef           string             `json:"flavor_ref"`
   316  	Volume              Volume             `json:"volume"`
   317  	SwitchStrategy      string             `json:"switch_strategy"`
   318  	BackupStrategy      BackupStrategy     `json:"backup_strategy"`
   319  	ChargeInfo          ChargeResponse     `json:"charge_info"`
   320  	MaintenanceWindow   string             `json:"maintenance_window"`
   321  	Collation           string             `json:"collation"`
   322  	Nodes               []Nodes            `json:"nodes"`
   323  	RelatedInstance     []RelatedInstance  `json:"related_instance"`
   324  	DiskEncryptionId    string             `json:"disk_encryption_id"`
   325  	EnterpriseProjectId string             `json:"enterprise_project_id"`
   326  	TimeZone            string             `json:"time_zone"`
   327  	Alias               string             `json:"alias"`
   328  	AssociatedWithDdm   bool               `json:"associated_with_ddm"`
   329  	BackupUsedSpace     float64            `json:"backup_used_space"`
   330  	Cpu                 string             `json:"cpu"`
   331  	EnableSsl           bool               `json:"enable_ssl"`
   332  	ExpirationTime      string             `json:"expiration_time"`
   333  	MaxIops             int                `json:"max_iops"`
   334  	Mem                 string             `json:"mem"`
   335  	PrivateDnsNames     []string           `json:"private_dns_names"`
   336  	ReadOnlyByUser      bool               `json:"read_only_by_user"`
   337  	StorageUsedSpace    float64            `json:"storage_used_space"`
   338  	Tags                []tags.ResourceTag `json:"tags"`
   339  }
   340  
   341  type Nodes struct {
   342  	Id               string `json:"id"`
   343  	Name             string `json:"name"`
   344  	Role             string `json:"role"`
   345  	Status           string `json:"status"`
   346  	AvailabilityZone string `json:"availability_zone"`
   347  }
   348  
   349  type RelatedInstance struct {
   350  	Id   string `json:"id"`
   351  	Type string `json:"type"`
   352  }
   353  
   354  type RdsPage struct {
   355  	pagination.SinglePageBase
   356  }
   357  
   358  type ErrorResponse struct {
   359  	ErrorCode string `json:"error_code"`
   360  	ErrorMsg  string `json:"error_msg"`
   361  }
   362  
   363  func (r RdsPage) IsEmpty() (bool, error) {
   364  	data, err := ExtractRdsInstances(r)
   365  	if err != nil {
   366  		return false, err
   367  	}
   368  	return len(data.Instances) == 0, err
   369  }
   370  
   371  // ExtractRdsInstances is a function that takes a ListResult and returns the instances' information.
   372  func ExtractRdsInstances(r pagination.Page) (ListRdsResponse, error) {
   373  	var s ListRdsResponse
   374  	err := (r.(RdsPage)).ExtractInto(&s)
   375  	return s, err
   376  }
   377  
   378  type ErrorLogResult struct {
   379  	golangsdk.Result
   380  }
   381  
   382  type ErrorLogResp struct {
   383  	ErrorLogList []Errorlog `json:"error_log_list"`
   384  	TotalRecord  int        `json:"total_record"`
   385  }
   386  
   387  type Errorlog struct {
   388  	Time    string `json:"time"`
   389  	Level   string `json:"level"`
   390  	Content string `json:"content"`
   391  }
   392  
   393  type ErrorLogPage struct {
   394  	pagination.SinglePageBase
   395  }
   396  
   397  // IsEmpty returns true if a ListResult contains no services.
   398  func (r ErrorLogPage) IsEmpty() (bool, error) {
   399  	data, err := ExtractErrorLog(r)
   400  	if err != nil {
   401  		return false, err
   402  	}
   403  	return len(data.ErrorLogList) == 0, err
   404  }
   405  
   406  func ExtractErrorLog(r pagination.Page) (ErrorLogResp, error) {
   407  	var s ErrorLogResp
   408  	err := (r.(ErrorLogPage)).ExtractInto(&s)
   409  	return s, err
   410  }
   411  
   412  type SlowLogResp struct {
   413  	Slowloglist []Slowloglist `json:"slow_log_list"`
   414  	TotalRecord int           `json:"total_record"`
   415  }
   416  
   417  type Slowloglist struct {
   418  	Count        string `json:"count"`
   419  	Time         string `json:"time"`
   420  	Locktime     string `json:"lock_time"`
   421  	Rowssent     string `json:"rows_sent"`
   422  	Rowsexamined string `json:"rows_examined"`
   423  	Database     string `json:"database"`
   424  	Users        string `json:"users"`
   425  	QuerySample  string `json:"query_sample"`
   426  	Type         string `json:"type"`
   427  }
   428  
   429  type SlowLogPage struct {
   430  	pagination.SinglePageBase
   431  }
   432  
   433  // IsEmpty returns true if a ListResult contains no services.
   434  func (r SlowLogPage) IsEmpty() (bool, error) {
   435  	data, err := ExtractSlowLog(r)
   436  	if err != nil {
   437  		return false, err
   438  	}
   439  	return len(data.Slowloglist) == 0, err
   440  }
   441  
   442  // ExtractCloudServers is a function that takes a ListResult and returns the services' information.
   443  func ExtractSlowLog(r pagination.Page) (SlowLogResp, error) {
   444  	var s SlowLogResp
   445  	err := (r.(SlowLogPage)).ExtractInto(&s)
   446  	return s, err
   447  }
   448  
   449  type RDSJobResult struct {
   450  	commonResult
   451  }
   452  
   453  type ListJob struct {
   454  	Job Job `json:"job"`
   455  }
   456  
   457  type Job struct {
   458  	ID         string `json:"id"`
   459  	Name       string `json:"name"`
   460  	Status     string `json:"status"`
   461  	Created    string `json:"created"`
   462  	Ended      string `json:"ended"`
   463  	Process    string `json:"process"`
   464  	FailReason string `json:"fail_reason"`
   465  }
   466  
   467  func (r RDSJobResult) Extract() (ListJob, error) {
   468  	var s ListJob
   469  	err := r.ExtractInto(&s)
   470  	return s, err
   471  }
   472  
   473  type Engine struct {
   474  	Versions []VersionInfo `json:"dataStores"`
   475  }
   476  
   477  type VersionInfo struct {
   478  	ID   string `json:"id"`
   479  	Name string `json:"name"`
   480  }
   481  
   482  // AutoExpansion is an object that represents the automatic expansion configuration.
   483  type AutoExpansion struct {
   484  	// Whether the automatic expansion is enabled.
   485  	SwitchOption bool `json:"switch_option"`
   486  	// The upper limit of automatic expansion of storage, in GB.
   487  	// This parameter is mandatory when switch_option is set to true.
   488  	// The value ranges from 40 GB to 4,000 GB and must be no less than the current storage of the instance.
   489  	LimitSize int `json:"limit_size"`
   490  	// The threshold to trigger automatic expansion.
   491  	// If the available storage drops to this threshold or 10 GB, the automatic expansion is triggered.
   492  	// This parameter is mandatory when switch_option is set to true.
   493  	// The valid values are as follows:
   494  	// + 10
   495  	// + 15
   496  	// + 20
   497  	TriggerThreshold int `json:"trigger_threshold"`
   498  }