func mountFloppyDrive(driver hypervcommon.Driver, vmName string, path string) error {

	var blockBuffer bytes.Buffer
	blockBuffer.WriteString("Set-VMFloppyDiskDrive -VMName ")
	blockBuffer.WriteString(vmName)
	blockBuffer.WriteString(" -Path ")
	blockBuffer.WriteString(path)

	err := driver.HypervManage(blockBuffer.String())

	return err
}
Exemple #2
0
func getHostAvailableMemory(driver hypervcommon.Driver) (string, error) {

	cmdOut, err := driver.HypervManageOutput("(Get-WmiObject Win32_OperatingSystem).FreePhysicalMemory / 1024")

	if err != nil {
		return "", err
	}

	var freeMemory = strings.TrimSpace(cmdOut)
	return freeMemory, err

}
Exemple #3
0
func getExternalOnlineVirtualSwitch(driver hypervcommon.Driver) (string, error) {

	var script = `
	$adapters = Get-NetAdapter -Physical -ErrorAction SilentlyContinue | Where-Object { $_.Status -eq 'Up' } | Sort-Object -Descending -Property Speed
	foreach ($adapter in $adapters) { 
	  $switch = Get-VMSwitch -SwitchType External | Where-Object { $_.NetAdapterInterfaceDescription -eq $adapter.InterfaceDescription }
	
	  if ($switch -ne $null) {
	    $switch.Name
	    break
	  }
	}
	`
	cmdOut, err := driver.HypervManageOutput(script)

	if err != nil {
		return "", err
	}

	var switchName = strings.TrimSpace(cmdOut)
	return switchName, err
}