示例#1
0
        /// <summary>
        /// Method to get the Azure site recovery sites
        /// </summary>
        /// <param name="vault">vault object</param>
        /// <returns>Site list response</returns>
        public SiteListResponse GetAzureSiteRecoverySites(ASRVault vault = null)
        {
            if (vault != null)
            {
                Utilities.UpdateVaultSettings(new ASRVaultCreds()
                {
                    CloudServiceName = vault.CloudServiceName,
                    ResourceName     = vault.Name
                });
            }

            return(this.GetSiteRecoveryClient().Sites.List(this.GetRequestHeaders(false)));
        }
示例#2
0
        /// <summary>
        /// Gets the vault credential object
        /// </summary>
        /// <param name="managementCert">certificate to be uploaded</param>
        /// <param name="vault">vault object</param>
        /// <param name="site">site object </param>
        /// <returns>credential object</returns>
        public ASRVaultCreds GenerateVaultCredential(X509Certificate2 managementCert, ASRVault vault, Site site)
        {
            string currentResourceName     = PSRecoveryServicesClient.asrVaultCreds.ResourceName;
            string currentCloudServiceName = PSRecoveryServicesClient.asrVaultCreds.CloudServiceName;

            // Update vault settings with the working vault to generate file
            Utilities.UpdateVaultSettings(new ASRVaultCreds()
            {
                CloudServiceName = vault.CloudServiceName,
                ResourceName     = vault.Name
            });

            // Get Channel Integrity key
            string        channelIntegrityKey;
            Task <string> getChannelIntegrityKey = this.GetChannelIntegrityKey();

            // Making sure we can generate the file, once the SDK and portal are inter-operable
            // upload certificate and fetch of ACIK can be made parallel to improvve the performace.
            getChannelIntegrityKey.Wait();

            // Upload certificate
            UploadCertificateResponse        acsDetails;
            Task <UploadCertificateResponse> uploadCertificate = this.UpdateVaultCertificate(managementCert);

            uploadCertificate.Wait();

            acsDetails          = uploadCertificate.Result;
            channelIntegrityKey = getChannelIntegrityKey.Result;

            ASRVaultCreds asrVaultCreds = this.GenerateCredentialObject(
                managementCert,
                acsDetails,
                channelIntegrityKey,
                vault,
                site);

            // Update back the original vault settings
            Utilities.UpdateVaultSettings(new ASRVaultCreds()
            {
                CloudServiceName = currentCloudServiceName,
                ResourceName     = currentResourceName
            });

            return(asrVaultCreds);
        }
示例#3
0
        /// <summary>
        /// Method to create a Site
        /// </summary>
        /// <param name="siteName">name of the site</param>
        /// <param name="siteType">type of the site</param>
        /// <param name="vault">vault object</param>
        /// <returns>job object for the creation.</returns>
        public JobResponse CreateAzureSiteRecoverySite(string siteName, string siteType = null, ASRVault vault = null)
        {
            if (vault != null)
            {
                Utilities.UpdateVaultSettings(new ASRVaultCreds()
                {
                    CloudServiceName = vault.CloudServiceName,
                    ResourceName     = vault.Name
                });
            }

            if (string.IsNullOrEmpty(siteType))
            {
                siteType = FabricProviders.HyperVSite;
            }

            SiteCreationInput input = new SiteCreationInput()
            {
                Name       = siteName,
                FabricType = siteType
            };

            return(this.GetSiteRecoveryClient().Sites.Create(input, this.GetRequestHeaders(false)));
        }
示例#4
0
        /// <summary>
        /// ProcessRecord of the command.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            this.WriteVerbose("Vault Settings File path: " + this.Path);

            ASRVaultCreds asrVaultCreds = null;

            if (File.Exists(this.Path))
            {
                try
                {
                    var serializer = new DataContractSerializer(typeof(ASRVaultCreds));
                    using (var s = new FileStream(
                               this.Path,
                               FileMode.Open,
                               FileAccess.Read,
                               FileShare.Read))
                    {
                        asrVaultCreds = (ASRVaultCreds)serializer.ReadObject(s);
                    }
                }
                catch (XmlException xmlException)
                {
                    throw new XmlException(
                              string.Format(Properties.Resources.InvalidXml, xmlException));
                }
                catch (SerializationException serializationException)
                {
                    throw new SerializationException(
                              string.Format(Properties.Resources.InvalidXml, serializationException));
                }
            }
            else
            {
                throw new FileNotFoundException(
                          Properties.Resources.VaultSettingFileNotFound,
                          this.Path);
            }

            // Validate required parameters taken from the Vault settings file.
            if (string.IsNullOrEmpty(asrVaultCreds.ResourceName))
            {
                throw new ArgumentException(
                          Properties.Resources.ResourceNameNullOrEmpty,
                          asrVaultCreds.ResourceName);
            }

            if (string.IsNullOrEmpty(asrVaultCreds.CloudServiceName))
            {
                throw new ArgumentException(
                          Properties.Resources.CloudServiceNameNullOrEmpty,
                          asrVaultCreds.CloudServiceName);
            }

            try
            {
                RecoveryServicesClient.ValidateVaultSettings(
                    asrVaultCreds.ResourceName,
                    asrVaultCreds.CloudServiceName);

                Utilities.UpdateVaultSettings(asrVaultCreds);
                this.WriteObject(new ASRVaultSettings(
                                     asrVaultCreds.ResourceName,
                                     asrVaultCreds.CloudServiceName));
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }