private static string createResourceGroupTry(string customerId, string subscriptionId, string groupName, string location) { string token = REST.getArmToken(customerId, UserAuth: true); if (token != null) { var credential = new TokenCredentials(token); var armClient = new Microsoft.Azure.Management.ResourceManager.ResourceManagementClient(credential) { SubscriptionId = subscriptionId }; var resourceGroup = new Microsoft.Azure.Management.ResourceManager.Models.ResourceGroup { Location = location }; try { var rg = armClient.ResourceGroups.CreateOrUpdate(groupName, resourceGroup); return(rg.Id.ToString()); } catch { return(null); } } else { return(null); } }
public static void getBackupCredentials(string customerId, string subscriptionId, string groupName, string vaultName) { string token = REST.getArmToken(customerId, UserAuth: true); var credential = new TokenCredentials(token); var backupClient = new RecoveryServicesBackupClient(credential) { SubscriptionId = subscriptionId }; //backupClient. }
public static void registerRS(string customerId, string subscriptionId, string rpName) { string token = REST.getArmToken(customerId, UserAuth: true); var credential = new TokenCredentials(token); var armClient = new Microsoft.Azure.Management.ResourceManager.ResourceManagementClient(credential) { SubscriptionId = subscriptionId }; bool rpRegistered = false; // Check the registration state until it is Registered. do { var RPlist = armClient.Providers.List().ToList(); foreach (var provider in RPlist) { if (provider.NamespaceProperty == rpName) { if (provider.RegistrationState == "NotRegistered") { armClient.Providers.Register(rpName); } else { if (provider.RegistrationState == "Registered") { rpRegistered = true; } else { Thread.Sleep(5000); } } } } } while (rpRegistered == false); }
public static string createSRVault(string customerId, string subscriptionId, string groupName, string vaultName, string location) { // Do we need to register the resource provider because it is a sandbox??? registerRS(customerId, subscriptionId, "Microsoft.RecoveryServices"); string token = REST.getArmToken(customerId, UserAuth: true); var credential = new TokenCredentials(token); var VaultClient = new RecoveryServicesClient(credential) { SubscriptionId = subscriptionId }; Vault vault = new Vault() { Location = location, Sku = new Microsoft.Azure.Management.RecoveryServices.Models.Sku() { Name = SkuName.Standard }, Properties = new VaultProperties() }; var newVault = VaultClient.Vaults.CreateOrUpdate(groupName, vaultName, vault); //return VaultClient return(newVault.Id.ToString()); }