Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a wrapper for CompactDisk of a VHD #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Roemer
Copy link

@Roemer Roemer commented Jul 9, 2024

I added a wrapper methods for CompactVirtualHardDisk.
As this process can take a bit longer, I created two wrappers:

  • CompactDiskAndWait which calls compact and waits until it is finished
  • CompactDisk which returns the created job object where the caller is responsible for closing the job object and waiting until it is finished. This has the benefit that the caller can for example print out a progress with something like:
job, err := mgmt.CompactDisk(diskPath, constant.VirtualHardDiskCompactModeFull)
if err != nil {
	return err
}
defer job.Close()
for !job.IsComplete() {
	fmt.Println(job.PercentComplete())
	time.Sleep(100 * time.Millisecond)
}

I also added a constant for the various compact modes.

@Roemer Roemer force-pushed the feature/CompactVirtualHardDisk branch from 889df6a to 12fcd5d Compare July 9, 2024 11:38

// Starts compacting a virtual hard disk and returns the job instance for progress.
// The caller is responsible for calling "Close" on the job instance when finished.
func (ims *ImageManagementService) CompactDisk(path string, mode constant.VirtualHardDiskCompactMode) (*wmi.WmiJob, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add some unit test in _test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants