Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,9 @@ func NewAntiDDoSV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts)
sc.ResourceBase = sc.Endpoint + "v2/" + client.ProjectID + "/"
return sc, err
}

// NewDMSServiceV1 creates a ServiceClient that may be used to access the v1 Distributed Message Service.
func NewDMSServiceV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "dms")
return sc, err
}
11 changes: 11 additions & 0 deletions openstack/dms/v1/availablezones/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package availablezones

import (
"github.com/huaweicloud/golangsdk"
)

// Get available zones
func Get(client *golangsdk.ServiceClient) (r GetResult) {
_, r.Err = client.Get(getURL(client), &r.Body, nil)
return
}
32 changes: 32 additions & 0 deletions openstack/dms/v1/availablezones/results.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package availablezones

import (
"github.com/huaweicloud/golangsdk"
)

// GetResponse response
type GetResponse struct {
RegionID string `json:"regionId"`
AvailableZones []AvailableZone `json:"available_zones"`
}

// AvailableZone for dms
type AvailableZone struct {
ID string `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
Port string `json:"port"`
ResourceAvailability string `json:"resource_availability"`
}

// GetResult contains the body of getting detailed
type GetResult struct {
golangsdk.Result
}

// Extract from GetResult
func (r GetResult) Extract() (*GetResponse, error) {
var s GetResponse
err := r.Result.ExtractInto(&s)
return &s, err
}
16 changes: 16 additions & 0 deletions openstack/dms/v1/availablezones/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package availablezones

import (
"strings"

"github.com/huaweicloud/golangsdk"
)

// endpoint/availablezones
const resourcePath = "availableZones"

// getURL will build the get url of get function
func getURL(client *golangsdk.ServiceClient) string {
// remove projectid from endpoint
return strings.Replace(client.ServiceURL(resourcePath), "/"+client.ProjectID, "", -1)
}
61 changes: 61 additions & 0 deletions openstack/dms/v1/groups/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package groups

import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)

// CreateOpsBuilder is used for creating group parameters.
// any struct providing the parameters should implement this interface
type CreateOpsBuilder interface {
ToGroupCreateMap() (map[string]interface{}, error)
}

// CreateOps is a struct that contains all the parameters.
type CreateOps struct {
// Indicates the informations of a consumer group.
Groups []GroupOps `json:"groups" required:"true"`
}

// GroupOps is referred by CreateOps
type GroupOps struct {
// Indicates the name of a consumer group.
// A string of 1 to 32 characters that contain
// a-z, A-Z, 0-9, hyphens (-), and underscores (_).
Name string `json:"name" required:"true"`
}

// ToGroupCreateMap is used for type convert
func (ops CreateOps) ToGroupCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(ops, "")
}

// Create a group with given parameters.
func Create(client *golangsdk.ServiceClient, queueID string, ops CreateOpsBuilder) (r CreateResult) {
b, err := ops.ToGroupCreateMap()
if err != nil {
r.Err = err
return
}

_, r.Err = client.Post(createURL(client, queueID), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{201},
})

return
}

// Delete a group by id
func Delete(client *golangsdk.ServiceClient, queueID string, groupID string) (r DeleteResult) {
_, r.Err = client.Delete(deleteURL(client, queueID, groupID), nil)
return
}

// List all the groups
func List(client *golangsdk.ServiceClient, queueID string, includeDeadLetter bool) pagination.Pager {
url := listURL(client, queueID, includeDeadLetter)

return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
return GroupPage{pagination.SinglePageBase(r)}
})
}
63 changes: 63 additions & 0 deletions openstack/dms/v1/groups/results.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package groups

import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)

// GroupCreate response
type GroupCreate struct {
ID string `json:"id"`
Name string `json:"name"`
}

// CreateResult is a struct that contains all the return parameters of creation
type CreateResult struct {
golangsdk.Result
}

// Extract from CreateResult
func (r CreateResult) Extract() ([]GroupCreate, error) {
var s struct {
GroupsCreate []GroupCreate `json:"groups"`
}
err := r.Result.ExtractInto(&s)
return s.GroupsCreate, err
}

// DeleteResult is a struct which contains the result of deletion
type DeleteResult struct {
golangsdk.ErrResult
}

// Group response
type Group struct {
ID string `json:"id"`
Name string `json:"name"`
ConsumedMessages int `json:"consumed_messages"`
AvailableMessages int `json:"available_messages"`
ProducedMessages int `json:"produced_messages"`
ProducedDeadletters int `json:"produced_deadletters"`
AvailableDeadletters int `json:"available_deadletters"`
}

// GroupPage may be embedded in a Page
// that contains all of the results from an operation at once.
type GroupPage struct {
pagination.SinglePageBase
}

// IsEmpty returns true if a ListResult contains no groups.
func (r GroupPage) IsEmpty() (bool, error) {
rs, err := ExtractGroups(r)
return len(rs) == 0, err
}

// ExtractGroups from List
func ExtractGroups(r pagination.Page) ([]Group, error) {
var s struct {
Groups []Group `json:"groups"`
}
err := (r.(GroupPage)).ExtractInto(&s)
return s.Groups, err
}
26 changes: 26 additions & 0 deletions openstack/dms/v1/groups/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package groups

import (
"fmt"

"github.com/huaweicloud/golangsdk"
)

// endpoint/queues/{queue_id}/groups
const resourcePathQueues = "queues"
const resourcePathGroups = "groups"

// createURL will build the rest query url of creation
func createURL(client *golangsdk.ServiceClient, queueID string) string {
return client.ServiceURL(resourcePathQueues, queueID, resourcePathGroups)
}

// deleteURL will build the url of deletion
func deleteURL(client *golangsdk.ServiceClient, queueID string, groupID string) string {
return client.ServiceURL(resourcePathQueues, queueID, resourcePathGroups, groupID)
}

// listURL will build the list url of list function
func listURL(client *golangsdk.ServiceClient, queueID string, includeDeadLetter bool) string {
return client.ServiceURL(resourcePathQueues, queueID, fmt.Sprintf("%s?include_deadletter=%t", resourcePathGroups, includeDeadLetter))
}
154 changes: 154 additions & 0 deletions openstack/dms/v1/instances/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package instances

import (
"github.com/huaweicloud/golangsdk"
)

// CreateOpsBuilder is used for creating instance parameters.
// any struct providing the parameters should implement this interface
type CreateOpsBuilder interface {
ToInstanceCreateMap() (map[string]interface{}, error)
}

// CreateOps is a struct that contains all the parameters.
type CreateOps struct {
// Indicates the name of an instance.
// An instance name starts with a letter,
// consists of 4 to 64 characters, and supports
// only letters, digits, and hyphens (-).
Name string `json:"name" required:"true"`

// Indicates the description of an instance.
// It is a character string containing not more than 1024 characters.
Description string `json:"description,omitempty"`

// Indicates a message engine.
// Currently, only RabbitMQ is supported.
Engine string `json:"engine" required:"true"`

// Indicates the version of a message engine.
EngineVersion string `json:"engine_version,omitempty"`

// Indicates the message storage space.
StorageSpace int `json:"storage_space" required:"true"`

// Indicates the password of an instance.
// An instance password must meet the following complexity requirements:
// Must be 6 to 32 characters long.
// Must contain at least two of the following character types:
// Lowercase letters
// Uppercase letters
// Digits
// Special characters (`~!@#$%^&*()-_=+\|[{}]:'",<.>/?)
Password string `json:"password" required:"true"`

// Indicates a username.
// A username consists of 1 to 64 characters
// and supports only letters, digits, and hyphens (-).
AccessUser string `json:"access_user" required:"true"`

// Indicates the ID of a VPC.
VPCID string `json:"vpc_id" required:"true"`

// Indicates the ID of a security group.
SecurityGroupID string `json:"security_group_id" required:"true"`

// Indicates the ID of a subnet.
SubnetID string `json:"subnet_id" required:"true"`

// Indicates the ID of an AZ.
// The parameter value can be left blank or an empty array.
AvailableZones []string `json:"available_zones,omitempty"`

// Indicates a product ID.
ProductID string `json:"product_id" required:"true"`

// Indicates the time at which a maintenance time window starts.
// Format: HH:mm:ss
MaintainBegin string `json:"maintain_begin,omitempty"`

// Indicates the time at which a maintenance time window ends.
// Format: HH:mm:ss
MaintainEnd string `json:"maintain_end,omitempty"`
}

