diff mbox series

[2/4] golang/xenlight: add DeviceNicAdd/Remove wrappers

Message ID 87323a6eb60fd908ea2f792c9754cb88b283c5a6.1586727061.git.rosbrookn@ainfosec.com (mailing list archive)
State Superseded
Headers show
Series More wrappers for xenlight Go package | expand

Commit Message

Nick Rosbrook April 12, 2020, 10:02 p.m. UTC
Add DeviceNicAdd and DeviceNicRemove as wrappers for
libxl_device_nic_add and libxl_device_nic_remove.

Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
---
 tools/golang/xenlight/xenlight.go | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

Comments

George Dunlap April 22, 2020, 6:18 p.m. UTC | #1
> On Apr 12, 2020, at 11:02 PM, Nick Rosbrook <rosbrookn@gmail.com> wrote:
> 
> Add DeviceNicAdd and DeviceNicRemove as wrappers for
> libxl_device_nic_add and libxl_device_nic_remove.
> 
> Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
> ---
> tools/golang/xenlight/xenlight.go | 34 +++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
> 
> diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
> index 8492bcec4e..a56f913b81 100644
> --- a/tools/golang/xenlight/xenlight.go
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -1068,3 +1068,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.

I feel like I want to say here what it is you actually have to fill in to remove the nic; but after 10 minutes of poking around the code, I’m not actually sure myself. :-)  (I think it *might* be just Devid and BackendDomid.)

So I’ll give this for now:

Reviewed-by: George Dunlap <george.dunlap@citrix.com>

And if I find it before I finish reviewing the end of the series, we can check it in and look at improving the documentation later.

 -George
Nick Rosbrook April 22, 2020, 7:58 p.m. UTC | #2
> I feel like I want to say here what it is you actually have to fill in to remove the nic; but after 10 minutes of poking around the code, I’m not actually sure myself. :-)  (I think it *might* be just Devid and BackendDomid.)

IIRC, you can use just the MAC or devid. I was using just the MAC when
I tested it out.

> So I’ll give this for now:
>
> Reviewed-by: George Dunlap <george.dunlap@citrix.com>
>
> And if I find it before I finish reviewing the end of the series, we can check it in and look at improving the documentation later.

Sounds good, thanks!

-NR
diff mbox series

Patch

diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go
index 8492bcec4e..a56f913b81 100644
--- a/tools/golang/xenlight/xenlight.go
+++ b/tools/golang/xenlight/xenlight.go
@@ -1068,3 +1068,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
+}