| 1 |
package ecs |
| 2 |
|
| 3 |
import "github.com/denverdino/aliyungo/common" |
| 4 |
|
| 5 |
type TagResourceType string |
| 6 |
|
| 7 |
const ( |
| 8 |
TagResourceImage = TagResourceType("image") |
| 9 |
TagResourceInstance = TagResourceType("instance") |
| 10 |
TagResourceSnapshot = TagResourceType("snapshot") |
| 11 |
TagResourceDisk = TagResourceType("disk") |
| 12 |
) |
| 13 |
|
| 14 |
type AddTagsArgs struct { |
| 15 |
ResourceId string |
| 16 |
ResourceType TagResourceType |
| 17 |
RegionId common.Region |
| 18 |
Tag map[string]string |
| 19 |
} |
| 20 |
|
| 21 |
type AddTagsResponse struct { |
| 22 |
common.Response |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
func (client *Client) AddTags(args *AddTagsArgs) error { |
| 29 |
response := AddTagsResponse{} |
| 30 |
err := client.Invoke("AddTags", args, &response) |
| 31 |
return err |
| 32 |
} |
| 33 |
|
| 34 |
type RemoveTagsArgs struct { |
| 35 |
ResourceId string |
| 36 |
ResourceType TagResourceType |
| 37 |
RegionId common.Region |
| 38 |
Tag map[string]string |
| 39 |
} |
| 40 |
|
| 41 |
type RemoveTagsResponse struct { |
| 42 |
common.Response |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
func (client *Client) RemoveTags(args *RemoveTagsArgs) error { |
| 49 |
response := RemoveTagsResponse{} |
| 50 |
err := client.Invoke("RemoveTags", args, &response) |
| 51 |
return err |
| 52 |
} |
| 53 |
|
| 54 |
type ResourceItemType struct { |
| 55 |
ResourceId string |
| 56 |
ResourceType TagResourceType |
| 57 |
RegionId common.Region |
| 58 |
} |
| 59 |
|
| 60 |
type DescribeResourceByTagsArgs struct { |
| 61 |
ResourceType TagResourceType |
| 62 |
RegionId common.Region |
| 63 |
Tag map[string]string |
| 64 |
common.Pagination |
| 65 |
} |
| 66 |
|
| 67 |
type DescribeResourceByTagsResponse struct { |
| 68 |
common.Response |
| 69 |
common.PaginationResult |
| 70 |
Resources struct { |
| 71 |
Resource []ResourceItemType |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
func (client *Client) DescribeResourceByTags(args *DescribeResourceByTagsArgs) (resources []ResourceItemType, pagination *common.PaginationResult, err error) { |
| 79 |
response, err := client.DescribeResourceByTagsWithRaw(args) |
| 80 |
if err != nil { |
| 81 |
return nil, nil, err |
| 82 |
} |
| 83 |
return response.Resources.Resource, &response.PaginationResult, nil |
| 84 |
} |
| 85 |
|
| 86 |
func (client *Client) DescribeResourceByTagsWithRaw(args *DescribeResourceByTagsArgs) (response *DescribeResourceByTagsResponse, err error) { |
| 87 |
args.Validate() |
| 88 |
response = &DescribeResourceByTagsResponse{} |
| 89 |
err = client.Invoke("DescribeResourceByTags", args, response) |
| 90 |
if err != nil { |
| 91 |
return nil, err |
| 92 |
} |
| 93 |
return response, nil |
| 94 |
} |
| 95 |
|
| 96 |
type TagItemType struct { |
| 97 |
TagKey string |
| 98 |
TagValue string |
| 99 |
} |
| 100 |
|
| 101 |
type DescribeTagsArgs struct { |
| 102 |
RegionId common.Region |
| 103 |
ResourceType TagResourceType |
| 104 |
ResourceId string |
| 105 |
Tag map[string]string |
| 106 |
common.Pagination |
| 107 |
} |
| 108 |
|
| 109 |
type DescribeTagsResponse struct { |
| 110 |
common.Response |
| 111 |
common.PaginationResult |
| 112 |
Tags struct { |
| 113 |
Tag []TagItemType |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
func (client *Client) DescribeTags(args *DescribeTagsArgs) (tags []TagItemType, pagination *common.PaginationResult, err error) { |
| 121 |
args.Validate() |
| 122 |
response := DescribeTagsResponse{} |
| 123 |
err = client.Invoke("DescribeTags", args, &response) |
| 124 |
if err != nil { |
| 125 |
return nil, nil, err |
| 126 |
} |
| 127 |
return response.Tags.Tag, &response.PaginationResult, nil |
| 128 |
} |