summaryrefslogtreecommitdiff
path: root/vendor/github.com/mitchellh/packer/vendor/github.com/denverdino/aliyungo/ecs/tags.go
blob: 5ffd4931aa6cff09a7892f789369ed511160ac89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package ecs

import "github.com/denverdino/aliyungo/common"

type TagResourceType string

const (
	TagResourceImage    = TagResourceType("image")
	TagResourceInstance = TagResourceType("instance")
	TagResourceSnapshot = TagResourceType("snapshot")
	TagResourceDisk     = TagResourceType("disk")
)

type AddTagsArgs struct {
	ResourceId   string
	ResourceType TagResourceType //image, instance, snapshot or disk
	RegionId     common.Region
	Tag          map[string]string
}

type AddTagsResponse struct {
	common.Response
}

// AddTags Add tags to resource
//
// You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/tags&addtags
func (client *Client) AddTags(args *AddTagsArgs) error {
	response := AddTagsResponse{}
	err := client.Invoke("AddTags", args, &response)
	return err
}

type RemoveTagsArgs struct {
	ResourceId   string
	ResourceType TagResourceType //image, instance, snapshot or disk
	RegionId     common.Region
	Tag          map[string]string
}

type RemoveTagsResponse struct {
	common.Response
}

// RemoveTags remove tags to resource
//
// You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/tags&removetags
func (client *Client) RemoveTags(args *RemoveTagsArgs) error {
	response := RemoveTagsResponse{}
	err := client.Invoke("RemoveTags", args, &response)
	return err
}

type ResourceItemType struct {
	ResourceId   string
	ResourceType TagResourceType
	RegionId     common.Region
}

type DescribeResourceByTagsArgs struct {
	ResourceType TagResourceType //image, instance, snapshot or disk
	RegionId     common.Region
	Tag          map[string]string
	common.Pagination
}

type DescribeResourceByTagsResponse struct {
	common.Response
	common.PaginationResult
	Resources struct {
		Resource []ResourceItemType
	}
}

// DescribeResourceByTags describe resource by tags
//
// You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/tags&describeresourcebytags
func (client *Client) DescribeResourceByTags(args *DescribeResourceByTagsArgs) (resources []ResourceItemType, pagination *common.PaginationResult, err error) {
	args.Validate()
	response := DescribeResourceByTagsResponse{}
	err = client.Invoke("DescribeResourceByTags", args, &response)
	if err != nil {
		return nil, nil, err
	}
	return response.Resources.Resource, &response.PaginationResult, nil
}

type TagItemType struct {
	TagKey   string
	TagValue string
}

type DescribeTagsArgs struct {
	RegionId     common.Region
	ResourceType TagResourceType //image, instance, snapshot or disk
	ResourceId   string
	Tag          map[string]string
	common.Pagination
}

type DescribeTagsResponse struct {
	common.Response
	common.PaginationResult
	Tags struct {
		Tag []TagItemType
	}
}

// DescribeResourceByTags describe resource by tags
//
// You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/tags&describeresourcebytags
func (client *Client) DescribeTags(args *DescribeTagsArgs) (tags []TagItemType, pagination *common.PaginationResult, err error) {
	args.Validate()
	response := DescribeTagsResponse{}
	err = client.Invoke("DescribeTags", args, &response)
	if err != nil {
		return nil, nil, err
	}
	return response.Tags.Tag, &response.PaginationResult, nil
}