github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/dms/v2/kafka/instances/requests.go (about)

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