-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathnic_update.go
89 lines (81 loc) · 2.3 KB
/
nic_update.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
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
package ovirtclient
import (
"fmt"
"net"
ovirtsdk "github.com/ovirt/go-ovirt"
)
func (o *oVirtClient) UpdateNIC(
vmid VMID,
nicID NICID,
params UpdateNICParameters,
retries ...RetryStrategy,
) (result NIC, err error) {
req := o.conn.SystemService().VmsService().VmService(string(vmid)).NicsService().NicService(string(nicID)).Update()
nicBuilder := ovirtsdk.NewNicBuilder().Id(string(nicID))
if name := params.Name(); name != nil {
nicBuilder.Name(*name)
}
if vnicProfileID := params.VNICProfileID(); vnicProfileID != nil {
nicBuilder.VnicProfile(ovirtsdk.NewVnicProfileBuilder().Id(string(*vnicProfileID)).MustBuild())
}
if mac := params.Mac(); mac != nil {
if _, err := net.ParseMAC(*mac); err != nil {
return nil, newError(EUnidentified, "Failed to parse MacAddress: %s", *mac)
}
nicBuilder.Mac(ovirtsdk.NewMacBuilder().Address(*mac).MustBuild())
}
req.Nic(nicBuilder.MustBuild())
retries = defaultRetries(retries, defaultReadTimeouts(o))
err = retry(
fmt.Sprintf("updating NIC %s for VM %s", nicID, vmid),
o.logger,
retries,
func() error {
update, err := req.Send()
if err != nil {
return wrap(err, EUnidentified, "Failed to update NIC %s", nicID)
}
sdkNIC, ok := update.Nic()
if !ok {
return newFieldNotFound("NIC update response", "NIC")
}
nic, err := convertSDKNIC(sdkNIC, o)
if err != nil {
return err
}
result = nic
return nil
})
return result, err
}
func (m *mockClient) UpdateNIC(vmid VMID, nicID NICID, params UpdateNICParameters, retries ...RetryStrategy) (
NIC,
error,
) {
m.lock.Lock()
defer m.lock.Unlock()
nic, ok := m.nics[nicID]
if !ok {
return nil, newError(ENotFound, "NIC not found")
}
if nic.vmid != vmid {
return nil, newError(ENotFound, "NIC not found")
}
if name := params.Name(); name != nil {
nic = nic.withName(*name)
}
if vnicProfileID := params.VNICProfileID(); vnicProfileID != nil {
if _, ok := m.vnicProfiles[*vnicProfileID]; !ok {
return nil, newError(ENotFound, "VNIC profile %s not found", *vnicProfileID)
}
nic = nic.withVNICProfileID(*vnicProfileID)
}
if mac := params.Mac(); mac != nil {
if _, err := net.ParseMAC(*mac); err != nil {
return nil, newError(EUnidentified, "Failed to parse MacAddress: %s", *mac)
}
nic = nic.withMac(*mac)
}
m.nics[nicID] = nic
return nic, nil
}