/// <summary> /// Creates a waiter using the provided configuration. /// </summary> /// <param name="request">Request to send.</param> /// <param name="config">Wait Configuration</param> /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param> /// <returns>a new Oci.common.Waiter instance</returns> public Waiter <GetMountTargetRequest, GetMountTargetResponse> ForMountTarget(GetMountTargetRequest request, WaiterConfiguration config, params MountTarget.LifecycleStateEnum[] targetStates) { var agent = new WaiterAgent <GetMountTargetRequest, GetMountTargetResponse>( request, request => client.GetMountTarget(request), response => targetStates.Contains(response.MountTarget.LifecycleState.Value), targetStates.Contains(MountTarget.LifecycleStateEnum.Deleted) ); return(new Waiter <GetMountTargetRequest, GetMountTargetResponse>(config, agent)); }
/** * 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); }
private void HandleOutput(GetMountTargetRequest request) { var waiterConfig = new WaiterConfiguration { MaxAttempts = MaxWaitAttempts, GetNextDelayInSeconds = (_) => WaitIntervalSeconds }; switch (ParameterSetName) { case LifecycleStateParamSet: response = client.Waiters.ForMountTarget(request, waiterConfig, WaitForLifecycleState).Execute(); break; case Default: response = client.GetMountTarget(request).GetAwaiter().GetResult(); break; } WriteOutput(response, response.MountTarget); }
protected override void ProcessRecord() { base.ProcessRecord(); GetMountTargetRequest request; try { request = new GetMountTargetRequest { MountTargetId = MountTargetId, OpcRequestId = OpcRequestId }; HandleOutput(request); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
/** * 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(); }
/// <summary> /// Creates a waiter using default wait configuration. /// </summary> /// <param name="request">Request to send.</param> /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param> /// <returns>a new Oci.common.Waiter instance</returns> public Waiter <GetMountTargetRequest, GetMountTargetResponse> ForMountTarget(GetMountTargetRequest request, params MountTarget.LifecycleStateEnum[] targetStates) { return(this.ForMountTarget(request, WaiterConfiguration.DefaultWaiterConfiguration, targetStates)); }