public static ResourceGroupExtended CreateResourceGroup( SubscriptionCloudCredentials creds, string name, string location )
 {
     var resourceMgmtClient = new ResourceManagementClient( creds );
     var resourceGroupsResponse = resourceMgmtClient.ResourceGroups.CreateOrUpdate( name, new ResourceGroup { Location = location } );
     
     return resourceGroupsResponse.ResourceGroup;
 }
        public ResourceGroupHelper(SubscriptionCloudCredentials credentials)
        {
            _client = new ResourceManagementClient(credentials);

            if (!IsProviderRegistered(_client.Providers.List(null), "Micorsoft.Network"))
            {
                _client.Providers.Register("Microsoft.Network");
            }
        }
        private static SubscriptionCloudCredentials GetCreds() 
        {
            if (Creds == null)
            {
                X509Certificate2 cert = new X509Certificate2(certName, certPassword);
                Creds = new CertificateCloudCredentials(testSubscription, cert);
                ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => { return true; };
            }

            return Creds;
        }
 public void CreateCloudService(SubscriptionCloudCredentials credentials,string cloudServiceName)
 {
     var cloudServiceClient = new CloudServiceManagementClient(credentials);
     var cloudServiceCreateParameters = new CloudServiceCreateParameters
     {
         Description = cloudServiceParameters.Description,
         GeoRegion = cloudServiceParameters.GeoRegion,
         Label = cloudServiceParameters.Label
     };
     cloudServiceClient.CloudServices.Create(cloudServiceName, cloudServiceCreateParameters);
 }
        public static string[] GetRegions( SubscriptionCloudCredentials creds )
        {
            var sbMgmt = new ServiceBusManagementClient( creds );
            var regionsResponse = sbMgmt.GetServiceBusRegionsAsync( ).Result;

            int currentRegion = 0, regionsCount = regionsResponse.Count( );
            string[] regions = new string[ regionsCount ];
            foreach( var region in regionsResponse )
            {
                regions[ currentRegion++ ] = region.FullName;
            }

            return regions;
        }
        public static ServiceBusNamespace[] GetNamespaces( SubscriptionCloudCredentials creds )
        {
            var sbMgmt = new ServiceBusManagementClient( creds );
            var regionsResponse = sbMgmt.Namespaces.List( );

            int currentNamespace = 0, namespaceCount = regionsResponse.Count( );
            ServiceBusNamespace[] namespaces = new ServiceBusNamespace[ namespaceCount ];
            foreach( var region in regionsResponse )
            {
                namespaces[ currentNamespace++ ] = region;
            }

            return namespaces;
        }
        public static ResourceGroupExtended[] GetResourceGroups( SubscriptionCloudCredentials creds )
        {
            var resourceMgmtClient = new ResourceManagementClient( creds );
            var resourceGroupsResponse = resourceMgmtClient.ResourceGroups.ListAsync( new ResourceGroupListParameters( ) ).Result;

            int currentGroup = 0, resourceGroupsCount = resourceGroupsResponse.ResourceGroups.Count;
            ResourceGroupExtended[] resourceGroups = new ResourceGroupExtended[ resourceGroupsCount ];
            foreach( var group in resourceGroupsResponse.ResourceGroups )
            {
                resourceGroups[ currentGroup++ ] = group;
            }

            return resourceGroups;
        }
            GetSubscriptionList( SubscriptionCloudCredentials credentials )
        {
            IList<SubscriptionListOperationResponse.Subscription> ret = null;

            using( var subscriptionClient = new SubscriptionClient( credentials ) )
            {
                var listSubscriptionResults =
                    await subscriptionClient.Subscriptions.ListAsync( );

                var subscriptions = listSubscriptionResults.Subscriptions;

                ret = subscriptions;
            }
            return ret;
        }
 public static RecoveryServicesManagementClient CreateRecoveryServicesManagementClient(this CloudClients clients, SubscriptionCloudCredentials credentials, Uri baseUri)
 {
     return(new RecoveryServicesManagementClient(credentials, baseUri));
 }
