Skip to content

Commit b3bc453

Browse files
committed
Merge pull request #17 from Azure/build
u
2 parents 8686d1b + 6f60546 commit b3bc453

13 files changed

+6204
-2976
lines changed

ChangeLog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* Get-AzureLoadBalancerBackendAddressPoolConfig
3333
* Get-AzureLoadBalancerFrontendIpConfig
3434
* Get-AzureLoadBalancerInboundNatRuleConfig
35-
* Get-AzureLoadBalancerProbeConfig*
35+
* Get-AzureLoadBalancerProbeConfig
3636
* Get-AzureLoadBalancerRuleConfig
3737
* New-AzureLoadBalancer
3838
* New-AzureLoadBalancerBackendAddressPoolConfig
@@ -60,6 +60,7 @@
6060
* Remove-AzureNetworkSecurityRuleConfig
6161
* Add-AzureNetworkSecurityRuleConfig
6262
* Set-AzureNetworkSecurityRuleConfig
63+
* Get-AzureRemoteDesktopFile
6364
* Azure Storage
6465
* Added cmdlets in AzureResourceManager Mode
6566
* New-AzureStorageAccount

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.5.0.0-preview\lib\net40\Microsoft.Azure.Management.Compute.dll</HintPath>
7777
<Private>True</Private>
7878
</Reference>
79+
<Reference Include="Microsoft.Azure.Management.Network">
80+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.2.0.0-preview\lib\net40\Microsoft.Azure.Management.Network.dll</HintPath>
81+
</Reference>
7982
<Reference Include="Microsoft.Azure.Management.Storage, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
8083
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Storage.2.4.0-preview\lib\net40\Microsoft.Azure.Management.Storage.dll</HintPath>
8184
<Private>True</Private>
@@ -170,6 +173,8 @@
170173
<Compile Include="Models\PSVirtualMachineExtension.cs" />
171174
<Compile Include="Models\PSAvailabilitySet.cs" />
172175
<Compile Include="Models\PSVirtualMachineInstanceView.cs" />
176+
<Compile Include="RemoteDesktop\VirtualMachineRemoteDesktopBaseCmdlet.cs" />
177+
<Compile Include="RemoteDesktop\GetAzureRemoteDesktopFileCommand.cs" />
173178
<Compile Include="StorageAccount\StorageManagementClient.cs" />
174179
<Compile Include="Models\SourceImageReferenceExtension.cs" />
175180
<Compile Include="StorageAccount\GetAzureStorageAccount.cs" />
@@ -227,6 +232,10 @@
227232
<Project>{c60342b1-47d3-4a0e-8081-9b97ce60b7af}</Project>
228233
<Name>Commands.Profile</Name>
229234
</ProjectReference>
235+
<ProjectReference Include="..\..\Network\Commands.Network\Commands.Network.csproj">
236+
<Project>{98cfd96b-a6bc-4f15-ae2c-603fc2b58981}</Project>
237+
<Name>Commands.Network</Name>
238+
</ProjectReference>
230239
<ProjectReference Include="..\..\Resources\Commands.Resources\Commands.Resources.csproj">
231240
<Project>{e1f5201d-6067-430e-b303-4e367652991b}</Project>
232241
<Name>Commands.Resources</Name>

src/ResourceManager/Compute/Commands.Compute/Common/ConstantStringTypes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public static class ProfileNouns
8989

9090
public const string VirtualMachineUsage = "AzureVMUsage";
9191

92+
public const string RemoteDesktopFile = "AzureRemoteDesktopFile";
9293
public const string SshPublicKey = "AzureVMSshPublicKeyConfig";
9394
public const string AdditionalUnattendContent = "AzureVMAdditionalUnattendContentConfig";
9495
public const string VaultCertificate = "AzureVMVaultCertificateConfig";

