Skip to content

Commit 8112575

Browse files
committed
Extension Image Cmdlets
1 parent f8adcbf commit 8112575

File tree

4 files changed

+182
-2
lines changed

4 files changed

+182
-2
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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.Compute.Common;
16+
using Microsoft.Azure.Commands.Compute.Models;
17+
using Microsoft.Azure.Management.Compute;
18+
using Microsoft.Azure.Management.Compute.Models;
19+
using System.Linq;
20+
using System.Management.Automation;
21+
22+
namespace Microsoft.Azure.Commands.Compute
23+
{
24+
[Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineExtensionImage)]
25+
[OutputType(typeof(PSVirtualMachineExtensionImage))]
26+
[OutputType(typeof(PSVirtualMachineExtensionImageDetails))]
27+
public class GetAzureVMExtensionImageCommand : VirtualMachineExtensionImageBaseCmdlet
28+
{
29+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
30+
public string Location { get; set; }
31+
32+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
33+
public string PublisherName { get; set; }
34+
35+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
36+
public string Type { get; set; }
37+
38+
[Parameter, ValidateNotNullOrEmpty]
39+
public string FilterExpression { get; set; }
40+
41+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true)]
42+
public string Version { get; set; }
43+
44+
protected override void ProcessRecord()
45+
{
46+
base.ProcessRecord();
47+
48+
ExecuteClientAction(() =>
49+
{
50+
if (string.IsNullOrEmpty(this.Version))
51+
{
52+
// TODO, FilterExpression
53+
var result = this.VirtualMachineExtensionImageClient.ListVersions(Location.Canonicalize(), PublisherName, Type);
54+
55+
var images = from r in result
56+
select new PSVirtualMachineExtensionImage
57+
{
58+
Id = r.Id,
59+
Location = r.Location,
60+
Version = r.Name,
61+
PublisherName = this.PublisherName,
62+
Type = this.Type,
63+
FilterExpression = this.FilterExpression
64+
};
65+
66+
WriteObject(result, true);
67+
// TODO: Cannot Write the Result from Linq Select.
68+
//WriteObject(images, true);
69+
}
70+
else
71+
{
72+
var result = this.VirtualMachineExtensionImageClient.Get(Location.Canonicalize(), PublisherName, Type, Version);
73+
74+
var image = new PSVirtualMachineExtensionImageDetails
75+
{
76+
Id = result.Id,
77+
Location = result.Location,
78+
HandlerSchema = result.HandlerSchema,
79+
OperatingSystem = result.OperatingSystem,
80+
ComputeRole = result.ComputeRole,
81+
SupportsMultipleExtensions = result.SupportsMultipleExtensions,
82+
VMScaleSetEnabled = result.VmScaleSetEnabled,
83+
Version = result.Name,
84+
PublisherName = this.PublisherName,
85+
Type = this.Type,
86+
FilterExpression = this.FilterExpression
87+
};
88+
89+
WriteObject(image);
90+
}
91+
});
92+
}
93+
}
94+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.Compute.Common;
16+
using Microsoft.Azure.Commands.Compute.Models;
17+
using Microsoft.Azure.Management.Compute;
18+
using Microsoft.Azure.Management.Compute.Models;
19+
using System.Linq;
20+
using System.Management.Automation;
21+
22+
namespace Microsoft.Azure.Commands.Compute
23+
{
24+
[Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineExtensionImageType)]
25+
[OutputType(typeof(PSVirtualMachineExtensionImageType))]
26+
public class GetAzureVMExtensionImageTypeCommand : VirtualMachineExtensionImageBaseCmdlet
27+
{
28+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
29+
public string Location { get; set; }
30+
31+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
32+
public string PublisherName { get; set; }
33+
34+
protected override void ProcessRecord()
35+
{
36+
base.ProcessRecord();
37+
38+
ExecuteClientAction(() =>
39+
{
40+
var result = this.VirtualMachineExtensionImageClient.ListTypes(Location.Canonicalize(), PublisherName);
41+
42+
var images = from r in result
43+
select new PSVirtualMachineExtensionImageType
44+
{
45+
Id = r.Id,
46+
Location = r.Location,
47+
Type = r.Name,
48+
PublisherName = this.PublisherName
49+
};
50+
51+
WriteObject(result, true);
52+
// TODO: Cannot Write the Result from Linq Select.
53+
//WriteObject(images, true);
54+
});
55+
}
56+
}
57+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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;
16+
17+
namespace Microsoft.Azure.Commands.Compute
18+
{
19+
public abstract class VirtualMachineExtensionImageBaseCmdlet : ComputeClientBaseCmdlet
20+
{
21+
public IVirtualMachineExtensionImagesOperations VirtualMachineExtensionImageClient
22+
{
23+
get
24+
{
25+
return ComputeClient.ComputeManagementClient.VirtualMachineExtensionImages;
26+
}
27+
}
28+
}
29+
}

src/CLU/Microsoft.Azure.Commands.Compute/Models/PSVirtualMachineExtensionImage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public class PSVirtualMachineExtensionImageDetails : PSVirtualMachineExtensionIm
3636

3737
public string ComputeRole { get; set; }
3838

39-
public bool SupportsMultipleExtensions { get; set; }
39+
public bool? SupportsMultipleExtensions { get; set; }
4040

41-
public bool VMScaleSetEnabled { get; set; }
41+
public bool? VMScaleSetEnabled { get; set; }
4242
}
4343
}

0 commit comments

Comments
 (0)