示例#1
0
        public static DynamicMemory GetDynamicMemory(PowerShellManager powerShell, string vmName)
        {
            DynamicMemory info = null;

            Command cmd = new Command("Get-VMMemory");

            cmd.Parameters.Add("VMName", vmName);
            Collection <PSObject> result = powerShell.Execute(cmd);

            if (result != null && result.Count > 0)
            {
                info          = new DynamicMemory();
                info.Enabled  = result[0].GetBool("DynamicMemoryEnabled");
                info.Minimum  = Convert.ToInt32(result[0].GetLong("Minimum") / Constants.Size1M);
                info.Maximum  = Convert.ToInt32(result[0].GetLong("Maximum") / Constants.Size1M);
                info.Buffer   = Convert.ToInt32(result[0].GetInt("Buffer"));
                info.Priority = Convert.ToInt32(result[0].GetInt("Priority"));
            }

            return(info);
        }
示例#2
0
        public static void Update(PowerShellManager powerShell, VirtualMachine vm, int ramMb, DynamicMemory dynamicMemory)
        {
            Command cmd = new Command("Set-VMMemory");

            cmd.Parameters.Add("VMName", vm.Name);
            cmd.Parameters.Add("StartupBytes", ramMb * Constants.Size1M);

            if (dynamicMemory != null && dynamicMemory.Enabled)
            {
                cmd.Parameters.Add("DynamicMemoryEnabled", true);
                cmd.Parameters.Add("MinimumBytes", dynamicMemory.Minimum * Constants.Size1M);
                cmd.Parameters.Add("MaximumBytes", dynamicMemory.Maximum * Constants.Size1M);
                cmd.Parameters.Add("Buffer", dynamicMemory.Buffer);
                cmd.Parameters.Add("Priority", dynamicMemory.Priority);
            }
            else
            {
                cmd.Parameters.Add("DynamicMemoryEnabled", false);
            }

            powerShell.Execute(cmd, true, true);
        }