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
8 changes: 8 additions & 0 deletions openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,14 @@ func NewComputeV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (
return sc, err
}

func NewRdsTagV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "network")
sc.Endpoint = strings.Replace(sc.Endpoint, "vpc", "rds", 1)
sc.Endpoint = sc.Endpoint + "v1/"
sc.ResourceBase = sc.Endpoint + client.ProjectID + "/rds/"
return sc, err
}

//NewAutoScalingService creates a ServiceClient that may be used to access the
//auto-scaling service of huawei public cloud
func NewAutoScalingService(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
Expand Down
79 changes: 79 additions & 0 deletions openstack/rds/v1/tags/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package tags

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

var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{
MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
}

// Tag is a structure of key value pair.
type CreateOpts struct {
//tag key
Key string `json:"key" required:"true"`
//tag value
Value string `json:"value" required:"true"`
}

type DeleteOpts struct {
//tag key
Key string `json:"key" required:"true"`
}

// ToCreateMap assembles a request body based on the contents of a
// CreateOpts.
func (opts CreateOpts) ToCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "tag")
}

// ToDeleteMap assembles a request body based on the contents of a
// DeleteOpts.
func (opts DeleteOpts) ToDeleteMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "")
}

type CreateOptsBuilder interface {
ToCreateMap() (map[string]interface{}, error)
}

type DeleteOptsBuilder interface {
ToDeleteMap() (map[string]interface{}, error)
}

// Create implements tag create request.
func Create(client *golangsdk.ServiceClient, id string, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(resourceURL(client, id), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: RequestOpts.MoreHeaders, JSONBody: nil,
})
return
}

// Delete implements tag delete request.
func Delete(client *golangsdk.ServiceClient, id string, opts DeleteOptsBuilder) (r DeleteResult) {
b, err := opts.ToDeleteMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.DeleteWithBody(resourceURL(client, id), b, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: RequestOpts.MoreHeaders, JSONBody: nil,
})
return
}

// Get implements tag get request.
func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
_, r.Err = client.Get(resourceURL(client, id), &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: RequestOpts.MoreHeaders, JSONBody: nil,
})
return
}
39 changes: 39 additions & 0 deletions openstack/rds/v1/tags/results.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package tags

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

type Tag struct {
//tag key
Key string `json:"key"`
//tag value
Value string `json:"value"`
}

type RespTags struct {
//contains list of tags, i.e.key value pair
Tags []Tag `json:"tags"`
}

type commonResult struct {
golangsdk.Result
}

type CreateResult struct {
golangsdk.ErrResult
}

type DeleteResult struct {
golangsdk.ErrResult
}

type GetResult struct {
commonResult
}

func (r commonResult) Extract() (*RespTags, error) {
var response RespTags
err := r.ExtractInto(&response)
return &response, err
}
7 changes: 7 additions & 0 deletions openstack/rds/v1/tags/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package tags

import "github.com/huaweicloud/golangsdk"

func resourceURL(c *golangsdk.ServiceClient, id string) string {
return c.ServiceURL(id, "tags")
}