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

     1  package instances
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // CreateOpsBuilder is used for creating instance parameters.
     9  // any struct providing the parameters should implement this interface
    10  type CreateOpsBuilder interface {
    11  	ToInstanceCreateMap() (map[string]interface{}, error)
    12  }
    13  
    14  // CreateOps is a struct that contains all the parameters.
    15  type CreateOps 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 RabbitMQ is supported.
    28  	Engine string `json:"engine" required:"true"`
    29  
    30  	// Indicates the version of a message engine.
    31  	EngineVersion string `json:"engine_version,omitempty"`
    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,omitempty"`
    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"`
    81  
    82  	//This parameter is mandatory if the engine is kafka.
    83  	//Indicates the baseline bandwidth of a Kafka instance, that is,
    84  	//the maximum amount of data transferred per unit time. Unit: byte/s.
    85  	Specification string `json:"specification,omitempty"`
    86  
    87  	//Indicates the storage I/O specification. For details on how to select a disk type
    88  	StorageSpecCode string `json:"storage_spec_code,omitempty"`
    89  }
    90  
    91  // ToInstanceCreateMap is used for type convert
    92  func (ops CreateOps) ToInstanceCreateMap() (map[string]interface{}, error) {
    93  	return golangsdk.BuildRequestBody(ops, "")
    94  }
    95  
    96  // Create an instance with given parameters.
    97  func Create(client *golangsdk.ServiceClient, ops CreateOpsBuilder) (r CreateResult) {
    98  	b, err := ops.ToInstanceCreateMap()
    99  	if err != nil {
   100  		r.Err = err
   101  		return
   102  	}
   103  
   104  	_, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{
   105  		OkCodes: []int{200},
   106  	})
   107  
   108  	return
   109  }
   110  
   111  // Delete an instance by id
   112  func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
   113  	_, r.Err = client.Delete(deleteURL(client, id), &golangsdk.RequestOpts{
   114  		MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
   115  	})
   116  	return
   117  }
   118  
   119  //UpdateOptsBuilder is an interface which can build the map paramter of update function
   120  type UpdateOptsBuilder interface {
   121  	ToInstanceUpdateMap() (map[string]interface{}, error)
   122  }
   123  
   124  //UpdateOpts is a struct which represents the parameters of update function
   125  type UpdateOpts struct {
   126  	// Indicates the name of an instance.
   127  	// An instance name starts with a letter,
   128  	// consists of 4 to 64 characters,
   129  	// and supports only letters, digits, and hyphens (-).
   130  	Name string `json:"name,omitempty"`
   131  
   132  	// Indicates the description of an instance.
   133  	// It is a character string containing not more than 1024 characters.
   134  	Description *string `json:"description,omitempty"`
   135  
   136  	// Indicates the time at which a maintenance time window starts.
   137  	// Format: HH:mm:ss
   138  	MaintainBegin string `json:"maintain_begin,omitempty"`
   139  
   140  	// Indicates the time at which a maintenance time window ends.
   141  	// Format: HH:mm:ss
   142  	MaintainEnd string `json:"maintain_end,omitempty"`
   143  
   144  	// Indicates the ID of a security group.
   145  	SecurityGroupID string `json:"security_group_id,omitempty"`
   146  }
   147  
   148  // ToInstanceUpdateMap is used for type convert
   149  func (opts UpdateOpts) ToInstanceUpdateMap() (map[string]interface{}, error) {
   150  	return golangsdk.BuildRequestBody(opts, "")
   151  }
   152  
   153  // Update is a method which can be able to update the instance
   154  // via accessing to the service with Put method and parameters
   155  func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
   156  	body, err := opts.ToInstanceUpdateMap()
   157  	if err != nil {
   158  		r.Err = err
   159  		return
   160  	}
   161  
   162  	_, r.Err = client.Put(updateURL(client, id), body, nil, &golangsdk.RequestOpts{
   163  		OkCodes: []int{204},
   164  	})
   165  	return
   166  }
   167  
   168  // Get a instance with detailed information by id
   169  func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
   170  	_, r.Err = client.Get(getURL(client, id), &r.Body, nil)
   171  	return
   172  }
   173  
   174  type ListDmsInstanceOpts struct {
   175  	Id                  string `q:"id"`
   176  	Name                string `q:"name"`
   177  	Engine              string `q:"engine"`
   178  	Status              string `q:"status"`
   179  	IncludeFailure      string `q:"includeFailure"`
   180  	ExactMatchName      string `q:"exactMatchName"`
   181  	EnterpriseProjectID int    `q:"enterprise_project_id"`
   182  }
   183  
   184  type ListDmsBuilder interface {
   185  	ToDmsListDetailQuery() (string, error)
   186  }
   187  
   188  func (opts ListDmsInstanceOpts) ToDmsListDetailQuery() (string, error) {
   189  	q, err := golangsdk.BuildQueryString(opts)
   190  	if err != nil {
   191  		return "", err
   192  	}
   193  	return q.String(), err
   194  }
   195  
   196  func List(client *golangsdk.ServiceClient, opts ListDmsBuilder) pagination.Pager {
   197  	url := listURL(client)
   198  	if opts != nil {
   199  		query, err := opts.ToDmsListDetailQuery()
   200  
   201  		if err != nil {
   202  			return pagination.Pager{Err: err}
   203  		}
   204  		url += query
   205  	}
   206  
   207  	pageDmsList := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
   208  		return DmsPage{pagination.SinglePageBase(r)}
   209  	})
   210  
   211  	dmsheader := map[string]string{"Content-Type": "application/json"}
   212  	pageDmsList.Headers = dmsheader
   213  	return pageDmsList
   214  }