Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make az.guestconfiguration cmdlet support ARC senario #12036

Merged
merged 4 commits into from
Jun 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PsModuleName>GuestConfiguration</PsModuleName>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)..\..\Az.Test.props" />

<PropertyGroup>
<RootNamespace>$(LegacyAssemblyPrefix)$(PsModuleName)$(AzTestAssemblySuffix)</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.GuestConfiguration" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.Management.GuestConfiguration" Version="1.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ Get guest configuration policy status history by Vm name scope
#>
function Get-AzVMGuestPolicyStatusHistory-VmNameScope
{
$rgName = "aashishGoodPolicy"
$vmName = "aashishvm1"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"

$historicalStatuses = Get-AzVMGuestPolicyStatusHistory -ResourceGroupName $rgName -VMName $vmName
Assert-NotNull $historicalStatuses
@@ -32,8 +32,8 @@ Get guest configuration policy status history by Vm name scope
#>
function Get-AzVMGuestPolicyStatusHistory-VmNameScope_Custom
{
$rgName = "aashishCustomrole7ux"
$vmName = "aashishCustomrole7ux"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"

$historicalStatuses = Get-AzVMGuestPolicyStatusHistory -ResourceGroupName $rgName -VMName $vmName
Assert-NotNull $historicalStatuses
@@ -46,9 +46,9 @@ Get guest configuration policy status history by Initiative id scope
#>
function Get-AzVMGuestPolicyStatusHistory-InitiativeIdScope
{
$rgName = "aashishGoodPolicy"
$vmName = "aashishvm1"
$initiativeId = "/providers/Microsoft.Authorization/policySetDefinitions/8bc55e6b-e9d5-4266-8dac-f688d151ec9c"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"
$initiativeId = "/subscriptions/f66367e1-cf7d-407b-ba39-53230cc79071/providers/Microsoft.Authorization/policySetDefinitions/92e09915-8806-493c-baac-4858b0eeea7b"

$historicalStatuses = Get-AzVMGuestPolicyStatusHistory -ResourceGroupName $rgName -VMName $vmName -InitiativeId $initiativeId
Assert-NotNull $historicalStatuses
@@ -61,9 +61,9 @@ Get guest configuration policy status history by Initiative id scope
#>
function Get-AzVMGuestPolicyStatusHistory-InitiativeIdScope_Custom
{
$rgName = "aashishCustomrole7ux"
$vmName = "aashishCustomrole7ux"
$initiativeId = "/subscriptions/b5e4748c-f69a-467c-8749-e2f9c8cd3db0/providers/Microsoft.Authorization/policySetDefinitions/60062d3c-3282-4a3d-9bc4-3557dded22ca"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"
$initiativeId = "/subscriptions/f66367e1-cf7d-407b-ba39-53230cc79071/providers/Microsoft.Authorization/policySetDefinitions/92e09915-8806-493c-baac-4858b0eeea7b"

$historicalStatuses = Get-AzVMGuestPolicyStatusHistory -ResourceGroupName $rgName -VMName $vmName -InitiativeId $initiativeId
Assert-NotNull $historicalStatuses
@@ -76,9 +76,9 @@ Get guest configuration policy status history by Initiative name scope
#>
function Get-AzVMGuestPolicyStatusHistory-InitiativeNameScope
{
$rgName = "aashishGoodPolicy"
$vmName = "aashishvm1"
$initiativeName = "8bc55e6b-e9d5-4266-8dac-f688d151ec9c"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"
$initiativeName = "92e09915-8806-493c-baac-4858b0eeea7b"

$historicalStatuses = Get-AzVMGuestPolicyStatusHistory -ResourceGroupName $rgName -VMName $vmName -InitiativeName $initiativeName
Assert-NotNull $historicalStatuses
@@ -91,9 +91,9 @@ Get guest configuration policy status history by Initiative name scope
#>
function Get-AzVMGuestPolicyStatusHistory-InitiativeNameScope_Custom
{
$rgName = "aashishCustomrole7ux"
$vmName = "aashishCustomrole7ux"
$initiativeName = "60062d3c-3282-4a3d-9bc4-3557dded22ca"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"
$initiativeName = "92e09915-8806-493c-baac-4858b0eeea7b"

$historicalStatuses = Get-AzVMGuestPolicyStatusHistory -ResourceGroupName $rgName -VMName $vmName -InitiativeName $initiativeName
Assert-NotNull $historicalStatuses
@@ -106,8 +106,8 @@ Get guest configuration policy by vmName scope, using ShowOnlyChange switch
#>
function Get-AzVMGuestPolicyStatusHistory-ShowOnlyChangeSwitch-VmNameScope
{
$rgName = "aashishGoodPolicy"
$vmName = "aashishvm1"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"

$historicalStatuses = Get-AzVMGuestPolicyStatusHistory -ResourceGroupName $rgName -VMName $vmName -ShowOnlyChange
Assert-NotNull $historicalStatuses
@@ -120,8 +120,8 @@ Get guest configuration policy by vmName scope, using ShowOnlyChange switch
#>
function Get-AzVMGuestPolicyStatusHistory-ShowOnlyChangeSwitch-VmNameScope_Custom
{
$rgName = "aashishCustomrole7ux"
$vmName = "aashishCustomrole7ux"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"

$historicalStatuses = Get-AzVMGuestPolicyStatusHistory -ResourceGroupName $rgName -VMName $vmName -ShowOnlyChange
Assert-NotNull $historicalStatuses
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ Get guest configuration policy report by Vm name scope
#>
function Get-AzVMGuestPolicyStatus-VmNameScope
{
$rgName = "vivga"
$vmName = "Viv1809SDDC"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"

$reports = Get-AzVMGuestPolicyStatus -ResourceGroupName $rgName -VMName $vmName
Assert-NotNull $reports
@@ -32,8 +32,8 @@ Get guest configuration policy report by Vm name scope for custom policy
#>
function Get-AzVMGuestPolicyStatus-VmNameScope_Custom
{
$rgName = "aashishCustomrole7ux"
$vmName = "aashishCustomrole7ux"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"

$reports = Get-AzVMGuestPolicyStatus -ResourceGroupName $rgName -VMName $vmName
Assert-NotNull $reports
@@ -46,9 +46,9 @@ Get guest configuration policy report by Initiative id scope
#>
function Get-AzVMGuestPolicyStatus-InitiativeIdScope
{
$rgName = "vivga"
$vmName = "Viv1809SDDC"
$initiativeId = "/providers/Microsoft.Authorization/policySetDefinitions/25ef9b72-4af2-4501-acd1-fc814e73dde1"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"
$initiativeId = "/subscriptions/f66367e1-cf7d-407b-ba39-53230cc79071/providers/Microsoft.Authorization/policySetDefinitions/92e09915-8806-493c-baac-4858b0eeea7b"

$reports = Get-AzVMGuestPolicyStatus -ResourceGroupName $rgName -VMName $vmName -InitiativeId $initiativeId
Assert-NotNull $reports
@@ -61,9 +61,9 @@ Get guest configuration custom policy report by Initiative id scope
#>
function Get-AzVMGuestPolicyStatus-InitiativeIdScope_Custom
{
$rgName = "aashishCustomrole7ux"
$vmName = "aashishCustomrole7ux"
$initiativeId = "/subscriptions/b5e4748c-f69a-467c-8749-e2f9c8cd3db0/providers/Microsoft.Authorization/policySetDefinitions/60062d3c-3282-4a3d-9bc4-3557dded22ca"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"
$initiativeId = "/subscriptions/f66367e1-cf7d-407b-ba39-53230cc79071/providers/Microsoft.Authorization/policySetDefinitions/92e09915-8806-493c-baac-4858b0eeea7b"

$reports = Get-AzVMGuestPolicyStatus -ResourceGroupName $rgName -VMName $vmName -InitiativeId $initiativeId
Assert-NotNull $reports
@@ -76,9 +76,9 @@ Get guest configuration policy report by Initiative name scope
#>
function Get-AzVMGuestPolicyStatus-InitiativeNameScope
{
$rgName = "vivga"
$vmName = "Viv1809SDDC"
$initiativeName = "25ef9b72-4af2-4501-acd1-fc814e73dde1"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"
$initiativeName = "92e09915-8806-493c-baac-4858b0eeea7b"

$reports = Get-AzVMGuestPolicyStatus -ResourceGroupName $rgName -VMName $vmName -InitiativeName $initiativeName
Assert-NotNull $reports
@@ -91,9 +91,9 @@ Get guest configuration custom policy report by Initiative name scope
#>
function Get-AzVMGuestPolicyStatus-InitiativeNameScope_Custom
{
$rgName = "aashishCustomrole7ux"
$vmName = "aashishCustomrole7ux"
$initiativeName = "60062d3c-3282-4a3d-9bc4-3557dded22ca"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"
$initiativeName = "92e09915-8806-493c-baac-4858b0eeea7b"

$reports = Get-AzVMGuestPolicyStatus -ResourceGroupName $rgName -VMName $vmName -InitiativeName $initiativeName
Assert-NotNull $reports
@@ -106,9 +106,9 @@ Get guest configuration policy by ReportId scope
#>
function Get-AzVMGuestPolicyStatus-ReportIdScope
{
$rgName = "vivga"
$vmName = "Viv1809SDDC"
$initiativeName = "25ef9b72-4af2-4501-acd1-fc814e73dde1"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"
$initiativeName = "92e09915-8806-493c-baac-4858b0eeea7b"
$reports = Get-AzVMGuestPolicyStatus -ResourceGroupName $rgName -VMName $vmName -InitiativeName $initiativeName
Assert-NotNull $reports
Assert-True { $reports.Count -gt 0 }
@@ -125,9 +125,9 @@ Get guest configuration custom policy by ReportId scope
#>
function Get-AzVMGuestPolicyStatus-ReportIdScope_Custom
{
$rgName = "aashishCustomrole7ux"
$vmName = "aashishCustomrole7ux"
$initiativeName = "60062d3c-3282-4a3d-9bc4-3557dded22ca"
$rgName = "PolicyE2ETest_58_20_10_06-08-2020"
$vmName = "pol-2016corsml"
$initiativeName = "92e09915-8806-493c-baac-4858b0eeea7b"
$reports = Get-AzVMGuestPolicyStatus -ResourceGroupName $rgName -VMName $vmName -InitiativeName $initiativeName
Assert-NotNull $reports
Assert-True { $reports.Count -gt 0 }

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/GuestConfiguration/GuestConfiguration/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Support ARC machines

## Version 0.10.7
* Update references in .psd1 to use relative path
Original file line number Diff line number Diff line change
@@ -196,18 +196,41 @@ protected IEnumerable<PolicyStatusDetailed> GetPolicyStatusesDetailedByInitiativ
foreach (var gcPolicyAssignment in gcPolicyAssignmentsArray)
{
var reportGuid = CommonHelpers.GetReportGUIDFromID(gcPolicyAssignment.LatestReportId);
GuestConfigurationAssignmentReport gcrpVMReport = null;
GuestConfigurationAssignmentReport gcrpHCReport = null;
GuestConfigurationAssignmentReport gcrpReport = null;
if (gcPolicyAssignment.LatestReportId != null)
{
gcrpReport = GuestConfigurationClient.GuestConfigurationAssignmentReports.Get(resourceGroupName, gcPolicyAssignment.Configuration.Name, reportGuid, vmName);
//check Azure VM
try
{
gcrpVMReport = GuestConfigurationClient.GuestConfigurationAssignmentReports.Get(resourceGroupName, gcPolicyAssignment.Configuration.Name, reportGuid, vmName);
}
catch (GuestConfigurationErrorResponseException exception) when (HttpStatusCode.NotFound.Equals(exception.Response.StatusCode))
{
this.WriteVerbose(string.Format(StringResources.NotFoundByReportId, reportGuid));
}

//check HybridCompute machine
try
{
gcrpHCReport = GuestConfigurationClient.GuestConfigurationHCRPAssignmentReports.Get(resourceGroupName, gcPolicyAssignment.Configuration.Name, reportGuid, vmName);
}
catch (GuestConfigurationErrorResponseException exception) when (HttpStatusCode.NotFound.Equals(exception.Response.StatusCode))
{
this.WriteVerbose(string.Format(StringResources.NotFoundByReportId, reportGuid));
}

gcrpReport = gcrpVMReport != null ? gcrpVMReport : gcrpHCReport;
}


PolicyStatusDetailed policyDetailed = new PolicyStatusDetailed(gcrpReport, gcPolicyAssignment);
QueryOptions queryOptions = new QueryOptions();
queryOptions.Filter = string.Format("resourceGroup eq '{0}' and policyDefinitionAction eq 'deployifnotexists' and contains(ResourceId,'{1}')", resourceGroupName, vmName);
queryOptions.Filter = string.Format("PolicySetDefinitionName eq '{0}' and contains(ResourceId,'{1}')", gcPolicyAssignment.PolicySetDefinitionName, vmName);
queryOptions.OrderBy = "Timestamp desc";
queryOptions.Top = 1;
PolicyStatesQueryResults policyDbResults = PolicyInsightsClient.PolicyStates.ListQueryResultsForPolicySetDefinition("latest", DefaultContext.Subscription.Id, gcPolicyAssignment.PolicySetDefinitionName, queryOptions);
PolicyStatesQueryResults policyDbResults= PolicyInsightsClient.PolicyStates.ListQueryResultsForResourceGroup("latest", DefaultContext.Subscription.Id, resourceGroupName, queryOptions);
if (policyDbResults.Odatacount > 0 && policyDbResults.Value[0].IsCompliant.HasValue && !policyDbResults.Value[0].IsCompliant.Value)
{
policyDetailed.ComplianceStatus = "NonCompliant";
@@ -286,15 +309,34 @@ protected PolicyStatusDetailed GetPolicyStatusDetailedByReportId(string reportId
protected IEnumerable<GuestConfigurationAssignment> GetAllGCRPAssignments(string resourceGroupName, string vmName)
{
IEnumerable<GuestConfigurationAssignment> gcrpAssignments = null;
IEnumerable<GuestConfigurationAssignment> gcrpVMAssignments = null;
IEnumerable<GuestConfigurationAssignment> gcrpHCAssignments = null;
//check Azure VM
try
{
gcrpAssignments = GuestConfigurationClient.GuestConfigurationAssignments.List(resourceGroupName, vmName);
gcrpVMAssignments = GuestConfigurationClient.GuestConfigurationAssignments.List(resourceGroupName, vmName);
}
catch (GuestConfigurationErrorResponseException exception) when (HttpStatusCode.NotFound.Equals(exception.Response.StatusCode))
{
this.WriteVerbose(string.Format(StringResources.InvalidRGOrVMName, resourceGroupName, vmName));
throw exception;
}

//check HybridCompute machine
try
{
gcrpHCAssignments = GuestConfigurationClient.GuestConfigurationHCRPAssignments.List(resourceGroupName, vmName);
}
catch (GuestConfigurationErrorResponseException exception) when (HttpStatusCode.NotFound.Equals(exception.Response.StatusCode))
{
this.WriteVerbose(string.Format(StringResources.InvalidRGOrVMName, resourceGroupName, vmName));
}

gcrpAssignments = gcrpVMAssignments != null ? gcrpVMAssignments : gcrpHCAssignments;
if (gcrpAssignments == null)
{
throw new ErrorResponseException(StringResources.InvalidRGOrVMName);
}

return gcrpAssignments;
}

@@ -466,7 +508,30 @@ private IEnumerable<PolicyStatus> GetPolicyStatusHistoryForAssignments(string re

foreach (var gcPolicyAssignment in policyStatusesArray)
{
var gcrpReportss = GuestConfigurationClient.GuestConfigurationAssignmentReports.List(resourceGroupName, gcPolicyAssignment.Configuration.Name, vmName);
GuestConfigurationAssignmentReportList gcrpVMReportss = null;
GuestConfigurationAssignmentReportList gcrpHCReportss = null;

//check Azure VM
try
{
gcrpVMReportss = GuestConfigurationClient.GuestConfigurationAssignmentReports.List(resourceGroupName, gcPolicyAssignment.Configuration.Name, vmName);
}
catch (GuestConfigurationErrorResponseException exception) when (HttpStatusCode.NotFound.Equals(exception.Response.StatusCode))
{
this.WriteVerbose(string.Format(StringResources.InvalidRGOrVMName, resourceGroupName, vmName));
}

//check HybridCompute machine
try
{
gcrpHCReportss = GuestConfigurationClient.GuestConfigurationHCRPAssignmentReports.List(resourceGroupName, gcPolicyAssignment.Configuration.Name, vmName);
}
catch (GuestConfigurationErrorResponseException exception) when (HttpStatusCode.NotFound.Equals(exception.Response.StatusCode))
{
this.WriteVerbose(string.Format(StringResources.InvalidRGOrVMName, resourceGroupName, vmName));
}

var gcrpReportss = gcrpVMReportss != null ? gcrpVMReportss : gcrpHCReportss;
var gcrpReportsList = gcrpReportss.Value;

if (isShowStatusChangeOnlyPresent)
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PsModuleName>GuestConfiguration</PsModuleName>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)..\..\Az.props" />

<PropertyGroup>
<RootNamespace>$(LegacyAssemblyPrefix)$(PsModuleName)</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.GuestConfiguration" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.Management.GuestConfiguration" Version="1.2.0" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>