Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/AutomationManagement/AutomationManagement.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
<ProjectGuid>{F9515973-831E-4447-924C-1578DF384D0F}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Azure.Management.Automation</RootNamespace>
<AssemblyName>Microsoft.Azure.Management.Automation</AssemblyName>
<RootNamespace>Microsoft.WindowsAzure.Management.Automation</RootNamespace>
<AssemblyName>Microsoft.WindowsAzure.Management.Automation</AssemblyName>
<OutputType>Library</OutputType>
<RestorePackages>true</RestorePackages>
<NuGetPackageImportStamp>de17033c</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Net40-Release'">
<DocumentationFile>bin\Net40-Release\Microsoft.WindowsAzure.Management.Automation.xml</DocumentationFile>
</PropertyGroup>
<Import Project="..\..\tools\Library.Settings.targets" />
<ItemGroup>
<Compile Include="Customizations\ResponseWithSkipToken.cs" />
Expand All @@ -21,8 +24,8 @@
<Compile Include="Customizations\AutomationManagementClient.Customization.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Microsoft.Azure.Management.Automation.nuget.proj" />
<None Include="Microsoft.Azure.Management.Automation.nuspec" />
<None Include="Microsoft.WindowsAzure.Management.Automation.nuget.proj" />
<None Include="Microsoft.WindowsAzure.Management.Automation.nuspec" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Hyak.Common;
using Microsoft.WindowsAzure.Management.Automation.Models;

namespace Microsoft.Azure.Management.Automation
namespace Microsoft.WindowsAzure.Management.Automation
{
public partial class AutomationManagementClient
{
Expand All @@ -34,4 +38,68 @@ public static List<T> ContinuationTokenHandler<T>(Func<string, ResponseWithSkipT
return models;
}
}
}

public static class AutomationManagementExtensions
{
public static void CreateAutomationAccount(this IAutomationManagementClient client, string automationAccountName, string location)
{
if (automationAccountName == null)
{
throw new ArgumentNullException("automationAccountName");
}

if (location == null)
{
throw new ArgumentNullException("location");
}

var generatedCsName = string.Format(CultureInfo.InvariantCulture, "OaasCS{0}-{1}", client.Credentials.SubscriptionId, location.Replace(' ', '-'));

try
{
client.CloudServices.Create(
new CloudServiceCreateParameters()
{
Name = generatedCsName,
GeoRegion = location,
Label = generatedCsName,
Description = "Cloud Service created via SDK client"
});
}
catch (CloudException)
{
// Ignore create cloud service error
}

client.AutomationAccounts.Create(generatedCsName,
new AutomationAccountCreateParameters()
{
Name = automationAccountName,
CloudServiceSettings = new CloudServiceSettings
{
GeoRegion = location
},
});
}

public static void DeleteAutomationAccount(this IAutomationManagementClient client, string automationAccountName)
{
if (automationAccountName == null)
{
throw new ArgumentNullException("automationAccountName");
}

var cloudServices = client.CloudServices.List().CloudServices;

foreach (var cloudService in cloudServices)
{
if (cloudService.Resources.Any(resource => 0 == String.Compare(resource.Name, automationAccountName, CultureInfo.InvariantCulture,
CompareOptions.IgnoreCase)))
{
client.AutomationAccounts.Delete(cloudService.Name, automationAccountName);
return;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

using System;
using System.Collections.Generic;
using Microsoft.Azure.Management.Automation.Models;
using Microsoft.WindowsAzure.Management.Automation.Models;

namespace Microsoft.Azure.Management.Automation
namespace Microsoft.WindowsAzure.Management.Automation
{
/// <summary>
/// The response with skip token.
Expand Down
Loading