Exemple #1
0
        public void LongListVolumes()
        {
            HttpMockServer.RecordsDirectory = GetSessionsDirectoryPath();
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var netAppMgmtClient = NetAppTestUtilities.GetNetAppManagementClient(context, new RecordedDelegatingHandler {
                    StatusCodeToReturn = HttpStatusCode.OK
                });

                //Create 100 volumes
                var createdVolumes = new List <string>();
                int length         = 103;
                try
                {
                    long setPoolSize = 4398046511104;
                    ResourceUtils.CreateVolume(netAppMgmtClient, poolSize: setPoolSize);
                    createdVolumes.Add(ResourceUtils.volumeName1);
                    for (int i = 0; i < length - 1; i++)
                    {
                        ResourceUtils.CreateVolume(netAppMgmtClient, $"{ResourceUtils.volumeName1}-{i}", volumeOnly: true);
                        createdVolumes.Add($"{ResourceUtils.volumeName1}-{i}");
                    }
                    if (Environment.GetEnvironmentVariable("AZURE_TEST_MODE") == "Record")
                    {
                        Thread.Sleep(30000);
                    }

                    //get list of volumnes
                    var volumesPage = netAppMgmtClient.Volumes.List(ResourceUtils.resourceGroup, ResourceUtils.accountName1, ResourceUtils.poolName1);
                    // Get all resources by polling on next page link
                    var volumeResponseList = ListNextLink <Volume> .GetAllResourcesByPollingNextLink(volumesPage, netAppMgmtClient.Volumes.ListNext);

                    Assert.Equal(length, volumeResponseList.Count);

                    // cleanup
                    foreach (var volumeName in createdVolumes)
                    {
                        ResourceUtils.DeleteVolume(netAppMgmtClient, volumeName: volumeName);
                    }
                }
                catch (CloudException)
                {
                    var volumesList = new List <Volume>();
                    foreach (var volumeName in createdVolumes)
                    {
                        try
                        {
                            ResourceUtils.DeleteVolume(netAppMgmtClient, volumeName: volumeName);
                        }
                        catch
                        {
                        }
                    }
                }
                ResourceUtils.DeletePool(netAppMgmtClient);
                ResourceUtils.DeleteAccount(netAppMgmtClient);
            }
        }
        private void WaitForPoolsDeleted(AzureNetAppFilesManagementClient netAppMgmtClient, string resourceGroup = ResourceUtils.resourceGroup, string accountName = ResourceUtils.accountName1)
        {
            int count = 0;

            do
            {
                var pools    = netAppMgmtClient.Pools.List(resourceGroup, accountName);
                var poolList = ListNextLink <CapacityPool> .GetAllResourcesByPollingNextLink(pools, netAppMgmtClient.Pools.ListNext);

                count = poolList.Count;
                Thread.Sleep(5);
            } while (count > 0);
        }
        private void WaitForVolumesDeleted(AzureNetAppFilesManagementClient netAppMgmtClient, string resourceGroup = ResourceUtils.resourceGroup, string accountName = ResourceUtils.accountName1, string poolName = ResourceUtils.poolName1)
        {
            int count = 0;

            do
            {
                var volumes     = netAppMgmtClient.Volumes.List(resourceGroup, accountName, poolName);
                var volumesList = ListNextLink <Volume> .GetAllResourcesByPollingNextLink(volumes, netAppMgmtClient.Volumes.ListNext);

                count = volumesList.Count;
                Thread.Sleep(5);
            } while (count > 0);
        }
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ResourceIdParameterSet)
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                var parentResources = resourceIdentifier.ParentResource.Split('/');
                AccountName = parentResources[1];
                PoolName    = parentResources[3];
                Name        = resourceIdentifier.ResourceName;
            }
            else if (ParameterSetName == ParentObjectParameterSet)
            {
                ResourceGroupName = PoolObject.ResourceGroupName;
                var NameParts = PoolObject.Name.Split('/');
                AccountName = NameParts[0];
                PoolName    = NameParts[1];
            }

            if (Name != null)
            {
                var anfVolume = AzureNetAppFilesManagementClient.Volumes.Get(ResourceGroupName, AccountName, PoolName, Name);
                WriteObject(anfVolume.ToPsNetAppFilesVolume());
            }
            else
            {
                //var anfVolumes = AzureNetAppFilesManagementClient.Volumes.List(ResourceGroupName, AccountName, PoolName).Select(e => e.ToPsNetAppFilesVolume());
                var volumes = AzureNetAppFilesManagementClient.Volumes.List(ResourceGroupName, AccountName, PoolName);

                // To get all volumes Get all volumes by polling on next page link
                var volumeResponseList = ListNextLink <Management.NetApp.Models.Volume> .GetAllResourcesByPollingNextLink(volumes, AzureNetAppFilesManagementClient.Volumes.ListNext);

                var volumesList = new List <PSNetAppFilesVolume>();

                foreach (var volume in volumeResponseList)
                {
                    volumesList.Add(volume.ToPsNetAppFilesVolume());
                }

                WriteObject(volumesList, true);
            }
        }
        public override void Execute()
        {
            base.Execute();

            if (!string.IsNullOrEmpty(this.Name))
            {
                var vApplicationSecurityGroup      = this.NetworkClient.NetworkManagementClient.ApplicationSecurityGroups.Get(ResourceGroupName, Name);
                var vApplicationSecurityGroupModel = Mapper.Map <CNM.PSApplicationSecurityGroup>(vApplicationSecurityGroup);
                vApplicationSecurityGroupModel.ResourceGroupName = this.ResourceGroupName;
                vApplicationSecurityGroupModel.Tag = TagsConversionHelper.CreateTagHashtable(vApplicationSecurityGroup.Tags);
                WriteObject(vApplicationSecurityGroupModel, true);
            }
            else
            {
                IPage <ApplicationSecurityGroup> vApplicationSecurityGroupPage;
                if (!string.IsNullOrEmpty(this.ResourceGroupName))
                {
                    vApplicationSecurityGroupPage = this.NetworkClient.NetworkManagementClient.ApplicationSecurityGroups.List(this.ResourceGroupName);
                }
                else
                {
                    vApplicationSecurityGroupPage = this.NetworkClient.NetworkManagementClient.ApplicationSecurityGroups.ListAll();
                }

                var vApplicationSecurityGroupList = ListNextLink <ApplicationSecurityGroup> .GetAllResourcesByPollingNextLink(vApplicationSecurityGroupPage,
                                                                                                                              this.NetworkClient.NetworkManagementClient.ApplicationSecurityGroups.ListNext);

                List <PSApplicationSecurityGroup> psApplicationSecurityGroupList = new List <PSApplicationSecurityGroup>();
                foreach (var vApplicationSecurityGroup in vApplicationSecurityGroupList)
                {
                    var vApplicationSecurityGroupModel = Mapper.Map <CNM.PSApplicationSecurityGroup>(vApplicationSecurityGroup);
                    vApplicationSecurityGroupModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(vApplicationSecurityGroup.Id);
                    vApplicationSecurityGroupModel.Tag = TagsConversionHelper.CreateTagHashtable(vApplicationSecurityGroup.Tags);
                    psApplicationSecurityGroupList.Add(vApplicationSecurityGroupModel);
                }
                WriteObject(psApplicationSecurityGroupList);
            }
        }
        public override void Execute()
        {
            base.Execute();

            if (ShouldGetByName(ResourceGroupName, Name))
            {
                var vDdosProtectionPlan      = this.NetworkClient.NetworkManagementClient.DdosProtectionPlans.Get(ResourceGroupName, Name);
                var vDdosProtectionPlanModel = NetworkResourceManagerProfile.Mapper.Map <CNM.PSDdosProtectionPlan>(vDdosProtectionPlan);
                vDdosProtectionPlanModel.ResourceGroupName = this.ResourceGroupName;
                vDdosProtectionPlanModel.Tag = TagsConversionHelper.CreateTagHashtable(vDdosProtectionPlan.Tags);
                WriteObject(vDdosProtectionPlanModel, true);
            }
            else
            {
                IPage <DdosProtectionPlan> vDdosProtectionPlanPage;
                if (ShouldListByResourceGroup(ResourceGroupName, Name))
                {
                    vDdosProtectionPlanPage = this.NetworkClient.NetworkManagementClient.DdosProtectionPlans.ListByResourceGroup(this.ResourceGroupName);
                }
                else
                {
                    vDdosProtectionPlanPage = this.NetworkClient.NetworkManagementClient.DdosProtectionPlans.List();
                }

                var vDdosProtectionPlanList = ListNextLink <DdosProtectionPlan> .GetAllResourcesByPollingNextLink(vDdosProtectionPlanPage,
                                                                                                                  this.NetworkClient.NetworkManagementClient.DdosProtectionPlans.ListNext);

                List <PSDdosProtectionPlan> psDdosProtectionPlanList = new List <PSDdosProtectionPlan>();
                foreach (var vDdosProtectionPlan in vDdosProtectionPlanList)
                {
                    var vDdosProtectionPlanModel = NetworkResourceManagerProfile.Mapper.Map <CNM.PSDdosProtectionPlan>(vDdosProtectionPlan);
                    vDdosProtectionPlanModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(vDdosProtectionPlan.Id);
                    vDdosProtectionPlanModel.Tag = TagsConversionHelper.CreateTagHashtable(vDdosProtectionPlan.Tags);
                    psDdosProtectionPlanList.Add(vDdosProtectionPlanModel);
                }
                WriteObject(TopLevelWildcardFilter(ResourceGroupName, Name, psDdosProtectionPlanList), true);
            }
        }