Exemple #10
0
 /// <summary>        
 /// Gets deployment response from MS azure using API call.        
 /// </summary>
 /// <param name="credentials">Subscription Cloud Credentials</param>
 /// <param name="serviceUrl">ServiceUrl of subscription</param>
 /// <param name="serviceName">Name of azure service</param>
 /// <param name="deploymentName">Name of azure service deployment</param>
 /// <returns>Deployment response for subscription </returns>
 private DeploymentGetResponse GetDeploymentResponseFromMSAzure(SubscriptionCloudCredentials credentials, Uri serviceUrl,
     string serviceName, string deploymentName)
 {
   string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
   Logger.Info(methodName, ProgressResources.GetDeploymentFromMSAzureStarted, ResourceType.CloudService.ToString());
   using (var client = new ComputeManagementClient(credentials, serviceUrl))
   {
     // Call management API to get list of CloudServices.
     DeploymentGetResponse deploymentResponse = Retry.RetryOperation(() => client.Deployments.GetByName(serviceName, deploymentName),
        (BaseParameters)importParameters,
         ResourceType.Deployment, deploymentName);
     Logger.Info(methodName, ProgressResources.GetDeploymentFromMSAzureCompleted, ResourceType.CloudService.ToString());
     return deploymentResponse;
   }
 }
 public DnsZoneHelper(SubscriptionCloudCredentials credentials)
 {
     _client = new DnsManagementClient(credentials);
 }
Exemple #12
0
 public static GalleryClient CreateGalleryClient(this CloudClients clients, SubscriptionCloudCredentials credentials)
 {
     return(new GalleryClient(credentials));
 }
 public static AutomationManagementClient CreateCloudServiceManagementClient(this CloudClients clients, SubscriptionCloudCredentials credentials)
 {
     return(new AutomationManagementClient(credentials));
 }
Exemple #14
0
 public static ResourceManagementClient CreateResourceManagementClient(this CloudClients clients, SubscriptionCloudCredentials credentials)
 {
     return(new ResourceManagementClient(credentials));
 }
        public static EventHubDescription SelectEventHub( NamespaceManager nsManager, SubscriptionCloudCredentials credentials )
        {
            Console.WriteLine( "Retrieving a list of created Event Hubs..." );

            EventHubDescription[ ] eventHubs = nsManager.GetEventHubs( ).ToArray( );
            int eventHubCount = eventHubs.Length;

            Console.WriteLine( "Created Event Hubs: " );

            for( int currentNamespace = 1; currentNamespace <= eventHubCount; ++currentNamespace )
            {
                Console.WriteLine( currentNamespace + ": " + eventHubs[ currentNamespace - 1 ].Path );
            }

            for( ;; )
            {
                Console.WriteLine( "Please select Event Hub you want to use: " );

                string answer = Console.ReadLine( );

                int selection;
                if( !int.TryParse( answer, out selection ) || selection > eventHubCount || selection < -1 )
                {
                    Console.WriteLine( "Incorrect Event Hub number." );
                    continue;
                }

                if( ConsoleHelper.Confirm( "Are you sure you want to select " + eventHubs[ selection - 1 ].Path + " Event Hub?" ) )
                {
                    return eventHubs[ selection - 1 ];
                }
            }
        }
        /// <summary>
        /// Refreshes the token used to access azure automation.
        /// This is currently called from a timer that runs on the Constants.tokenRefreshInterval
        /// If it is about to expire (2 minutes from the next refresh, it will renew)
        /// </summary>
        public void RefreshAutomationClientwithNewToken()
        {
            // Get the token for the tenant on this subscription and check if it is about to expire.
            // If it is, refresh it if possible.
            if (currSubscription == null) return;
            if (azureARMAuthResult.ExpiresOn.ToLocalTime() < DateTime.Now.AddMinutes(Constants.tokenRefreshInterval + 2))
            {
                azureARMAuthResult = AuthenticateHelper.RefreshTokenByAuthority(currSubscription.ActiveDirectoryTenantId);
                subscriptionCreds = new TokenCloudCredentials(currSubscription.SubscriptionId, azureARMAuthResult.AccessToken);

                automationManagementClient = new AutomationManagementClient(subscriptionCreds);

                // Add user agent string to indicate this is coming from the ISE automation client.
                ProductInfoHeaderValue ISEClientAgent = new ProductInfoHeaderValue(Constants.ISEUserAgent, Constants.ISEVersion);
                automationManagementClient.UserAgent.Add(ISEClientAgent);
            }
        }
