github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/rds/v3/backups/RestoreToNew.go (about)

     1  package backups
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/rds/v3/instances"
     8  )
     9  
    10  type RestoreToNewOpts struct {
    11  	// Specifies the DB instance name.
    12  	// DB instances of the same type can have same names under the same tenant.
    13  	// The value must be 4 to 64 characters in length and start with a letter. It is case-insensitive and can contain only letters, digits, hyphens (-), and underscores (_).
    14  	Name string `json:"name" required:"true"`
    15  	// Specifies the HA configuration parameters, which are used when creating primary/standby DB instances.
    16  	Ha *instances.Ha `json:"ha,omitempty"`
    17  	// Specifies the parameter template ID.
    18  	ConfigurationId string `json:"configuration_id,omitempty"`
    19  	// Specifies the database port information.
    20  	//
    21  	// The MySQL database port ranges from 1024 to 65535 (excluding 12017 and 33071, which are occupied by the RDS system and cannot be used).
    22  	// The PostgreSQL database port ranges from 2100 to 9500.
    23  	// The Microsoft SQL Server database port is 1433 or ranges from 2100 to 9500 (excluding 5355 and 5985).
    24  	// If this parameter is not set, the default value is as follows:
    25  	//
    26  	// For MySQL, the default value is 3306.
    27  	// For PostgreSQL, the default value is 5432.
    28  	// For Microsoft SQL Server, the default value is 1433.
    29  	Port string `json:"port,omitempty"`
    30  	// Specifies the database password.
    31  	// Valid value:
    32  	// The value cannot be empty and should contain 8 to 32 characters, including uppercase and lowercase letters, digits, and the following special characters: ~!@#%^*-_=+?
    33  	// You are advised to enter a strong password to improve security, preventing security risks such as brute force cracking.
    34  	// If provided password will be considered by system as weak, you will receive an error and you should provide stronger password.
    35  	Password string `json:"password" required:"true"`
    36  	// Specifies the advanced backup policy.
    37  	BackupStrategy *instances.BackupStrategy `json:"backup_strategy,omitempty"`
    38  	// Specifies the key ID for disk encryption. The default value is empty.
    39  	DiskEncryptionId string `json:"disk_encryption_id,omitempty"`
    40  	// Specifies the specification code. The value cannot be empty.
    41  	FlavorRef string `json:"flavor_ref" required:"true"`
    42  	// Specifies the volume information.
    43  	Volume *instances.Volume `json:"volume" required:"true"`
    44  	// Specifies the AZ ID. If the DB instance is not a single instance, you need to specify an AZ for each node of the instance and separate the AZs with commas (,). For details, see the example.
    45  	// The value cannot be empty.
    46  	AvailabilityZone string `json:"availability_zone" required:"true"`
    47  	// Specifies the VPC ID. To obtain this parameter value, use either of the following methods:
    48  	//
    49  	// Method 1: Log in to VPC console and view the VPC ID in the VPC details.
    50  	// Method 2: See the "Querying VPCs" section in the Virtual Private Cloud API Reference.
    51  	VpcId string `json:"vpc_id" required:"true"`
    52  	// Specifies the network ID. To obtain this parameter value, use either of the following methods:
    53  	//
    54  	// Method 1: Log in to VPC console and click the target subnet on the Subnets page. You can view the network ID on the displayed page.
    55  	// Method 2: See the "Querying Subnets" section under "APIs" or the "Querying Networks" section under "OpenStack Neutron APIs" in Virtual Private Cloud API Reference.
    56  	SubnetId string `json:"subnet_id" required:"true"`
    57  	// Specifies the floating IP address of a DB instance. To obtain this parameter value, use either of the following methods:
    58  	//
    59  	// Method 1: Log in to VPC console and click the target subnet on the Subnets page. You can view the subnet CIDR block on the displayed page.
    60  	// Method 2: See the "Querying Subnets" section under "APIs" in the Virtual Private Cloud API Reference.
    61  	DataVip string `json:"data_vip,omitempty"`
    62  	// Specifies the security group which the RDS DB instance belongs to. To obtain this parameter value, use either of the following methods:
    63  	//
    64  	// Method 1: Log in to VPC console. Choose Access Control > Security Groups in the navigation pane on the left. On the displayed page, click the target security group. You can view the security group ID on the displayed page.
    65  	// Method 2: See the "Querying Security Groups" section in the Virtual Private Cloud API Reference.
    66  	SecurityGroupId string `json:"security_group_id" required:"true"`
    67  	// Specifies the restoration information.
    68  	RestorePoint RestorePoint `json:"restore_point" required:"true"`
    69  	// This parameter applies only to Microsoft SQL Server DB instances.
    70  	Collation         string           `json:"collation,omitempty"`
    71  	UnchangeableParam *instances.Param `json:"unchangeable_param,omitempty"`
    72  }
    73  
    74  type RestoreType string
    75  
    76  const (
    77  	TypeBackup    RestoreType = "backup"
    78  	TypeTimestamp RestoreType = "timestamp"
    79  )
    80  
    81  type RestorePoint struct {
    82  	// Specifies the DB instance ID.
    83  	InstanceID string `json:"instance_id" required:"true"`
    84  	// Specifies the restoration mode. Enumerated values include:
    85  	//
    86  	// backup: indicates restoration from backup files. In this mode, backup_id is mandatory when type is not mandatory.
    87  	// timestamp: indicates point-in-time restoration. In this mode, restore_time is mandatory when type is mandatory.
    88  	Type RestoreType `json:"type" required:"true"`
    89  	// Specifies the ID of the backup used to restore data. This parameter must be specified when the backup file is used for restoration.
    90  	//
    91  	// NOTICE:
    92  	// When type is not mandatory, backup_id is mandatory.
    93  	BackupID string `json:"backup_id,omitempty"`
    94  	// Specifies the time point of data restoration in the UNIX timestamp. The unit is millisecond and the time zone is UTC.
    95  	//
    96  	// NOTICE:
    97  	// When type is mandatory, restore_time is mandatory.
    98  	RestoreTime int `json:"restore_time,omitempty"`
    99  }
   100  
   101  func RestoreToNew(c *golangsdk.ServiceClient, opts RestoreToNewOpts) (*instances.CreateRds, error) {
   102  	b, err := build.RequestBody(opts, "")
   103  	if err != nil {
   104  		return nil, err
   105  	}
   106  
   107  	// POST https://{Endpoint}/v3/{project_id}/instances
   108  	raw, err := c.Post(c.ServiceURL("instances"), b, nil, &golangsdk.RequestOpts{
   109  		OkCodes: []int{200, 201, 202},
   110  	})
   111  	if err != nil {
   112  		return nil, err
   113  	}
   114  
   115  	var res instances.CreateRds
   116  	err = extract.Into(raw.Body, &res)
   117  	return &res, err
   118  }