Exemple #7
0
        public override void Execute()
        {
            base.Execute();

            if (!string.IsNullOrEmpty(this.Name))
            {
                var vRouteTable      = this.NetworkClient.NetworkManagementClient.RouteTables.Get(ResourceGroupName, Name, ExpandResource);
                var vRouteTableModel = Mapper.Map <CNM.PSRouteTable>(vRouteTable);
                vRouteTableModel.ResourceGroupName = this.ResourceGroupName;
                vRouteTableModel.Tag = TagsConversionHelper.CreateTagHashtable(vRouteTable.Tags);
                WriteObject(vRouteTableModel, true);
            }
            else
            {
                IPage <RouteTable> vRouteTablePage;
                if (!string.IsNullOrEmpty(this.ResourceGroupName))
                {
                    vRouteTablePage = this.NetworkClient.NetworkManagementClient.RouteTables.List(this.ResourceGroupName);
                }
                else
                {
                    vRouteTablePage = this.NetworkClient.NetworkManagementClient.RouteTables.ListAll();
                }

                var vRouteTableList = ListNextLink <RouteTable> .GetAllResourcesByPollingNextLink(vRouteTablePage,
                                                                                                  this.NetworkClient.NetworkManagementClient.RouteTables.ListNext);

                List <PSRouteTable> psRouteTableList = new List <PSRouteTable>();
                foreach (var vRouteTable in vRouteTableList)
                {
                    var vRouteTableModel = Mapper.Map <CNM.PSRouteTable>(vRouteTable);
                    vRouteTableModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(vRouteTable.Id);
                    vRouteTableModel.Tag = TagsConversionHelper.CreateTagHashtable(vRouteTable.Tags);
                    psRouteTableList.Add(vRouteTableModel);
                }
                WriteObject(psRouteTableList);
            }
        }
        public void LongListVolumes()
        {
            HttpMockServer.RecordsDirectory = GetSessionsDirectoryPath();
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var netAppMgmtClient = NetAppTestUtilities.GetNetAppManagementClient(context, new RecordedDelegatingHandler {
                    StatusCodeToReturn = HttpStatusCode.OK
                });
                //get list of volumnes
                var volumesPage = netAppMgmtClient.Volumes.List("sara-systemic", "Sara-Systemic-NA", "Sara-Systemic-CP");
                // Get all resources by polling on next page link
                var volumeResponseList = ListNextLink <Volume> .GetAllResourcesByPollingNextLink(volumesPage, netAppMgmtClient.Volumes.ListNext);

                var volumesList = new List <Volume>();

                foreach (var volume in volumeResponseList)
                {
                    volumesList.Add(volume);
                }

                Assert.Equal(166, volumesList.Count());
            }
        }
