public override void ExecuteCmdlet() { if (ShouldProcess(Name, "Create Container Group")) { var creationParameter = new ContainerGroupCreationParameters { Name = Name, ResourceGroupName = ResourceGroupName, Location = Location ?? GetResourceGroupLocation(ResourceGroupName), Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true), OsType = OsType ?? ContainerGroupCreationParameters.DefaultOsType, RestartPolicy = RestartPolicy ?? ContainerGroupRestartPolicy.Always, IpAddressType = IpAddressType, DnsNameLabel = DnsNameLabel, Ports = Port ?? ContainerGroupCreationParameters.DefaultPorts, ContainerImage = Image, EnvironmentVariables = ConvertHashtableToDictionary(EnvironmentVariable), Cpu = Cpu ?? ContainerGroupCreationParameters.DefaultCpu, MemoryInGb = MemoryInGB ?? ContainerGroupCreationParameters.DefaultMemory, RegistryServer = RegistryServerDomain, RegistryUsername = RegistryCredential?.UserName, RegistryPassword = ContainerGroupCreationParameters.ConvertToString(RegistryCredential?.Password), AzureFileVolumeShareName = AzureFileVolumeShareName, AzureFileVolumeAccountName = AzureFileVolumeAccountCredential?.UserName, AzureFileVolumeAccountKey = ContainerGroupCreationParameters.ConvertToString(AzureFileVolumeAccountCredential?.Password), AzureFileVolumeMountPath = AzureFileVolumeMountPath, Identity = ParseIdentity() }; if (!string.IsNullOrWhiteSpace(this.Command)) { ParseError[] errors; Token[] tokens; Parser.ParseInput(this.Command, out tokens, out errors); if (errors.Any()) { throw new ArgumentException($"Invalid 'Command' parameter: {string.Join("; ", errors.Select(err => err.Message))}"); } creationParameter.ContainerCommand = tokens.Select(token => token.Text.Trim('\'', '"')).Where(token => !string.IsNullOrEmpty(token)).ToList(); } creationParameter.Validate(); var psContainerGroup = PSContainerGroup.FromContainerGroup( CreateContainerGroup(creationParameter)); WriteObject(psContainerGroup); } }
public override void ExecuteCmdlet() { if (this.ShouldProcess(this.Name, "Create Container Group")) { var creationParameter = new ContainerGroupCreationParameters() { Name = this.Name, ResourceGroupName = this.ResourceGroupName, Location = this.Location ?? this.GetResourceGroupLocation(this.ResourceGroupName), Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true), OsType = this.OsType ?? ContainerGroupCreationParameters.DefaultOsType, RestartPolicy = this.RestartPolicy ?? ContainerGroupRestartPolicy.Always, IpAddressType = this.IpAddressType, DnsNameLabel = this.DnsNameLabel, Ports = this.Port ?? ContainerGroupCreationParameters.DefaultPorts, ContainerImage = this.Image, EnvironmentVariables = this.ConvertHashtableToDictionary(this.EnvironmentVariable), Cpu = this.Cpu ?? ContainerGroupCreationParameters.DefaultCpu, MemoryInGb = this.MemoryInGB ?? ContainerGroupCreationParameters.DefaultMemory, RegistryServer = this.RegistryServerDomain, RegistryUsername = this.RegistryCredential?.UserName, RegistryPassword = ContainerGroupCreationParameters.ConvertToString(this.RegistryCredential?.Password), AzureFileVolumeShareName = this.AzureFileVolumeShareName, AzureFileVolumeAccountName = this.AzureFileVolumeAccountCredential?.UserName, AzureFileVolumeAccountKey = ContainerGroupCreationParameters.ConvertToString(this.AzureFileVolumeAccountCredential?.Password), AzureFileVolumeMountPath = this.AzureFileVolumeMountPath }; #if !NETSTANDARD if (!string.IsNullOrWhiteSpace(this.Command)) { Collection <PSParseError> errors; var commandTokens = PSParser.Tokenize(this.Command, out errors); if (errors.Any()) { throw new ArgumentException($"Invalid 'Command' parameter: {string.Join("; ", errors.Select(err => err.Message))}"); } creationParameter.ContainerCommand = commandTokens.Select(token => token.Content).ToList(); } #endif creationParameter.Validate(); var psContainerGroup = PSContainerGroup.FromContainerGroup( this.CreateContainerGroup(creationParameter)); this.WriteObject(psContainerGroup); } }