コード例 #1
0
        /**
         * Creates a file system and waits for it to become available. We recommend to retry these requests
         * so that if you receive a timeout or server error and you won't run into the risk of creating multiple resources.
         *
         * @param fsClient the service client to use to create the File System
         * @param compartmentId the OCID of the compartment where the file system will be created
         * @param availabilityDomain the availability domain where the file system will be created
         *
         * @return the created file system
         */
        private static async Task <FileSystem> CreateFileSystem(FileStorageClient fsClient, string compartmentId,
                                                                string displayName, AvailabilityDomain availabilityDomain)
        {
            logger.Info("Creating file system......");

            CreateFileSystemDetails createDetails = new CreateFileSystemDetails
            {
                DisplayName        = displayName,
                CompartmentId      = compartmentId,
                AvailabilityDomain = availabilityDomain.Name
            };
            CreateFileSystemRequest createRequest = new CreateFileSystemRequest
            {
                CreateFileSystemDetails = createDetails
            };
            CreateFileSystemResponse createResponse = await fsClient.CreateFileSystem(createRequest, new RetryConfiguration
            {
                MaxAttempts = 5
            });

            logger.Info($"Created file system: {createResponse.FileSystem.DisplayName}");

            GetFileSystemRequest getRequest = new GetFileSystemRequest
            {
                FileSystemId = createResponse.FileSystem.Id
            };
            GetFileSystemResponse getResponse = fsClient.Waiters.ForFileSystem(getRequest, FileSystem.LifecycleStateEnum.Active).Execute();

            logger.Info($"Waited for file system to become available: {createResponse.FileSystem.DisplayName}");

            return(getResponse.FileSystem);
        }
コード例 #2
0
        /**
         * Creates a point in time snapshot of a file system and waits for it to become available. Note that snapshot
         * names are immutable and must be unique amongst all non-DELETED snapshots for a file system.
         *
         * We recommend using a retry token on these requests so that if you receive a timeout or server error
         * and need to retry the request you won't run the risk of creating multiple resources.
         *
         * @param fsClient the service client used to communicate with the File Storage service
         * @param fileSystem the file system to create the snapshot of
         */
        private static async Task <Snapshot> CreateSnapshot(FileStorageClient fsClient, FileSystem fileSystem)
        {
            logger.Info("Creating Snapshot...");

            CreateSnapshotDetails createSnapshotDetails = new CreateSnapshotDetails
            {
                FileSystemId = fileSystem.Id,
                Name         = "example_snapshot"
            };
            CreateSnapshotRequest createRequest = new CreateSnapshotRequest
            {
                CreateSnapshotDetails = createSnapshotDetails
            };
            CreateSnapshotResponse createResponse = await fsClient.CreateSnapshot(createRequest);

            logger.Info($"Created snapshot: {createResponse.Snapshot.Name}");

            logger.Info($"Waiting for snapshot to become available");
            GetSnapshotRequest getRequest = new GetSnapshotRequest
            {
                SnapshotId = createResponse.Snapshot.Id
            };
            GetSnapshotResponse getResponse = fsClient.Waiters.ForSnapshot(getRequest, Snapshot.LifecycleStateEnum.Active).Execute();

            logger.Info($"Snapshot state: {getResponse.Snapshot.LifecycleState}");

            return(getResponse.Snapshot);
        }
コード例 #3
0
 protected override void ProcessRecord()
 {
     base.ProcessRecord();
     try
     {
         client?.Dispose();
         int timeout = GetPreferredTimeout();
         WriteDebug($"Cmdlet Timeout : {timeout} milliseconds.");
         client = new FileStorageClient(AuthProvider, new Oci.Common.ClientConfiguration
         {
             RetryConfiguration = retryConfig,
             TimeoutMillis      = timeout,
             ClientUserAgent    = PSUserAgent
         });
         string region = GetPreferredRegion();
         if (region != null)
         {
             WriteDebug("Choosing Region:" + region);
             client.SetRegion(region);
         }
         if (Endpoint != null)
         {
             WriteDebug("Choosing Endpoint:" + Endpoint);
             client.SetEndpoint(Endpoint);
         }
     }
     catch (Exception ex)
     {
         TerminatingErrorDuringExecution(ex);
     }
 }
