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 @@ -499,3 +499,9 @@ func NewDMSServiceV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts
sc, err := initClientOpts(client, eo, "dms")
return sc, err
}

// NewDCSServiceV1 creates a ServiceClient that may be used to access the v1 Distributed Cache Service.
func NewDCSServiceV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "dcs")
return sc, err
}
11 changes: 11 additions & 0 deletions openstack/dcs/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/dcs/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 dcs
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/dcs/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)
}
198 changes: 198 additions & 0 deletions openstack/dcs/v1/instances/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
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 {
// DCS instance name.
// An instance name is a string of 4–64 characters
// that contain letters, digits, underscores (_), and hyphens (-).
// An instance name must start with letters.
Name string `json:"name" required:"true"`

// Brief description of the DCS instance.
// A brief description supports up to 1024 characters.
Description string `json:"description,omitempty"`

// Cache engine, which is Redis.
Engine string `json:"engine" required:"true"`

// Cache engine version, which is 3.0.7.
EngineVersion string `json:"engine_version" required:"true"`

// Indicates the message storage space.
// Cache capacity.

// Unit: GB.
// For a DCS Redis instance in single-node or master/standby mode,
// the cache capacity can be 2 GB, 4 GB, 8 GB, 16 GB, 32 GB, or 64 GB.
// For a DCS Redis instance in cluster mode, the cache capacity can be
// 64, 128, 256, 512, or 1024 GB.
Capacity int `json:"capacity" required:"true"`

// Indicates the password of an instance.
// An instance password must meet the following complexity requirements:

// Password of a DCS instance.
// The password of a DCS Redis instance must meet
// the following complexity requirements:
// A string of 6–32 characters.
// Contains at least two of the following character types:
// Uppercase letters
// Lowercase letters
// Digits
// Special characters, such as `~!@#$%^&*()-_=+\|[{}]:'",<.>/?
Password string `json:"password" required:"true"`

// Tenant's VPC ID.
VPCID string `json:"vpc_id" required:"true"`

// Tenant's security group ID.
SecurityGroupID string `json:"security_group_id" required:"true"`

// Subnet ID.
SubnetID string `json:"subnet_id" required:"true"`

// IDs of the AZs where cache nodes reside.
// In the current version, only one AZ ID can be set in the request.
AvailableZones []string `json:"available_zones,omitempty"`

// Product ID used to differentiate DCS instance types.
ProductID string `json:"product_id" required:"true"`

// Backup policy.
// This parameter is available for master/standby DCS instances.
InstanceBackupPolicy InstanceBackupPolicy `json:"instance_backup_policy,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"`
}

// InstanceBackupPolicy for dcs
type InstanceBackupPolicy struct {
// Retention time.
// Unit: day.
// Range: 1–7.
SaveDays int `json:"save_days" required:"true"`

// Backup type. Options:
// auto: automatic backup.
// manual: manual backup.
BackupType string `json:"backup_type" required:"true"`

// Backup plan.
PeriodicalBackupPlan PeriodicalBackupPlan `json:"periodical_backup_plan" required:"true"`
}

// PeriodicalBackupPlan for dcs
type PeriodicalBackupPlan struct {
// Time at which backup starts.
// "00:00-01:00" indicates that backup starts at 00:00:00.
BeginAt int `json:"begin_at" required:"true"`

// Interval at which backup is performed.
// Currently, only weekly backup is supported.
PeriodType string `json:"period_type" required:"true"`

// Day in a week on which backup starts.
// Range: 1–7. Where: 1 indicates Monday; 7 indicates Sunday.
BackupAt []int `json:"backup_at" required:"true"`
}

// 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 {
// DCS instance name.
// An instance name is a string of 4–64 characters
// that contain letters, digits, underscores (_), and hyphens (-).
// An instance name must start with letters.
Name string `json:"name,omitempty"`

// Brief description of the DCS instance.
// A brief description supports up to 1024 characters.
Description string `json:"description,omitempty"`

// Backup policy.
// This parameter is available for master/standby DCS instances.
InstanceBackupPolicy InstanceBackupPolicy `json:"instance_backup_policy,omitempty"`

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

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

// Security group ID.
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
}
79 changes: 79 additions & 0 deletions openstack/dcs/v1/instances/results.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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"`
Capacity int `json:"capacity"`
IP string `json:"ip"`
Port int `json:"port"`
Status string `json:"status"`
Description string `json:"description"`
InstanceID string `json:"instance_id"`
ResourceSpecCode string `json:"resource_spec_code"`
EngineVersion string `json:"engine_version"`
InternalVersion string `json:"internal_version"`
ChargingMode int `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"`
MaxMemory int `json:"max_memory"`
UsedMemory int `json:"used_memory"`
InstanceBackupPolicy InstanceBackupPolicy `json:"instance_backup_policy"`
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
}
26 changes: 26 additions & 0 deletions openstack/dcs/v1/instances/urls.go
Original file line number Diff line number Diff line change
@@ -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)
}
11 changes: 11 additions & 0 deletions openstack/dcs/v1/maintainwindows/requests.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading