forked from oVirt/go-ovirt-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnic_get.go
53 lines (50 loc) · 1.17 KB
/
nic_get.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
package ovirtclient
import (
"fmt"
)
func (o *oVirtClient) GetNIC(vmid VMID, id NICID, retries ...RetryStrategy) (result NIC, err error) {
retries = defaultRetries(retries, defaultReadTimeouts(o))
err = retry(
fmt.Sprintf("getting NIC %s for VM %s", id, vmid),
o.logger,
retries,
func() error {
response, err := o.conn.SystemService().VmsService().VmService(string(vmid)).NicsService().NicService(string(id)).Get().Send()
if err != nil {
return err
}
sdkObject, ok := response.Nic()
if !ok {
return newError(
ENotFound,
"no NIC returned when getting NIC %s on VM %s",
id,
vmid,
)
}
result, err = convertSDKNIC(sdkObject, o)
if err != nil {
return wrap(
err,
EBug,
"failed to convert NIC %s on VM %s",
id,
vmid,
)
}
return nil
},
)
return result, err
}
func (m *mockClient) GetNIC(vmid VMID, id NICID, _ ...RetryStrategy) (NIC, error) {
m.lock.Lock()
defer m.lock.Unlock()
if nic, ok := m.nics[id]; ok {
if nic.vmid != vmid {
return nil, newError(ENotFound, "nic with ID %s not found", id)
}
return nic, nil
}
return nil, newError(ENotFound, "nic with ID %s not found", id)
}