...
1
2
3 package main
4
5 import (
6 gcontext "context"
7
8 "github.com/Microsoft/hcsshim/internal/appargs"
9 "github.com/Microsoft/hcsshim/internal/lcow"
10 "github.com/Microsoft/hcsshim/internal/oc"
11 "github.com/Microsoft/hcsshim/internal/uvm"
12 "github.com/Microsoft/hcsshim/osversion"
13 "github.com/pkg/errors"
14 "github.com/urfave/cli"
15 )
16
17 var createScratchCommand = cli.Command{
18 Name: "create-scratch",
19 Usage: "creates a scratch vhdx at 'destpath' that is ext4 formatted",
20 Description: "Creates a scratch vhdx at 'destpath' that is ext4 formatted",
21 Flags: []cli.Flag{
22 cli.StringFlag{
23 Name: "destpath",
24 Usage: "Required: describes the destination vhd path",
25 },
26 cli.UintFlag{
27 Name: "sizeGB",
28 Value: 0,
29 Usage: "optional: The size in GB of the scratch file to create",
30 },
31 cli.StringFlag{
32 Name: "cache-path",
33 Usage: "optional: The path to an existing scratch.vhdx to copy instead of create.",
34 },
35 },
36 Before: appargs.Validate(),
37 Action: func(context *cli.Context) (err error) {
38 ctx, span := oc.StartSpan(gcontext.Background(), "create-scratch")
39 defer span.End()
40 defer func() { oc.SetSpanStatus(span, err) }()
41
42 dest := context.String("destpath")
43 if dest == "" {
44 return errors.New("'destpath' is required")
45 }
46
47 if osversion.Build() < osversion.RS5 {
48 return errors.New("LCOW is not supported pre-RS5")
49 }
50
51 opts := uvm.NewDefaultOptionsLCOW("createscratch-uvm", context.GlobalString("owner"))
52
53
54 opts.MemorySizeInMB = 256
55 opts.VPMemDeviceCount = 1
56
57
58 opts.SCSIControllerCount = 1
59
60 sizeGB := uint32(context.Uint("sizeGB"))
61 if sizeGB == 0 {
62 sizeGB = lcow.DefaultScratchSizeGB
63 }
64
65 convertUVM, err := uvm.CreateLCOW(ctx, opts)
66 if err != nil {
67 return errors.Wrapf(err, "failed to create '%s'", opts.ID)
68 }
69 defer convertUVM.Close()
70 if err := convertUVM.Start(ctx); err != nil {
71 return errors.Wrapf(err, "failed to start '%s'", opts.ID)
72 }
73 if err := lcow.CreateScratch(ctx, convertUVM, dest, sizeGB, context.String("cache-path")); err != nil {
74 return errors.Wrapf(err, "failed to create ext4vhdx for '%s'", opts.ID)
75 }
76
77 return nil
78 },
79 }
80
View as plain text