Skip to content

Commit

Permalink
reformate the utiles file
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Nov 30, 2023
1 parent 0b2d40c commit 9f34ad0
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions pkg/primitives/vm/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ import (
"github.com/threefoldtech/zos/pkg/stubs"
)

var (
networkResourceNet = net.IPNet{
IP: net.ParseIP("100.64.0.0"),
Mask: net.IPv4Mask(0xff, 0xff, 0, 0),
}
)
var networkResourceNet = net.IPNet{
IP: net.ParseIP("100.64.0.0"),
Mask: net.IPv4Mask(0xff, 0xff, 0, 0),
}

// fill up the VM (machine) object with write boot config for a full virtual machine (with a disk image)
func (p *Manager) prepVirtualMachine(
Expand All @@ -36,8 +34,7 @@ func (p *Manager) prepVirtualMachine(
deployment *gridtypes.Deployment,
wl *gridtypes.WorkloadWithID,
) error {

var storage = stubs.NewStorageModuleStub(p.zbus)
storage := stubs.NewStorageModuleStub(p.zbus)
// if a VM the vm has to have at least one mount
if len(config.Mounts) == 0 {
return fmt.Errorf("at least one mount has to be attached for Vm mode")
Expand All @@ -62,7 +59,7 @@ func (p *Manager) prepVirtualMachine(
return errors.Wrap(err, "disk does not exist")
}

//TODO: DiskWrite will not override the disk if it already has a partition table
// TODO: DiskWrite will not override the disk if it already has a partition table
// or a filesystem. this means that if later the disk is assigned to a new VM with
// a different flist it will have the same old operating system copied from previous
// setup.
Expand Down Expand Up @@ -102,18 +99,15 @@ func (p *Manager) prepContainer(
// create a persisted volume for the vm. we don't do it automatically
// via the flist, so we have control over when to decomission this volume.
// remounting in RW mode
volName := fmt.Sprintf("rootfs:%s", wl.ID.String())

volName := fmt.Sprintf("rootfs:%s", wl.ID.String())
volume, err := storage.VolumeLookup(ctx, volName)
isFirstBoot := false
if err != nil {
isFirstBoot = true
_, err := storage.VolumeLookup(ctx, volName)
isFirstBoot := err != nil

volume, err = storage.VolumeCreate(ctx, volName, rootfsSize)
if err != nil {
return errors.Wrap(err, "failed to create vm rootfs")
}
}
volume, err := storage.VolumeCreate(ctx, volName, rootfsSize)
if err != nil {
return errors.Wrap(err, "failed to create vm rootfs")
}

defer func() {
if err != nil {
Expand All @@ -128,7 +122,6 @@ func (p *Manager) prepContainer(
ReadOnly: false,
PersistedVolume: volume.Path,
})

if err != nil {
return errors.Wrapf(err, "failed to mount flist: %s", wl.ID.String())
}
Expand Down Expand Up @@ -181,8 +174,8 @@ func (p *Manager) prepContainer(
func (p *Manager) newYggNetworkInterface(ctx context.Context, wl *gridtypes.WorkloadWithID) (pkg.VMIface, error) {
network := stubs.NewNetworkerStub(p.zbus)

//TODO: if we use `ygg` as a network name. this will conflict
//if the user has a network that is called `ygg`.
// TODO: if we use `ygg` as a network name. this will conflict
// if the user has a network that is called `ygg`.
tapName := wl.ID.Unique("ygg")
iface, err := network.SetupYggTap(ctx, tapName)
if err != nil {
Expand Down

0 comments on commit 9f34ad0

Please sign in to comment.