public override void ExecuteCmdlet() { if (ShouldProcess(this.IotHubName, Properties.Resources.SetIotHubConfiguration)) { IotHubDescription iotHubDescription; if (ParameterSetName.Equals(InputObjectParameterSet)) { this.ResourceGroupName = this.InputObject.Resourcegroup; this.IotHubName = this.InputObject.Name; iotHubDescription = IotHubUtils.ConvertObject <PSIotHub, IotHubDescription>(this.InputObject); } else { if (ParameterSetName.Equals(ResourceIdParameterSet)) { this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.ResourceId); this.IotHubName = IotHubUtils.GetIotHubName(this.ResourceId); } iotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.IotHubName); } IEnumerable <SharedAccessSignatureAuthorizationRule> authPolicies = this.IotHubClient.IotHubResource.ListKeys(this.ResourceGroupName, this.IotHubName); SharedAccessSignatureAuthorizationRule policy = IotHubUtils.GetPolicy(authPolicies, PSAccessRights.RegistryWrite); PSIotHubConnectionString psIotHubConnectionString = IotHubUtils.ToPSIotHubConnectionString(policy, iotHubDescription.Properties.HostName); RegistryManager registryManager = RegistryManager.CreateFromConnectionString(psIotHubConnectionString.PrimaryConnectionString); Configuration config = registryManager.GetConfigurationAsync(this.Name).GetAwaiter().GetResult(); if (config != null && config.Content.ModulesContent != null) { PSDeployment psDeployment = IotHubDataPlaneUtils.ToPSDeployment(config); if (this.IsParameterBound(c => c.Priority)) { psDeployment.Priority = this.Priority; } if (this.IsParameterBound(c => c.TargetCondition)) { psDeployment.TargetCondition = this.TargetCondition; } if (this.IsParameterBound(c => c.Label)) { psDeployment.Labels = this.Label; } if (this.IsParameterBound(c => c.Metric)) { psDeployment.Metrics.Queries = this.Metric; } this.WriteObject(IotHubDataPlaneUtils.ToPSDeployment(registryManager.UpdateConfigurationAsync(IotHubDataPlaneUtils.ToConfiguration(psDeployment), this.Force.IsPresent).GetAwaiter().GetResult())); } else { throw new ArgumentException("The deployment doesn't exist."); } } }
public static PSDeployment ToPSDeployment(this DeploymentExtended result) { PSDeployment deployment = new PSDeployment(); if (result != null) { deployment = CreatePSDeployment(result.Name, result.Location, result.Properties); } return(deployment); }
public static PSDeployment ToPSDeployment(this DeploymentExtended result, string managementGroupId = null, string resourceGroupName = null) { PSDeployment deployment = new PSDeployment(); if (result != null) { deployment = CreatePSDeployment(result, managementGroupId, resourceGroupName); } return(deployment); }
private static PSDeployment CreatePSDeployment( string name, string location, DeploymentPropertiesExtended properties) { PSDeployment deploymentObject = new PSDeployment(); deploymentObject.DeploymentName = name; deploymentObject.Location = location; SetDeploymentProperties(deploymentObject, properties); return(deploymentObject); }
private static PSDeployment CreatePSDeployment( DeploymentExtended deployment, string managementGroupId, string resourceGroup) { PSDeployment deploymentObject = new PSDeployment(); deploymentObject.Id = deployment.Id; deploymentObject.DeploymentName = deployment.Name; deploymentObject.Location = deployment.Location; deploymentObject.ManagementGroupId = managementGroupId; deploymentObject.ResourceGroupName = resourceGroup; SetDeploymentProperties(deploymentObject, deployment.Properties); return(deploymentObject); }
private static PSDeployment CreatePSDeployment( DeploymentExtended deployment, string managementGroupId, string resourceGroup) { PSDeployment deploymentObject = new PSDeployment { Id = deployment.Id, DeploymentName = deployment.Name, Location = deployment.Location, ManagementGroupId = managementGroupId, ResourceGroupName = resourceGroup, Tags = deployment.Tags == null ? new Dictionary <string, string>() : new Dictionary <string, string>(deployment.Tags) }; SetDeploymentProperties(deploymentObject, deployment.Properties); return(deploymentObject); }
public override void ExecuteCmdlet() { if (ShouldProcess(this.IotHubName, Properties.Resources.InvokeIotHubConfigurationMetricsQuery)) { IotHubDescription iotHubDescription; if (ParameterSetName.Equals(InputObjectParameterSet)) { this.ResourceGroupName = this.InputObject.Resourcegroup; this.IotHubName = this.InputObject.Name; iotHubDescription = IotHubUtils.ConvertObject <PSIotHub, IotHubDescription>(this.InputObject); } else { if (ParameterSetName.Equals(ResourceIdParameterSet)) { this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.ResourceId); this.IotHubName = IotHubUtils.GetIotHubName(this.ResourceId); } iotHubDescription = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.IotHubName); } IEnumerable <SharedAccessSignatureAuthorizationRule> authPolicies = this.IotHubClient.IotHubResource.ListKeys(this.ResourceGroupName, this.IotHubName); SharedAccessSignatureAuthorizationRule policy = IotHubUtils.GetPolicy(authPolicies, PSAccessRights.RegistryWrite); PSIotHubConnectionString psIotHubConnectionString = IotHubUtils.ToPSIotHubConnectionString(policy, iotHubDescription.Properties.HostName); RegistryManager registryManager = RegistryManager.CreateFromConnectionString(psIotHubConnectionString.PrimaryConnectionString); Configuration config = registryManager.GetConfigurationAsync(this.Name).GetAwaiter().GetResult(); if (config != null && config.Content.ModulesContent != null) { PSDeployment psDeployment = IotHubDataPlaneUtils.ToPSDeployment(config); Hashtable queries; string metricKey = this.MetricName; if (this.MetricType.Equals(PSConfigurationMetricType.System)) { if (this.MetricName.Equals("targeted", StringComparison.OrdinalIgnoreCase)) { metricKey = "targetedCount"; } if (this.MetricName.Equals("applied", StringComparison.OrdinalIgnoreCase)) { metricKey = "appliedCount"; } if (this.MetricName.Equals("reporting success", StringComparison.OrdinalIgnoreCase)) { metricKey = "reportedSuccessfulCount"; } if (this.MetricName.Equals("reporting failure", StringComparison.OrdinalIgnoreCase)) { metricKey = "reportedFailedCount"; } queries = psDeployment.SystemMetrics.Queries; } else { queries = psDeployment.Metrics.Queries; } if (queries.ContainsKey(metricKey)) { PSConfigurationMetricsResult psConfigurationMetricsResult = new PSConfigurationMetricsResult(); psConfigurationMetricsResult.Name = this.MetricName; psConfigurationMetricsResult.Criteria = queries[metricKey].ToString(); IQuery metricQuery = registryManager.CreateQuery(queries[metricKey].ToString()); psConfigurationMetricsResult.Result = metricQuery.GetNextAsJsonAsync().GetAwaiter().GetResult().ToList(); this.WriteObject(psConfigurationMetricsResult); } else { throw new ArgumentException(string.Format("The metric '{0}' is not defined in the deployment '{1}'", this.MetricName, this.Name)); } } else { throw new ArgumentException("The deployment doesn't exist."); } } }