コード例 #4
0
        /**
         * Creates an export and waits for it to become available. This export enables us to access the file system
         * via the mount target. We recommend using a retry token on these requests
         * so that if you receive a timeout or server error and need to retry the request you won't run the risk of
         * creating multiple resources.
         *
         * There are rules around export paths and file system associations which you should review here:
         * https://docs.cloud.oracle.com/api/#/en/filestorage/20171215/Export/
         *
         * @param fsClient the service client to use to create the export
         * @param fileSystemId the OCID of the file system to associate with the export
         * @param exportSetId the OCID of the MountTarget's export set
         *
         * @return the created export
         */
        private static async Task <Export> CreateExport(FileStorageClient fsClient, string fileSystemId, string exportSetId)
        {
            logger.Info("Creating export.....");

            CreateExportDetails createExportDetails = new CreateExportDetails
            {
                ExportSetId  = exportSetId,
                FileSystemId = fileSystemId,
                Path         = ExportPath
            };
            CreateExportRequest createExportRequest = new CreateExportRequest
            {
                CreateExportDetails = createExportDetails
            };
            CreateExportResponse createResponse = await fsClient.CreateExport(createExportRequest,
                                                                              new RetryConfiguration
            {
                MaxAttempts = 5
            });

            logger.Info($"Created Export");

            logger.Info($"Waiting for export to become available");
            GetExportRequest getRequest = new GetExportRequest
            {
                ExportId = createResponse.Export.Id
            };
            GetExportResponse getExportResponse = fsClient.Waiters.ForExport(getRequest, Export.LifecycleStateEnum.Active).Execute();

            logger.Info($"Export path state: {getExportResponse.Export.LifecycleState}");

            return(getExportResponse.Export);
        }
コード例 #5
0
        /**
         * Displays the export paths
         *
         * @param fsClient the service client to use to retrieve the exports
         * @param listExportsRequest contains the parameters and filters to get the exports
         */
        private static void IterateExports(FileStorageClient fsClient, ListExportsRequest listExportsRequest)
        {
            IEnumerable <ExportSummary> exportSummaries = fsClient.Paginators.ListExportsRecordEnumerator(listExportsRequest);

            foreach (ExportSummary exportSummary in exportSummaries)
            {
                logger.Info($"Export path: {exportSummary.Path}");
            }
        }
コード例 #6
0
        /**
         * Retrieves the details of an export set for a mount target
         *
         * @param exportSetId the OCID of the export set (obtained from a MountTarget)
         */
        private static async Task GetExportSet(FileStorageClient fileStorageClient, string exportSetId)
        {
            logger.Info("Get export set for mount target");

            GetExportSetRequest getExportSetRequest = new GetExportSetRequest
            {
                ExportSetId = exportSetId
            };
            GetExportSetResponse getExportSetResponse = await fileStorageClient.GetExportSet(getExportSetRequest);

            logger.Info($"Export set for mount target: {getExportSetResponse.ExportSet.DisplayName}");
        }
コード例 #7
0
        /**
         * Deletes a snapshot and waits for it to be deleted.
         *
         * @param fsClient the service client used to communicate with the File Storage service
         * @param snapshot the snapshot to delete
         */
        private static async Task DeleteSnapshot(FileStorageClient fsClient, Snapshot snapshot)
        {
            logger.Info("Deleting snapshot");

            DeleteSnapshotRequest deleteSnapshotRequest = new DeleteSnapshotRequest
            {
                SnapshotId = snapshot.Id
            };
            await fsClient.DeleteSnapshot(deleteSnapshotRequest);

            GetSnapshotRequest getSnapshotRequest = new GetSnapshotRequest
            {
                SnapshotId = snapshot.Id
            };

            fsClient.Waiters.ForSnapshot(getSnapshotRequest, Snapshot.LifecycleStateEnum.Deleted).Execute();
        }
コード例 #8
0
        /**
         * Deletes an export and waits for it to be deleted.
         *
         * @param fsClient the service client used to communicate with the File Storage service
         * @param export the export to delete
         */
        private static async Task DeleteExport(FileStorageClient fsClient, Export export)
        {
            logger.Info("Deleting export");

            DeleteExportRequest deleteExportRequest = new DeleteExportRequest
            {
                ExportId = export.Id
            };
            await fsClient.DeleteExport(deleteExportRequest);

            GetExportRequest getExportRequest = new GetExportRequest
            {
                ExportId = export.Id
            };

            fsClient.Waiters.ForExport(getExportRequest, Export.LifecycleStateEnum.Deleted).Execute();
        }
