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

func NewEcsV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "ecs")
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)
Expand Down
61 changes: 61 additions & 0 deletions openstack/ecs/v1/cloudservertags/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cloudservertags

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

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

// BatchOptsBuilder allows extensions to add additional parameters to the
// BatchAction request.
type BatchOptsBuilder interface {
ToTagsBatchMap() (map[string]interface{}, error)
}

// BatchOpts contains all the values needed to perform BatchAction on the instance tags.
type BatchOpts struct {
//List of tags to perform batch operation
Tags []Tag `json:"tags,omitempty"`
//Operator , Possible values are:create, update,delete
Action ActionType `json:"action" required:"true"`
}

//ActionType specifies the type of batch operation action to be performed
type ActionType string

var (
// ActionCreate is used to set action operator to create
ActionCreate ActionType = "create"
// ActionDelete is used to set action operator to delete
ActionDelete ActionType = "delete"
)

// ToTagsBatchMap builds a BatchAction request body from BatchOpts.
func (opts BatchOpts) ToTagsBatchMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "")
}

//BatchAction is used to create ,update or delete the tags of a specified instance.
func BatchAction(client *golangsdk.ServiceClient, serverID string, opts BatchOptsBuilder) (r ActionResults) {
b, err := opts.ToTagsBatchMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(actionURL(client, serverID), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{204},
})
return
}

// Get retrieves the tags of a specific instance.
func Get(client *golangsdk.ServiceClient, serverID string) (r GetResult) {
_, r.Err = client.Get(resourceURL(client, serverID), &r.Body, nil)
return
}
28 changes: 28 additions & 0 deletions openstack/ecs/v1/cloudservertags/results.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cloudservertags

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

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

type commonResult struct {
golangsdk.Result
}

type ActionResults struct {
commonResult
}

type GetResult struct {
commonResult
}

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

import "github.com/huaweicloud/golangsdk"

const (
rootPath = "cloudservers"
resourcePath = "tags"
actionPath = "tags/action"
)

func actionURL(c *golangsdk.ServiceClient, id string) string {
return c.ServiceURL(rootPath, id, actionPath)
}

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