Skip to content

Commit

Permalink
Regen compute based on 2017-03-30 and network based on 2017-08-01 (Az…
Browse files Browse the repository at this point in the history
…ure#3)

* Regen compute based on 2017-03-30 and changes to make it compile  (Azure#773)

* Regenerating compute from 2017-03-30 spec

* Rename [1]. Rest.Azure.SubResource -> Microsoft.Azure.Management.ResourceManager.Fluent.SubResource [2]. Rest.Azure.Resource -> Microsoft.Azure.Management.ResourceManager.Fluent.Resource

* Deleting generated VirtualMachineSizeTypes, Rename [1]. VirtualMachineInstanceViewInner -> VirtualMachineInstanceView [2]. VirtualMachineScaleSetExtensionInner -> VirtualMachineScaleSetExtension [3]. ContainerServiceOchestratorTypes -> ContainerServiceOrchestratorTypes

* DiskInner & SnapshotInner replaced accountType property with sku property (Types are different), updating the Impl in non-breaking way

* Updating Tests and Sample utilities to reflect Container orchestrator typo fix

* Regen network based on 2017 08 01 and changes to make it compile   (Azure#774)

* Regenerating network from 2017-08-01

* Rename [1]. Rest.Azure.SubResource -> Microsoft.Azure.Management.ResourceManager.Fluent.SubResource [2]. Rest.Azure.Resource -> Microsoft.Azure.Management.ResourceManager.Fluent.Resource

* Deleting the generated types for which we already have ExpandableEnum version available

* Using SubResource type for reference

* porting Subnet enhancements from Java SDK

* bunch of rerecordings, test polish, some bug fixes

* more test rerecordings

* more test rerecordings

* fluent 1.2 release and branch info (Azure#3683)

* more rerecordings...

* recordings...

* more re-recordings

* porting network peering support from Java SDK

* first network peering sample

* netlwork peering printing and recording

* updating msi samples to use updated az cli

* re-recordings

* addressing PR feedbakc

* NetworkPeering.CheckAccessBetweenNetworks() - port from Java SDK

* Removed generated Sync Methods.

* Fixed code issues in network.
  • Loading branch information
Hovsep authored Sep 18, 2017
1 parent 71fd4e2 commit 2261fe8
Show file tree
Hide file tree
Showing 692 changed files with 164,619 additions and 98,069 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public static void RunSample(IAzure azure)
var rgName = Utilities.CreateRandomName("rgCOMV");
var pipName = Utilities.CreateRandomName("pip1");
var userName = "tirekicker";
var password = "12NewPA$$w0rd!";
var password = "12NewPA34w0rd!";
var region = Region.USWestCentral;

var installScript = "https://raw.githubusercontent.com/Azure/azure-sdk-for-net/Fluent/Samples/Asset/create_resources_with_msi.sh";
var installCommand = "bash create_resources_with_msi.sh {subscriptionID} {port} {stgName} {rgName} {location}";
var installCommand = "bash create_resources_with_msi.sh {stgName} {rgName} {location}";
List<String> fileUris = new List<String>();
fileUris.Add(installScript);
try
Expand Down Expand Up @@ -120,8 +120,7 @@ public static void RunSample(IAzure azure)
// Prepare custom script to install az cli that uses MSI to create a storage account
//
var stgName = Utilities.CreateRandomName("st44");
installCommand = installCommand.Replace("{subscriptionID}", azure.SubscriptionId)
.Replace("{port}", "50342")
installCommand = installCommand
.Replace("{stgName}", stgName)
.Replace("{rgName}", rgName)
.Replace("{location}", region.Name);
Expand Down
7 changes: 3 additions & 4 deletions Samples/Compute/ManageStorageFromMSIEnabledVirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public static void RunSample(IAzure azure)
var rgName = Utilities.CreateRandomName("rgCOMV");
var pipName = Utilities.CreateRandomName("pip1");
var userName = "tirekicker";
var password = "12NewPA$$w0rd!";
var password = "12NewPA34w0rd!";
var region = Region.USWestCentral;

var installScript = "https://raw.githubusercontent.com/Azure/azure-sdk-for-net/Fluent/Samples/Asset/create_resources_with_msi.sh";
var installCommand = "bash create_resources_with_msi.sh {subscriptionID} {port} {stgName} {rgName} {location}";
var installCommand = "bash create_resources_with_msi.sh {stgName} {rgName} {location}";
List<String> fileUris = new List<String>();
fileUris.Add(installScript);
try
Expand Down Expand Up @@ -68,8 +68,7 @@ public static void RunSample(IAzure azure)
// Prepare custom script to install az cli that uses MSI to create a storage account
//
var stgName = Utilities.CreateRandomName("st44");
installCommand = installCommand.Replace("{subscriptionID}", azure.SubscriptionId)
.Replace("{port}", "50342")
installCommand = installCommand
.Replace("{stgName}", stgName)
.Replace("{rgName}", rgName)
.Replace("{location}", region.Name);
Expand Down
187 changes: 187 additions & 0 deletions Samples/Network/ManageNetworkPeeringInSameSubscription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Azure.Management.Compute.Fluent;
using Microsoft.Azure.Management.Compute.Fluent.Models;
using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.Network.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using Microsoft.Azure.Management.Samples.Common;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core.ResourceActions;
using System;
using System.Linq;

namespace ManageNetworkPeeringInSameSubscription
{
public class Program
{

/**
* Azure Network sample for enabling and updating network peering between two virtual networks
*
* Summary ...
*
* - This sample creates two virtual networks in the same subscription and then peers them, modifying various options on the peering.
*
* Details ...
*
* 1. Create two virtual networks, network "A" and network "B"...
* - network A with two subnets
* - network B with one subnet
* - the networks' address spaces must not overlap
* - the networks must be in the same region
*
* 2. Peer the networks...
* - the peering will initially have default settings:
* - each network's IP address spaces will be accessible from the other network
* - no traffic forwarding will be enabled between the networks
* - no gateway transit between one network and the other will be enabled
*
* 3. Update the peering...
* - disable IP address space between the networks
* - enable traffic forwarding from network A to network B
*
* 4. Delete the peering
* - the removal of the peering takes place on both networks, as long as they are in the same subscription
* Notes:
* - Once a peering is created, it cannot be pointed at another remote network later.
* - The address spaces of the peered networks cannot be changed as long as the networks are peered.
* - Gateway transit scenarios as well as peering networks in different subscriptions are possible but beyond the scope of this sample.
* - Network peering in reality results in pairs of peering objects: one pointing from one network to the other,
* and the other peering object pointing the other way. For simplicity though, the SDK provides a unified way to
* manage the peering as a whole, in a single command flow, without the need to duplicate commands for both sides of the peering,
* while enforcing the required restrictions between the two peerings automatically, as this sample shows. But it is also possible
* to modify each peering separately, which becomes required when working with networks in different subscriptions.
*/
public static void RunSample(IAzure azure)
{
Region region = Region.USEast;
string resourceGroupName = SdkContext.RandomResourceName("rg", 15);
string vnetAName = SdkContext.RandomResourceName("net", 15);
string vnetBName = SdkContext.RandomResourceName("net", 15);
string peeringABName = SdkContext.RandomResourceName("peer", 15);

try
{
//=============================================================
// Define two virtual networks to peer

Utilities.Log("Creating two virtual networks in the same region and subscription...");

ICreatable<INetwork> networkADefinition = azure.Networks.Define(vnetAName)
.WithRegion(region)
.WithNewResourceGroup(resourceGroupName)
.WithAddressSpace("10.0.0.0/27")
.WithSubnet("subnet1", "10.0.0.0/28")
.WithSubnet("subnet2", "10.0.0.16/28");

ICreatable<INetwork> networkBDefinition = azure.Networks.Define(vnetBName)
.WithRegion(region)
.WithNewResourceGroup(resourceGroupName)
.WithAddressSpace("10.1.0.0/27")
.WithSubnet("subnet3", "10.1.0.0/27");

// Create the networks in parallel for better performance
var created = azure.Networks.Create(networkADefinition, networkBDefinition);

// Print virtual network details
foreach (INetwork network in created)
{
Utilities.PrintVirtualNetwork(network);
Utilities.Log();
}

// Retrieve the created networks using their definition keys
INetwork networkA = created.FirstOrDefault(n => n.Key == networkADefinition.Key);
INetwork networkB = created.FirstOrDefault(n => n.Key == networkBDefinition.Key);

//=============================================================
// Peer the two networks using default settings

Utilities.Log(
"Peering the networks using default settings...\n"
+ "- Network access enabled\n"
+ "- Traffic forwarding disabled\n"
+ "- Gateway use (transit) by the peered network disabled");

INetworkPeering peeringAB = networkA.Peerings.Define(peeringABName)
.WithRemoteNetwork(networkB)
.Create(); // This implicitly creates a matching peering object on network B as well, if both networks are in the same subscription

// Print network details showing new peering
Utilities.Log("Created a peering");
Utilities.PrintVirtualNetwork(networkA);
Utilities.PrintVirtualNetwork(networkB);

//=============================================================
// Update a the peering disallowing access from B to A but allowing traffic forwarding from B to A

Utilities.Log("Updating the peering ...");
peeringAB.Update()
.WithoutAccessFromEitherNetwork()
.WithTrafficForwardingFromRemoteNetwork()
.Apply();

Utilities.Log("Updated the peering to disallow network access between B and A but allow traffic forwarding from B to A.");

//=============================================================
// Show the new network information

Utilities.PrintVirtualNetwork(networkA);
Utilities.PrintVirtualNetwork(networkB);

//=============================================================
// Remove the peering

Utilities.Log("Deleting the peering from the networks...");
networkA.Peerings.DeleteById(peeringAB.Id); // This deletes the peering from both networks, if they're in the same subscription
Utilities.Log("Deleted the peering from both sides.");

Utilities.PrintVirtualNetwork(networkA);
Utilities.PrintVirtualNetwork(networkB);
}
finally
{
try
{
Utilities.Log("Deleting Resource Group: " + resourceGroupName);
azure.ResourceGroups.BeginDeleteByName(resourceGroupName);
}
catch (NullReferenceException)
{
Utilities.Log("Did not create any resources in Azure. No clean up is necessary");
}
catch (Exception ex)
{
Utilities.Log(ex);
}
}
}

public static void Main(string[] args)
{
try
{
//=================================================================
// Authenticate
var credentials = SdkContext.AzureCredentialsFactory.FromFile(Environment.GetEnvironmentVariable("AZURE_AUTH_LOCATION"));

var azure = Azure.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(credentials)
.WithDefaultSubscription();

// Print selected subscription
Utilities.Log("Selected subscription: " + azure.SubscriptionId);

RunSample(azure);
}
catch (Exception ex)
{
Utilities.Log(ex);
}
}
}
}
21 changes: 20 additions & 1 deletion Samples/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -783,11 +783,30 @@ public static void PrintVirtualNetwork(INetwork network)
{
info.Append("\n\tSubnet: ").Append(subnet.Name)
.Append("\n\t\tAddress prefix: ").Append(subnet.AddressPrefix);

// Output associated NSG
var subnetNsg = subnet.GetNetworkSecurityGroup();
if (subnetNsg != null)
{
info.Append("\n\t\tNetwork security group: ").Append(subnetNsg.Id);
}

// Output associated route table
var routeTable = subnet.GetRouteTable();
if (routeTable != null)
{
info.Append("\n\tRoute table ID: ").Append(routeTable.Id);
}
}

// Output peerings
foreach (var peering in network.Peerings.List())
{
info.Append("\n\tPeering: ").Append(peering.Name)
.Append("\n\t\tRemote network ID: ").Append(peering.RemoteNetworkId)
.Append("\n\t\tPeering state: ").Append(peering.State)
.Append("\n\t\tIs traffic forwarded from remote network allowed? ").Append(peering.IsTrafficForwardingFromRemoteNetworkAllowed)
.Append("\n\t\tGateway use: ").Append(peering.GatewayUse);
}

Utilities.Log(info.ToString());
Expand Down Expand Up @@ -1594,7 +1613,7 @@ public static void Print(IContainerService containerService)
.Append("\n\t\tAgent pool leaf domain label: ").Append(containerService.AgentPoolLeafDomainLabel)
.Append("\n\tLinux user name: ").Append(containerService.LinuxRootUsername)
.Append("\n\tSSH key: ").Append(containerService.SshKey);
if (containerService.OrchestratorType == ContainerServiceOchestratorTypes.Kubernetes)
if (containerService.OrchestratorType == ContainerServiceOrchestratorTypes.Kubernetes)
{
info.Append("\n\tName: ").Append(containerService.ServicePrincipalClientId);
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/Fluent.Tests/Batch/BatchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task CanCRUDBatchAccounts()
Assert.Null(batchAccount.AutoStorage);
// List
var accounts = batchManager.BatchAccounts.ListByResourceGroup(rgName);
Assert.True(accounts.Any(account => StringComparer.OrdinalIgnoreCase.Equals(account.Name, batchAccountName)));
Assert.Contains(accounts, account => StringComparer.OrdinalIgnoreCase.Equals(account.Name, batchAccountName));
// Get
batchAccount = batchManager.BatchAccounts.GetByResourceGroup(rgName, batchAccountName);
Assert.NotNull(batchAccount);
Expand Down Expand Up @@ -164,7 +164,7 @@ public async Task CanCRUDBatchAccounts()

var batchAccounts = batchManager.BatchAccounts.ListByResourceGroup(rgName);

Assert.Equal(batchAccounts.Count(), 0);
Assert.Empty(batchAccounts);
}
finally
{
Expand Down Expand Up @@ -208,7 +208,7 @@ public async Task CanCreateBatchAccountWithApplication()

// List
var accounts = batchManager.BatchAccounts.ListByResourceGroup(rgName);
Assert.True(accounts.Any(account => StringComparer.OrdinalIgnoreCase.Equals(account.Name, batchAccountName)));
Assert.Contains(accounts, account => StringComparer.OrdinalIgnoreCase.Equals(account.Name, batchAccountName));

// Get
batchAccount = batchManager.BatchAccounts.GetByResourceGroup(rgName, batchAccountName);
Expand All @@ -230,7 +230,7 @@ public async Task CanCreateBatchAccountWithApplication()
}
var batchAccounts = batchManager.BatchAccounts.ListByResourceGroup(rgName);

Assert.Equal(batchAccounts.Count(), 0);
Assert.Empty(batchAccounts);
}
finally
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fluent.Tests/Common/TestTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public T VerifyGetting()
{
T resourceByGroup = collection.GetByResourceGroup(resource.ResourceGroupName, resource.Name);
T resourceById = collection.GetById(resourceByGroup.Id);
Assert.True(resourceById.Id.Equals(resourceByGroup.Id, StringComparison.OrdinalIgnoreCase));
Assert.Equal(resourceById.Id, resourceByGroup.Id, ignoreCase: true);
return resourceById;
}

Expand Down
6 changes: 1 addition & 5 deletions Tests/Fluent.Tests/Compute/AvailabilitySetsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void CanCRUDAvailabilitySet()
.WithFaultDomainCount(3)
.Create();

Assert.True(string.Equals(availabilitySet.ResourceGroupName, rgName));
Assert.Equal(availabilitySet.ResourceGroupName, rgName);
Assert.True(availabilitySet.UpdateDomainCount == 2);
Assert.True(availabilitySet.FaultDomainCount == 3);

Expand All @@ -54,10 +54,6 @@ public void CanCRUDAvailabilitySet()
// Delete
computeManager.AvailabilitySets.DeleteById(availabilitySet.Id);
}
catch
{
//
}
finally
{
try
Expand Down
6 changes: 3 additions & 3 deletions Tests/Fluent.Tests/Compute/ContainerServicesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public void ContainerServiceCRUDTest()
Assert.NotNull(containerService.Id);
Assert.Equal(containerService.Region, Region.USWest);
Assert.Equal(containerService.MasterNodeCount, (int)ContainerServiceMasterProfileCount.MIN);
Assert.Equal(containerService.LinuxRootUsername, "testusername");
Assert.Equal(containerService.AgentPoolCount, 1);
Assert.Equal("testusername", containerService.LinuxRootUsername);
Assert.Equal(1, containerService.AgentPoolCount);
Assert.Equal(containerService.AgentPoolName, "agentPool0" + csName);
Assert.Equal(containerService.AgentPoolLeafDomainLabel, "ap0" + dnsPrefix);
Assert.Equal(containerService.AgentPoolVMSize, ContainerServiceVMSizeTypes.StandardA1);
Assert.Equal(containerService.OrchestratorType, ContainerServiceOchestratorTypes.DCOS);
Assert.Equal(ContainerServiceOrchestratorTypes.DCOS, containerService.OrchestratorType);
Assert.True(containerService.IsDiagnosticsEnabled);
Assert.True(containerService.Tags.ContainsKey("tag1"));

Expand Down
Loading

0 comments on commit 2261fe8

Please sign in to comment.