Skip to content

Commit

Permalink
use latest yavirt lib, revise vol defines
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed May 12, 2023
1 parent 03348e6 commit f4113e2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
24 changes: 16 additions & 8 deletions engine/virt/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ import (

"github.com/cockroachdb/errors"
coretypes "github.com/projecteru2/core/types"
virttypes "github.com/projecteru2/libyavirt/types"
)

const sep = "@"

func (v *Virt) parseVolumes(volumes []string) ([]string, error) {
vols := []string{}

// format `/source:/dir0:rw:1G:1000:1000:10M:10M`
for _, bind := range volumes {
func (v *Virt) parseVolumes(volumes []string) ([]virttypes.Volume, error) {
vols := make([]virttypes.Volume, len(volumes))
// format `/source:/dir0:rw:1024:1000:1000:10M:10M`
for i, bind := range volumes {
parts := strings.Split(bind, ":")
if len(parts) != 4 && len(parts) != 8 {
return nil, errors.Wrapf(coretypes.ErrInvalidVolumeBind, "bind: %s", bind)
}

src := parts[0]
dest := filepath.Join("/", parts[1])
dest := parts[1]
if !strings.HasPrefix(dest, "/") {
dest = filepath.Join("/", parts[1])
}

mnt := dest
// the src part has been translated to real host directory by eru-sched or kept it to empty.
Expand All @@ -38,10 +41,15 @@ func (v *Virt) parseVolumes(volumes []string) ([]string, error) {

ioConstraints := ""
if len(parts) > 4 {
ioConstraints = fmt.Sprintf(":%s", strings.Join(parts[4:], ":"))
ioConstraints = strings.Join(parts[4:], ":")
}

vols = append(vols, fmt.Sprintf("%s:%d%s", mnt, capacity, ioConstraints))
volume := virttypes.Volume{
Mount: mnt,
Capacity: capacity,
IO: ioConstraints,
}
vols[i] = volume
}

return vols, nil
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/alphadose/haxmap v1.2.0
github.com/cenkalti/backoff/v4 v4.2.1
github.com/cockroachdb/errors v1.9.1
github.com/docker/distribution v2.8.1+incompatible
github.com/docker/distribution v2.8.2+incompatible
github.com/docker/docker v23.0.4+incompatible
github.com/docker/go-connections v0.4.0
github.com/docker/go-units v0.5.0
Expand All @@ -23,7 +23,7 @@ require (
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b
github.com/panjf2000/ants/v2 v2.7.3
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/projecteru2/libyavirt v0.0.0-20230511035158-650f74b8b68c
github.com/projecteru2/libyavirt v0.0.0-20230512040131-dd14c75027c3
github.com/prometheus/client_golang v1.15.0
github.com/rs/zerolog v1.29.1
github.com/sanity-io/litter v1.5.5
Expand All @@ -39,7 +39,7 @@ require (
golang.org/x/crypto v0.8.0
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53
golang.org/x/net v0.10.0
google.golang.org/grpc v1.54.0
google.golang.org/grpc v1.54.1
google.golang.org/protobuf v1.30.0
)

Expand All @@ -54,7 +54,7 @@ require (
github.com/benbjohnson/clock v1.3.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.3.2 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/containerd/containerd v1.7.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
github.com/cloudflare/circl v1.3.2 h1:VWp8dY3yH69fdM7lM6A1+NhhVoDu9vqK0jOgmkQHFWk=
github.com/cloudflare/circl v1.3.2/go.mod h1:+CauBF6R70Jqcyl8N2hC8pAXYbWkGIezuSbuGLtRhnw=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
Expand Down Expand Up @@ -138,8 +138,8 @@ github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6ps
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68=
github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=
github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v23.0.4+incompatible h1:Kd3Bh9V/rO+XpTP/BLqM+gx8z7+Yb0AA2Ibj+nNo4ek=
github.com/docker/docker v23.0.4+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
Expand Down Expand Up @@ -459,8 +459,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/projecteru2/libyavirt v0.0.0-20230511035158-650f74b8b68c h1:R88Kqp6sKjw1PebzKxfCqvunPtIww9ALhCjRCteQRrU=
github.com/projecteru2/libyavirt v0.0.0-20230511035158-650f74b8b68c/go.mod h1:+D8ICExygXdwkRG7PbZTy7ITcUL+AAM/aGGaQMNDI84=
github.com/projecteru2/libyavirt v0.0.0-20230512040131-dd14c75027c3 h1:Ac8sKZ+sVujRYssY27cFBOo+SVyvKhjJXpWpNKFO9c0=
github.com/projecteru2/libyavirt v0.0.0-20230512040131-dd14c75027c3/go.mod h1:N41KaKmqbailweGs4x/mt2H0O0Y7MizObZQ+igLdzpw=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=
Expand Down Expand Up @@ -993,8 +993,8 @@ google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAG
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
google.golang.org/grpc v1.54.0 h1:EhTqbhiYeixwWQtAEZAxmV9MGqcjEU2mFx52xCzNyag=
google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g=
google.golang.org/grpc v1.54.1 h1:zQZQNqQZU9cHv2vLdDhB2mFeDZ2hGpgYM1A0PKjFsSM=
google.golang.org/grpc v1.54.1/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down

0 comments on commit f4113e2

Please sign in to comment.