Skip to content

Commit

Permalink
feat: resize local disk.
Browse files Browse the repository at this point in the history
  • Loading branch information
anrs committed Apr 16, 2020
1 parent cad066d commit 5e2333c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
5 changes: 2 additions & 3 deletions engine/virt/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ import (

"github.com/docker/go-units"

enginetypes "github.com/projecteru2/core/engine/types"
coretypes "github.com/projecteru2/core/types"
)

// MinVirtStorage define min virt storage
const MinVirtStorage = int64(units.GiB * 50)

func (v *Virt) parseVolumes(opts *enginetypes.VirtualizationCreateOptions) (map[string]int64, error) {
func (v *Virt) parseVolumes(volumes []string) (map[string]int64, error) {
vols := map[string]int64{}

for _, bind := range opts.Volumes {
for _, bind := range volumes {
parts := strings.Split(bind, ":")
if len(parts) != 4 {
return nil, coretypes.NewDetailedErr(coretypes.ErrInvalidBind, bind)
Expand Down
20 changes: 16 additions & 4 deletions engine/virt/virt.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (v *Virt) BuildContent(ctx context.Context, scm coresource.Source, opts *en

// VirtualizationCreate creates a guest.
func (v *Virt) VirtualizationCreate(ctx context.Context, opts *enginetypes.VirtualizationCreateOptions) (guest *enginetypes.VirtualizationCreated, err error) {
vols, err := v.parseVolumes(opts)
vols, err := v.parseVolumes(opts.Volumes)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -236,9 +236,21 @@ func (v *Virt) VirtualizationWait(ctx context.Context, ID, state string) (*engin
}

// VirtualizationUpdateResource updates resource.
func (v *Virt) VirtualizationUpdateResource(ctx context.Context, ID string, opts *enginetypes.VirtualizationResource) (err error) {
log.Warnf("VirtualizationUpdateResource does not implement")
return
func (v *Virt) VirtualizationUpdateResource(ctx context.Context, ID string, opts *enginetypes.VirtualizationResource) error {
vols, err := v.parseVolumes(opts.Volumes)
if err != nil {
return err
}

args := virttypes.ResizeGuestReq{
Cpu: int(opts.Quota),
Mem: opts.Memory,
Volumes: vols,
}
args.ID = ID

_, err = v.client.ResizeGuest(ctx, args)
return err
}

// VirtualizationCopyFrom copies from another.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
github.com/opencontainers/runc v0.0.0-20180615140650-ad0f5255060d // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/projecteru2/libyavirt v0.0.0-20200323074159-8995ed0d1372
github.com/projecteru2/libyavirt v0.0.0-20200416012650-52fb8b0c58d8
github.com/prometheus/client_golang v0.9.3
github.com/sanity-io/litter v1.1.0
github.com/sirupsen/logrus v1.4.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ github.com/projecteru2/libyavirt v0.0.0-20191216061912-ff6d6a2732f3 h1:PtWw3+4YV
github.com/projecteru2/libyavirt v0.0.0-20191216061912-ff6d6a2732f3/go.mod h1:hLHHuglFKcVGlCrmqPMFVMS6N3A4WCjyXSGktxnba8M=
github.com/projecteru2/libyavirt v0.0.0-20200323074159-8995ed0d1372 h1:oq9F9anuSTyGq1sV7VjmjIK6KZlWvUQTWv+wOhIR9wE=
github.com/projecteru2/libyavirt v0.0.0-20200323074159-8995ed0d1372/go.mod h1:L+QcwDnJUIQYX7mM9//2KNF32e1aknOFFzutbVNyKfg=
github.com/projecteru2/libyavirt v0.0.0-20200416012650-52fb8b0c58d8 h1:zvHrGCA2quNA7nSM/jmbHIXsT4PNbikSY0a0Ew2hyek=
github.com/projecteru2/libyavirt v0.0.0-20200416012650-52fb8b0c58d8/go.mod h1:L+QcwDnJUIQYX7mM9//2KNF32e1aknOFFzutbVNyKfg=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3 h1:9iH4JKXLzFbOAdtqv/a+j8aewx2Y8lAjAydhbaScPF8=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
Expand Down

0 comments on commit 5e2333c

Please sign in to comment.