github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dms/v2/instances/requests.go (about)

     1  package instances
     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  // CreateOps is a struct that contains all the parameters.
    11  type CreateOpts struct {
    12  	// Indicates the name of an instance.
    13  	// An instance name starts with a letter,
    14  	// consists of 4 to 64 characters, and supports
    15  	// only letters, digits, hyphens (-), and underscores (_).
    16  	Name string `json:"name" required:"true"`
    17  
    18  	// Indicates the description of an instance.
    19  	// It is a character string containing not more than 1024 characters.
    20  	Description string `json:"description,omitempty"`
    21  
    22  	// Indicates a message engine.
    23  	Engine string `json:"engine" required:"true"`
    24  
    25  	// Indicates the version of a message engine.
    26  	EngineVersion string `json:"engine_version" required:"true"`
    27  
    28  	// Indicates the message storage space.
    29  	StorageSpace int `json:"storage_space" required:"true"`
    30  
    31  	// Indicates the baseline bandwidth of a Kafka instance, that is,
    32  	// the maximum amount of data transferred per unit time. Unit: byte/s.
    33  	Specification string `json:"specification,omitempty"`
    34  
    35  	// Indicates the maximum number of topics in a Kafka instance.
    36  	PartitionNum int `json:"partition_num,omitempty"`
    37  
    38  	// Indicates a username.
    39  	// A username consists of 1 to 64 characters
    40  	// and supports only letters, digits, and hyphens (-).
    41  	AccessUser string `json:"access_user,omitempty"`
    42  
    43  	// Indicates the password of an instance.
    44  	// An instance password must meet the following complexity requirements:
    45  	// Must be 6 to 32 characters long.
    46  	// Must contain at least two of the following character types:
    47  	// Lowercase letters
    48  	// Uppercase letters
    49  	// Digits
    50  	// Special characters (`~!@#$%^&*()-_=+\|[{}]:'",<.>/?)
    51  	Password string `json:"password,omitempty"`
    52  
    53  	// Indicates the ID of a VPC.
    54  	VpcID string `json:"vpc_id" required:"true"`
    55  
    56  	// Indicates the ID of a security group.
    57  	SecurityGroupID string `json:"security_group_id" required:"true"`
    58  
    59  	// Indicates the ID of a subnet.
    60  	SubnetID string `json:"subnet_id" required:"true"`
    61  
    62  	// Indicates the ID of an AZ.
    63  	// The parameter value can be left blank or an empty array.
    64  	AvailableZones []string `json:"available_zones" required:"true"`
    65  
    66  	// Indicates a product ID.
    67  	ProductID string `json:"product_id" required:"true"`
    68  
    69  	// Indicates the time at which a maintenance time window starts.
    70  	// Format: HH:mm:ss
    71  	MaintainBegin string `json:"maintain_begin,omitempty"`
    72  
    73  	// Indicates the time at which a maintenance time window ends.
    74  	// Format: HH:mm:ss
    75  	MaintainEnd string `json:"maintain_end,omitempty"`
    76  
    77  	// Indicates whether to open the public network access function. Default to false.
    78  	EnablePublicIP bool `json:"enable_publicip,omitempty"`
    79  
    80  	// Indicates the bandwidth of the public network.
    81  	PublicBandWidth int `json:"public_bandwidth,omitempty"`
    82  
    83  	// Indicates the ID of the Elastic IP address bound to the instance.
    84  	PublicIpID string `json:"publicip_id,omitempty"`
    85  
    86  	// Indicates whether to enable SSL-encrypted access.
    87  	SslEnable *bool `json:"ssl_enable,omitempty"`
    88  
    89  	// Indicates the action to be taken when the memory usage reaches the disk capacity threshold. Options:
    90  	// time_base: Automatically delete the earliest messages.
    91  	// produce_reject: Stop producing new messages.
    92  	RetentionPolicy string `json:"retention_policy,omitempty"`
    93  
    94  	// Indicates whether to enable automatic topic creation.
    95  	EnableAutoTopic *bool `json:"enable_auto_topic,omitempty"`
    96  
    97  	// Indicates the storage I/O specification. For details on how to select a disk type
    98  	StorageSpecCode string `json:"storage_spec_code,omitempty"`
    99  
   100  	// Indicates whether disk encryption is enabled.
   101  	DiskEncryptedEnable *bool `json:"disk_encrypted_enable,omitempty"`
   102  
   103  	// Disk encryption key. If disk encryption is not enabled, this parameter is left blank.
   104  	DiskEncryptedKey string `json:"disk_encrypted_key,omitempty"`
   105  
   106  	// Indicates the tags of the instance
   107  	Tags []tags.ResourceTag `json:"tags,omitempty"`
   108  }
   109  
   110  // Create an instance with given parameters.
   111  func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*InstanceCreate, error) {
   112  	b, err := build.RequestBody(opts, "")
   113  	if err != nil {
   114  		return nil, err
   115  	}
   116  
   117  	raw, err := client.Post(createURL(client), b, nil, &golangsdk.RequestOpts{
   118  		OkCodes: []int{200},
   119  	})
   120  	if err != nil {
   121  		return nil, err
   122  	}
   123  
   124  	var res InstanceCreate
   125  	err = extract.Into(raw.Body, &res)
   126  	return &res, err
   127  }
   128  
   129  // Delete an instance by id
   130  func Delete(client *golangsdk.ServiceClient, id string) error {
   131  	_, err := client.Delete(deleteURL(client, id), &golangsdk.RequestOpts{
   132  		OkCodes: []int{204},
   133  	})
   134  	return err
   135  }
   136  
   137  // UpdateOpts is a struct which represents the parameters of update function
   138  type UpdateOpts struct {
   139  	// Indicates the name of an instance.
   140  	// An instance name starts with a letter,
   141  	// consists of 4 to 64 characters,
   142  	// and supports only letters, digits, and hyphens (-).
   143  	Name string `json:"name,omitempty"`
   144  
   145  	// Indicates the description of an instance.
   146  	// It is a character string containing not more than 1024 characters.
   147  	Description *string `json:"description,omitempty"`
   148  
   149  	// Indicates the time at which a maintenance time window starts.
   150  	// Format: HH:mm:ss
   151  	MaintainBegin string `json:"maintain_begin,omitempty"`
   152  
   153  	// Indicates the time at which a maintenance time window ends.
   154  	// Format: HH:mm:ss
   155  	MaintainEnd string `json:"maintain_end,omitempty"`
   156  
   157  	// Indicates the ID of a security group.
   158  	SecurityGroupID string `json:"security_group_id,omitempty"`
   159  
   160  	// Indicates the action to be taken when the memory usage reaches the disk capacity threshold. Options:
   161  	// time_base: Automatically delete the earliest messages.
   162  	// produce_reject: Stop producing new messages.
   163  	RetentionPolicy string `json:"retention_policy,omitempty"`
   164  }
   165  
   166  // Update is a method which can be able to update the instance
   167  // via accessing to the service with Put method and parameters
   168  func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (*InstanceCreate, error) {
   169  	body, err := build.RequestBody(opts, "")
   170  	if err != nil {
   171  		return nil, err
   172  	}
   173  
   174  	raw, err := client.Put(updateURL(client, id), body, nil, &golangsdk.RequestOpts{
   175  		OkCodes: []int{204},
   176  	})
   177  	if err != nil {
   178  		return nil, err
   179  	}
   180  
   181  	var res InstanceCreate
   182  	err = extract.Into(raw.Body, &res)
   183  	return &res, err
   184  }
   185  
   186  // Get an instance with detailed information by id
   187  func Get(client *golangsdk.ServiceClient, id string) (*Instance, error) {
   188  	raw, err := client.Get(getURL(client, id), nil, nil)
   189  	if err != nil {
   190  		return nil, err
   191  	}
   192  
   193  	var res Instance
   194  	err = extract.Into(raw.Body, &res)
   195  	return &res, err
   196  }
   197  
   198  type ListOpts struct {
   199  	InstanceId     string `q:"instance_id"`
   200  	Name           string `q:"name"`
   201  	Engine         string `q:"engine"`
   202  	Status         string `q:"status"`
   203  	IncludeFailure string `q:"include_failure"`
   204  	ExactMatchName string `q:"exact_match_name"`
   205  }
   206  
   207  func List(client *golangsdk.ServiceClient, opts ListOpts) (*ListResponse, error) {
   208  	url, err := golangsdk.NewURLBuilder().WithEndpoints(resourcePath).WithQueryParams(&opts).Build()
   209  	if err != nil {
   210  		return nil, err
   211  	}
   212  
   213  	raw, err := client.Get(client.ServiceURL(url.String()), nil, nil)
   214  	if err != nil {
   215  		return nil, err
   216  	}
   217  
   218  	var res ListResponse
   219  	err = extract.Into(raw.Body, &res)
   220  	return &res, err
   221  }
   222  
   223  // CrossVpcUpdateOpts is the structure required by the UpdateCrossVpc method to update the internal IP address for
   224  // cross-VPC access.
   225  type CrossVpcUpdateOpts struct {
   226  	// User-defined advertised IP contents key-value pair.
   227  	// The key is the listeners IP.
   228  	// The value is advertised.listeners IP, or domain name.
   229  	Contents map[string]string `json:"advertised_ip_contents" required:"true"`
   230  }
   231  
   232  // UpdateCrossVpc is a method to update the internal IP address for cross-VPC access using given parameters.
   233  func UpdateCrossVpc(c *golangsdk.ServiceClient, instanceId string, opts CrossVpcUpdateOpts) (*CrossVpc, error) {
   234  	body, err := build.RequestBody(opts, "")
   235  	if err != nil {
   236  		return nil, err
   237  	}
   238  
   239  	raw, err := c.Post(crossVpcURL(c, instanceId), body, nil, nil)
   240  	if err != nil {
   241  		return nil, err
   242  	}
   243  
   244  	var r CrossVpc
   245  	err = extract.Into(raw.Body, &r)
   246  
   247  	return &r, err
   248  }
   249  
   250  type PasswordOpts struct {
   251  	NewPassword string `json:"new_password" required:"true"`
   252  }
   253  
   254  // ChangePassword is a method to update the password using given parameters.
   255  func ChangePassword(c *golangsdk.ServiceClient, instanceId string, opts PasswordOpts) error {
   256  	body, err := build.RequestBody(opts, "")
   257  	if err != nil {
   258  		return err
   259  	}
   260  
   261  	_, err = c.Post(changePasswordURL(c, instanceId), body, nil, &golangsdk.RequestOpts{
   262  		OkCodes: []int{204},
   263  	})
   264  
   265  	return err
   266  }