src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@
129129
<data name="VirtualMachineExtensionRemovalConfirmation" xml:space="preserve">
130130
<value>This cmdlet will remove the specified virtual machine extension. Do you want to continue?</value>
131131
</data>
132+
<data name="VirtualMachineNotAssociatedWithPublicIPOrPublicLoadBalancer" xml:space="preserve">
133+
<value>The RDP file cannot be generated because the network interface of the virtual machine does not reference a PublicIP or an InboundNatRule of a public load balancer. </value>
134+
</data>
135+
<data name="VirtualMachineNotAssociatedWithPublicLoadBalancer" xml:space="preserve">
136+
<value>The RDP file cannot be generated because the network interface of the virtual machine does not reference an InboundNatRule of a public load balancer.</value>
137+
</data>
138+
<data name="VirtualMachineReferencesInternalNetworkInterface" xml:space="preserve">
139+
<value>The RDP file cannot be generated because the network interface of the virtual machine does not reference a PublicIP or an InboungNatRule of the load balancer.</value>
140+
</data>
132141
<data name="VirtualMachineRemovalCaption" xml:space="preserve">
133142
<value>Virtual machine removal operation</value>
134143
</data>
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.IO;
17+
using System.Linq;
18+
using System.Management.Automation;
19+
using Microsoft.Azure.Commands.Compute.Common;
20+
using Microsoft.Azure.Management.Compute;
21+
using Microsoft.Azure.Management.Network;
22+
23+
namespace Microsoft.Azure.Commands.Compute
24+
{
25+
[Cmdlet(VerbsCommon.Get, ProfileNouns.RemoteDesktopFile)]
26+
public class GetAzureRemoteDesktopFileCommand : VirtualMachineRemoteDesktopBaseCmdlet
27+
{
28+
[Parameter(
29+
Mandatory = true,
30+
Position = 0,
31+
ValueFromPipelineByPropertyName = true,
32+
HelpMessage = "The resource group name.")]
33+
[ValidateNotNullOrEmpty]
34+
public override string ResourceGroupName { get; set; }
35+
36+
[Alias("ResourceName", "VMName")]
37+
[Parameter(
38+
Mandatory = true,
39+
Position = 1,
40+
ValueFromPipelineByPropertyName = true,
41+
HelpMessage = "The resource name.")]
42+
[ValidateNotNullOrEmpty]
43+
public override string Name { get; set; }
44+
45+
[Parameter(
46+
Mandatory = true,
47+
Position = 2,
48+
ValueFromPipelineByPropertyName = true,
49+
HelpMessage = "Path and name of the output RDP file.")]
50+
[ValidateNotNullOrEmpty]
51+
public string LocalPath { get; set;}
52+
53+
public override void ExecuteCmdlet()
54+
{
55+
base.ExecuteCmdlet();
56+
57+
const string fullAddressPrefix = "full address:s:";
58+
const string promptCredentials = "prompt for credentials:i:1";
59+
const int defaultPort = 3389;
60+
61+
string address = string.Empty;
62+
int port = defaultPort;
63+
64+
// Get Azure VM
65+
var vmResponse = this.VirtualMachineClient.Get(this.ResourceGroupName, this.Name);
66+
67+
// Get the NIC
68+
var nicResourceGroupName =
69+
this.GetResourceGroupName(vmResponse.VirtualMachine.NetworkProfile.NetworkInterfaces.First().ReferenceUri);
70+
71+
var nicName =
72+
this.GetResourceName(
73+
vmResponse.VirtualMachine.NetworkProfile.NetworkInterfaces.First().ReferenceUri, "networkInterfaces");
74+
75+
var nicResponse =
76+
this.NetworkClient.NetworkResourceProviderClient.NetworkInterfaces.Get(nicResourceGroupName, nicName);
77+
78+
if (nicResponse.NetworkInterface.IpConfigurations.First().PublicIpAddress != null && !string.IsNullOrEmpty(nicResponse.NetworkInterface.IpConfigurations.First().PublicIpAddress.Id))
79+
{
80+
// Get PublicIPAddress resource if present
81+
address = this.GetAddressFromPublicIPResource(nicResponse.NetworkInterface.IpConfigurations.First().PublicIpAddress.Id);
82+
}
83+
else if (nicResponse.NetworkInterface.IpConfigurations.First().LoadBalancerInboundNatRules.Any())
84+
{
85+
address = string.Empty;
86+
87+
// Get ipaddress and port from loadbalancer
88+
foreach (var nicRuleRef in nicResponse.NetworkInterface.IpConfigurations.First().LoadBalancerInboundNatRules)
89+
{
90+
var lbName = this.GetResourceName(nicRuleRef.Id, "loadBalancers");
91+
var lbResourceGroupName = this.GetResourceGroupName(nicRuleRef.Id);
92+
93+
var loadbalancer =
94+
this.NetworkClient.NetworkResourceProviderClient.LoadBalancers.Get(lbResourceGroupName, lbName).LoadBalancer;
95+
96+
// Iterate over the InboundNatRules where Backendport = 3389
97+
var inboundRule =
98+
loadbalancer.InboundNatRules.Where(
99+
rule =>
100+
rule.BackendPort == defaultPort
101+
&& string.Equals(
102+
rule.Id,
103+
nicRuleRef.Id,
104+
StringComparison.OrdinalIgnoreCase));
105+
106+
if (inboundRule.Any())
107+
{
108+
port = inboundRule.First().FrontendPort;
109+
110+
// Get the corresponding frontendIPConfig -> publicIPAddress
111+
var frontendIPConfig =
112+
loadbalancer.FrontendIpConfigurations.First(
113+
frontend =>
114+
string.Equals(
115+
inboundRule.First().FrontendIPConfiguration.Id,
116+
frontend.Id,
117+
StringComparison.OrdinalIgnoreCase));
118+
119+
if (frontendIPConfig.PublicIpAddress != null)
120+
{
121+
address = this.GetAddressFromPublicIPResource(frontendIPConfig.PublicIpAddress.Id);
122+
break;
123+
}
124+
}
125+
}
126+
127+
if (string.IsNullOrEmpty(address))
128+
{
129+
throw new ArgumentException(Properties.Resources.VirtualMachineNotAssociatedWithPublicLoadBalancer);
130+
}
131+
}
132+
else
133+
{
134+
throw new ArgumentException(Properties.Resources.VirtualMachineNotAssociatedWithPublicIPOrPublicLoadBalancer);
135+
}
136+
137+
// Write to file
138+
using (var file = new StreamWriter(this.LocalPath))
139+
{
140+
file.WriteLine(fullAddressPrefix + address + ":" + port);
141+
file.WriteLine(promptCredentials);
142+
}
143+
}
144+
145+
private string GetAddressFromPublicIPResource(string resourceId)
146+
{
147+
string address = string.Empty;
148+
149+
// Get IpAddress from public IPAddress resource
150+
var publicIPResourceGroupName = this.GetResourceGroupName(resourceId);
151+
var publicIPName = this.GetResourceName(resourceId, "publicIPAddresses");
152+
153+
var publicIpResponse =
154+
this.NetworkClient.NetworkResourceProviderClient.PublicIpAddresses.Get(
155+
publicIPResourceGroupName,
156+
publicIPName);
157+
158+
159+
// Use the FQDN if present
160+
if (publicIpResponse.PublicIpAddress.DnsSettings != null
161+
&& !string.IsNullOrEmpty(publicIpResponse.PublicIpAddress.DnsSettings.Fqdn))
162+
{
163+
address = publicIpResponse.PublicIpAddress.DnsSettings.Fqdn;
164+
}
165+
else
166+
{
167+
address = publicIpResponse.PublicIpAddress.IpAddress;
168+
}
169+
170+
return address;
171+
}
172+
private string GetResourceGroupName(string resourceId)
173+
{
174+
return resourceId.Split('/')[4];
175+
}
176+
177+
private string GetResourceName(string resourceId, string resource)
178+
{
179+
return resourceId.Split('/')[8];
180+
}
181+
}
182+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Network;
16+
17+
namespace Microsoft.Azure.Commands.Compute
18+
{
19+
public class VirtualMachineRemoteDesktopBaseCmdlet : VirtualMachineBaseCmdlet
20+
{
21+
22+
private NetworkClient networkClient;
23+
24+
public NetworkClient NetworkClient
25+
{
26+
get
27+
{
28+
if (networkClient == null)
29+
{
30+
networkClient = new NetworkClient(Profile)
31+
{
32+
VerboseLogger = WriteVerboseWithTimestamp,
33+
ErrorLogger = WriteErrorWithTimestamp,
34+
WarningLogger = WriteWarningWithTimestamp
35+
};
36+
}
37+
return networkClient;
38+
}
39+
40+
set { networkClient = value; }
41+
}
42+
}
43+
}

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/AddAzureVMNetworkInterfaceCommand.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,20 @@ public override void ExecuteCmdlet()
7777

7878
if (!this.Primary.IsPresent)
7979
{
80-
networkProfile.NetworkInterfaces.Add(
81-
new NetworkInterfaceReference
80+
81+
networkProfile.NetworkInterfaces.Add(new NetworkInterfaceReference
8282
{
8383
ReferenceUri = this.Id,
8484
});
85+
86+
if (networkProfile.NetworkInterfaces.Count > 1)
87+
{
88+
// run through the entire list of networkInterfaces and if Primary is not set, set them to false
89+
foreach (var nic in networkProfile.NetworkInterfaces)
90+
{
91+
nic.Primary = nic.Primary ?? false;
92+
}
93+
}
8594
}
8695
else
8796
{

src/ResourceManager/Compute/Commands.Compute/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<package id="Microsoft.Azure.Graph.RBAC" version="1.7.0-preview" targetFramework="net45" />
99
<package id="Microsoft.Azure.Management.Authorization" version="0.18.2-preview" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Management.Compute" version="5.0.0-preview" targetFramework="net45" />
11+
<package id="Microsoft.Azure.Management.Network" version="2.0.0-preview" targetFramework="net45" />
1112
<package id="Microsoft.Azure.Management.Resources" version="2.18.0-preview" targetFramework="net45" />
1213
<package id="Microsoft.Azure.Management.Storage" version="2.4.0-preview" targetFramework="net45" />
1314
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />

0 commit comments

Comments
 (0)