Exemple #17
0
 /// <summary>
 /// Checks for storage account name availability
 /// </summary>
 /// <param name="storageAccountName">Destination storage account name</param>
 /// <param name="credentials">Destination subscription credentials</param>
 /// <returns>false if storage account name is reserved</returns>
 private bool CheckStorageNameAvailability(string storageAccountName, SubscriptionCloudCredentials credentials)
 {
   string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
   Logger.Info(methodName, String.Format(ProgressResources.CheckStorageNameAvailabilityFromMSAzureStarted, storageAccountName),
       ResourceType.StorageAccount.ToString(), storageAccountName);
   using (var client = new StorageManagementClient(credentials))
   {
     CheckNameAvailabilityResponse storageResponse = Retry.RetryOperation(() => client.StorageAccounts.CheckNameAvailability(
         storageAccountName), (BaseParameters)importParameters, ResourceType.StorageAccount, storageAccountName);
     Logger.Info(methodName, String.Format(ProgressResources.CheckStorageNameAvailabilityFromMSAzureCompleted,
         storageAccountName), ResourceType.StorageAccount.ToString(), storageAccountName);
     return storageResponse.IsAvailable;
   }
 }
Exemple #18
0
        /// <summary>
        /// Gets network configuration from MS azure using management API call.
        /// Changed in v2.0
        /// </summary>
        /// <param name="credentials">Source subscription credentials</param>
        /// <param name="serviceUrl">Subscription service Url</param>
        /// <returns>Network configuration for subscription</returns>
        private NetworkGetConfigurationResponse GetNetworkConfigurationFromMSAzure(SubscriptionCloudCredentials credentials, Uri serviceUrl)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            Logger.Info(methodName, ProgressResources.GetVirtualNetworkConfigFromMSAzureStarted, ResourceType.VirtualNetwork.ToString());
            dcMigration.ReportProgress(ProgressResources.GetVirtualNetworkConfigFromMSAzureStarted);
            NetworkGetConfigurationResponse ventConfig = null;

            using (var vnetClient = new NetworkManagementClient(credentials, serviceUrl))
            {
                try
                {
                    ventConfig = vnetClient.Networks.GetConfiguration();
                    Logger.Info(methodName, ProgressResources.GetVirtualNetworkConfigFromMSAzureCompleted, ResourceType.VirtualNetwork.ToString());
                    return ventConfig;
                }
                catch (CloudException cex)
                {
                    if (ventConfig == null)
                    {
                        return ventConfig;
                    }

                    if (string.Compare(cex.Error.ToString(), Constants.ResourceNotFound, StringComparison.CurrentCultureIgnoreCase) == 0)
                    {
                        return null;
                    }
                    else
                    {
                        Logger.Error(methodName, cex, ResourceType.VirtualNetwork.ToString());
                        throw;
                    }
                }
            }
        }
Exemple #19
0
 /// <summary>
 /// Gets list of storage account operation response from MS azure using API call. 
 /// </summary>
 /// <param name="credentials">Source Subscription Credentials</param>
 /// <returns>list of storage account</returns>
 internal StorageAccountListResponse GetStorageAccountListResponseFromMSAzure(SubscriptionCloudCredentials credentials)
 {
     string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
     dcMigration.ReportProgress(ProgressResources.GetStorageAccountsFromMSAzureStarted);
     try
     {
         Logger.Info(methodName, ProgressResources.GetStorageAccountsFromMSAzureStarted, ResourceType.StorageAccount.ToString());
         using (var client = new StorageManagementClient(credentials))
         {
             // Call management API to get list of storage accounts.
             StorageAccountListResponse storageResponse = Retry.RetryOperation(() => client.StorageAccounts.List(),(BaseParameters)exportParameters,ResourceType.StorageAccount);
             Logger.Info(methodName, ProgressResources.GetStorageAccountsFromMSAzureCompleted, ResourceType.StorageAccount.ToString());
             return storageResponse;
         }
     }
     catch (Exception ex)
     {
         Logger.Error(methodName, ex, ResourceType.StorageAccount.ToString());
         throw;
     }
 }