// ToInstanceCreateMap is used for type convert
func (ops CreateOps) ToInstanceCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(ops, "")
}

// Create an instance with given parameters.
func Create(client *golangsdk.ServiceClient, ops CreateOpsBuilder) (r CreateResult) {
b, err := ops.ToInstanceCreateMap()
if err != nil {
r.Err = err
return
}

_, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
})

return
}

// Delete an instance by id
func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
_, r.Err = client.Delete(deleteURL(client, id), nil)
return
}

//UpdateOptsBuilder is an interface which can build the map paramter of update function
type UpdateOptsBuilder interface {
ToInstanceUpdateMap() (map[string]interface{}, error)
}

//UpdateOpts is a struct which represents the parameters of update function
type UpdateOpts struct {
// Indicates the name of an instance.
// An instance name starts with a letter,
// consists of 4 to 64 characters,
// and supports only letters, digits, and hyphens (-).
Name string `json:"name,omitempty"`

// Indicates the description of an instance.
// It is a character string containing not more than 1024 characters.
Description string `json:"description,omitempty"`

// Indicates the time at which a maintenance time window starts.
// Format: HH:mm:ss
MaintainBegin string `json:"maintain_begin,omitempty"`

// Indicates the time at which a maintenance time window ends.
// Format: HH:mm:ss
MaintainEnd string `json:"maintain_end,omitempty"`

// Indicates the ID of a security group.
SecurityGroupID string `json:"security_group_id,omitempty"`
}

// ToInstanceUpdateMap is used for type convert
func (opts UpdateOpts) ToInstanceUpdateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "")
}

// Update is a method which can be able to update the instance
// via accessing to the service with Put method and parameters
func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
body, err := opts.ToInstanceUpdateMap()
if err != nil {
r.Err = err
return
}

_, r.Err = client.Put(updateURL(client, id), body, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{204},
})
return
}

// Get a instance with detailed information by id
func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
_, r.Err = client.Get(getURL(client, id), &r.Body, nil)
return
}
Loading