Skip to content

Commit 76f78e5

Browse files
committed
Merge pull request #81 from huangpf/clu
Image Commands
2 parents 913f895 + f8adcbf commit 76f78e5

10 files changed

+565
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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,
25+
ProfileNouns.VirtualMachineImage)]
26+
[OutputType(typeof(PSVirtualMachineImage),
27+
ParameterSetName = new [] {ListVMImageParamSetName})]
28+
[OutputType(typeof(PSVirtualMachineImageDetail),
29+
ParameterSetName = new [] {GetVMImageDetailParamSetName})]
30+
public class GetAzureVMImageCommand : VirtualMachineImageBaseCmdlet
31+
{
32+
protected const string ListVMImageParamSetName = "ListVMImage";
33+
protected const string GetVMImageDetailParamSetName = "GetVMImageDetail";
34+
35+
[Parameter(ParameterSetName = ListVMImageParamSetName,
36+
Mandatory = true,
37+
ValueFromPipelineByPropertyName = true)]
38+
[Parameter(ParameterSetName = GetVMImageDetailParamSetName,
39+
Mandatory = true,
40+
ValueFromPipelineByPropertyName = true)]
41+
[ValidateNotNullOrEmpty]
42+
public string Location { get; set; }
43+
44+
[Parameter(ParameterSetName = ListVMImageParamSetName,
45+
Mandatory = true,
46+
ValueFromPipelineByPropertyName = true)]
47+
[Parameter(ParameterSetName = GetVMImageDetailParamSetName,
48+
Mandatory = true,
49+
ValueFromPipelineByPropertyName = true)]
50+
[ValidateNotNullOrEmpty]
51+
public string PublisherName { get; set; }
52+
53+
[Parameter(ParameterSetName = ListVMImageParamSetName,
54+
Mandatory = true,
55+
ValueFromPipelineByPropertyName = true)]
56+
[Parameter(ParameterSetName = GetVMImageDetailParamSetName,
57+
Mandatory = true,
58+
ValueFromPipelineByPropertyName = true)]
59+
[ValidateNotNullOrEmpty]
60+
public string Offer { get; set; }
61+
62+
[Parameter(ParameterSetName = ListVMImageParamSetName,
63+
Mandatory = true,
64+
ValueFromPipelineByPropertyName = true)]
65+
[Parameter(ParameterSetName = GetVMImageDetailParamSetName,
66+
Mandatory = true,
67+
ValueFromPipelineByPropertyName = true)]
68+
[ValidateNotNullOrEmpty]
69+
public string Skus { get; set; }
70+
71+
[Parameter(ParameterSetName = ListVMImageParamSetName,
72+
ValueFromPipelineByPropertyName = false),
73+
ValidateNotNullOrEmpty]
74+
public string FilterExpression { get; set; }
75+
76+
[Parameter(ParameterSetName = GetVMImageDetailParamSetName,
77+
Mandatory = true,
78+
ValueFromPipelineByPropertyName = true),
79+
ValidateNotNullOrEmpty]
80+
public string Version { get; set; }
81+
82+
protected override void ProcessRecord()
83+
{
84+
base.ProcessRecord();
85+
86+
ExecuteClientAction(() =>
87+
{
88+
if (this.ParameterSetName.Equals(ListVMImageParamSetName))
89+
{
90+
// TODO : FilterExpression
91+
var result = this.VirtualMachineImageClient.List(Location.Canonicalize(), PublisherName, Offer, Skus, null);
92+
93+
/*var images = from r in result
94+
select new PSVirtualMachineImage
95+
{
96+
Id = r.Id,
97+
Location = r.Location,
98+
Version = r.Name,
99+
PublisherName = this.PublisherName,
100+
Offer = this.Offer,
101+
Skus = this.Skus,
102+
FilterExpression = this.FilterExpression
103+
};
104+
105+
WriteObject(images, true);*/
106+
WriteObject(result, true);
107+
}
108+
else
109+
{
110+
var result = this.VirtualMachineImageClient.Get(Location.Canonicalize(), PublisherName, Offer, Skus, Version);
111+
112+
/*var image = new PSVirtualMachineImageDetail
113+
{
114+
Id = result.Id,
115+
Location = result.Location,
116+
Name = result.Name,
117+
Version = result.Name,
118+
PublisherName = this.PublisherName,
119+
Offer = this.Offer,
120+
Skus = this.Skus,
121+
OSDiskImage = result.OsDiskImage,
122+
DataDiskImages = result.DataDiskImages,
123+
PurchasePlan = result.Plan,
124+
};
125+
126+
WriteObject(image);*/
127+
WriteObject(result);
128+
}
129+
});
130+
}
131+
}
132+
}
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.Collections.Generic;
20+
using System.Linq;
21+
using System.Management.Automation;
22+
23+
namespace Microsoft.Azure.Commands.Compute
24+
{
25+
[Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineImageOffer)]
26+
[OutputType(typeof(PSVirtualMachineImageOffer))]
27+
public class GetAzureVMImageOfferCommand : VirtualMachineImageBaseCmdlet
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+
protected override void ProcessRecord()
36+
{
37+
base.ProcessRecord();
38+
39+
ExecuteClientAction(() =>
40+
{
41+
IList<VirtualMachineImageResource> result = this.VirtualMachineImageClient.ListOffers(Location.Canonicalize(), PublisherName);
42+
43+
/*var images = from r in result
44+
select new PSVirtualMachineImageOffer
45+
{
46+
Id = r.Id,
47+
Location = r.Location,
48+
Offer = r.Name,
49+
PublisherName = this.PublisherName
50+
};
51+
52+
WriteObject(images, true);*/
53+
WriteObject(result, true);
54+
});
55+
}
56+
}
57+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.Collections.Generic;
20+
using System.Linq;
21+
using System.Management.Automation;
22+
23+
namespace Microsoft.Azure.Commands.Compute
24+
{
25+
[Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineImagePublisher)]
26+
[OutputType(typeof(PSVirtualMachineImagePublisher))]
27+
public class GetAzureVMImagePublisherCommand : VirtualMachineImageBaseCmdlet
28+
{
29+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true), ValidateNotNullOrEmpty]
30+
public string Location { get; set; }
31+
32+
protected override void ProcessRecord()
33+
{
34+
base.ProcessRecord();
35+
36+
ExecuteClientAction(() =>
37+
{
38+
IList<VirtualMachineImageResource> result = this.VirtualMachineImageClient.ListPublishers(Location.Canonicalize());
39+
40+
var images = from r in result
41+
select new PSVirtualMachineImagePublisher
42+
{
43+
Id = r.Id,
44+
Location = r.Location,
45+
PublisherName = r.Name
46+
};
47+
48+
WriteObject(result, true);
49+
// TODO: Cannot Write the Result from Linq Select.
50+
//WriteObject(images, true);
51+
});
52+
}
53+
}
54+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.Collections.Generic;
20+
using System.Linq;
21+
using System.Management.Automation;
22+
23+
namespace Microsoft.Azure.Commands.Compute
24+
{
25+
[Cmdlet(VerbsCommon.Get, ProfileNouns.VirtualMachineImageSku)]
26+
[OutputType(typeof(PSVirtualMachineImageSku))]
27+
public class GetAzureVMImageSkuCommand : VirtualMachineImageBaseCmdlet
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 Offer { get; set; }
37+
38+
protected override void ProcessRecord()
39+
{
40+
base.ProcessRecord();
41+
42+
ExecuteClientAction(() =>
43+
{
44+
IList<VirtualMachineImageResource> result = this.VirtualMachineImageClient.ListSkus(Location.Canonicalize(), PublisherName, Offer);
45+
46+
/*var images = from r in result
47+
select new PSVirtualMachineImageSku
48+
{
49+
Id = r.Id,
50+
Location = r.Location,
51+
PublisherName = this.PublisherName,
52+
Offer = this.Offer,
53+
Skus = r.Name
54+
};
55+
56+
WriteObject(images, true);*/
57+
WriteObject(result, true);
58+
});
59+
}
60+
}
61+
}
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 VirtualMachineImageBaseCmdlet : ComputeClientBaseCmdlet
20+
{
21+
public IVirtualMachineImagesOperations VirtualMachineImageClient
22+
{
23+
get
24+
{
25+
return ComputeClient.ComputeManagementClient.VirtualMachineImages;
26+
}
27+
}
28+
}
29+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.Azure.Management.Compute.Models;
2+
using Newtonsoft.Json;
3+
4+
namespace Microsoft.Azure.Commands.Compute.Models
5+
{
6+
class AzureDiskEncryptionStatusContext
7+
{
8+
public bool OsVolumeEncrypted { get; set; }
9+
public DiskEncryptionSettings OsVolumeEncryptionSettings { get; set; }
10+
11+
[JsonIgnore]
12+
public string OsVolumeEncryptionSettingsText
13+
{
14+
get { return JsonConvert.SerializeObject(OsVolumeEncryptionSettings, Formatting.Indented); }
15+
}
16+
public bool DataVolumesEncrypted { get; set;}
17+
}
18+
}

0 commit comments

Comments
 (0)