github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dcs/v1/lifecycle/Create.go (about)

     1  package lifecycle
     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/common/tags"
     8  )
     9  
    10  type CreateOps struct {
    11  	// DCS instance name.
    12  	// An instance name is a string of 4–64 characters
    13  	// that contain letters, digits, underscores (_), and hyphens (-).
    14  	// An instance name must start with letters.
    15  	Name string `json:"name" required:"true"`
    16  	// Brief description of the DCS instance.
    17  	// The description supports up to 1024 characters.
    18  	// The backslash (\) and quotation mark (") are special characters for JSON messages.
    19  	// When using these characters in a parameter value,
    20  	// add the escape character (\) before the characters, for example, \\ and \".
    21  	Description string `json:"description,omitempty"`
    22  	// Cache engine, which is Redis.
    23  	Engine string `json:"engine" required:"true"`
    24  	// Cache engine version. If the cache engine is Redis, the value can be 3.0, 4.0, or 5.0.
    25  	EngineVersion string `json:"engine_version" required:"true"`
    26  	// DCS instance specification code.
    27  	// To obtain the value, go to the instance creation page on the DCS console,
    28  	// and view Flavor Name in the Instance Specification table.
    29  	SpecCode string `json:"spec_code" required:"true"`
    30  	// Cache capacity. Unit: GB.
    31  	// For a single-node or master/standby DCS Redis 3.0 instance,
    32  	// the value can be 2, 4, 8, 16, 32, or 64. For a Proxy Cluster DCS Redis 3.0 instance,
    33  	// the value can be 64, 128, 256, 512, or 1024.
    34  	// For a single-node or master/standby DCS Redis 4.0 or 5.0 instance,
    35  	// the value can be 0.125, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 24, 48, or 64.
    36  	// For a Redis Cluster DCS Redis 4.0 or 5.0 instance,
    37  	// the value can be 4, 8, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, or 1024.
    38  	Capacity float64 `json:"capacity" required:"true"`
    39  	// Password of a DCS instance.
    40  	// The password of a DCS Redis instance must meet the following complexity requirements:
    41  	// Must be a string consisting of 8 to 32 characters.
    42  	// Must be different from the old password.
    43  	// Contains at least three of the following character types:
    44  	// Lowercase letters
    45  	// Uppercase letters
    46  	// Digits
    47  	// Special characters (`~!@#$^&*()-_=+\|{}:,<.>/?)
    48  	Password string `json:"password,omitempty"`
    49  	// VPC ID.
    50  	// Obtain the value by using either of the following methods:
    51  	// Method 1: Log in to VPC console and view the VPC ID in the VPC details.
    52  	// Method 2: Call the API for querying VPCs.
    53  	// For details, see the "Querying VPCs" section in the Virtual Private Cloud API Reference.
    54  	VPCId string `json:"vpc_id" required:"true"`
    55  	// ID of the security group which the instance belongs to.
    56  	// This parameter is mandatory when the engine is Redis and engine_version is 3.0.
    57  	// DCS Redis 3.0 instances support security group access control.
    58  	// This parameter is optional when the engine is Redis and engine_version is 4.0 or 5.0.
    59  	// DCS Redis 4.0 and 5.0 instances do not support security groups.
    60  	// Obtain the value by using either of the following methods:
    61  	// Method 1: Log in to the VPC console and view the security group ID on the security group details page.
    62  	// Method 2: Call the API for querying security groups. For details,
    63  	// see the "Querying Security Groups" section in the Virtual Private Cloud API Reference.
    64  	SecurityGroupID string `json:"security_group_id,omitempty"`
    65  	// Network ID of the subnet.
    66  	// Obtain the value by using either of the following methods:
    67  	// Method 1: Log in to VPC console and click the target subnet on the Subnets tab page.
    68  	// You can view the network ID on the displayed page.
    69  	// Method 2: Call the API for querying subnets.
    70  	// For details, see the "Querying Subnets" section in the Virtual Private Cloud API Reference.
    71  	SubnetID string `json:"subnet_id" required:"true"`
    72  	// ID of the AZ where the cache node resides and which has available resources.
    73  	// For details on how to obtain the value, see Querying AZ Information.
    74  	// Check whether the AZ has available resources.
    75  	// Master/Standby, Proxy Cluster, and Redis Cluster DCS instances support cross-AZ deployment.
    76  	// You can specify an AZ for the standby node. When specifying AZs for nodes,
    77  	// use commas (,) to separate multiple AZs. For details, see the example request.
    78  	AvailableZones []string `json:"available_zones" required:"true"`
    79  	// Backup policy.
    80  	// This parameter is available for master/standby and cluster DCS instances.
    81  	InstanceBackupPolicy *InstanceBackupPolicy `json:"instance_backup_policy,omitempty"`
    82  	// An indicator of whether to enable public access for a DCS Redis instance.
    83  	EnablePublicIp *bool `json:"enable_publicip,omitempty"`
    84  	// ID of the elastic IP address bound to a DCS Redis instance.
    85  	// This parameter is mandatory if public access is enabled (that is, enable_publicip is set to true).
    86  	PublicIpId string `json:"publicip_id,omitempty"`
    87  	// IP address that is manually specified for a DCS instance.
    88  	PrivateIps []string `json:"private_ips,omitempty"`
    89  	// An indicator of whether to enable SSL for public access to a DCS Redis instance.
    90  	EnableSsl *bool `json:"enable_ssl,omitempty"`
    91  	// Time at which the maintenance time window starts.
    92  	// Format: hh:mm:ss.
    93  	// The start time and end time of the maintenance time window
    94  	// must indicate the time segment of a supported maintenance time window.
    95  	// For details on how to query the time segments of supported maintenance time windows,
    96  	// see Querying Maintenance Time Window.
    97  	// The start time must be set to 22:00:00, 02:00:00, 06:00:00, 10:00:00, 14:00:00, or 18:00: 00.
    98  	// Parameters maintain_begin and maintain_end must be set in pairs.
    99  	// If parameter maintain_start is left blank, parameter maintain_end is also blank.
   100  	// In this case, the system automatically set the start time to 02:00:00.
   101  	MaintainBegin string `json:"maintain_begin,omitempty"`
   102  	// The end time is four hours later than the start time.
   103  	// For example, if the start time is 22:00:00, the end time is 02:00:00.
   104  	// ...In this case, the system automatically set the end time to 06:00:00.
   105  	MaintainEnd string `json:"maintain_end,omitempty"`
   106  	// Port customization, which is supported only by Redis 4.0 and Redis 5.0 instances and not by Redis 3.0 instances.
   107  	// If this parameter is not sent or is left empty when you create a Redis 4.0 or 5.0 instance,
   108  	// the default port 6379 will be used. To customize a port, specify a port number in the range from 1 to 65535.
   109  	Port int32 `json:"port,omitempty"`
   110  	// Critical command renaming, which is supported only by Redis 4.0 and Redis 5.0 instances and not by Redis 3.0 instances.
   111  	// If this parameter is not sent or is left empty when you create a Redis 4.0 or 5.0 instance, no critical command will be renamed.
   112  	// Currently, only COMMAND, KEYS, FLUSHDB, FLUSHALL, and HGETALL commands can be renamed.
   113  	RenameCommands *interface{} `json:"rename_commands,omitempty"`
   114  	// An indicator of whether a DCS instance can be accessed in password-free mode.
   115  	// true: indicates that a DCS instance can be accessed without a password.
   116  	// false: indicates that a DCS instance can be accessed only after password authentication.
   117  	NoPasswordAccess string `json:"no_password_access"`
   118  	// Tags
   119  	Tags []tags.ResourceTag `json:"tags,omitempty"`
   120  }
   121  
   122  type InstanceBackupPolicy struct {
   123  	// Retention time.
   124  	// Unit: day.
   125  	// Range: 1–7.
   126  	SaveDays int `json:"save_days"`
   127  	// Backup type. Options:
   128  	// auto: automatic backup.
   129  	// manual: manual backup.
   130  	BackupType string `json:"backup_type"`
   131  	// Backup plan.
   132  	PeriodicalBackupPlan PeriodicalBackupPlan `json:"periodical_backup_plan" required:"true"`
   133  }
   134  
   135  type PeriodicalBackupPlan struct {
   136  	// Time at which backup starts.
   137  	// "00:00-01:00" indicates that backup starts at 00:00:00.
   138  	BeginAt string `json:"begin_at" required:"true"`
   139  	// Interval at which backup is performed.
   140  	// Currently, only weekly backup is supported.
   141  	PeriodType string `json:"period_type" required:"true"`
   142  	// Day in a week on which backup starts.
   143  	// Range: 1–7. Where: 1 indicates Monday; 7 indicates Sunday.
   144  	BackupAt []int `json:"backup_at" required:"true"`
   145  	// Time zone in which backup is performed.
   146  	// Value range: GMT–12:00 to GMT+12:00. If this parameter is left blank,
   147  	// the current time zone of the DCS-Server VM is used by default.
   148  	TimezoneOffset string `json:"timezone_offset,omitempty"`
   149  }
   150  
   151  // Create an instance with given parameters.
   152  func Create(client *golangsdk.ServiceClient, opts CreateOps) (string, error) {
   153  	b, err := build.RequestBody(opts, "")
   154  	if err != nil {
   155  		return "", err
   156  	}
   157  
   158  	raw, err := client.Post(client.ServiceURL("instances"), b, nil, &golangsdk.RequestOpts{
   159  		OkCodes: []int{200},
   160  	})
   161  	if err != nil {
   162  		return "", err
   163  	}
   164  
   165  	var res struct {
   166  		InstanceID string `json:"instance_id"`
   167  	}
   168  	err = extract.Into(raw.Body, &res)
   169  	return res.InstanceID, err
   170  }