github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/rds/v3/instances/requests.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 CreateOpts struct {
    10  	Name                string             `json:"name"  required:"true"`
    11  	Datastore           *Datastore         `json:"datastore" required:"true"`
    12  	Ha                  *Ha                `json:"ha,omitempty"`
    13  	ConfigurationId     string             `json:"configuration_id,omitempty"`
    14  	Port                string             `json:"port,omitempty"`
    15  	Password            string             `json:"password,omitempty"`
    16  	BackupStrategy      *BackupStrategy    `json:"backup_strategy,omitempty"`
    17  	EnterpriseProjectId string             `json:"enterprise_project_id,omitempty"`
    18  	DiskEncryptionId    string             `json:"disk_encryption_id,omitempty"`
    19  	FlavorRef           string             `json:"flavor_ref" required:"true"`
    20  	Volume              *Volume            `json:"volume" required:"true"`
    21  	Region              string             `json:"region" required:"true"`
    22  	AvailabilityZone    string             `json:"availability_zone" required:"true"`
    23  	VpcId               string             `json:"vpc_id" required:"true"`
    24  	SubnetId            string             `json:"subnet_id" required:"true"`
    25  	SecurityGroupId     string             `json:"security_group_id" required:"true"`
    26  	RestorePoint        *RestorePoint      `json:"restore_point,omitempty"`
    27  	ChargeInfo          *ChargeInfo        `json:"charge_info,omitempty"`
    28  	TimeZone            string             `json:"time_zone,omitempty"`
    29  	DssPoolId           string             `json:"dsspool_id,omitempty"`
    30  	FixedIp             string             `json:"data_vip,omitempty"`
    31  	Collation           string             `json:"collation,omitempty"`
    32  	UnchangeableParam   *UnchangeableParam `json:"unchangeable_param,omitempty"`
    33  	Tags                []tags.ResourceTag `json:"tags,omitempty"`
    34  }
    35  
    36  type CreateReplicaOpts struct {
    37  	Name                string      `json:"name"  required:"true"`
    38  	ReplicaOfId         string      `json:"replica_of_id" required:"true"`
    39  	EnterpriseProjectId string      `json:"enterprise_project_id,omitempty"`
    40  	DiskEncryptionId    string      `json:"disk_encryption_id,omitempty"`
    41  	FlavorRef           string      `json:"flavor_ref" required:"true"`
    42  	Volume              *Volume     `json:"volume" required:"true"`
    43  	Region              string      `json:"region,omitempty"`
    44  	AvailabilityZone    string      `json:"availability_zone" required:"true"`
    45  	ChargeInfo          *ChargeInfo `json:"charge_info,omitempty"`
    46  }
    47  
    48  type Datastore struct {
    49  	Type            string `json:"type" required:"true"`
    50  	Version         string `json:"version" required:"true"`
    51  	CompleteVersion string `json:"complete_version,omitempty"`
    52  }
    53  
    54  type Ha struct {
    55  	Mode            string `json:"mode" required:"true"`
    56  	ReplicationMode string `json:"replication_mode,omitempty"`
    57  }
    58  
    59  type UnchangeableParam struct {
    60  	LowerCaseTableNames string `json:"lower_case_table_names"`
    61  }
    62  
    63  type BackupStrategy struct {
    64  	StartTime string `json:"start_time" required:"true"`
    65  	KeepDays  int    `json:"keep_days,omitempty"`
    66  }
    67  
    68  type Volume struct {
    69  	Type string `json:"type" required:"true"`
    70  	Size int    `json:"size" required:"true"`
    71  }
    72  
    73  type RestorePoint struct {
    74  	InstanceId   string            `json:"instance_id" required:"true"`
    75  	Type         string            `json:"type" required:"true"`
    76  	BackupId     string            `json:"backup_id,omitempty"`
    77  	RestoreTime  string            `json:"restore_time,omitempty"`
    78  	DatabaseName map[string]string `json:"database_name,omitempty"`
    79  }
    80  
    81  type ChargeInfo struct {
    82  	ChargeMode  string `json:"charge_mode" required:"true"`
    83  	PeriodType  string `json:"period_type,omitempty"`
    84  	PeriodNum   int    `json:"period_num,omitempty"`
    85  	IsAutoRenew bool   `json:"is_auto_renew,omitempty"`
    86  	IsAutoPay   bool   `json:"is_auto_pay,omitempty"`
    87  }
    88  
    89  type CreateRdsBuilder interface {
    90  	ToInstancesCreateMap() (map[string]interface{}, error)
    91  }
    92  
    93  type RestRootPasswordOpts struct {
    94  	DbUserPwd string `json:"db_user_pwd" required:"true"`
    95  }
    96  
    97  var RequestOpts = golangsdk.RequestOpts{
    98  	MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
    99  }
   100  
   101  func (opts CreateOpts) ToInstancesCreateMap() (map[string]interface{}, error) {
   102  	b, err := golangsdk.BuildRequestBody(opts, "")
   103  	if err != nil {
   104  		return nil, err
   105  	}
   106  	return b, nil
   107  }
   108  
   109  func Create(client *golangsdk.ServiceClient, opts CreateRdsBuilder) (r CreateResult) {
   110  	b, err := opts.ToInstancesCreateMap()
   111  	if err != nil {
   112  		r.Err = err
   113  		return
   114  	}
   115  
   116  	_, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{
   117  		OkCodes: []int{200, 202},
   118  	})
   119  	return
   120  }
   121  
   122  func (opts CreateReplicaOpts) ToInstancesCreateMap() (map[string]interface{}, error) {
   123  	b, err := golangsdk.BuildRequestBody(opts, "")
   124  	if err != nil {
   125  		return nil, err
   126  	}
   127  	return b, nil
   128  }
   129  
   130  func CreateReplica(client *golangsdk.ServiceClient, opts CreateRdsBuilder) (r CreateResult) {
   131  	b, err := opts.ToInstancesCreateMap()
   132  	if err != nil {
   133  		r.Err = err
   134  		return
   135  	}
   136  
   137  	_, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{
   138  		OkCodes: []int{200, 202},
   139  	})
   140  
   141  	return
   142  }
   143  
   144  type DeleteOpts struct {
   145  	InstanceId string `json:"instance_id" required:"true"`
   146  }
   147  
   148  type DeleteInstanceBuilder interface {
   149  	ToInstancesDeleteMap() (map[string]interface{}, error)
   150  }
   151  
   152  func (opts DeleteOpts) ToInstancesDeleteMap() (map[string]interface{}, error) {
   153  	b, err := golangsdk.BuildRequestBody(&opts, "")
   154  	if err != nil {
   155  		return nil, err
   156  	}
   157  	return b, nil
   158  }
   159  
   160  func Delete(client *golangsdk.ServiceClient, instanceId string) (r JobResult) {
   161  
   162  	url := deleteURL(client, instanceId)
   163  
   164  	_, r.Err = client.Delete(url, &golangsdk.RequestOpts{
   165  		JSONResponse: &r.Body,
   166  		MoreHeaders:  map[string]string{"Content-Type": "application/json"},
   167  	})
   168  	return
   169  }
   170  
   171  type ListOpts struct {
   172  	Id            string `q:"id"`
   173  	Name          string `q:"name"`
   174  	Type          string `q:"type"`
   175  	DataStoreType string `q:"datastore_type"`
   176  	VpcId         string `q:"vpc_id"`
   177  	SubnetId      string `q:"subnet_id"`
   178  	Offset        int    `q:"offset"`
   179  	Limit         int    `q:"limit"`
   180  }
   181  
   182  type ListRdsBuilder interface {
   183  	ToRdsListDetailQuery() (string, error)
   184  }
   185  
   186  func (opts ListOpts) ToRdsListDetailQuery() (string, error) {
   187  	q, err := golangsdk.BuildQueryString(opts)
   188  	if err != nil {
   189  		return "", err
   190  	}
   191  	return q.String(), err
   192  }
   193  
   194  func List(client *golangsdk.ServiceClient, opts ListRdsBuilder) pagination.Pager {
   195  	url := listURL(client)
   196  	if opts != nil {
   197  		query, err := opts.ToRdsListDetailQuery()
   198  
   199  		if err != nil {
   200  			return pagination.Pager{Err: err}
   201  		}
   202  		url += query
   203  	}
   204  
   205  	pageRdsList := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
   206  		return RdsPage{pagination.SinglePageBase(r)}
   207  	})
   208  
   209  	rdsheader := map[string]string{"Content-Type": "application/json"}
   210  	pageRdsList.Headers = rdsheader
   211  	return pageRdsList
   212  }
   213  
   214  type ActionInstanceBuilder interface {
   215  	ToActionInstanceMap() (map[string]interface{}, error)
   216  }
   217  
   218  func toActionInstanceMap(opts ActionInstanceBuilder) (map[string]interface{}, error) {
   219  	b, err := golangsdk.BuildRequestBody(opts, "")
   220  	if err != nil {
   221  		return nil, err
   222  	}
   223  	return b, nil
   224  }
   225  
   226  type RestartInstanceOpts struct {
   227  	Restart string `json:"restart" required:"true"`
   228  }
   229  
   230  func (opts RestartInstanceOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   231  	return toActionInstanceMap(opts)
   232  }
   233  
   234  func Restart(client *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r JobResult) {
   235  	b, err := opts.ToActionInstanceMap()
   236  	if err != nil {
   237  		r.Err = err
   238  		return
   239  	}
   240  
   241  	_, r.Err = client.Post(updateURL(client, instanceId, "action"), b, &r.Body, &golangsdk.RequestOpts{
   242  		OkCodes: []int{202},
   243  	})
   244  	return
   245  }
   246  
   247  type RenameInstanceOpts struct {
   248  	Name string `json:"name" required:"true"`
   249  }
   250  
   251  func (opts RenameInstanceOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   252  	return toActionInstanceMap(opts)
   253  }
   254  
   255  func Rename(client *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r RenameResult) {
   256  	b, err := opts.ToActionInstanceMap()
   257  	if err != nil {
   258  		r.Err = err
   259  		return
   260  	}
   261  	_, r.Err = client.Put(updateURL(client, instanceId, "name"), b, nil, &golangsdk.RequestOpts{
   262  		OkCodes: []int{200, 202},
   263  	})
   264  	return
   265  }
   266  
   267  type SingleToHaRdsOpts struct {
   268  	SingleToHa *SingleToHaRds `json:"single_to_ha" required:"true"`
   269  }
   270  
   271  type SingleToHaRds struct {
   272  	AzCodeNewNode string `json:"az_code_new_node" required:"true"`
   273  	Password      string `json:"password,omitempty"`
   274  }
   275  
   276  func (opts SingleToHaRdsOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   277  	return toActionInstanceMap(opts)
   278  }
   279  
   280  func SingleToHa(client *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r JobResult) {
   281  	b, err := opts.ToActionInstanceMap()
   282  	if err != nil {
   283  		r.Err = err
   284  		return
   285  	}
   286  	_, r.Err = client.Post(updateURL(client, instanceId, "action"), b, &r.Body, &golangsdk.RequestOpts{
   287  		OkCodes: []int{202},
   288  	})
   289  
   290  	return
   291  }
   292  
   293  type SpecCode struct {
   294  	Speccode  string `json:"spec_code" required:"true"`
   295  	IsAutoPay bool   `json:"is_auto_pay,omitempty"`
   296  }
   297  
   298  type ResizeFlavorOpts struct {
   299  	ResizeFlavor *SpecCode `json:"resize_flavor" required:"true"`
   300  }
   301  
   302  func (opts ResizeFlavorOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   303  	return toActionInstanceMap(opts)
   304  }
   305  
   306  func Resize(client *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r ResizeFlavorResult) {
   307  	b, err := opts.ToActionInstanceMap()
   308  	if err != nil {
   309  		r.Err = err
   310  		return
   311  	}
   312  	_, r.Err = client.Post(updateURL(client, instanceId, "action"), b, &r.Body, &golangsdk.RequestOpts{
   313  		OkCodes: []int{202},
   314  	})
   315  
   316  	return
   317  }
   318  
   319  type EnlargeVolumeOpts struct {
   320  	EnlargeVolume *EnlargeVolumeSize `json:"enlarge_volume" required:"true"`
   321  }
   322  
   323  type EnlargeVolumeSize struct {
   324  	Size      int  `json:"size" required:"true"`
   325  	IsAutoPay bool `json:"is_auto_pay,omitempty"`
   326  }
   327  
   328  func (opts EnlargeVolumeOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   329  	return toActionInstanceMap(opts)
   330  }
   331  
   332  func EnlargeVolume(client *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r EnlargeVolumeResult) {
   333  	b, err := opts.ToActionInstanceMap()
   334  	if err != nil {
   335  		r.Err = err
   336  		return
   337  	}
   338  	_, r.Err = client.Post(updateURL(client, instanceId, "action"), b, &r.Body, &golangsdk.RequestOpts{
   339  		OkCodes: []int{202},
   340  	})
   341  
   342  	return
   343  }
   344  
   345  type DbErrorlogOpts struct {
   346  	StartDate string `q:"start_date"`
   347  	EndDate   string `q:"end_date"`
   348  	Offset    string `q:"offset"`
   349  	Limit     string `q:"limit"`
   350  	Level     string `q:"level"`
   351  }
   352  
   353  type DbErrorlogBuilder interface {
   354  	DbErrorlogQuery() (string, error)
   355  }
   356  
   357  func (opts DbErrorlogOpts) DbErrorlogQuery() (string, error) {
   358  	q, err := golangsdk.BuildQueryString(opts)
   359  	if err != nil {
   360  		return "", err
   361  	}
   362  	return q.String(), err
   363  }
   364  
   365  func ListErrorLog(client *golangsdk.ServiceClient, opts DbErrorlogBuilder, instanceID string) pagination.Pager {
   366  	url := updateURL(client, instanceID, "errorlog")
   367  	if opts != nil {
   368  		query, err := opts.DbErrorlogQuery()
   369  
   370  		if err != nil {
   371  			return pagination.Pager{Err: err}
   372  		}
   373  		url += query
   374  	}
   375  
   376  	pageRdsList := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
   377  		return ErrorLogPage{pagination.SinglePageBase(r)}
   378  	})
   379  
   380  	rdsheader := map[string]string{"Content-Type": "application/json"}
   381  	pageRdsList.Headers = rdsheader
   382  	return pageRdsList
   383  }
   384  
   385  type DbSlowLogOpts struct {
   386  	StartDate string `q:"start_date"`
   387  	EndDate   string `q:"end_date"`
   388  	Offset    string `q:"offset"`
   389  	Limit     string `q:"limit"`
   390  	Level     string `q:"level"`
   391  }
   392  
   393  type DbSlowLogBuilder interface {
   394  	ToDbSlowLogListQuery() (string, error)
   395  }
   396  
   397  func (opts DbSlowLogOpts) ToDbSlowLogListQuery() (string, error) {
   398  	q, err := golangsdk.BuildQueryString(opts)
   399  	if err != nil {
   400  		return "", err
   401  	}
   402  	return q.String(), err
   403  }
   404  
   405  func ListSlowLog(client *golangsdk.ServiceClient, opts DbSlowLogBuilder, instanceID string) pagination.Pager {
   406  	url := updateURL(client, instanceID, "slowlog")
   407  	if opts != nil {
   408  		query, err := opts.ToDbSlowLogListQuery()
   409  
   410  		if err != nil {
   411  			return pagination.Pager{Err: err}
   412  		}
   413  		url += query
   414  	}
   415  
   416  	pageRdsList := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
   417  		return ErrorLogPage{pagination.SinglePageBase(r)}
   418  	})
   419  
   420  	rdsheader := map[string]string{"Content-Type": "application/json"}
   421  	pageRdsList.Headers = rdsheader
   422  	return pageRdsList
   423  }
   424  
   425  type RDSJobOpts struct {
   426  	JobID string `q:"id"`
   427  }
   428  
   429  type RDSJobBuilder interface {
   430  	ToRDSJobQuery() (string, error)
   431  }
   432  
   433  func (opts RDSJobOpts) ToRDSJobQuery() (string, error) {
   434  	q, err := golangsdk.BuildQueryString(opts)
   435  	if err != nil {
   436  		return "", err
   437  	}
   438  	return q.String(), err
   439  }
   440  
   441  func GetRDSJob(client *golangsdk.ServiceClient, opts RDSJobBuilder) (r RDSJobResult) {
   442  	url := jobURL(client)
   443  	if opts != nil {
   444  		query, err := opts.ToRDSJobQuery()
   445  		if err != nil {
   446  			r.Err = err
   447  			return
   448  		}
   449  		url += query
   450  	}
   451  	_, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{
   452  		MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
   453  	})
   454  	return
   455  }
   456  
   457  func ListEngine(client *golangsdk.ServiceClient, dbName string) (*Engine, error) {
   458  	var rst golangsdk.Result
   459  	_, err := client.Get(engineURL(client, dbName), &rst.Body, nil)
   460  	if err == nil {
   461  		var s Engine
   462  		err := rst.ExtractInto(&s)
   463  		return &s, err
   464  	}
   465  	return nil, err
   466  }
   467  
   468  func RestRootPassword(c *golangsdk.ServiceClient, instanceID string, opts RestRootPasswordOpts) (*ErrorResponse, error) {
   469  	b, err := golangsdk.BuildRequestBody(opts, "")
   470  	if err != nil {
   471  		return nil, err
   472  	}
   473  
   474  	var r ErrorResponse
   475  	_, err = c.Post(updateURL(c, instanceID, "password"), b, &r, &golangsdk.RequestOpts{
   476  		MoreHeaders: RequestOpts.MoreHeaders,
   477  	})
   478  	return &r, err
   479  }
   480  
   481  type ApplyConfigurationOpts struct {
   482  	InstanceIds []string `json:"instance_ids" required:"true"`
   483  }
   484  
   485  func ApplyConfiguration(c *golangsdk.ServiceClient, configID string, opts ApplyConfigurationOpts) (r ApplyConfigurationOptsResult) {
   486  	b, err := golangsdk.BuildRequestBody(opts, "")
   487  	if err != nil {
   488  		r.Err = err
   489  		return
   490  	}
   491  
   492  	_, r.Err = c.Put(applyConfigurationURL(c, configID), b, &r.Body, &golangsdk.RequestOpts{
   493  		MoreHeaders: RequestOpts.MoreHeaders,
   494  	})
   495  	return
   496  }
   497  
   498  type ModifyConfigurationOpts struct {
   499  	Values map[string]string `json:"values" required:"true"`
   500  }
   501  
   502  func ModifyConfiguration(c *golangsdk.ServiceClient, instanceID string, opts ModifyConfigurationOpts) (r ModifyConfigurationResult) {
   503  	b, err := golangsdk.BuildRequestBody(opts, "")
   504  	if err != nil {
   505  		r.Err = err
   506  		return
   507  	}
   508  
   509  	_, r.Err = c.Put(updateURL(c, instanceID, "configurations"), b, &r.Body, &golangsdk.RequestOpts{
   510  		OkCodes: []int{200, 202},
   511  	})
   512  	return
   513  }
   514  
   515  func GetConfigurations(c *golangsdk.ServiceClient, instanceID string) (r GetConfigurationResult) {
   516  	_, r.Err = c.Get(getURL(c, instanceID, "configurations"), &r.Body, &golangsdk.RequestOpts{
   517  		MoreHeaders: map[string]string{"Content-Type": "application/json"},
   518  	})
   519  	return
   520  }
   521  
   522  func RebootInstance(c *golangsdk.ServiceClient, instanceID string) (r JobResult) {
   523  	b, err := golangsdk.BuildRequestBody(struct{}{}, "restart")
   524  	if err != nil {
   525  		r.Err = err
   526  		return
   527  	}
   528  
   529  	_, r.Err = c.Post(updateURL(c, instanceID, "action"), b, &r.Body, &golangsdk.RequestOpts{
   530  		OkCodes: []int{200, 202},
   531  	})
   532  	return
   533  }
   534  
   535  var (
   536  	enableAutoExpand  bool = true
   537  	disableAutoExpand bool = false
   538  )
   539  
   540  // EnableAutoExpandOpts is the structure used to enable the volume automatic expansion of RDS instance.
   541  type EnableAutoExpandOpts struct {
   542  	// The instnace ID.
   543  	InstanceId string `json:"-" required:"true"`
   544  	// The upper limit of automatic expansion of storage, in GB.
   545  	// This parameter is mandatory when switch_option is set to true.
   546  	// The value ranges from 40 GB to 4,000 GB and must be no less than the current storage of the instance.
   547  	LimitSize int `json:"limit_size" required:"true"`
   548  	// The threshold to trigger automatic expansion.
   549  	// If the available storage drops to this threshold or 10 GB, the automatic expansion is triggered.
   550  	// This parameter is mandatory when switch_option is set to true.
   551  	// The valid values are as follows:
   552  	// + 10
   553  	// + 15
   554  	// + 20
   555  	TriggerThreshold int `json:"trigger_threshold" required:"true"`
   556  }
   557  
   558  // autoExpandOpts is the structure used to configure the volume automatic expansion of RDS instance.
   559  type autoExpandOpts struct {
   560  	// Whether the auto-expansion is enabled.
   561  	SwitchOption *bool `json:"switch_option" required:"true"`
   562  	// The upper limit of automatic expansion of storage, in GB.
   563  	// This parameter is mandatory when switch_option is set to true.
   564  	// The value ranges from 40 GB to 4,000 GB and must be no less than the current storage of the instance.
   565  	LimitSize int `json:"limit_size,omitempty"`
   566  	// The threshold to trigger automatic expansion.
   567  	// If the available storage drops to this threshold or 10 GB, the automatic expansion is triggered.
   568  	// This parameter is mandatory when switch_option is set to true.
   569  	// The valid values are as follows:
   570  	// + 10
   571  	// + 15
   572  	// + 20
   573  	TriggerThreshold int `json:"trigger_threshold,omitempty"`
   574  }
   575  
   576  var requestOpts = golangsdk.RequestOpts{
   577  	MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
   578  }
   579  
   580  // EnableAutoExpand is a method used to configure the volume automatic expansion of RDS instance.
   581  func EnableAutoExpand(c *golangsdk.ServiceClient, opts EnableAutoExpandOpts) error {
   582  	enableOpts := autoExpandOpts{
   583  		SwitchOption:     &enableAutoExpand,
   584  		LimitSize:        opts.LimitSize,
   585  		TriggerThreshold: opts.TriggerThreshold,
   586  	}
   587  	b, err := golangsdk.BuildRequestBody(enableOpts, "")
   588  	if err != nil {
   589  		return err
   590  	}
   591  
   592  	_, err = c.Put(updateURL(c, opts.InstanceId, "disk-auto-expansion"), b, nil, &golangsdk.RequestOpts{
   593  		MoreHeaders: requestOpts.MoreHeaders,
   594  	})
   595  	return err
   596  }
   597  
   598  // DisableAutoExpand is a method used to remove the volume automatic expansion configuration of RDS instance.
   599  func DisableAutoExpand(c *golangsdk.ServiceClient, instanceId string) error {
   600  	autoExpandOpts := autoExpandOpts{
   601  		SwitchOption: &disableAutoExpand,
   602  	}
   603  	b, err := golangsdk.BuildRequestBody(autoExpandOpts, "")
   604  	if err != nil {
   605  		return err
   606  	}
   607  
   608  	_, err = c.Put(updateURL(c, instanceId, "disk-auto-expansion"), b, nil, &golangsdk.RequestOpts{
   609  		MoreHeaders: requestOpts.MoreHeaders,
   610  	})
   611  	return err
   612  }
   613  
   614  // GetAutoExpand is a method used to obtain the automatic expansion configuarion of instance storage.
   615  func GetAutoExpand(c *golangsdk.ServiceClient, instanceId string) (*AutoExpansion, error) {
   616  	var r AutoExpansion
   617  	_, err := c.Get(getURL(c, instanceId, "disk-auto-expansion"), &r, &golangsdk.RequestOpts{
   618  		MoreHeaders: requestOpts.MoreHeaders,
   619  	})
   620  	return &r, err
   621  }
   622  
   623  type ModifyAliasOpts struct {
   624  	Alias string `json:"alias,omitempty"`
   625  }
   626  
   627  func (opts ModifyAliasOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   628  	return toActionInstanceMap(opts)
   629  }
   630  
   631  // ModifyAlias is a method used to modify the alias.
   632  func ModifyAlias(c *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r ModifyAliasResult) {
   633  	b, err := opts.ToActionInstanceMap()
   634  	if err != nil {
   635  		r.Err = err
   636  		return
   637  	}
   638  	_, r.Err = c.Put(updateURL(c, instanceId, "alias"), b, nil, &golangsdk.RequestOpts{
   639  		OkCodes: []int{200, 202},
   640  	})
   641  	return
   642  }
   643  
   644  type ModifyMaintainWindowOpts struct {
   645  	StartTime string `json:"start_time" required:"true"`
   646  	EndTime   string `json:"end_time" required:"true"`
   647  }
   648  
   649  func (opts ModifyMaintainWindowOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   650  	return toActionInstanceMap(opts)
   651  }
   652  
   653  // ModifyMaintainWindow is a method used to modify maintain window.
   654  func ModifyMaintainWindow(c *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r ModifyMaintainWindowResult) {
   655  	b, err := opts.ToActionInstanceMap()
   656  	if err != nil {
   657  		r.Err = err
   658  		return
   659  	}
   660  	_, r.Err = c.Put(updateURL(c, instanceId, "ops-window"), b, nil, &golangsdk.RequestOpts{})
   661  	return
   662  }
   663  
   664  type ModifyReplicationModeOpts struct {
   665  	Mode string `json:"mode" required:"true"`
   666  }
   667  
   668  func (opts ModifyReplicationModeOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   669  	return toActionInstanceMap(opts)
   670  }
   671  
   672  // ModifyReplicationMode is a method used to modify replication mode.
   673  func ModifyReplicationMode(c *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r ModifyReplicationModeResult) {
   674  	b, err := opts.ToActionInstanceMap()
   675  	if err != nil {
   676  		r.Err = err
   677  		return
   678  	}
   679  	_, r.Err = c.Put(updateURL(c, instanceId, "failover/mode"), b, &r.Body, &golangsdk.RequestOpts{})
   680  	return
   681  }
   682  
   683  type ModifySwitchStrategyOpts struct {
   684  	RepairStrategy string `json:"repairStrategy" required:"true"`
   685  }
   686  
   687  func (opts ModifySwitchStrategyOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   688  	return toActionInstanceMap(opts)
   689  }
   690  
   691  // ModifySwitchStrategy is a method used to modify replication mode.
   692  func ModifySwitchStrategy(c *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r ModifySwitchStrategyResult) {
   693  	b, err := opts.ToActionInstanceMap()
   694  	if err != nil {
   695  		r.Err = err
   696  		return
   697  	}
   698  	_, r.Err = c.Put(updateURL(c, instanceId, "failover/strategy"), b, &r.Body, &golangsdk.RequestOpts{})
   699  	return
   700  }
   701  
   702  type ModifyCollationOpts struct {
   703  	Collation string `json:"collation" required:"true"`
   704  }
   705  
   706  func (opts ModifyCollationOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   707  	return toActionInstanceMap(opts)
   708  }
   709  
   710  // ModifyCollation is a method used to modify collation.
   711  func ModifyCollation(c *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r JobResult) {
   712  	b, err := opts.ToActionInstanceMap()
   713  	if err != nil {
   714  		r.Err = err
   715  		return
   716  	}
   717  	_, r.Err = c.Put(updateURL(c, instanceId, "collations"), b, &r.Body, &golangsdk.RequestOpts{})
   718  	return
   719  }
   720  
   721  type ModifyBinlogRetentionHoursOpts struct {
   722  	BinlogRetentionHours int `json:"binlog_retention_hours"`
   723  }
   724  
   725  func (opts ModifyBinlogRetentionHoursOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   726  	return toActionInstanceMap(opts)
   727  }
   728  
   729  // ModifyBinlogRetentionHours is a method used to modify binlog retention hours.
   730  func ModifyBinlogRetentionHours(c *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r JobResult) {
   731  	b, err := opts.ToActionInstanceMap()
   732  	if err != nil {
   733  		r.Err = err
   734  		return
   735  	}
   736  	_, r.Err = c.Put(updateURL(c, instanceId, "binlog/clear-policy"), b, &r.Body, &golangsdk.RequestOpts{})
   737  	return
   738  }
   739  
   740  // GetBinlogRetentionHours is a method used to obtain the binlog retention hours.
   741  func GetBinlogRetentionHours(c *golangsdk.ServiceClient, instanceId string) (r GetBinlogRetentionHoursResult) {
   742  	_, r.Err = c.Get(getURL(c, instanceId, "binlog/clear-policy"), &r.Body, &golangsdk.RequestOpts{
   743  		MoreHeaders: requestOpts.MoreHeaders,
   744  	})
   745  	return
   746  }
   747  
   748  type ModifyMsdtcHostsOpts struct {
   749  	Hosts []Host `json:"hosts" required:"true"`
   750  }
   751  
   752  type Host struct {
   753  	HostName string `json:"host_name" required:"true"`
   754  	Ip       string `json:"ip" required:"true"`
   755  }
   756  
   757  func (opts ModifyMsdtcHostsOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   758  	return toActionInstanceMap(opts)
   759  }
   760  
   761  // ModifyMsdtcHosts is a method used to modify msdtc hosts.
   762  func ModifyMsdtcHosts(c *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r JobResult) {
   763  	b, err := opts.ToActionInstanceMap()
   764  	if err != nil {
   765  		r.Err = err
   766  		return
   767  	}
   768  	_, r.Err = c.Post(updateURL(c, instanceId, "msdtc/host"), b, &r.Body, &golangsdk.RequestOpts{})
   769  	return
   770  }
   771  
   772  // GetMsdtcHosts is a method used to obtain the msdtc hosts.
   773  func GetMsdtcHosts(c *golangsdk.ServiceClient, instanceId string) ([]RdsMsdtcHosts, error) {
   774  	url := updateURL(c, instanceId, "msdtc/hosts")
   775  
   776  	pages, err := pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
   777  		return MsdtcHostsPage{pagination.OffsetPageBase{PageResult: r}}
   778  	}).AllPages()
   779  	if err != nil {
   780  		return nil, err
   781  	}
   782  	res, err := ExtractRdsMsdtcHosts(pages)
   783  	if err != nil {
   784  		return nil, err
   785  	}
   786  	return res.Hosts, err
   787  }
   788  
   789  func Startup(client *golangsdk.ServiceClient, instanceId string) (r JobResult) {
   790  	_, r.Err = client.Post(updateURL(client, instanceId, "action/startup"), nil, &r.Body, &golangsdk.RequestOpts{
   791  		MoreHeaders: map[string]string{"Content-Type": "application/json"},
   792  	})
   793  	return
   794  }
   795  
   796  func Shutdown(client *golangsdk.ServiceClient, instanceId string) (r JobResult) {
   797  	_, r.Err = client.Post(updateURL(client, instanceId, "action/shutdown"), nil, &r.Body, &golangsdk.RequestOpts{
   798  		MoreHeaders: map[string]string{"Content-Type": "application/json"},
   799  	})
   800  	return
   801  }
   802  
   803  type ModifyTdeOpts struct {
   804  	RotateDay     int    `json:"rotate_day,omitempty"`
   805  	SecretId      string `json:"secret_id,omitempty"`
   806  	SecretName    string `json:"secret_name,omitempty"`
   807  	SecretVersion string `json:"secret_version,omitempty"`
   808  }
   809  
   810  func (opts ModifyTdeOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   811  	return toActionInstanceMap(opts)
   812  }
   813  
   814  // OpenTde is a method used to open TDE of the instance.
   815  func OpenTde(c *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r JobResult) {
   816  	b, err := opts.ToActionInstanceMap()
   817  	if err != nil {
   818  		r.Err = err
   819  		return
   820  	}
   821  	_, r.Err = c.Put(updateURL(c, instanceId, "tde"), b, &r.Body, &golangsdk.RequestOpts{})
   822  	return
   823  }
   824  
   825  // GetTdeStatus is a method used to obtain the TDE status.
   826  func GetTdeStatus(c *golangsdk.ServiceClient, instanceId string) (r GetTdeStatusResult) {
   827  	_, r.Err = c.Get(getURL(c, instanceId, "tde-status"), &r.Body, &golangsdk.RequestOpts{
   828  		MoreHeaders: requestOpts.MoreHeaders,
   829  	})
   830  	return
   831  }
   832  
   833  type ModifyReadWritePermissionsOpts struct {
   834  	Readonly bool `json:"readonly"`
   835  }
   836  
   837  func (opts ModifyReadWritePermissionsOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   838  	return toActionInstanceMap(opts)
   839  }
   840  
   841  // ModifyReadWritePermissions is a method used to modify the read write permissions of the instance.
   842  func ModifyReadWritePermissions(c *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r JobResult) {
   843  	b, err := opts.ToActionInstanceMap()
   844  	if err != nil {
   845  		r.Err = err
   846  		return
   847  	}
   848  	_, r.Err = c.Put(updateURL(c, instanceId, "readonly-status"), b, &r.Body, &golangsdk.RequestOpts{})
   849  	return
   850  }
   851  
   852  type ModifySecondLevelMonitoringOpts struct {
   853  	SwitchOption bool `json:"switch_option"`
   854  	Interval     int  `json:"interval" required:"true"`
   855  }
   856  
   857  func (opts ModifySecondLevelMonitoringOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   858  	return toActionInstanceMap(opts)
   859  }
   860  
   861  // ModifySecondLevelMonitoring is a method used to switch second level monitoring of the instance.
   862  func ModifySecondLevelMonitoring(c *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r ModifySecondLevelMonitoringResult) {
   863  	b, err := opts.ToActionInstanceMap()
   864  	if err != nil {
   865  		r.Err = err
   866  		return
   867  	}
   868  	_, r.Err = c.Put(updateURL(c, instanceId, "second-level-monitor"), b, &r.Body, &golangsdk.RequestOpts{})
   869  	return
   870  }
   871  
   872  // GetSecondLevelMonitoring is a method used to obtain the second level monitoring.
   873  func GetSecondLevelMonitoring(c *golangsdk.ServiceClient, instanceId string) (r GetSecondLevelMonitoringResult) {
   874  	_, r.Err = c.Get(getURL(c, instanceId, "second-level-monitor"), &r.Body, &golangsdk.RequestOpts{
   875  		MoreHeaders: requestOpts.MoreHeaders,
   876  	})
   877  	return
   878  }
   879  
   880  type ModifyPrivateDnsNamePrefixOpts struct {
   881  	DnsName string `json:"dns_name" required:"true"`
   882  }
   883  
   884  func (opts ModifyPrivateDnsNamePrefixOpts) ToActionInstanceMap() (map[string]interface{}, error) {
   885  	return toActionInstanceMap(opts)
   886  }
   887  
   888  // ModifyPrivateDnsNamePrefix is a method used to private dns name prefix of the instance.
   889  func ModifyPrivateDnsNamePrefix(c *golangsdk.ServiceClient, opts ActionInstanceBuilder, instanceId string) (r JobResult) {
   890  	b, err := opts.ToActionInstanceMap()
   891  	if err != nil {
   892  		r.Err = err
   893  		return
   894  	}
   895  	_, r.Err = c.Put(updateURL(c, instanceId, "modify-dns"), b, &r.Body, &golangsdk.RequestOpts{})
   896  	return
   897  }