diff --git a/openstack/client.go b/openstack/client.go index d0f591a32..09f11dbd6 100644 --- a/openstack/client.go +++ b/openstack/client.go @@ -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 +} diff --git a/openstack/dcs/v1/availablezones/requests.go b/openstack/dcs/v1/availablezones/requests.go new file mode 100644 index 000000000..47d242ca3 --- /dev/null +++ b/openstack/dcs/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/dcs/v1/availablezones/results.go b/openstack/dcs/v1/availablezones/results.go new file mode 100644 index 000000000..9b3949524 --- /dev/null +++ b/openstack/dcs/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 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 +} diff --git a/openstack/dcs/v1/availablezones/urls.go b/openstack/dcs/v1/availablezones/urls.go new file mode 100644 index 000000000..9ce0f01e8 --- /dev/null +++ b/openstack/dcs/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/dcs/v1/instances/requests.go b/openstack/dcs/v1/instances/requests.go new file mode 100644 index 000000000..68f0b3ff4 --- /dev/null +++ b/openstack/dcs/v1/instances/requests.go @@ -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 +} diff --git a/openstack/dcs/v1/instances/results.go b/openstack/dcs/v1/instances/results.go new file mode 100644 index 000000000..7ddf6d2b9 --- /dev/null +++ b/openstack/dcs/v1/instances/results.go @@ -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 +} diff --git a/openstack/dcs/v1/instances/urls.go b/openstack/dcs/v1/instances/urls.go new file mode 100644 index 000000000..9308ec2c8 --- /dev/null +++ b/openstack/dcs/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) +} diff --git a/openstack/dcs/v1/maintainwindows/requests.go b/openstack/dcs/v1/maintainwindows/requests.go new file mode 100644 index 000000000..4f866c638 --- /dev/null +++ b/openstack/dcs/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/dcs/v1/maintainwindows/results.go b/openstack/dcs/v1/maintainwindows/results.go new file mode 100644 index 000000000..2605249ec --- /dev/null +++ b/openstack/dcs/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 dcs +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/dcs/v1/maintainwindows/urls.go b/openstack/dcs/v1/maintainwindows/urls.go new file mode 100644 index 000000000..b5d8186b7 --- /dev/null +++ b/openstack/dcs/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/dcs/v1/products/requests.go b/openstack/dcs/v1/products/requests.go new file mode 100644 index 000000000..5542f6e0f --- /dev/null +++ b/openstack/dcs/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/dcs/v1/products/results.go b/openstack/dcs/v1/products/results.go new file mode 100644 index 000000000..48fafe9eb --- /dev/null +++ b/openstack/dcs/v1/products/results.go @@ -0,0 +1,34 @@ +package products + +import ( + "github.com/huaweicloud/golangsdk" +) + +// GetResponse response +type GetResponse struct { + Products []Product `json:"products"` +} + +// Product for dcs +type Product struct { + Price float64 `json:"price"` + Currency string `json:"currency"` + ProductID string `json:"product_id"` + SpecCode string `json:"spec_code"` + SpecDetails string `json:"spec_details"` + ChargingType string `json:"charging_type"` + SpecDetails2 string `json:"spec_details2"` + ProdType string `json:"prod_type"` +} + +// 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/dcs/v1/products/urls.go b/openstack/dcs/v1/products/urls.go new file mode 100644 index 000000000..6ac6acc75 --- /dev/null +++ b/openstack/dcs/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) +} diff --git a/openstack/dms/v1/instances/results.go b/openstack/dms/v1/instances/results.go index 3ab328518..7e82e9fa5 100644 --- a/openstack/dms/v1/instances/results.go +++ b/openstack/dms/v1/instances/results.go @@ -41,7 +41,7 @@ type Instance struct { InstanceID string `json:"instance_id"` ResourceSpecCode string `json:"resource_spec_code"` Type string `json:"type"` - ChargingMode string `json:"charging_mode"` + ChargingMode int `json:"charging_mode"` VPCID string `json:"vpc_id"` VPCName string `json:"vpc_name"` CreatedAt string `json:"created_at"`