Exemple #20
0
        /// <summary>
        /// Gets list of affinity group operation response from MS azure using API call.
        /// </summary>
        /// <param name="credentials">credentials</param>
        /// <returns>List of affinity group operation response for subscription </returns>
        private AffinityGroupListResponse GetAffinityGroupListResponseFromMSAzure(SubscriptionCloudCredentials credentials)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            Logger.Info(methodName, ProgressResources.GetAffinityGroupsFromMSAzureStarted, ResourceType.AffinityGroup.ToString());
            dcMigration.ReportProgress(ProgressResources.GetAffinityGroupsFromMSAzureStarted);
            try
            {
                using (var client = new ManagementClient(credentials))
                {
                    //// Call management API to get list of affinity groups.

                    AffinityGroupListResponse agResponse = Retry.RetryOperation(() => client.AffinityGroups.List(),(BaseParameters)exportParameters,ResourceType.AffinityGroup);
                    Logger.Info(methodName, ProgressResources.GetAffinityGroupsFromMSAzureCompleted, ResourceType.AffinityGroup.ToString());
                    return agResponse;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(methodName, ex, ResourceType.AffinityGroup.ToString());
                throw;
            }
        }
Exemple #21
0
 /// <summary>        
 /// Gets list of hosted service operation response from MS azure using API call.        
 /// </summary>
 /// <param name="credentials">credentials</param>
 /// <param name="serviceUrl">serviceUrl</param>
 /// <returns>List of hosted service operation response for subscription </returns>
 private HostedServiceListResponse GetCloudServiceListResponseFromMSAzure(SubscriptionCloudCredentials credentials, Uri serviceUrl)
 {
     string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
     Logger.Info(methodName, ProgressResources.GetServicesFromMSAzureStarted, ResourceType.CloudService.ToString());
     dcMigration.ReportProgress(ProgressResources.GetServicesFromMSAzureStarted);
     try
     {
         using (var client = new ComputeManagementClient(credentials, serviceUrl))
         {
             ////Call management API to get list of CloudServices.
             ////HostedServiceListResponse serviceResponse = Retry.RetryOperation(() => client.HostedServices.List(), exportParameters.RetryCount, exportParameters.MinBackOff, exportParameters.MaxBackOff, exportParameters.DeltaBackOff, ResourceType.CloudService);
             HostedServiceListResponse serviceResponse = Retry.RetryOperation(() => client.HostedServices.List(),
                (BaseParameters)exportParameters,
                 ResourceType.CloudService);
             Logger.Info(methodName, ProgressResources.GetServicesFromMSAzureCompleted, ResourceType.CloudService.ToString());
             return serviceResponse;
         }
     }
     catch (Exception ex)
     {
         Logger.Error(methodName, ex, ResourceType.CloudService.ToString());
         throw;
     }
 }
Exemple #22
0
 private StorageAccountGetKeysResponse GetStorageAccountKeysFromMSAzure(SubscriptionCloudCredentials credentials, string storageAccountName)
 {
     string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
     using (var client = new StorageManagementClient(credentials))
     {
         Logger.Info(methodName, string.Format(ProgressResources.GetStorageAccountKeysStarted, storageAccountName),ResourceType.StorageAccount.ToString(),storageAccountName);
         ////Call management API to get keys of storage account.
         StorageAccountGetKeysResponse storageKeyResponse = Retry.RetryOperation(() => client.StorageAccounts.GetKeys(storageAccountName),
             (BaseParameters)exportParameters,
             ResourceType.StorageAccount, storageAccountName);
         Logger.Info(methodName, string.Format(ProgressResources.GetStorageAccountKeysCompleted, storageAccountName),
         ResourceType.StorageAccount.ToString(), storageAccountName);
         return storageKeyResponse;
     }
 }
Exemple #23
0
 public static GalleryClient CreateCloudServiceManagementClient(this CloudClients clients, SubscriptionCloudCredentials credentials, Uri baseUri)
 {
     return(new GalleryClient(credentials, baseUri));
 }
