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

     1  package instances
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     6  )
     7  
     8  // CreateOptsBuilder is used for creating instance parameters.
     9  // any struct providing the parameters should implement this interface
    10  type CreateOptsBuilder interface {
    11  	ToInstanceCreateMap() (map[string]interface{}, error)
    12  }
    13  
    14  // CreateOpts is a struct that contains all the parameters.
    15  type CreateOpts struct {
    16  	// Indicates the name of an instance.
    17  	// An instance name starts with a letter,
    18  	// consists of 4 to 64 characters, and supports
    19  	// only letters, digits, and hyphens (-).
    20  	Name string `json:"name" required:"true"`
    21  
    22  	// Indicates the description of an instance.
    23  	// It is a character string containing not more than 1024 characters.
    24  	Description string `json:"description,omitempty"`
    25  
    26  	// Indicates a message engine.
    27  	// Currently, only kafka is supported.
    28  	Engine string `json:"engine" required:"true"`
    29  
    30  	// Indicates the version of a message engine.
    31  	EngineVersion string `json:"engine_version" required:"true"`
    32  
    33  	// Indicates the message storage space.
    34  	StorageSpace int `json:"storage_space" required:"true"`
    35  
    36  	// Indicates the password of an instance.
    37  	// An instance password must meet the following complexity requirements:
    38  	// Must be 6 to 32 characters long.
    39  	// Must contain at least two of the following character types:
    40  	// Lowercase letters
    41  	// Uppercase letters
    42  	// Digits
    43  	// Special characters (`~!@#$%^&*()-_=+\|[{}]:'",<.>/?)
    44  	Password string `json:"password,omitempty"`
    45  
    46  	// Indicates a username.
    47  	// A username consists of 1 to 64 characters
    48  	// and supports only letters, digits, and hyphens (-).
    49  	AccessUser string `json:"access_user,omitempty"`
    50  
    51  	// Indicates the ID of a VPC.
    52  	VpcID string `json:"vpc_id" required:"true"`
    53  
    54  	// Indicates the ID of a security group.
    55  	SecurityGroupID string `json:"security_group_id" required:"true"`
    56  
    57  	// Indicates the ID of a subnet.
    58  	SubnetID string `json:"subnet_id" required:"true"`
    59  
    60  	// Indicates the ID of an AZ.
    61  	// The parameter value can be left blank or an empty array.
    62  	AvailableZones []string `json:"available_zones" required:"true"`
    63  
    64  	// Indicates a product ID.
    65  	ProductID string `json:"product_id" required:"true"`
    66  
    67  	// Indicates the time at which a maintenance time window starts.
    68  	// Format: HH:mm:ss
    69  	MaintainBegin string `json:"maintain_begin,omitempty"`
    70  
    71  	// Indicates the time at which a maintenance time window ends.
    72  	// Format: HH:mm:ss
    73  	MaintainEnd string `json:"maintain_end,omitempty"`
    74  
    75  	// This parameter is mandatory when a Kafka instance is created.
    76  	// Indicates the maximum number of topics in a Kafka instance.
    77  	PartitionNum int `json:"partition_num,omitempty"`
    78  
    79  	// Indicates whether to enable SSL-encrypted access.
    80  	SslEnable bool `json:"ssl_enable,omitempty"`
    81  
    82  	// Indicates whether to enable public access for the instance.
    83  	EnablePublicIp *bool `json:"enable_publicip,omitempty"`
    84  
    85  	// Indicates the public network bandwidth. Unit: Mbit/s
    86  	PublicBandwidth string `json:"public_bandwidth,omitempty"`
    87  
    88  	// This parameter is mandatory if the engine is kafka.
    89  	// Indicates the baseline bandwidth of a Kafka instance, that is,
    90  	// the maximum amount of data transferred per unit time. Unit: Mbit/s.
    91  	Specification string `json:"specification,omitempty"`
    92  
    93  	// Indicates the action to be taken when the memory usage reaches the disk capacity threshold.
    94  	// Options:
    95  	// produce_reject: New messages cannot be created.
    96  	// time_base: The earliest messages are deleted.
    97  	RetentionPolicy string `json:"retention_policy,omitempty"`
    98  
    99  	// Indicates the storage I/O specification. For details on how to select a disk type
   100  	StorageSpecCode string `json:"storage_spec_code,omitempty"`
   101  }
   102  
   103  // ToInstanceCreateMap is used for type convert
   104  func (opts CreateOpts) ToInstanceCreateMap() (map[string]interface{}, error) {
   105  	return golangsdk.BuildRequestBody(opts, "")
   106  }
   107  
   108  // Create an instance with given parameters.
   109  func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
   110  	b, err := opts.ToInstanceCreateMap()
   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},
   118  	})
   119  	return
   120  }
   121  
   122  // Delete an instance by id
   123  func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
   124  	_, r.Err = client.Delete(deleteURL(client, id), nil)
   125  	return
   126  }
   127  
   128  // UpdateOptsBuilder is an interface which can build the map parameter of update function
   129  type UpdateOptsBuilder interface {
   130  	ToInstanceUpdateMap() (map[string]interface{}, error)
   131  }
   132  
   133  // UpdateOpts is a struct which represents the parameters of update function
   134  type UpdateOpts struct {
   135  	// Indicates the name of an instance.
   136  	// An instance name starts with a letter,
   137  	// consists of 4 to 64 characters,
   138  	// and supports only letters, digits, and hyphens (-).
   139  	Name string `json:"name,omitempty"`
   140  
   141  	// Indicates the description of an instance.
   142  	// It is a character string containing not more than 1024 characters.
   143  	Description *string `json:"description,omitempty"`
   144  
   145  	// Indicates the time at which a maintenance time window starts.
   146  	// Format: HH:mm:ss
   147  	MaintainBegin string `json:"maintain_begin,omitempty"`
   148  
   149  	// Indicates the time at which a maintenance time window ends.
   150  	// Format: HH:mm:ss
   151  	MaintainEnd string `json:"maintain_end,omitempty"`
   152  
   153  	// Indicates the ID of a security group.
   154  	SecurityGroupID string `json:"security_group_id,omitempty"`
   155  }
   156  
   157  // ToInstanceUpdateMap is used for type convert
   158  func (opts UpdateOpts) ToInstanceUpdateMap() (map[string]interface{}, error) {
   159  	return golangsdk.BuildRequestBody(opts, "")
   160  }
   161  
   162  // Update is a method which can be able to update the instance
   163  // via accessing to the service with Put method and parameters
   164  func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
   165  	b, err := opts.ToInstanceUpdateMap()
   166  	if err != nil {
   167  		r.Err = err
   168  		return
   169  	}
   170  
   171  	_, r.Err = client.Put(updateURL(client, id), b, nil, &golangsdk.RequestOpts{
   172  		OkCodes: []int{204},
   173  	})
   174  	return
   175  }
   176  
   177  // Get an instance with detailed information by id
   178  func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
   179  	_, r.Err = client.Get(getURL(client, id), &r.Body, nil)
   180  	return
   181  }
   182  
   183  type ListDmsInstanceOpts struct {
   184  	Id                  string `q:"id"`
   185  	Name                string `q:"name"`
   186  	Engine              string `q:"engine"`
   187  	Status              string `q:"status"`
   188  	IncludeFailure      string `q:"includeFailure"`
   189  	ExactMatchName      string `q:"exactMatchName"`
   190  	EnterpriseProjectID int    `q:"enterprise_project_id"`
   191  }
   192  
   193  type ListDmsBuilder interface {
   194  	ToDmsListDetailQuery() (string, error)
   195  }
   196  
   197  func (opts ListDmsInstanceOpts) ToDmsListDetailQuery() (string, error) {
   198  	q, err := golangsdk.BuildQueryString(opts)
   199  	if err != nil {
   200  		return "", err
   201  	}
   202  	return q.String(), err
   203  }
   204  
   205  func List(client *golangsdk.ServiceClient, opts ListDmsBuilder) pagination.Pager {
   206  	url := listURL(client)
   207  	if opts != nil {
   208  		query, err := opts.ToDmsListDetailQuery()
   209  
   210  		if err != nil {
   211  			return pagination.Pager{Err: err}
   212  		}
   213  		url += query
   214  	}
   215  
   216  	pageDmsList := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
   217  		return DmsPage{pagination.SinglePageBase(r)}
   218  	})
   219  
   220  	pageDmsList.Headers = map[string]string{"Content-Type": "application/json"}
   221  	return pageDmsList
   222  }