зеркало из https://github.com/Azure/azure-hpc.git
VRay DR Pool Manager
This commit is contained in:
Родитель
ecce3212a0
Коммит
4eea1a3116
|
@ -0,0 +1,22 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26430.4
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VRayPoolManager", "VRayPoolManager\VRayPoolManager.csproj", "{F812B2D6-7E75-4FFD-B78A-318148E8C52D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{F812B2D6-7E75-4FFD-B78A-318148E8C52D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F812B2D6-7E75-4FFD-B78A-318148E8C52D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F812B2D6-7E75-4FFD-B78A-318148E8C52D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F812B2D6-7E75-4FFD-B78A-318148E8C52D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="BatchAccount" value=""/>
|
||||
<add key="BatchKey" value=""/>
|
||||
<add key="BatchUrl" value=""/>
|
||||
|
||||
<add key="RestrictToPublicIp" value="false"/>
|
||||
<add key="MyPublicIp" value=""/>
|
||||
|
||||
<add key="VirtualMachineCount" value="2"/>
|
||||
<add key="UseLowPriority" value="false"/>
|
||||
<add key="VirtualMachineSize" value="Standard_F16"/>
|
||||
|
||||
<add key="ImagePublisher" value="batch"/>
|
||||
<add key="ImageOffer" value="rendering-windows2016"/>
|
||||
<add key="ImageSku" value="rendering"/>
|
||||
<add key="ImageVersion" value="latest"/>
|
||||
<add key="NodeAgentSku" value="batch.node.windows amd64"/>
|
||||
|
||||
<add key="VRaySetupCommand" value="cmd.exe /c C:\Autodesk\MayaIO2017\vray\bin\vray.exe -server -portNumber=20207"/>
|
||||
<add key="VRayDRConfigPath" value="Autodesk\3dsMax\2018 - 64bit\ENU\en-US\plugcfg"/>
|
||||
|
||||
<add key="VRayDRConfig" value="restart_slaves 0
|
||||
list_in_scene 0
|
||||
max_servers 0
|
||||
use_local_machine 0
|
||||
transfer_missing_assets 0
|
||||
use_cached_assets 1
|
||||
cache_limit_type 2
|
||||
cache_limit 100.000000
|
||||
"/>
|
||||
<add key="VRayRTDRConfig" value="autostart_local_slave 0
|
||||
"/>
|
||||
|
||||
</appSettings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -0,0 +1,213 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Azure.Batch;
|
||||
using Microsoft.Azure.Batch.Auth;
|
||||
using Microsoft.Azure.Batch.Common;
|
||||
|
||||
namespace VRayPoolManager
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private static BatchClient Client;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Client = BatchClient.Open(
|
||||
new BatchSharedKeyCredentials(
|
||||
ConfigurationManager.AppSettings["BatchUrl"],
|
||||
ConfigurationManager.AppSettings["BatchAccount"],
|
||||
ConfigurationManager.AppSettings["BatchKey"]));
|
||||
|
||||
if (args.Length != 2)
|
||||
{
|
||||
Usage();
|
||||
}
|
||||
|
||||
var action = args[0];
|
||||
var poolName = args[1];
|
||||
|
||||
if (string.IsNullOrEmpty(poolName))
|
||||
{
|
||||
Usage();
|
||||
}
|
||||
|
||||
if (action == "create")
|
||||
{
|
||||
CreatePool(poolName);
|
||||
}
|
||||
else if (action == "delete")
|
||||
{
|
||||
DeletePool(poolName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Usage();
|
||||
}
|
||||
}
|
||||
|
||||
private static void CreatePool(string poolName)
|
||||
{
|
||||
var restrictToPublicIp = Boolean.Parse(ConfigurationManager.AppSettings["RestrictToPublicIp"]);
|
||||
var vmSize = ConfigurationManager.AppSettings["VirtualMachineSize"];
|
||||
|
||||
var dedicatedVmCount = Int32.Parse(ConfigurationManager.AppSettings["VirtualMachineCount"]);
|
||||
var lowPriorityVmCount = 0;
|
||||
|
||||
|
||||
if (Boolean.Parse(ConfigurationManager.AppSettings["UseLowPriority"]))
|
||||
{
|
||||
lowPriorityVmCount = dedicatedVmCount;
|
||||
dedicatedVmCount = 0;
|
||||
}
|
||||
|
||||
var pool = Client.PoolOperations.CreatePool(
|
||||
poolName,
|
||||
vmSize,
|
||||
new VirtualMachineConfiguration(
|
||||
new ImageReference(
|
||||
ConfigurationManager.AppSettings["ImageOffer"],
|
||||
ConfigurationManager.AppSettings["ImagePublisher"],
|
||||
ConfigurationManager.AppSettings["ImageSku"],
|
||||
ConfigurationManager.AppSettings["ImageVersion"]),
|
||||
ConfigurationManager.AppSettings["NodeAgentSku"]),
|
||||
dedicatedVmCount,
|
||||
lowPriorityVmCount);
|
||||
|
||||
|
||||
NetworkSecurityGroupRule[] nsgRules = null;
|
||||
|
||||
if (restrictToPublicIp)
|
||||
{
|
||||
var publicIp = GetPublicIp();
|
||||
nsgRules = new[]
|
||||
{
|
||||
new NetworkSecurityGroupRule(200, NetworkSecurityGroupRuleAccess.Allow, publicIp),
|
||||
new NetworkSecurityGroupRule(201, NetworkSecurityGroupRuleAccess.Deny, "*"),
|
||||
};
|
||||
}
|
||||
|
||||
var inboundNatPools = new List<InboundNatPool>
|
||||
{
|
||||
new InboundNatPool("VRay", InboundEndpointProtocol.Tcp, 20207, 20000, 20099, nsgRules)
|
||||
};
|
||||
|
||||
pool.NetworkConfiguration = new NetworkConfiguration();
|
||||
pool.NetworkConfiguration.EndpointConfiguration = new PoolEndpointConfiguration(inboundNatPools.AsReadOnly());
|
||||
pool.InterComputeNodeCommunicationEnabled = true;
|
||||
pool.ApplicationLicenses = new List<string> { "3dsmax", "vray" };
|
||||
pool.Commit();
|
||||
|
||||
var job = Client.JobOperations.CreateJob("vray-dr-" + poolName, new PoolInformation {PoolId = poolName});
|
||||
job.Commit();
|
||||
job.Refresh();
|
||||
|
||||
var vmCount = Math.Max(lowPriorityVmCount, dedicatedVmCount);
|
||||
|
||||
var task = new CloudTask("setup-vray-dr", "dir");
|
||||
task.MultiInstanceSettings = new MultiInstanceSettings(ConfigurationManager.AppSettings["VRaySetupCommand"], vmCount);
|
||||
job.AddTask(task);
|
||||
|
||||
Console.WriteLine("Waiting for pool nodes to allocate...");
|
||||
pool.Refresh();
|
||||
while (pool.AllocationState.Value != AllocationState.Steady)
|
||||
{
|
||||
Thread.Sleep(10000);
|
||||
pool.Refresh();
|
||||
}
|
||||
|
||||
if (pool.CurrentDedicatedComputeNodes != dedicatedVmCount)
|
||||
{
|
||||
Console.WriteLine("Failed to allocate enough dedicated nodes: {0} or {1}", pool.TargetDedicatedComputeNodes, dedicatedVmCount);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
if (pool.CurrentLowPriorityComputeNodes != lowPriorityVmCount)
|
||||
{
|
||||
Console.WriteLine("Failed to allocate enough low priority nodes: {0} or {1}", pool.TargetDedicatedComputeNodes, dedicatedVmCount);
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
Console.WriteLine("Endpoints");
|
||||
var vrayConfig = Path.Combine(
|
||||
Environment.GetEnvironmentVariable("LOCALAPPDATA"),
|
||||
ConfigurationManager.AppSettings["VRayDRConfigPath"],
|
||||
"vray_dr.cfg");
|
||||
|
||||
var vrayRtConfig = Path.Combine(
|
||||
Environment.GetEnvironmentVariable("LOCALAPPDATA"),
|
||||
ConfigurationManager.AppSettings["VRayDRConfigPath"],
|
||||
"vrayrt_dr.cfg");
|
||||
|
||||
File.WriteAllText(vrayConfig, "");
|
||||
File.WriteAllText(vrayRtConfig, "");
|
||||
foreach (var computeNode in pool.ListComputeNodes())
|
||||
{
|
||||
if (computeNode.EndpointConfiguration != null && computeNode.EndpointConfiguration.InboundEndpoints != null)
|
||||
{
|
||||
foreach (var endpoint in computeNode.EndpointConfiguration.InboundEndpoints)
|
||||
{
|
||||
if (endpoint.Name.StartsWith("VRay"))
|
||||
{
|
||||
Console.WriteLine(" {0} {1}:{2}", computeNode.Id, endpoint.PublicIPAddress, endpoint.FrontendPort);
|
||||
File.AppendAllText(vrayConfig, string.Format("{0} 1 {1}\n", endpoint.PublicIPAddress, endpoint.FrontendPort));
|
||||
File.AppendAllText(vrayRtConfig, string.Format("{0} 1 {1}\n", endpoint.PublicIPAddress, endpoint.FrontendPort));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File.AppendAllText(vrayConfig, ConfigurationManager.AppSettings["VRayDRConfig"]);
|
||||
File.AppendAllText(vrayRtConfig, ConfigurationManager.AppSettings["VRayRTDRConfig"]);
|
||||
Console.WriteLine("Updated VRay DR config file: " + vrayConfig);
|
||||
Console.WriteLine("Updated VRayRT DR config file: " + vrayConfig);
|
||||
|
||||
Console.WriteLine("Waiting for configuration task to complete...");
|
||||
task = Client.JobOperations.GetTask(job.Id, task.Id);
|
||||
while (task.State.Value == TaskState.Active)
|
||||
{
|
||||
Thread.Sleep(15000);
|
||||
task = Client.JobOperations.GetTask(job.Id, task.Id);
|
||||
}
|
||||
|
||||
Console.WriteLine("Done");
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
private static void DeletePool(string poolName)
|
||||
{
|
||||
Client.PoolOperations.DeletePool(poolName);
|
||||
}
|
||||
|
||||
private static string GetPublicIp()
|
||||
{
|
||||
var myIp = ConfigurationManager.AppSettings["MyPublicIp"];
|
||||
if (string.IsNullOrEmpty(myIp))
|
||||
{
|
||||
string url = "http://checkip.dyndns.org";
|
||||
System.Net.WebRequest req = System.Net.WebRequest.Create(url);
|
||||
System.Net.WebResponse resp = req.GetResponse();
|
||||
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
|
||||
string response = sr.ReadToEnd().Trim();
|
||||
string[] a = response.Split(':');
|
||||
string a2 = a[1].Substring(1);
|
||||
string[] a3 = a2.Split('<');
|
||||
string a4 = a3[0];
|
||||
myIp = a4;
|
||||
}
|
||||
return myIp;
|
||||
}
|
||||
|
||||
private static void Usage()
|
||||
{
|
||||
Console.WriteLine("Invalid arguments.");
|
||||
Console.WriteLine("Usage: VRayPoolManager create <poolName>");
|
||||
Console.WriteLine("Usage: VRayPoolManager delete <poolName>");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("VRayPoolManager")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("VRayPoolManager")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("f812b2d6-7e75-4ffd-b78a-318148e8c52d")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{F812B2D6-7E75-4FFD-B78A-318148E8C52D}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>VRayPoolManager</RootNamespace>
|
||||
<AssemblyName>VRayPoolManager</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Azure.Batch, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Azure.Batch.8.0.1\lib\net452\Microsoft.Azure.Batch.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Rest.ClientRuntime.2.3.10\lib\net452\Microsoft.Rest.ClientRuntime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.10\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Azure.Batch" version="8.0.1" targetFramework="net452" />
|
||||
<package id="Microsoft.Rest.ClientRuntime" version="2.3.10" targetFramework="net452" />
|
||||
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.10" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net452" />
|
||||
</packages>
|
Загрузка…
Ссылка в новой задаче