Skip to content

Commit 55ee202

Browse files
committed
VM Commands:
azure vmadditional unattend content add azure vmdata disk add azure vmnetwork interface add azure vmsecret add azure vmssh public key add azure vmconfig new azure vmdata disk remove azure vmnetwork interface remove azure vmboot diagnostics set azure vmdata disk set azure vmoperating system set azure vmosdisk set azure vmsource image set azure vmboot diagnostics data get azure vm get azure vm new azure vm remove azure vm update azure vmsize get
1 parent 8112575 commit 55ee202

29 files changed

+3065
-2
lines changed

src/CLU/Microsoft.Azure.Commands.Compute/Common/ComputeAutoMapperProfile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ public static bool Initialize()
6868
protected override void Configure()
6969
{
7070
//Mapper.CreateMap<Microsoft.Azure.AzureOperationResponse, TO.PSOperation>();
71-
//Mapper.CreateMap<FROM.ComputeLongRunningOperationResponse, TO.PSComputeLongRunningOperation>();
71+
Mapper.CreateMap<FROM.VirtualMachineCaptureResult, TO.PSComputeLongRunningOperation>();
7272
//Mapper.CreateMap<FROM.DeleteOperationResponse, TO.PSComputeLongRunningOperation>();
7373

7474
Mapper.CreateMap<FROM.AvailabilitySet, TO.PSAvailabilitySet>();
7575
//Mapper.CreateMap<Microsoft.Azure.AzureOperationResponse, TO.PSAvailabilitySet>();
7676

77-
//Mapper.CreateMap<FROM.VirtualMachine, TO.PSVirtualMachine>();
77+
Mapper.CreateMap<FROM.VirtualMachine, TO.PSVirtualMachine>();
7878
//Mapper.CreateMap<Microsoft.Azure.AzureOperationResponse, TO.PSVirtualMachine>();
7979

8080
Mapper.CreateMap<FROM.VirtualMachineSize, TO.PSVirtualMachineSize>();
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
//
2+
// Copyright (c) Microsoft and contributors. All rights reserved.
3+
//
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+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
//
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
// Warning: This code was generated by a tool.
18+
//
19+
// Changes to this file may cause incorrect behavior and will be lost if the
20+
// code is regenerated.
21+
22+
using Microsoft.Azure.Management.Compute.Models;
23+
using Newtonsoft.Json;
24+
using System.Collections.Generic;
25+
using System.Text.RegularExpressions;
26+
27+
namespace Microsoft.Azure.Commands.Compute.Models
28+
{
29+
public class PSVirtualMachine : PSOperation
30+
{
31+
// Gets or sets the property of 'ResourceGroupName'
32+
public string ResourceGroupName
33+
{
34+
get
35+
{
36+
if (string.IsNullOrEmpty(Id)) return null;
37+
Regex r = new Regex(@"(.*?)/resourcegroups/(?<rgname>\S+)/providers/(.*?)", RegexOptions.IgnoreCase);
38+
Match m = r.Match(Id);
39+
return m.Success ? m.Groups["rgname"].Value : null;
40+
}
41+
}
42+
43+
// Gets or sets the property of 'Id'
44+
public string Id { get; set; }
45+
46+
// Gets or sets the property of 'Name'
47+
public string Name { get; set; }
48+
49+
// Gets or sets the property of 'Type'
50+
public string Type { get; set; }
51+
52+
// Gets or sets the property of 'Location'
53+
public string Location { get; set; }
54+
55+
// Gets or sets the property of 'Tags'
56+
public IDictionary<string, string> Tags { get; set; }
57+
58+
[JsonIgnore]
59+
public string TagsText
60+
{
61+
get { return JsonConvert.SerializeObject(Tags, Formatting.Indented); }
62+
}
63+
64+
// Gets or sets the reference Id of the availailbity set to which this virtual machine belongs.
65+
public SubResource AvailabilitySetReference { get; set; }
66+
67+
[JsonIgnore]
68+
public string AvailabilitySetReferenceText
69+
{
70+
get { return JsonConvert.SerializeObject(AvailabilitySetReference, Formatting.Indented); }
71+
}
72+
73+
// Gets or sets the diagnostics profile.
74+
public DiagnosticsProfile DiagnosticsProfile { get; set; }
75+
76+
[JsonIgnore]
77+
public string DiagnosticsProfileText
78+
{
79+
get { return JsonConvert.SerializeObject(DiagnosticsProfile, Formatting.Indented); }
80+
}
81+
82+
// Gets the virtual machine child extension resources.
83+
public IList<VirtualMachineExtension> Extensions { get; set; }
84+
85+
[JsonIgnore]
86+
public string ExtensionsText
87+
{
88+
get { return JsonConvert.SerializeObject(Extensions, Formatting.Indented); }
89+
}
90+
91+
// Gets or sets the hardware profile.
92+
public HardwareProfile HardwareProfile { get; set; }
93+
94+
[JsonIgnore]
95+
public string HardwareProfileText
96+
{
97+
get { return JsonConvert.SerializeObject(HardwareProfile, Formatting.Indented); }
98+
}
99+
100+
// Gets the virtual machine instance view.
101+
public VirtualMachineInstanceView InstanceView { get; set; }
102+
103+
[JsonIgnore]
104+
public string InstanceViewText
105+
{
106+
get { return JsonConvert.SerializeObject(InstanceView, Formatting.Indented); }
107+
}
108+
109+
// Gets or sets the network profile.
110+
public NetworkProfile NetworkProfile { get; set; }
111+
112+
[JsonIgnore]
113+
public string NetworkProfileText
114+
{
115+
get { return JsonConvert.SerializeObject(NetworkProfile, Formatting.Indented); }
116+
}
117+
118+
// Gets or sets the OS profile.
119+
public OSProfile OSProfile { get; set; }
120+
121+
[JsonIgnore]
122+
public string OSProfileText
123+
{
124+
get { return JsonConvert.SerializeObject(OSProfile, Formatting.Indented); }
125+
}
126+
127+
// Gets or sets the purchase plan when deploying virtual machine from VM Marketplace images.
128+
public Plan Plan { get; set; }
129+
130+
[JsonIgnore]
131+
public string PlanText
132+
{
133+
get { return JsonConvert.SerializeObject(Plan, Formatting.Indented); }
134+
}
135+
136+
// Gets or sets the provisioning state, which only appears in the response.
137+
public string ProvisioningState { get; set; }
138+
139+
// Gets or sets the storage profile.
140+
public StorageProfile StorageProfile { get; set; }
141+
142+
[JsonIgnore]
143+
public string StorageProfileText
144+
{
145+
get { return JsonConvert.SerializeObject(StorageProfile, Formatting.Indented); }
146+
}
147+
148+
[JsonIgnore]
149+
public string[] DataDiskNames
150+
{
151+
get
152+
{
153+
if (this.StorageProfile == null) return null;
154+
var listStr = new List<string>();
155+
foreach (var item in StorageProfile.DataDisks)
156+
{
157+
listStr.Add(item.Name);
158+
}
159+
return listStr.ToArray();
160+
}
161+
}
162+
163+
[JsonIgnore]
164+
public string[] NetworkInterfaceIDs
165+
{
166+
get
167+
{
168+
if (this.NetworkProfile == null) return null;
169+
var listStr = new List<string>();
170+
foreach (var item in NetworkProfile.NetworkInterfaces)
171+
{
172+
listStr.Add(item.Id);
173+
}
174+
return listStr.ToArray();
175+
}
176+
}
177+
}
178+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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.Management.Compute.Models;
16+
using Newtonsoft.Json;
17+
using System.Collections.Generic;
18+
19+
namespace Microsoft.Azure.Commands.Compute.Models
20+
{
21+
public class PSVirtualMachineInstanceView
22+
{
23+
public string ResourceGroupName { get; set; }
24+
25+
public string Name { get; set; }
26+
27+
public BootDiagnosticsInstanceView BootDiagnostics { get; set; }
28+
29+
[JsonIgnore]
30+
public string BootDiagnosticsText
31+
{
32+
get { return JsonConvert.SerializeObject(BootDiagnostics, Formatting.Indented); }
33+
}
34+
35+
public IList<DiskInstanceView> Disks { get; set; }
36+
37+
[JsonIgnore]
38+
public string DisksText
39+
{
40+
get { return JsonConvert.SerializeObject(Disks, Formatting.Indented); }
41+
}
42+
43+
public IList<VirtualMachineExtensionInstanceView> Extensions { get; set; }
44+
45+
[JsonIgnore]
46+
public string ExtensionsText
47+
{
48+
get { return JsonConvert.SerializeObject(Extensions, Formatting.Indented); }
49+
}
50+
51+
public int? PlatformFaultDomain { get; set; }
52+
53+
public int? PlatformUpdateDomain { get; set; }
54+
55+
public string RemoteDesktopThumbprint { get; set; }
56+
57+
public VirtualMachineAgentInstanceView VMAgent { get; set; }
58+
59+
[JsonIgnore]
60+
public string VMAgentText
61+
{
62+
get { return JsonConvert.SerializeObject(VMAgent, Formatting.Indented); }
63+
}
64+
65+
public IList<InstanceViewStatus> Statuses { get; set; }
66+
67+
[JsonIgnore]
68+
public string StatusesText
69+
{
70+
get { return JsonConvert.SerializeObject(Statuses, Formatting.Indented); }
71+
}
72+
}
73+
74+
public static class PSVirtualMachineInstanceViewExtension
75+
{
76+
public static PSVirtualMachineInstanceView ToPSVirtualMachineInstanceView(
77+
this VirtualMachineInstanceView virtualMachineInstanceView,
78+
string resourceGroupName = null,
79+
string vmName = null)
80+
{
81+
PSVirtualMachineInstanceView result = new PSVirtualMachineInstanceView
82+
{
83+
ResourceGroupName = resourceGroupName,
84+
Name = vmName,
85+
BootDiagnostics = virtualMachineInstanceView.BootDiagnostics,
86+
Disks = virtualMachineInstanceView.Disks,
87+
Extensions = virtualMachineInstanceView.Extensions,
88+
Statuses = virtualMachineInstanceView.Statuses,
89+
PlatformFaultDomain = virtualMachineInstanceView.PlatformFaultDomain,
90+
PlatformUpdateDomain = virtualMachineInstanceView.PlatformUpdateDomain,
91+
RemoteDesktopThumbprint = virtualMachineInstanceView.RdpThumbPrint,
92+
VMAgent = virtualMachineInstanceView.VmAgent
93+
};
94+
95+
return result;
96+
}
97+
98+
public static PSVirtualMachineInstanceView ToPSVirtualMachineInstanceView(
99+
this VirtualMachine response,
100+
string resourceGroupName = null,
101+
string vmName = null)
102+
{
103+
if (response == null)
104+
{
105+
return null;
106+
}
107+
108+
return response.InstanceView == null ? null : response.InstanceView.ToPSVirtualMachineInstanceView(resourceGroupName, vmName);
109+
}
110+
}
111+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 AutoMapper;
16+
using Microsoft.Azure.Commands.Compute.Common;
17+
using Microsoft.Azure.Commands.Compute.Models;
18+
using Microsoft.Azure.Management.Compute;
19+
using System.Management.Automation;
20+
21+
namespace Microsoft.Azure.Commands.Compute
22+
{
23+
[Cmdlet(VerbsLifecycle.Restart, ProfileNouns.VirtualMachine, DefaultParameterSetName = ResourceGroupNameParameterSet)]
24+
[OutputType(typeof(PSComputeLongRunningOperation))]
25+
public class RestartAzureVMCommand : VirtualMachineActionBaseCmdlet
26+
{
27+
[Parameter(
28+
Mandatory = true,
29+
Position = 1,
30+
ValueFromPipelineByPropertyName = true,
31+
HelpMessage = "The virtual machine name.")]
32+
[ValidateNotNullOrEmpty]
33+
public string Name { get; set; }
34+
35+
protected override void ProcessRecord()
36+
{
37+
base.ProcessRecord();
38+
39+
ExecuteClientAction(() =>
40+
{
41+
this.VirtualMachineClient.Restart(this.ResourceGroupName, this.Name);
42+
});
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)