Skip to content

Commit 16e9b9b

Browse files
committed
Add UpdateGuestNetworkInterface
While both Drive and NetworkInterface can have RateLimiters on creation, updating RateLimiters is only supported by NetworkInterface (via PartialNetworkInterface). Fixes #66.
1 parent a585107 commit 16e9b9b

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

firecracker.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,27 @@ func (f *Client) PutGuestNetworkInterfaceByID(ctx context.Context, ifaceID strin
141141
return f.client.Operations.PutGuestNetworkInterfaceByID(cfg)
142142
}
143143

144+
// PatchGuestNetworkInterfaceByIDOpt is a functional option to be used for the
145+
// PatchGuestNetworkInterfaceByID API in setting any additional optional fields.
146+
type PatchGuestNetworkInterfaceByIDOpt func(*ops.PatchGuestNetworkInterfaceByIDParams)
147+
148+
// PatchGuestNetworkInterfaceByID is a wrapper for the swagger generated client to make calling of the
149+
// API easier.
150+
func (f *Client) PatchGuestNetworkInterfaceByID(ctx context.Context, ifaceID string, ifaceCfg *models.PartialNetworkInterface, opts ...PatchGuestNetworkInterfaceByIDOpt) (*ops.PatchGuestNetworkInterfaceByIDNoContent, error) {
151+
timeout, cancel := context.WithTimeout(ctx, firecrackerRequestTimeout)
152+
defer cancel()
153+
154+
cfg := ops.NewPatchGuestNetworkInterfaceByIDParamsWithContext(timeout)
155+
cfg.SetBody(ifaceCfg)
156+
cfg.SetIfaceID(ifaceID)
157+
158+
for _, opt := range opts {
159+
opt(cfg)
160+
}
161+
162+
return f.client.Operations.PatchGuestNetworkInterfaceByID(cfg)
163+
}
164+
144165
// PutGuestDriveByIDOpt is a functional option to be used for the
145166
// PutGuestDriveByID API in setting any additional optional fields.
146167
type PutGuestDriveByIDOpt func(*ops.PutGuestDriveByIDParams)

machine.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,17 @@ func (m *Machine) createNetworkInterface(ctx context.Context, iface NetworkInter
564564
return err
565565
}
566566

567+
// UpdateGuestNetworkInterface modifies the current guest network interface of ID index
568+
func (m *Machine) UpdateGuestNetworkInterface(ctx context.Context, ifaceID string, iface models.PartialNetworkInterface, opts ...PatchGuestNetworkInterfaceByIDOpt) error {
569+
if _, err := m.client.PatchGuestNetworkInterfaceByID(ctx, ifaceID, &iface, opts...); err != nil {
570+
m.logger.Errorf("Update network interface failed: %s: %v", ifaceID, err)
571+
return err
572+
}
573+
574+
m.logger.Infof("Updated network interface: %s", ifaceID)
575+
return nil
576+
}
577+
567578
// attachDrive attaches a secondary block device
568579
func (m *Machine) attachDrive(ctx context.Context, dev models.Drive) error {
569580
hostPath := StringValue(dev.PathOnHost)

machineiface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ package firecracker
1515

1616
import (
1717
"context"
18+
19+
models "github.com/firecracker-microvm/firecracker-go-sdk/client/models"
1820
)
1921

2022
// This ensures the interface method signatures match that of Machine
@@ -29,4 +31,5 @@ type MachineIface interface {
2931
Wait(context.Context) error
3032
SetMetadata(context.Context, interface{}) error
3133
UpdateGuestDrive(context.Context, string, string, ...PatchGuestDriveByIDOpt) error
34+
UpdateGuestNetworkInterface(context.Context, string, models.PartialNetworkInterface, ...PatchGuestNetworkInterfaceByIDOpt) error
3235
}

0 commit comments

Comments
 (0)