golang/xenlight: add DeviceNicAdd/Remove wrappers
authorNick Rosbrook <rosbrookn@gmail.com>
Sun, 12 Apr 2020 22:02:40 +0000 (18:02 -0400)
committerGeorge Dunlap <george.dunlap@citrix.com>
Thu, 23 Apr 2020 10:30:54 +0000 (11:30 +0100)
Add DeviceNicAdd and DeviceNicRemove as wrappers for
libxl_device_nic_add and libxl_device_nic_remove.

Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
tools/golang/xenlight/xenlight.go

index 3f1b0baa0cb4d69aa04167f7cf036c50df94dec5..961939e947bd2496c1787ff253b107270b7619f9 100644 (file)
@@ -1045,3 +1045,37 @@ func (Ctx *Context) PrimaryConsoleGetTty(domid uint32) (path string, err error)
        path = C.GoString(cpath)
        return
 }
+
+// DeviceNicAdd adds a nic to a domain.
+func (Ctx *Context) DeviceNicAdd(domid Domid, nic *DeviceNic) error {
+       var cnic C.libxl_device_nic
+
+       if err := nic.toC(&cnic); err != nil {
+               return err
+       }
+       defer C.libxl_device_nic_dispose(&cnic)
+
+       ret := C.libxl_device_nic_add(Ctx.ctx, C.uint32_t(domid), &cnic, nil)
+       if ret != 0 {
+               return Error(ret)
+       }
+
+       return nil
+}
+
+// DeviceNicRemove removes a nic from a domain.
+func (Ctx *Context) DeviceNicRemove(domid Domid, nic *DeviceNic) error {
+       var cnic C.libxl_device_nic
+
+       if err := nic.toC(&cnic); err != nil {
+               return err
+       }
+       defer C.libxl_device_nic_dispose(&cnic)
+
+       ret := C.libxl_device_nic_remove(Ctx.ctx, C.uint32_t(domid), &cnic, nil)
+       if ret != 0 {
+               return Error(ret)
+       }
+
+       return nil
+}