コード例 #9
0
        /**
         * Creates a mount target and waits for it to become available. We recommend to retry these requests
         * so that if you receive a timeout or server error and you won't run into the risk of creating multiple resources.
         *
         * This creates a mount target WITHOUT specifying a hostname. This means that the mount target will only be accessible
         * via its private IP address.
         *
         * @param fsClient the service client to use to create the mount target
         * @param vcnClient a client used to communiate with the Virtual Networking service
         * @param compartmentId the OCID of the compartment where the file system will be created
         * @param displayName the display name of the mount target
         * @param availabilityDomain the availability domain where the file system will be created
         * @param subnet the subnet where the mount target will reside. If no private IP address is explicitly specified at
         * creation time then the mount target will be assigned a free private IP address from the subnet
         *
         * @return the created mount target
         */
        private static async Task <MountTarget> CreateMountTarget(FileStorageClient fsClient, VirtualNetworkClient vcnClient,
                                                                  string compartmentId, string displayName, AvailabilityDomain availabilityDomain, Subnet subnet)
        {
            logger.Info("Creating mount target......");

            CreateMountTargetDetails createDetails = new CreateMountTargetDetails
            {
                AvailabilityDomain = availabilityDomain.Name,
                SubnetId           = subnet.Id,
                CompartmentId      = compartmentId,
                DisplayName        = displayName
            };
            CreateMountTargetRequest createRequest = new CreateMountTargetRequest
            {
                CreateMountTargetDetails = createDetails
            };
            var retryConfiguration = new RetryConfiguration
            {
                MaxAttempts = 5
            };
            CreateMountTargetResponse createResponse = await fsClient.CreateMountTarget(createRequest, retryConfiguration);

            logger.Info($"Created Mount target: {createResponse.MountTarget.DisplayName}");

            logger.Info("Waiting for mount target to become available");
            GetMountTargetRequest getRequest = new GetMountTargetRequest
            {
                MountTargetId = createResponse.MountTarget.Id
            };
            GetMountTargetResponse getResponse = fsClient.Waiters.ForMountTarget(getRequest, MountTarget.LifecycleStateEnum.Active).Execute();

            logger.Info($"Mount target state: {getResponse.MountTarget.LifecycleState}");

            string mountTargetPrivateIpId           = getResponse.MountTarget.PrivateIpIds[0];
            GetPrivateIpRequest getPrivateIpRequest = new GetPrivateIpRequest
            {
                PrivateIpId = mountTargetPrivateIpId
            };
            GetPrivateIpResponse getPrivateIpResponse = await vcnClient.GetPrivateIp(getPrivateIpRequest);

            logger.Info($"Mount target private IP: {getPrivateIpResponse.PrivateIp.IpAddress}");

            return(getResponse.MountTarget);
        }
コード例 #10
0
        /**
         * Deletes a file system and waits for it to be deleted.
         *
         * @param fsClient the service client used to communicate with the File Storage service
         * @param fileSystem the file system to delete
         */
        private static async Task DeleteFileSystem(FileStorageClient fsClient, FileSystem fileSystem)
        {
            logger.Info("Deleting file system");

            DeleteFileSystemRequest deleteRequest = new DeleteFileSystemRequest
            {
                FileSystemId = fileSystem.Id
            };
            await fsClient.DeleteFileSystem(deleteRequest);

            WaiterConfiguration waiterConfiguration = new WaiterConfiguration
            {
                MaxAttempts           = 20,
                GetNextDelayInSeconds = DelayStrategy.GetExponentialDelayInSeconds
            };
            GetFileSystemRequest getRequest = new GetFileSystemRequest
            {
                FileSystemId = fileSystem.Id
            };

            fsClient.Waiters.ForFileSystem(getRequest, waiterConfiguration, FileSystem.LifecycleStateEnum.Deleted).Execute();
        }
コード例 #11
0
        /**
         * Demonstrates how to list exports and using various criteria. Note that listing exports is a paginated call, so we should
         * get all pages until there is no more opcNextPage token
         *
         * @param fsClient the service client used to communicate with the File Storage service
         * @param compartmentId the OCID of the compartment which owns the resources
         * @param fileSystem the file system which we're working with
         * @param mountTarget the mount target which we're working with
         */
        private static void ListExports(FileStorageClient fsClient, String compartmentId, FileSystem fileSystem, MountTarget mountTarget)
        {
            // The most basic call is to list exports by comparment ID
            ListExportsRequest listExportsRequest = new ListExportsRequest
            {
                CompartmentId = compartmentId
            };

            logger.Info("Listing exports by compartment ID");
            IterateExports(fsClient, listExportsRequest);

            // We can find all exports in a given export set
            listExportsRequest.ExportSetId = mountTarget.ExportSetId;
            logger.Info("Listing exports by export set");
            IterateExports(fsClient, listExportsRequest);

            // We can find all exports for a given file system
            listExportsRequest.ExportSetId  = null;
            listExportsRequest.FileSystemId = fileSystem.Id;
            logger.Info("Listing exports by file system");
            IterateExports(fsClient, listExportsRequest);
        }
