From 7768da2384b7132412742982a48dd57d1b6cf7fd Mon Sep 17 00:00:00 2001 From: anrs Date: Fri, 21 Aug 2020 15:08:03 +0800 Subject: [PATCH] feat: connect guest to a specific extra network. (#245) --- engine/virt/virt.go | 16 ++++++++++++++-- go.mod | 2 +- go.sum | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/engine/virt/virt.go b/engine/virt/virt.go index e6baad22a..fc1eb3b1f 100644 --- a/engine/virt/virt.go +++ b/engine/virt/virt.go @@ -111,8 +111,20 @@ func (v *Virt) ExecResize(ctx context.Context, execID string, height, width uint } // NetworkConnect connects to a network. -func (v *Virt) NetworkConnect(ctx context.Context, network, target, ipv4, ipv6 string) (subnet []string, err error) { - log.Warnf("NetworkConnect does not implement") +func (v *Virt) NetworkConnect(ctx context.Context, network, target, ipv4, ipv6 string) (cidrs []string, err error) { + req := virttypes.ConnectNetworkReq{ + Network: network, + IPv4: ipv4, + } + req.ID = target + + var cidr string + if cidr, err = v.client.ConnectNetwork(ctx, req); err != nil { + return + } + + cidrs = append(cidrs, cidr) + return } diff --git a/go.mod b/go.mod index 20eb7b8ed..23dfffee6 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/opencontainers/runc v0.1.1 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 - github.com/projecteru2/libyavirt v0.0.0-20200803015801-c31d39b6e15c + github.com/projecteru2/libyavirt v0.0.0-20200821065010-ea41aa314ef3 github.com/prometheus/client_golang v1.7.1 github.com/sanity-io/litter v1.3.0 github.com/sirupsen/logrus v1.6.0 diff --git a/go.sum b/go.sum index caa05127d..ec1fabc89 100644 --- a/go.sum +++ b/go.sum @@ -244,6 +244,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/projecteru2/libyavirt v0.0.0-20200803015801-c31d39b6e15c h1:I9i6hagi+VJ3sSJsSULYkml3xhJp8HRV9qdBml9NW14= github.com/projecteru2/libyavirt v0.0.0-20200803015801-c31d39b6e15c/go.mod h1:9/SNmdphwl12ubwihkRa9YtOozM6liYLDxsricra1mY= +github.com/projecteru2/libyavirt v0.0.0-20200821023248-f3b5f25499a6 h1:0khPPFC/mDwa4bLRCJp+m+EzzigK/sHV/nQ1eqn1FJU= +github.com/projecteru2/libyavirt v0.0.0-20200821023248-f3b5f25499a6/go.mod h1:9/SNmdphwl12ubwihkRa9YtOozM6liYLDxsricra1mY= +github.com/projecteru2/libyavirt v0.0.0-20200821065010-ea41aa314ef3 h1:P8K+3LbU4cf3DXsLL+6/RavsJ9GWUVv3W36gi/Yv9dY= +github.com/projecteru2/libyavirt v0.0.0-20200821065010-ea41aa314ef3/go.mod h1:9/SNmdphwl12ubwihkRa9YtOozM6liYLDxsricra1mY= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0 h1:vrDKnkGzuGvhNAL56c7DBz29ZL+KxnoR0x7enabFceM= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=