コード例 #1
0
        public static PSNetAppFilesVolumeGroupDetail ConvertToPs(this Management.NetApp.Models.VolumeGroupDetails volumeGroupDetails)
        {
            var psVolumeGroupDetail = new PSNetAppFilesVolumeGroupDetail()
            {
                ResourceGroupName = new ResourceIdentifier(volumeGroupDetails.Id).ResourceGroupName,
                Id   = volumeGroupDetails.Id,
                Name = volumeGroupDetails.Name,
                Type = volumeGroupDetails.Type,
                ProvisioningState = volumeGroupDetails.ProvisioningState,
                Tags          = volumeGroupDetails.Tags,
                GroupMetaData = volumeGroupDetails.GroupMetaData.ConvertToPs(),
                Volumes       = volumeGroupDetails.Volumes.ConvertToPs()
            };

            return(psVolumeGroupDetail);
        }
コード例 #2
0
        public override void ExecuteCmdlet()
        {
            IDictionary <string, string> tagPairs = null;

            if (Tag != null)
            {
                tagPairs = new Dictionary <string, string>();

                foreach (string key in Tag.Keys)
                {
                    tagPairs.Add(key, Tag[key].ToString());
                }
            }
            if (ParameterSetName == ParentObjectParameterSet)
            {
                ResourceGroupName = AccountObject.ResourceGroupName;
                var NameParts = AccountObject.Name.Split('/');
                AccountName = NameParts[0];
            }
            try
            {
                ResourceIdentifier targetResourceInfo = new ResourceIdentifier(this.Vnet);
            }
            catch (ArgumentException)
            {
                Vnet = $"/subscriptions/{this.AzureNetAppFilesManagementClient.SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Network/virtualNetworks/{this.Vnet}";
            }

            try
            {
                ResourceIdentifier targetResourceInfo = new ResourceIdentifier(this.SubnetId);
            }
            catch (ArgumentException)
            {
                SubnetId = $"{Vnet}/subnets/{SubnetId}";
            }

            //check existing
            Management.NetApp.Models.VolumeGroupDetails existingVolumeGroup = null;

            try
            {
                existingVolumeGroup = AzureNetAppFilesManagementClient.VolumeGroups.Get(ResourceGroupName, AccountName, Name);
            }
            catch
            {
                existingVolumeGroup = null;
            }
            if (existingVolumeGroup != null)
            {
                throw new AzPSResourceNotFoundCloudException($"A VolumeGroup with name '{this.Name}' in resource group '{this.ResourceGroupName}' already exists. Please use Update-AzNetAppFilesVolumeGroup to update an existing VolumeGroup.");
            }

            //check existing Pool
            Management.NetApp.Models.CapacityPool existingPool = null;
            try
            {
                existingPool = AzureNetAppFilesManagementClient.Pools.Get(ResourceGroupName, AccountName, this.PoolName);
            }
            catch
            {
                existingPool = null;
            }
            if (existingPool == null)
            {
                throw new AzPSResourceNotFoundCloudException($"A Pool with name '{this.PoolName}' in resource group '{this.ResourceGroupName}' does not exist. Please provide PoolName for an existing pool, use New-AzNetAppFilesPool to create a new Capacity Pool if needed.");
            }
            else
            {
                poolResourceId = existingPool.Id;
            }
            var volumeGroup = CreateVolumeGroup(Name, ResourceGroupName, AccountName, poolResourceId, tagPairs);

            if (ShouldProcess(Name, string.Format(PowerShell.Cmdlets.NetAppFiles.Properties.Resources.CreateResourceMessage, ResourceGroupName)))
            {
                var anfVolumeGroups = AzureNetAppFilesManagementClient.VolumeGroups.Create(volumeGroup, ResourceGroupName, AccountName, Name);
                var ret             = anfVolumeGroups.ConvertToPs();
                WriteObject(ret);
            }
        }