Exemple #24
0
        /// <summary>
        /// Gets network configuration from MS azure using management API call.
        /// </summary>
        /// <param name="credentials">Subscription Cloud Credentials</param>
        /// <param name="serviceUrl">service url of subscription</param>
        /// <returns>Network configuration for subscription</returns>
        private NetworkGetConfigurationResponse GetNetworkConfigurationFromMSAzure(SubscriptionCloudCredentials credentials, Uri serviceUrl)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            Logger.Info(methodName, ProgressResources.ExecutionStarted, ResourceType.VirtualNetwork.ToString());

            Logger.Info(methodName, ProgressResources.GetVirtualNetworkConfigFromMSAzureStarted);
            using (var vnetClient = new NetworkManagementClient(credentials, serviceUrl))
            {
                try
                {
                    NetworkGetConfigurationResponse ventConfig = vnetClient.Networks.GetConfiguration();
                    Logger.Info(methodName, ProgressResources.GetVirtualNetworkConfigFromMSAzureCompleted, ResourceType.VirtualNetwork.ToString());
                    Logger.Info(methodName, ProgressResources.ExecutionCompleted, ResourceType.VirtualNetwork.ToString());

                    return ventConfig;
                }
                catch (CloudException cex)
                {
                    if (cex.Error.ToString() == Constants.ResourceNotFound)
                    {
                        return null;
                    }
                    else
                    {
                        Logger.Error(methodName, cex);
                        throw cex;
                    }
                }
            }
        }
        public async Task<IList<ResourceGroupExtended>> GetResourceGroups()
        {
            if (currSubscription == null)
                throw new Exception(Properties.Resources.SubscriptionNotSet);

            // Get the token for the tenant on this subscription.
            var cloudtoken = AuthenticateHelper.RefreshTokenByAuthority(currSubscription.ActiveDirectoryTenantId);
            subscriptionCreds = new TokenCloudCredentials(currSubscription.SubscriptionId, cloudtoken.AccessToken);

            resourceManagementClient = new ResourceManagementClient(subscriptionCreds);

            ResourceGroupListResult resourceGroupResult = await resourceManagementClient.ResourceGroups.ListAsync(null);
            return resourceGroupResult.ResourceGroups;
        }
        private static void ValidateClientWithCredentials(
            DataFactoryManagementClient client,
            SubscriptionCloudCredentials expectedCredentials, 
            Mock<TokenCloudCredentials> mockCredentials)
        {
            ValidateDefaultClientProperties(client);
            Assert.Equal(expectedCredentials, client.Credentials);
            Assert.Equal(expectedCredentials, client.InternalClient.Credentials);

            Assert.NotNull(client.InternalClient.BaseUri);
            Assert.NotNull(client.BaseUri);

            ValidateCredentialMock(mockCredentials, client);
        }
        public async Task<IList<AutomationAccount>> GetAutomationAccounts()
        {
            if(currSubscription == null)
                throw new Exception(Properties.Resources.SubscriptionNotSet);

            // Get the token for the tenant on this subscription.
            azureARMAuthResult = AuthenticateHelper.RefreshTokenByAuthority(currSubscription.ActiveDirectoryTenantId);
            subscriptionCreds = new TokenCloudCredentials(currSubscription.SubscriptionId, azureARMAuthResult.AccessToken);

            automationManagementClient = new AutomationManagementClient(subscriptionCreds);
            
            // Add user agent string to indicate this is coming from the ISE automation client.
            ProductInfoHeaderValue ISEClientAgent = new ProductInfoHeaderValue(Constants.ISEUserAgent, Constants.ISEVersion);
            automationManagementClient.UserAgent.Add(ISEClientAgent);

            //TODO: does this belong here?
            if (accountResourceGroups == null)
                accountResourceGroups = new Dictionary<AutomationAccount, ResourceGroupExtended>();
            else
                accountResourceGroups.Clear();
            IList<AutomationAccount> result = new List<AutomationAccount>();
            IList<ResourceGroupExtended> resourceGroups = await this.GetResourceGroups();
            foreach (ResourceGroupExtended resourceGroup in resourceGroups)
            {
                AutomationAccountListResponse accountListResponse = await automationManagementClient.AutomationAccounts.ListAsync(resourceGroup.Name);
                foreach (AutomationAccount account in accountListResponse.AutomationAccounts)
                {
                    result.Add(account);
                    accountResourceGroups.Add(account, resourceGroup);
                }
            }
            return result;
        }
 public static ManagedCacheClient CreateManagedCacheManagementClient(this CloudClients clients, SubscriptionCloudCredentials credentials, Uri baseUri)
 {
     return(new ManagedCacheClient(credentials, baseUri));
 }