Exemple #9
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ResourceIdParameterSet)
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                var parentResources = resourceIdentifier.ParentResource.Split('/');
                AccountName = parentResources[1];
                PoolName    = parentResources[3];
                VolumeName  = parentResources[5];
                Name        = resourceIdentifier.ResourceName;
            }
            else if (ParameterSetName == ParentObjectParameterSet)
            {
                ResourceGroupName = VolumeObject.ResourceGroupName;
                var NameParts = VolumeObject.Name.Split('/');
                AccountName = NameParts[0];
                PoolName    = NameParts[1];
                VolumeName  = NameParts[2];
            }

            if (Name != null)
            {
                var anfSubvolume = AzureNetAppFilesManagementClient.Subvolumes.Get(ResourceGroupName, AccountName, PoolName, VolumeName, Name);
                WriteObject(anfSubvolume.ConvertToPs());
            }
            else
            {
                //List<PSNetAppFilesSubvolumeInfo> anfSubvolumes = null;
                var volumes = AzureNetAppFilesManagementClient.Subvolumes.ListByVolume(ResourceGroupName, AccountName, PoolName, VolumeName);
                // To get all subvolumes Get all subvolumes by polling on next page link
                var subVolumeResponseList = ListNextLink <Management.NetApp.Models.SubvolumeInfo> .GetAllResourcesByPollingNextLink(volumes, AzureNetAppFilesManagementClient.Subvolumes.ListByVolumeNext).ConvertToPS();

                WriteObject(subVolumeResponseList, true);
            }
        }