Skip to content
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ install:
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/goimports
go:
- 1.8
- "1.9"
- "1.10"
- tip
env:
global:
Expand Down
18 changes: 18 additions & 0 deletions openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,21 @@ 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
}

// 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
}

// NewOBSService creates a ServiceClient that may be used to access the Object Storage Service.
func NewOBSService(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "object")
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)
}
240 changes: 240 additions & 0 deletions openstack/dcs/v1/instances/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
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,omitempty"`

// 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,omitempty"`

// 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" required:"true"`

// 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
}

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

//UpdatePasswordOpts is a struct which represents the parameters of update function
type UpdatePasswordOpts struct {
// Old password. It may be empty.
OldPassword string `json:"old_password" required:"true"`

// New password.
// Password complexity requirements:
// A string of 6–32 characters.
// Must be different from the old password.
// Contains at least two types of the following characters:
// Uppercase letters
// Lowercase letters
// Digits
// Special characters `~!@#$%^&*()-_=+\|[{}]:'",<.>/?
NewPassword string `json:"new_password" required:"true"`
}

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

// UpdatePassword is updating password for a dcs instance
func UpdatePassword(client *golangsdk.ServiceClient, id string, opts UpdatePasswordOptsBuilder) (r UpdatePasswordResult) {

body, err := opts.ToPasswordUpdateMap()
if err != nil {
r.Err = err
return
}

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