/// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.ShouldProcess(
                    this.FriendlyName,
                    VerbsCommon.New))
            {
                // Validate the Fabric Type for VMWare.
                if (this.ProtectionContainer.FabricType != Constants.VMware)
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  Resources.UnsupportedFabricTypeForDiscoverVirtualMachines,
                                  this.ProtectionContainer.FabricType));
                }

                // Set the Fabric Name.
                this.fabricName = Utilities.GetValueFromArmId(
                    this.ProtectionContainer.ID,
                    ARMResourceTypeConstants.ReplicationFabrics);

                // Create the Discover Protectable Item input request.
                var input = new DiscoverProtectableItemRequest
                {
                    Properties = new DiscoverProtectableItemRequestProperties
                    {
                        FriendlyName = this.FriendlyName,
                        IpAddress    = this.IPAddress,
                        OsType       = this.OSType
                    }
                };

                // Discover the Protectable Item.
                var response = this.RecoveryServicesClient.NewAzureSiteRecoveryProtectableItem(
                    this.fabricName,
                    this.ProtectionContainer.Name,
                    input);

                var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(
                    PSRecoveryServicesClient.GetJobIdFromReponseLocation(
                        response.Location));

                this.WriteObject(new ASRJob(jobResponse));
            }
        }
Exemple #2
0
        /// <summary>
        ///     Discovers Protectable Items.
        /// </summary>
        /// <param name="fabricName">Fabric Name</param>
        /// <param name="protectionContainerName">Protection Container Name</param>
        /// <param name="input">Discover Protectable Item Request</param>
        /// <returns>Long running operation response</returns>
        public PSSiteRecoveryLongRunningOperation NewAzureSiteRecoveryProtectableItem(
            string fabricName,
            string protectionContainerName,
            DiscoverProtectableItemRequest input)
        {
            var op = this.GetSiteRecoveryClient()
                     .ReplicationProtectionContainers.BeginDiscoverProtectableItemWithHttpMessagesAsync(
                fabricName,
                protectionContainerName,
                input,
                this.GetRequestHeaders(true))
                     .GetAwaiter()
                     .GetResult();

            var result = SiteRecoveryAutoMapperProfile.Mapper.Map <PSSiteRecoveryLongRunningOperation>(op);

            return(result);
        }
 /// <summary>
 /// Discovers a protectable item.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.SiteRecovery.IProtectionContainerOperations.
 /// </param>
 /// <param name='fabricName'>
 /// Required. Fabric name.
 /// </param>
 /// <param name='protectionContainerName'>
 /// Required. Protection container name.
 /// </param>
 /// <param name='input'>
 /// Required. Discover Protectable Item Request.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// A standard service response for long running operations.
 /// </returns>
 public static Task <LongRunningOperationResponse> BeginDiscoverProtectableItemAsync(this IProtectionContainerOperations operations, string fabricName, string protectionContainerName, DiscoverProtectableItemRequest input, CustomRequestHeaders customRequestHeaders)
 {
     return(operations.BeginDiscoverProtectableItemAsync(fabricName, protectionContainerName, input, customRequestHeaders, CancellationToken.None));
 }
 /// <summary>
 /// Discovers a protectable item.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.SiteRecovery.IProtectionContainerOperations.
 /// </param>
 /// <param name='fabricName'>
 /// Required. Fabric name.
 /// </param>
 /// <param name='protectionContainerName'>
 /// Required. Protection container name.
 /// </param>
 /// <param name='input'>
 /// Required. Discover Protectable Item Request.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// A standard service response for long running operations.
 /// </returns>
 public static LongRunningOperationResponse BeginDiscoverProtectableItem(this IProtectionContainerOperations operations, string fabricName, string protectionContainerName, DiscoverProtectableItemRequest input, CustomRequestHeaders customRequestHeaders)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IProtectionContainerOperations)s).BeginDiscoverProtectableItemAsync(fabricName, protectionContainerName, input, customRequestHeaders);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 /// <summary>
 /// Adds a protectable item to the replication protection container.
 /// </summary>
 /// <remarks>
 /// The operation to a add a protectable item to a protection container(Add
 /// physical server).
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='fabricName'>
 /// The name of the fabric.
 /// </param>
 /// <param name='protectionContainerName'>
 /// The name of the protection container.
 /// </param>
 /// <param name='discoverProtectableItemRequest'>
 /// The request object to add a protectable item.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <ProtectionContainer> BeginDiscoverProtectableItemAsync(this IReplicationProtectionContainersOperations operations, string fabricName, string protectionContainerName, DiscoverProtectableItemRequest discoverProtectableItemRequest, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginDiscoverProtectableItemWithHttpMessagesAsync(fabricName, protectionContainerName, discoverProtectableItemRequest, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Adds a protectable item to the replication protection container.
 /// </summary>
 /// <remarks>
 /// The operation to a add a protectable item to a protection container(Add
 /// physical server).
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='fabricName'>
 /// The name of the fabric.
 /// </param>
 /// <param name='protectionContainerName'>
 /// The name of the protection container.
 /// </param>
 /// <param name='discoverProtectableItemRequest'>
 /// The request object to add a protectable item.
 /// </param>
 public static ProtectionContainer BeginDiscoverProtectableItem(this IReplicationProtectionContainersOperations operations, string fabricName, string protectionContainerName, DiscoverProtectableItemRequest discoverProtectableItemRequest)
 {
     return(operations.BeginDiscoverProtectableItemAsync(fabricName, protectionContainerName, discoverProtectableItemRequest).GetAwaiter().GetResult());
 }