From 628eece89bcfe29d519edb48ba737cec29c3cb6e Mon Sep 17 00:00:00 2001 From: edisonxiang Date: Tue, 29 May 2018 15:52:27 +0800 Subject: [PATCH 1/4] add dms queue resource --- openstack/client.go | 6 ++ openstack/dms/v1/queues/requests.go | 94 +++++++++++++++++++++++++++++ openstack/dms/v1/queues/results.go | 78 ++++++++++++++++++++++++ openstack/dms/v1/queues/urls.go | 30 +++++++++ 4 files changed, 208 insertions(+) create mode 100644 openstack/dms/v1/queues/requests.go create mode 100644 openstack/dms/v1/queues/results.go create mode 100644 openstack/dms/v1/queues/urls.go diff --git a/openstack/client.go b/openstack/client.go index a3362cee3..d0f591a32 100644 --- a/openstack/client.go +++ b/openstack/client.go @@ -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 +} diff --git a/openstack/dms/v1/queues/requests.go b/openstack/dms/v1/queues/requests.go new file mode 100644 index 000000000..f3fba217c --- /dev/null +++ b/openstack/dms/v1/queues/requests.go @@ -0,0 +1,94 @@ +package queues + +import ( + "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/pagination" +) + +// CreateOpsBuilder is used for creating queue parameters. +// any struct providing the parameters should implement this interface +type CreateOpsBuilder interface { + ToQueueCreateMap() (map[string]interface{}, error) +} + +// CreateOps is a struct that contains all the parameters. +type CreateOps struct { + // Indicates the unique name of a queue. + // A string of 1 to 64 characters that contain + // a-z, A-Z, 0-9, hyphens (-), and underscores (_). + // The name cannot be modified once specified. + Name string `json:"name" required:"true"` + + // Indicates the queue type. Default value: NORMAL. Options: + // NORMAL: Standard queue. Best-effort ordering. + // FIFO: First-ln-First-out (FIFO) queue. FIFO delivery. + // KAFKA_HA: High-availability Kafka queue. + // KAFKA_HT: High-throughput Kafka queue. + // AMQP: Advanced Message Queuing Protocol (AMQP) queue. + QueueMode string `json:"queue_mode,omitempty"` + + // Indicates the basic information about a queue. + // The queue description must be 0 to 160 characters in length, + // and does not contain angle brackets (<) and (>). + Description string `json:"description,omitempty"` + + // This parameter is mandatory only when queue_mode is NORMAL or FIFO. + // Indicates whether to enable dead letter messages. + // Default value: disable. Options: enable, disable. + RedrivePolicy string `json:"redrive_policy,omitempty"` + + // This parameter is mandatory only when + // redrive_policy is set to enable. + // This parameter indicates the maximum number + // of allowed message consumption failures. + // Value range: 1-100. + MaxConsumeCount int `json:"max_consume_count,omitempty"` + + // This parameter is mandatory only when + // queue_mode is set to KAFKA_HA or KAFKA_HT. + // This parameter indicates the retention time + // of messages in Kafka queues. + // Value range: 1 to 72 hours. + RetentionHours int `json:"retention_hours,omitempty"` +} + +// ToQueueCreateMap is used for type convert +func (ops CreateOps) ToQueueCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(ops, "") +} + +// Create a queue with given parameters. +func Create(client *golangsdk.ServiceClient, ops CreateOpsBuilder) (r CreateResult) { + b, err := ops.ToQueueCreateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{201}, + }) + + return +} + +// Delete a queue by id +func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, id), nil) + return +} + +// Get a queue with detailed information by id +func Get(client *golangsdk.ServiceClient, id string, includeDeadLetter bool) (r GetResult) { + _, r.Err = client.Get(getURL(client, id, includeDeadLetter), &r.Body, nil) + return +} + +// List all the queues +func List(client *golangsdk.ServiceClient, includeDeadLetter bool) pagination.Pager { + url := listURL(client, includeDeadLetter) + + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return QueuePage{pagination.SinglePageBase(r)} + }) +} diff --git a/openstack/dms/v1/queues/results.go b/openstack/dms/v1/queues/results.go new file mode 100644 index 000000000..17b9c6523 --- /dev/null +++ b/openstack/dms/v1/queues/results.go @@ -0,0 +1,78 @@ +package queues + +import ( + "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/pagination" +) + +// QueueCreate response +type QueueCreate struct { + ID string `json:"id"` + Name string `json:"name"` + KafkaTopic string `json:"kafka_topic"` +} + +// CreateResult is a struct that contains all the return parameters of creation +type CreateResult struct { + golangsdk.Result +} + +// Extract from CreateResult +func (r CreateResult) Extract() (*QueueCreate, error) { + var s QueueCreate + err := r.Result.ExtractInto(&s) + return &s, err +} + +// DeleteResult is a struct which contains the result of deletion +type DeleteResult struct { + golangsdk.ErrResult +} + +// Queue response +type Queue struct { + ID string `json:"id"` + Name string `json:"name"` + Created string `json:"created"` + Description string `json:"description"` + QueueMode string `json:"queue_mode"` + Reservation int `json:"reservation"` + MaxMsgSizeByte int `json:"max_msg_size_byte"` + ProducedMessages int `json:"produced_messages"` + RedrivePolicy string `json:"redrive_policy"` + MaxConsumeCount int `json:"max_consume_count"` + GroupCount int `json:"group_count"` +} + +// GetResult contains the body of getting detailed +type GetResult struct { + golangsdk.Result +} + +// Extract from GetResult +func (r GetResult) Extract() (*Queue, error) { + var s Queue + err := r.Result.ExtractInto(&s) + return &s, err +} + +// QueuePage may be embedded in a Page +// that contains all of the results from an operation at once. +type QueuePage struct { + pagination.SinglePageBase +} + +// IsEmpty returns true if a ListResult contains no queues. +func (r QueuePage) IsEmpty() (bool, error) { + rs, err := ExtractQueues(r) + return len(rs) == 0, err +} + +// ExtractQueues from List +func ExtractQueues(r pagination.Page) ([]Queue, error) { + var s struct { + Queues []Queue `json:"queues"` + } + err := (r.(QueuePage)).ExtractInto(&s) + return s.Queues, err +} diff --git a/openstack/dms/v1/queues/urls.go b/openstack/dms/v1/queues/urls.go new file mode 100644 index 000000000..83bfdf07b --- /dev/null +++ b/openstack/dms/v1/queues/urls.go @@ -0,0 +1,30 @@ +package queues + +import ( + "fmt" + + "github.com/huaweicloud/golangsdk" +) + +// endpoint/queues +const resourcePath = "queues" + +// createURL will build the rest query url of creation +func createURL(client *golangsdk.ServiceClient) string { + return client.ServiceURL(resourcePath) +} + +// deleteURL will build the url of deletion +func deleteURL(client *golangsdk.ServiceClient, id string) string { + return client.ServiceURL(resourcePath, id) +} + +// getURL will build the get url of get function +func getURL(client *golangsdk.ServiceClient, id string, includeDeadLetter bool) string { + return client.ServiceURL(resourcePath, fmt.Sprintf("%s?include_deadletter=%t", id, includeDeadLetter)) +} + +// listURL will build the list url of list function +func listURL(client *golangsdk.ServiceClient, includeDeadLetter bool) string { + return client.ServiceURL(fmt.Sprintf("%s?include_deadletter=%t", resourcePath, includeDeadLetter)) +} From 885e0c6293fe3afe3df267b44e5b319ae65e9eaf Mon Sep 17 00:00:00 2001 From: edisonxiang Date: Tue, 29 May 2018 19:56:05 +0800 Subject: [PATCH 2/4] add dms group resource --- openstack/dms/v1/groups/requests.go | 61 ++++++++++++++++++++++++++++ openstack/dms/v1/groups/results.go | 63 +++++++++++++++++++++++++++++ openstack/dms/v1/groups/urls.go | 26 ++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 openstack/dms/v1/groups/requests.go create mode 100644 openstack/dms/v1/groups/results.go create mode 100644 openstack/dms/v1/groups/urls.go diff --git a/openstack/dms/v1/groups/requests.go b/openstack/dms/v1/groups/requests.go new file mode 100644 index 000000000..e73310643 --- /dev/null +++ b/openstack/dms/v1/groups/requests.go @@ -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)} + }) +} diff --git a/openstack/dms/v1/groups/results.go b/openstack/dms/v1/groups/results.go new file mode 100644 index 000000000..27ba9ef86 --- /dev/null +++ b/openstack/dms/v1/groups/results.go @@ -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 +} diff --git a/openstack/dms/v1/groups/urls.go b/openstack/dms/v1/groups/urls.go new file mode 100644 index 000000000..ccba6c887 --- /dev/null +++ b/openstack/dms/v1/groups/urls.go @@ -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)) +} From 0b6e98f92463876b10628732a059d26061bbe879 Mon Sep 17 00:00:00 2001 From: edisonxiang Date: Wed, 30 May 2018 09:47:15 +0800 Subject: [PATCH 3/4] add dms instance resource --- openstack/dms/v1/instances/requests.go | 154 +++++++++++++++++++++++++ openstack/dms/v1/instances/results.go | 78 +++++++++++++ openstack/dms/v1/instances/urls.go | 26 +++++ 3 files changed, 258 insertions(+) create mode 100644 openstack/dms/v1/instances/requests.go create mode 100644 openstack/dms/v1/instances/results.go create mode 100644 openstack/dms/v1/instances/urls.go diff --git a/openstack/dms/v1/instances/requests.go b/openstack/dms/v1/instances/requests.go new file mode 100644 index 000000000..29cc9a277 --- /dev/null +++ b/openstack/dms/v1/instances/requests.go @@ -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 +} diff --git a/openstack/dms/v1/instances/results.go b/openstack/dms/v1/instances/results.go new file mode 100644 index 000000000..3ab328518 --- /dev/null +++ b/openstack/dms/v1/instances/results.go @@ -0,0 +1,78 @@ +package instances + +import ( + "github.com/huaweicloud/golangsdk" +) + +// InstanceCreate response +type InstanceCreate struct { + InstanceID string `json:"instance_id"` +} + +// CreateResult is a struct that contains all the return parameters of creation +type CreateResult struct { + golangsdk.Result +} + +// Extract from CreateResult +func (r CreateResult) Extract() (*InstanceCreate, error) { + var s InstanceCreate + err := r.Result.ExtractInto(&s) + return &s, err +} + +// DeleteResult is a struct which contains the result of deletion +type DeleteResult struct { + golangsdk.ErrResult +} + +// Instance response +type Instance struct { + Name string `json:"name"` + Engine string `json:"engine"` + EngineVersion string `json:"engine_version"` + Specification string `json:"specification"` + StorageSpace int `json:"storage_space"` + UsedStorageSpace int `json:"used_storage_space"` + ConnectAddress string `json:"connect_address"` + Port int `json:"port"` + Status string `json:"status"` + Description string `json:"description"` + InstanceID string `json:"instance_id"` + ResourceSpecCode string `json:"resource_spec_code"` + Type string `json:"type"` + ChargingMode string `json:"charging_mode"` + VPCID string `json:"vpc_id"` + VPCName string `json:"vpc_name"` + CreatedAt string `json:"created_at"` + ErrorCode string `json:"error_code"` + ProductID string `json:"product_id"` + SecurityGroupID string `json:"security_group_id"` + SecurityGroupName string `json:"security_group_name"` + SubnetID string `json:"subnet_id"` + SubnetName string `json:"subnet_name"` + SubnetCIDR string `json:"subnet_cidr"` + AvailableZones []string `json:"available_zones"` + UserID string `json:"user_id"` + UserName string `json:"user_name"` + OrderID string `json:"order_id"` + MaintainBegin string `json:"maintain_begin"` + MaintainEnd string `json:"maintain_end"` +} + +// UpdateResult is a struct from which can get the result of update method +type UpdateResult struct { + golangsdk.Result +} + +// GetResult contains the body of getting detailed +type GetResult struct { + golangsdk.Result +} + +// Extract from GetResult +func (r GetResult) Extract() (*Instance, error) { + var s Instance + err := r.Result.ExtractInto(&s) + return &s, err +} diff --git a/openstack/dms/v1/instances/urls.go b/openstack/dms/v1/instances/urls.go new file mode 100644 index 000000000..9308ec2c8 --- /dev/null +++ b/openstack/dms/v1/instances/urls.go @@ -0,0 +1,26 @@ +package instances + +import "github.com/huaweicloud/golangsdk" + +// endpoint/instances +const resourcePath = "instances" + +// createURL will build the rest query url of creation +func createURL(client *golangsdk.ServiceClient) string { + return client.ServiceURL(resourcePath) +} + +// deleteURL will build the url of deletion +func deleteURL(client *golangsdk.ServiceClient, id string) string { + return client.ServiceURL(resourcePath, id) +} + +// updateURL will build the url of update +func updateURL(c *golangsdk.ServiceClient, id string) string { + return c.ServiceURL(resourcePath, id) +} + +// getURL will build the get url of get function +func getURL(client *golangsdk.ServiceClient, id string) string { + return client.ServiceURL(resourcePath, id) +} From e5c5bd9fb4d34e1aec1039d24ef619cf6fdda81b Mon Sep 17 00:00:00 2001 From: edisonxiang Date: Wed, 30 May 2018 11:43:50 +0800 Subject: [PATCH 4/4] add dms other resources --- openstack/dms/v1/availablezones/requests.go | 11 ++++ openstack/dms/v1/availablezones/results.go | 32 ++++++++++++ openstack/dms/v1/availablezones/urls.go | 16 ++++++ openstack/dms/v1/maintainwindows/requests.go | 11 ++++ openstack/dms/v1/maintainwindows/results.go | 30 +++++++++++ openstack/dms/v1/maintainwindows/urls.go | 16 ++++++ openstack/dms/v1/products/requests.go | 11 ++++ openstack/dms/v1/products/results.go | 53 ++++++++++++++++++++ openstack/dms/v1/products/urls.go | 16 ++++++ 9 files changed, 196 insertions(+) create mode 100644 openstack/dms/v1/availablezones/requests.go create mode 100644 openstack/dms/v1/availablezones/results.go create mode 100644 openstack/dms/v1/availablezones/urls.go create mode 100644 openstack/dms/v1/maintainwindows/requests.go create mode 100644 openstack/dms/v1/maintainwindows/results.go create mode 100644 openstack/dms/v1/maintainwindows/urls.go create mode 100644 openstack/dms/v1/products/requests.go create mode 100644 openstack/dms/v1/products/results.go create mode 100644 openstack/dms/v1/products/urls.go diff --git a/openstack/dms/v1/availablezones/requests.go b/openstack/dms/v1/availablezones/requests.go new file mode 100644 index 000000000..47d242ca3 --- /dev/null +++ b/openstack/dms/v1/availablezones/requests.go @@ -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 +} diff --git a/openstack/dms/v1/availablezones/results.go b/openstack/dms/v1/availablezones/results.go new file mode 100644 index 000000000..b2d9ecbd4 --- /dev/null +++ b/openstack/dms/v1/availablezones/results.go @@ -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 +} diff --git a/openstack/dms/v1/availablezones/urls.go b/openstack/dms/v1/availablezones/urls.go new file mode 100644 index 000000000..9ce0f01e8 --- /dev/null +++ b/openstack/dms/v1/availablezones/urls.go @@ -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) +} diff --git a/openstack/dms/v1/maintainwindows/requests.go b/openstack/dms/v1/maintainwindows/requests.go new file mode 100644 index 000000000..4f866c638 --- /dev/null +++ b/openstack/dms/v1/maintainwindows/requests.go @@ -0,0 +1,11 @@ +package maintainwindows + +import ( + "github.com/huaweicloud/golangsdk" +) + +// Get maintain windows +func Get(client *golangsdk.ServiceClient) (r GetResult) { + _, r.Err = client.Get(getURL(client), &r.Body, nil) + return +} diff --git a/openstack/dms/v1/maintainwindows/results.go b/openstack/dms/v1/maintainwindows/results.go new file mode 100644 index 000000000..1327e2dbb --- /dev/null +++ b/openstack/dms/v1/maintainwindows/results.go @@ -0,0 +1,30 @@ +package maintainwindows + +import ( + "github.com/huaweicloud/golangsdk" +) + +// GetResponse response +type GetResponse struct { + MaintainWindows []MaintainWindow `json:"maintain_windows"` +} + +// MaintainWindow for dms +type MaintainWindow struct { + ID int `json:"seq"` + Begin string `json:"begin"` + End string `json:"end"` + Default bool `json:"default"` +} + +// 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 +} diff --git a/openstack/dms/v1/maintainwindows/urls.go b/openstack/dms/v1/maintainwindows/urls.go new file mode 100644 index 000000000..b5d8186b7 --- /dev/null +++ b/openstack/dms/v1/maintainwindows/urls.go @@ -0,0 +1,16 @@ +package maintainwindows + +import ( + "strings" + + "github.com/huaweicloud/golangsdk" +) + +// endpoint/instances/maintain-windows +const resourcePath = "instances/maintain-windows" + +// 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) +} diff --git a/openstack/dms/v1/products/requests.go b/openstack/dms/v1/products/requests.go new file mode 100644 index 000000000..5542f6e0f --- /dev/null +++ b/openstack/dms/v1/products/requests.go @@ -0,0 +1,11 @@ +package products + +import ( + "github.com/huaweicloud/golangsdk" +) + +// Get products +func Get(client *golangsdk.ServiceClient) (r GetResult) { + _, r.Err = client.Get(getURL(client), &r.Body, nil) + return +} diff --git a/openstack/dms/v1/products/results.go b/openstack/dms/v1/products/results.go new file mode 100644 index 000000000..333e87ba1 --- /dev/null +++ b/openstack/dms/v1/products/results.go @@ -0,0 +1,53 @@ +package products + +import ( + "github.com/huaweicloud/golangsdk" +) + +// GetResponse response +type GetResponse struct { + Hourly []Parameter `json:"Hourly"` + Monthly []Parameter `json:"Monthly"` +} + +// Parameter for dms +type Parameter struct { + Name string `json:"name"` + Version string `json:"version"` + Values []Value `json:"values"` +} + +// Value for dms +type Value struct { + Details []Detail `json:"detail"` + Name string `json:"name"` +} + +// Detail for dms +type Detail struct { + Storage string `json:"storage"` + ProductID string `json:"product_id"` + SpecCode string `json:"spec_code"` + VMSpecification string `json:"vm_specification"` + ProductInfos []ProductInfo `json:"product_info"` +} + +// ProductInfo for dms +type ProductInfo struct { + Storage string `json:"storage"` + NodeNum int `json:"node_num"` + ProductID string `json:"product_id"` + SpecCode string `json:"spec_code"` +} + +// 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 +} diff --git a/openstack/dms/v1/products/urls.go b/openstack/dms/v1/products/urls.go new file mode 100644 index 000000000..6ac6acc75 --- /dev/null +++ b/openstack/dms/v1/products/urls.go @@ -0,0 +1,16 @@ +package products + +import ( + "strings" + + "github.com/huaweicloud/golangsdk" +) + +// endpoint/products +const resourcePath = "products" + +// 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) +}