Exemplo n.º 1
0
        /// <summary>
        /// ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            RecoveryServicesProviderListResponse recoveryServicesProviderListResponse =
                RecoveryServicesClient.GetAzureSiteRecoveryProvider(
                    this.Site.Name);

            if (recoveryServicesProviderListResponse.RecoveryServicesProviders.Count != 0)
            {
                throw new PSInvalidOperationException(Properties.Resources.SiteRemovalWithRegisteredHyperVHostsError);
            }

            LongRunningOperationResponse response;

            if (!this.Force.IsPresent)
            {
                response =
                    RecoveryServicesClient.DeleteAzureSiteRecoveryFabric(this.Site.Name);
            }
            else
            {
                response =
                    RecoveryServicesClient.PurgeAzureSiteRecoveryFabric(this.Site.Name);
            }

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

            WriteObject(new ASRJob(jobResponse.Job));
        }
Exemplo n.º 2
0
        /// <summary>
        /// ProcessRecord of the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            try
            {
                RecoveryServicesProviderListResponse recoveryServicesProviderListResponse =
                    RecoveryServicesClient.GetAzureSiteRecoveryProvider(
                        this.Site.Name);

                if (recoveryServicesProviderListResponse.RecoveryServicesProviders.Count != 0)
                {
                    throw new PSInvalidOperationException(Properties.Resources.SiteRemovalWithRegisteredHyperVHostsError);
                }

                FabricDeletionInput input = new FabricDeletionInput()
                {
                    Properties = new FabricDeletionInputProperties()
                };

                LongRunningOperationResponse response =
                    RecoveryServicesClient.DeleteAzureSiteRecoveryFabric(this.Site.Name, input);

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

                WriteObject(new ASRJob(jobResponse.Job));
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Queries by friendly name.
        /// </summary>
        private void GetByFriendlyName()
        {
            bool found = false;

            RecoveryServicesProviderListResponse recoveryServicesProviderListResponse =
                RecoveryServicesClient.GetAzureSiteRecoveryProvider(
                    Fabric.Name);

            foreach (RecoveryServicesProvider recoveryServicesProvider in recoveryServicesProviderListResponse.RecoveryServicesProviders)
            {
                if (0 == string.Compare(this.FriendlyName, recoveryServicesProvider.Properties.FriendlyName, true))
                {
                    this.WriteServicesProvider(recoveryServicesProvider);
                    found = true;
                }
            }

            if (!found)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Properties.Resources.ServicesProviderNotFound,
                              this.FriendlyName,
                              PSRecoveryServicesClient.asrVaultCreds.ResourceName));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Queries by name.
        /// </summary>
        private void GetByName()
        {
            try
            {
                var recoveryServicesProviderResponse = RecoveryServicesClient.GetAzureSiteRecoveryProvider(
                    Fabric.Name,
                    this.Name);

                if (recoveryServicesProviderResponse.RecoveryServicesProvider != null)
                {
                    this.WriteServicesProvider(recoveryServicesProviderResponse.RecoveryServicesProvider);
                }
            }
            catch (CloudException ex)
            {
                if (string.Compare(ex.Error.Code, "NotFound", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  Properties.Resources.ServicesProviderNotFound,
                                  this.Name,
                                  PSRecoveryServicesClient.asrVaultCreds.ResourceName));
                }
                else
                {
                    throw;
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Queries all / by default.
        /// </summary>
        private void GetAll()
        {
            RecoveryServicesProviderListResponse recoveryServicesProviderListResponse =
                RecoveryServicesClient.GetAzureSiteRecoveryProvider(
                    Fabric.Name);

            foreach (RecoveryServicesProvider recoveryServicesProvider in recoveryServicesProviderListResponse.RecoveryServicesProviders)
            {
                this.WriteServicesProvider(recoveryServicesProvider);
            }
        }
        /// <summary>
        /// ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (ShouldProcess(this.Site.FriendlyName, VerbsCommon.Remove))
            {
                this.WriteWarningWithTimestamp(
                    string.Format(Properties.Resources.CmdletWillBeDeprecatedSoon,
                                  this.MyInvocation.MyCommand.Name,
                                  "Remove-AzureRmSiteRecoveryFabric"));

                RecoveryServicesProviderListResponse recoveryServicesProviderListResponse =
                    RecoveryServicesClient.GetAzureSiteRecoveryProvider(
                        this.Site.Name);

                if (recoveryServicesProviderListResponse.RecoveryServicesProviders.Count != 0)
                {
                    throw new PSInvalidOperationException(
                              Properties.Resources.SiteRemovalWithRegisteredHyperVHostsError);
                }

                LongRunningOperationResponse response;

                if (!this.Force.IsPresent)
                {
                    response =
                        RecoveryServicesClient.DeleteAzureSiteRecoveryFabric(this.Site.Name);
                }
                else
                {
                    response =
                        RecoveryServicesClient.PurgeAzureSiteRecoveryFabric(this.Site.Name);
                }

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

                WriteObject(new ASRJob(jobResponse.Job));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Queries by friendly name.
        /// </summary>
        private void GetByFriendlyName()
        {
            FabricListResponse fabricListResponse =
                RecoveryServicesClient.GetAzureSiteRecoveryFabric();

            bool found = false;

            foreach (Fabric fabric in fabricListResponse.Fabrics)
            {
                // Do not process for fabrictype other than Vmm|HyperVSite
                if (String.Compare(fabric.Properties.CustomDetails.InstanceType, Constants.VMM) != 0 && String.Compare(fabric.Properties.CustomDetails.InstanceType, Constants.HyperVSite) != 0)
                {
                    continue;
                }

                RecoveryServicesProviderListResponse recoveryServicesProviderListResponse =
                    RecoveryServicesClient.GetAzureSiteRecoveryProvider(
                        fabric.Name);

                foreach (RecoveryServicesProvider recoveryServicesProvider in recoveryServicesProviderListResponse.RecoveryServicesProviders)
                {
                    if (0 == string.Compare(this.FriendlyName, recoveryServicesProvider.Properties.FriendlyName, true))
                    {
                        this.WriteServer(fabric, recoveryServicesProvider);
                        found = true;
                    }
                }
            }

            if (!found)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Properties.Resources.ServerNotFound,
                              this.FriendlyName,
                              PSRecoveryServicesClient.asrVaultCreds.ResourceName));
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Queries all / by default.
        /// </summary>
        private void GetAll()
        {
            FabricListResponse fabricListResponse =
                RecoveryServicesClient.GetAzureSiteRecoveryFabric();

            foreach (Fabric fabric in fabricListResponse.Fabrics)
            {
                // Do not process for fabrictype other than Vmm|HyperVSite
                if (String.Compare(fabric.Properties.CustomDetails.InstanceType, Constants.VMM) != 0 && String.Compare(fabric.Properties.CustomDetails.InstanceType, Constants.HyperVSite) != 0)
                {
                    continue;
                }

                RecoveryServicesProviderListResponse recoveryServicesProviderListResponse =
                    RecoveryServicesClient.GetAzureSiteRecoveryProvider(
                        fabric.Name);

                foreach (RecoveryServicesProvider recoveryServicesProvider in recoveryServicesProviderListResponse.RecoveryServicesProviders)
                {
                    this.WriteServer(fabric, recoveryServicesProvider);
                }
            }
        }