-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtag_create.go
62 lines (55 loc) · 1.32 KB
/
tag_create.go
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
package ovirtclient
import (
ovirtsdk "github.com/ovirt/go-ovirt"
)
func (o *oVirtClient) CreateTag(name string, params CreateTagParams, retries ...RetryStrategy) (result Tag, err error) {
retries = defaultRetries(retries, defaultReadTimeouts(o))
if params == nil {
params = NewCreateTagParams()
}
err = retry(
"creating tag",
o.logger,
retries,
func() error {
tagBuilder := ovirtsdk.NewTagBuilder().Name(name)
if description := params.Description(); description != nil {
tagBuilder.Description(*description)
}
response, e := o.conn.SystemService().TagsService().Add().Tag(tagBuilder.MustBuild()).Send()
if e != nil {
return e
}
tag, ok := response.Tag()
if !ok {
return newError(EFieldMissing, "missing Tag in response")
}
result, err = convertSDKTag(tag, o)
if err != nil {
return wrap(
err,
EBug,
"failed to convert Tag",
)
}
return nil
})
return result, err
}
func (m *mockClient) CreateTag(name string, params CreateTagParams, _ ...RetryStrategy) (result Tag, err error) {
m.lock.Lock()
defer m.lock.Unlock()
id := TagID(m.GenerateUUID())
if params == nil {
params = NewCreateTagParams()
}
tag := &tag{
client: m,
id: id,
name: name,
description: params.Description(),
}
m.tags[id] = tag
result = tag
return
}