File: doc.go

package info (click to toggle)
golang-github-gophercloud-utils 0.0~git20231010.80377ec-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 816 kB
  • sloc: sh: 20; makefile: 7
file content (135 lines) | stat: -rw-r--r-- 3,768 bytes parent folder | download | duplicates (3)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
Package resources provides the ability to retrieve resources through the Gnocchi API.

Example of Listing resources

	resourceType: "instance",
	listOpts := resources.ListOpts{
		Details: True,
	}

	allPages, err := resources.List(gnocchiClient, listOpts, resourceType).AllPages()
	if err != nil {
		panic(err)
	}

	allResources, err := resources.ExtractResources(allPages)
	if err != nil {
		panic(err)
	}

	for _, resource := range allResources {
		fmt.Printf("%+v\n", resource)
	}

Example of Getting a resource

	resourceID = "23d5d3f7-9dfa-4f73-b72b-8b0b0063ec55"
	resourceType = "generic"
	resource, err := resources.Get(gnocchiClient, resourceType, resourceID).Extract()
	if err != nil {
		panic(err)
	}

Example of Creating a resource without a metric

	createOpts := resources.CreateOpts{
		ID: "23d5d3f7-9dfa-4f73-b72b-8b0b0063ec55",
	}
	resourceType = "generic"
	resource, err := resources.Create(gnocchiClient, resourceType, createOpts).Extract()
	if err != nil {
		panic(err)
	}

Example of Creating a resource with links to some existing metrics with a starting timestamp of the resource

	startedAt := time.Date(2018, 1, 4, 10, 0, 0, 0, time.UTC)
	createOpts := resources.CreateOpts{
		ID: "23d5d3f7-9dfa-4f73-b72b-8b0b0063ec55",
		ProjectID: "4154f088-8333-4e04-94c4-1155c33c0fc9",
		StartedAt: &startedAt,
		Metrics: map[string]interface{}{
			"disk.read.bytes.rate": "ed1bb76f-6ccc-4ad2-994c-dbb19ddccbae",
			"disk.write.bytes.rate": "0a2da84d-4753-43f5-a65f-0f8d44d2766c",
		},
	}
	resourceType = "compute_instance_disk"
	resource, err := resources.Create(gnocchiClient, resourceType, createOpts).Extract()
	if err != nil {
		panic(err)
	}

Example of Creating a resource and a metric a the same time

	createOpts := resources.CreateOpts{
		ID: "23d5d3f7-9dfa-4f73-b72b-8b0b0063ec55",
		ProjectID: "4154f088-8333-4e04-94c4-1155c33c0fc9",
		UserID: "bd5874d6-6662-4b24-a9f01c128871e4ac",
		Metrics: map[string]interface{}{
			"cpu.delta": map[string]string{
				"archive_policy_name": "medium",
			},
		},
	}
	resourceType = "compute_instance"
	resource, err := resources.Create(gnocchiClient, resourceType, createOpts).Extract()
	if err != nil {
		panic(err)
	}

Example of Updating a resource

	updateOpts := resources.UpdateOpts{
		ProjectID: "4154f08883334e0494c41155c33c0fc9",
	}
	resourceType = "generic"
	resourceID = "23d5d3f7-9dfa-4f73-b72b-8b0b0063ec55"
	resource, err := resources.Update(gnocchiClient, resourceType, resourceID, updateOpts).Extract()
	if err != nil {
		panic(err)
	}

Example of Updating a resource and associating an existing metric to it

	endedAt := time.Date(2018, 1, 16, 12, 0, 0, 0, time.UTC)
	metrics := map[string]interface{}{
			"disk.write.bytes.rate": "0a2da84d-4753-43f5-a65f-0f8d44d2766c",
	}
	updateOpts := resources.UpdateOpts{
		EndedAt: &endedAt,
		Metrics: &metrics,
	}
	resourceType = "compute_instance_disk"
	resourceID = "23d5d3f7-9dfa-4f73-b72b-8b0b0063ec55"
	resource, err := resources.Update(gnocchiClient, resourceType, resourceID, updateOpts).Extract()
	if err != nil {
		panic(err)
	}

Example of Updating a resource and creating an associated metric at the same time

	metrics := map[string]interface{}{
		"cpu.delta": map[string]string{
			"archive_policy_name": "medium",
		},
	}
	updateOpts := resources.UpdateOpts{
		Metrics: &metrics,
	}
	resourceType = "compute_instance"
	resourceID = "23d5d3f7-9dfa-4f73-b72b-8b0b0063ec55"
	resource, err := resources.Update(gnocchiClient, resourceType, resourceID, updateOpts).Extract()
	if err != nil {
		panic(err)
	}

Example of Deleting a Gnocchi resource

	resourceID := "23d5d3f7-9dfa-4f73-b72b-8b0b0063ec55"
	err := resources.Delete(gnocchiClient, resourceType, resourceID).ExtractErr()
	if err != nil {
		panic(err)
	}
*/
package resources