/// <summary>
 /// 根据限制参数修改主机设置
 /// </summary>
 public static HostConfig WithLimitation(
     HostConfig hostConfig, ContainerLimitation limitation, ContainerConfiguration containerConfiguration)
 {
     if (limitation.CPUPeriod.HasValue)
     {
         hostConfig.CPUPeriod = limitation.CPUPeriod.Value;
     }
     if (limitation.CPUQuota.HasValue)
     {
         hostConfig.CPUQuota = limitation.CPUQuota.Value;
     }
     if (limitation.Memory.HasValue)
     {
         hostConfig.Memory = limitation.Memory.Value;
     }
     if (limitation.MemorySwap.HasValue)
     {
         hostConfig.MemorySwap = limitation.MemorySwap.Value;
     }
     if (limitation.BlkioDeviceReadBps.HasValue)
     {
         hostConfig.BlkioDeviceReadBps = hostConfig.BlkioDeviceReadBps ?? new List <ThrottleDevice>();
         hostConfig.BlkioDeviceReadBps.Add(new ThrottleDevice()
         {
             Path = containerConfiguration.DevicePath,
             Rate = (ulong)limitation.BlkioDeviceReadBps.Value
         });
     }
     if (limitation.BlkioDeviceWriteBps.HasValue)
     {
         hostConfig.BlkioDeviceWriteBps = hostConfig.BlkioDeviceWriteBps ?? new List <ThrottleDevice>();
         hostConfig.BlkioDeviceWriteBps.Add(new ThrottleDevice()
         {
             Path = containerConfiguration.DevicePath,
             Rate = (ulong)limitation.BlkioDeviceWriteBps.Value
         });
     }
     if (limitation.Ulimit.Count > 0)
     {
         hostConfig.Ulimits = limitation.Ulimit.Select(x =>
                                                       new Ulimit()
         {
             Name = x.Key, Soft = x.Value, Hard = x.Value
         }).ToList();
     }
     return(hostConfig);
 }
示例#2
0
 public JoyOIManagementConfiguration()
 {
     Name      = "Default";
     TestMode  = false;
     Container = new ContainerConfiguration()
     {
         DevicePath          = "/dev/sda",
         MaxRunningJobs      = 32,
         WorkDir             = "/workdir/",
         ActorExecutablePath = "/actor/bin/Debug/netcoreapp2.0/actor.dll",
         ActorExecuteCommand = "/actor/run-actor.sh &> /actor/run-actor.log",
         ActorExecuteLogPath = "/actor/run-actor.log",
         ResultPath          = "/workdir/return.json"
     };
     Limitation = new ContainerLimitation();
     Nodes      = new Dictionary <string, Node>();
 }