コード例 #12
0
        /**
         * Deletes a mount target and waits for it to be deleted.
         *
         * @param fsClient the service client used to communicate with the File Storage service
         * @param mountTarget the mount target to delete
         */
        private static async Task DeleteMountTarget(FileStorageClient fsClient, MountTarget mountTarget)
        {
            logger.Info("Deleting mount target");

            DeleteMountTargetRequest deleteRequest = new DeleteMountTargetRequest
            {
                MountTargetId = mountTarget.Id
            };
            await fsClient.DeleteMountTarget(deleteRequest);

            WaiterConfiguration waiterConfiguration = new WaiterConfiguration
            {
                MaxAttempts           = 20,
                GetNextDelayInSeconds = DelayStrategy.GetExponentialDelayInSeconds
            };
            GetMountTargetRequest getRequest = new GetMountTargetRequest
            {
                MountTargetId = mountTarget.Id
            };

            fsClient.Waiters.ForMountTarget(getRequest, waiterConfiguration, MountTarget.LifecycleStateEnum.Deleted).Execute();
        }
コード例 #13
0
 public FileStorageWaiters(FileStorageClient client)
 {
     this.client = client;
 }
コード例 #14
0
 public FileStoragePaginators(FileStorageClient client)
 {
     this.client = client;
 }
コード例 #15
0
 public void WhenConnectionStringIsNull_ThenThrowException()
 {
     Assert.Throws <ArgumentNullException>(() => _ = new FileStorageClient(null, ShareName, false));
 }
コード例 #16
0
        protected FileTestBase(string shareName)
        {
            ConnectionString = GetTestConnectionString();

            _client = new FileStorageClient(ConnectionString, shareName, true);
        }
コード例 #17
0
        public static async Task MainFileStorage()
        {
            logger.Info("Starting example");

            var provider              = new ConfigFileAuthenticationDetailsProvider("DEFAULT");
            var compartmentId         = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID");
            var fileSystemDisplayName = Environment.GetEnvironmentVariable("FILE_SYSTEM_DISPLAY_NAME");

            var identityClient    = new IdentityClient(provider);
            var fileStorageClient = new FileStorageClient(provider);
            var vcnClient         = new VirtualNetworkClient(provider);

            Vcn         vcn         = null;
            Subnet      subnet      = null;
            FileSystem  fileSystem  = null;
            MountTarget mountTarget = null;
            Export      export      = null;
            Snapshot    snapshot    = null;

            try
            {
                var availablityDomain = await GetAvailabilityDomain(identityClient, compartmentId);

                logger.Info($"availability domain is {availablityDomain.Name}");

                // A VCN and subnet is required to create a mount target
                vcn = await CreateVcn(vcnClient, compartmentId);

                subnet = await CreateSubnet(vcnClient, compartmentId, availablityDomain, vcn);

                fileSystem = await CreateFileSystem(fileStorageClient, compartmentId,
                                                    fileSystemDisplayName, availablityDomain);

                mountTarget = await CreateMountTarget(fileStorageClient, vcnClient,
                                                      compartmentId, fileSystemDisplayName + "-mnt", availablityDomain, subnet);
                await GetExportSet(fileStorageClient, mountTarget.ExportSetId);

                export = await CreateExport(fileStorageClient, fileSystem.Id, mountTarget.ExportSetId);

                ListExports(fileStorageClient, compartmentId, fileSystem, mountTarget);

                snapshot = await CreateSnapshot(fileStorageClient, fileSystem);
            }
            catch (Exception e)
            {
                logger.Error($"Failed to mount file system: {e}");
            }
            finally
            {
                logger.Info("cleaning resources....");

                if (snapshot != null)
                {
                    await DeleteSnapshot(fileStorageClient, snapshot);
                }

                if (export != null)
                {
                    await DeleteExport(fileStorageClient, export);
                }

                if (mountTarget != null)
                {
                    await DeleteMountTarget(fileStorageClient, mountTarget);
                }

                if (fileSystem != null)
                {
                    await DeleteFileSystem(fileStorageClient, fileSystem);
                }

                if (subnet != null)
                {
                    await DeleteSubnet(vcnClient, subnet);
                }

                if (vcn != null)
                {
                    await DeleteVcn(vcnClient, vcn);
                }

                identityClient.Dispose();
                fileStorageClient.Dispose();
                vcnClient.Dispose();

                logger.Info("End example");
            }
        }
コード例 #18
0
 public void WhenQueueNameIsNull_ThenThrowException()
 {
     Assert.Throws <ArgumentNullException>(() => _ = new FileStorageClient(TestConnectionStrings.Valid, null, false));
 }
コード例 #19
0
        public void SetUp()
        {
            var connString = GetTestConnectionString();

            _sut = new FileStorageClient(connString, ShareName, true);
        }