Exemple #29
0
 public static AutomationManagementClient CreateAutomationManagementClient(this CloudClients clients, SubscriptionCloudCredentials credentials, Uri baseUri)
 {
     return(new AutomationManagementClient(credentials, baseUri));
 }
Exemple #30
0
 /// <summary>
 /// Checks for service name availability
 /// </summary>
 /// <param name="serviceName"> Service Name</param>
 /// <param name="credentials"> Destination subscription credentials</param>
 /// <param name="serviceUrl"> Destination subscription service Url</param>
 /// <returns>false if service name is reserved</returns>
 private bool CheckServiceNameAvailability(string serviceName, SubscriptionCloudCredentials credentials, Uri serviceUrl)
 {
   string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
   Logger.Info(methodName, string.Format(ProgressResources.CheckServiceNameAvailabilityFromMSAzureStarted, serviceName), ResourceType.CloudService.ToString(), serviceName);
   using (var client = new ComputeManagementClient(credentials, serviceUrl))
   {
     HostedServiceCheckNameAvailabilityResponse availabilityResponse = Retry.RetryOperation(() =>
         client.HostedServices.CheckNameAvailability(serviceName),
        (BaseParameters)importParameters, ResourceType.CloudService, serviceName);
     Logger.Info(methodName, String.Format(ProgressResources.CheckServiceNameAvailabilityFromMSAzureCompleted, serviceName),
         ResourceType.CloudService.ToString(), serviceName);
     return availabilityResponse.IsAvailable;
   }
 }
Exemple #31
0
        /// <summary>
        /// Exports list of SubscriptionId specific dataCenters.
        /// </summary>
        /// <param name="credentials"> Subscription credentials</param>                
        /// <param name="retryCount"> No. of times to retry in case of exception</param>
        /// <param name="minBackOff">Minimum backoff in seconds</param>
        /// <param name="maxBackOff">Maximum backoff in seconds</param>
        /// <param name="deltaBackOff">Delta Backoff in seconds</param>
        /// <returns>List of SubscriptionId specific dataCenters.</returns>
        private static List<string> ExportDataCenterLocations(SubscriptionCloudCredentials credentials, int retryCount,
            double minBackOff, double maxBackOff, double deltaBackOff)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            Logger.Info(methodName, ProgressResources.ExecutionStarted);
            try
            {
                using (var client = new ManagementClient(credentials))
                {
                    BaseParameters baseParams = new BaseParameters()
                    {
                        RetryCount = retryCount,
                        MinBackOff = TimeSpan.FromSeconds(minBackOff),
                        MaxBackOff = TimeSpan.FromSeconds(maxBackOff),
                        DeltaBackOff = TimeSpan.FromSeconds(deltaBackOff)
                    };

                    // Call management API to get list of locations.
                    var locations = Retry.RetryOperation(() => client.Locations.List(), baseParams, ResourceType.None);
                    Logger.Info(methodName, ProgressResources.ExecutionCompleted);
                    return locations.Select(l => l.Name).ToList();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(methodName, ex, ResourceType.None.ToString());
                throw;
            }
        }
Exemple #32
0
    /// <summary>
    /// Checks that the provided reserved ip name is present in destination and also it is not allocated to any service.
    /// </summary>
    /// <param name="credentials">Subscription credentials</param>
    /// <param name="serviceUrl">Subscription service url</param>
    /// <param name="reservedIPName">Reserved ip name</param>
    /// <param name="serviceName">Service name</param>
    /// <returns>Returns true if ReservedIPName is present in destination and it is not allocated to any deployment /
    /// returns <see cref="ValidationException"/> if the ReservedIPName is not available in destination subscription or it is available but already assigned to any service.
    /// </returns>
    private bool CheckReservedIPNameAvailability(SubscriptionCloudCredentials credentials, Uri serviceUrl, string reservedIPName, string serviceName)
    {
      string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
      Logger.Info(methodName, ProgressResources.GetVirtualNetworkConfigFromMSAzureStarted, ResourceType.VirtualNetwork.ToString());
      using (var vnetClient = new NetworkManagementClient(credentials, serviceUrl))
      {
        var reservedIPLists = vnetClient.ReservedIPs.List();
        NetworkReservedIPListResponse.ReservedIP reservedIpPresent = (from ri in reservedIPLists
                                                                      where (ri.Name == reservedIPName)
                                                                      select ri).FirstOrDefault();

        if (reservedIpPresent == null)
        {
          throw new ValidationException(string.Format(ProgressResources.MissingReservedIPName, reservedIPName));
        }
        else if (reservedIpPresent.ServiceName != null && !(serviceName.Equals(reservedIpPresent.ServiceName, StringComparison.InvariantCultureIgnoreCase)))
        {
          throw new ValidationException(string.Format(ProgressResources.OccupiedReservedIpName, reservedIPName, reservedIpPresent.ServiceName));
        }
      }
      return true;
    }
        public static ServiceBusNamespace SelectNamespace( SubscriptionCloudCredentials credentials,
            string requestMessageText = "Please select namespace you want to use: ",
            string manualOption = null )
        {
            Console.WriteLine( "Retrieving a list of created namespaces..." );
            ServiceBusNamespace[] namespaces = AzureProvider.GetNamespaces( credentials );
            int namespaceCount = namespaces.Length;

            Console.WriteLine( "Created namespaces: " );

            for( int currentNamespace = 1; currentNamespace <= namespaceCount; ++currentNamespace )
            {
                Console.WriteLine( currentNamespace + ": " + 
                    namespaces[ currentNamespace - 1 ].Name + " (" + namespaces[currentNamespace - 1].Region+ ")" );
            }

            if( manualOption != null )
            {
                Console.WriteLine( "*: " + manualOption );
            }
            Console.WriteLine( "0: Exit without processing" );

            for( ;; )
            {
                Console.WriteLine( requestMessageText );

                string answer = Console.ReadLine( );

                if( answer.StartsWith( "*" ) )
                {
                    if( manualOption == null )
                    {
                        Console.WriteLine( "Incorrect namespace number." );
                        continue;    
                    }
                    
                    if( !ConsoleHelper.Confirm( "Are you sure you want to enter name prefix manually?" ) )
                    {
                        continue;
                    }

                    for( ;; )
                    {
                        Console.WriteLine( "Enter a name prefix: " );
                        string namePrefix = Console.ReadLine( );
                        if( string.IsNullOrEmpty( namePrefix ) )
                        {
                            Console.WriteLine( "Incorrect namespace prefix." );
                            continue;
                        }
                        if( ConsoleHelper.Confirm( "Are you sure you want to use namespace prefix " + namePrefix + "?" ) )
                        {
                            return new ServiceBusNamespace
                            {
                                Name = namePrefix
                            };
                        }
                    }
                }

                int selection;
                if( !int.TryParse( answer, out selection ) || selection > namespaceCount || selection < -1 )
                {
                    Console.WriteLine( "Incorrect namespace number." );
                    continue;
                }

                if( selection == 0 )
                {
                    return null;
                }

                if( ConsoleHelper.Confirm( "Are you sure you want to select " + namespaces[ selection - 1 ].Name + " namespace?" ) )
                {
                    if( namespaces[ selection - 1 ].Name.EndsWith( "-ns" ) )
                    {
                        namespaces[ selection - 1 ].Name = namespaces[ selection - 1 ].Name.Substring( 0,
                            namespaces[ selection - 1 ].Name.Length - 3 );
                    }

                    return namespaces[ selection - 1 ];
                }
            }
        }
 public static SiteRecoveryManagementClient CreateSiteRecoveryManagementClient(this CloudClients clients, SubscriptionCloudCredentials credentials, Uri baseUri)
 {
     return(new SiteRecoveryManagementClient("", "", credentials, baseUri));
 }