/// <summary> /// Create virtual machine /// </summary> /// <param name="hostedServiceName"></param> /// <param name="osVirtualHardDisk"></param> /// <param name="configurationSets"></param> /// <param name="dataVirtualHardDisks"></param> /// <param name="virtualMachineName"></param> /// <param name="deploymentName"></param> /// <returns></returns> public string CreateVirtualMachine( string hostedServiceName, OSVirtualHardDisk osVirtualHardDisk, IList <ConfigurationSet> configurationSets, IList <DataVirtualHardDisk> dataVirtualHardDisks = null, string virtualMachineName = "", string deploymentName = "") { if (string.IsNullOrEmpty(deploymentName)) { deploymentName = Dependencies.TestResourcesCollector.GetUniqueDeploymentName(); } if (string.IsNullOrEmpty(virtualMachineName)) { virtualMachineName = Dependencies.TestResourcesCollector.GetUniqueVirtualMachineName(); } var csm = new AzureCloudServiceManager(); csm.CreateOrUpdateDeployment(hostedServiceName, new DeploymentCreateParameters { Name = deploymentName }); var vmDeployment = csm.CreateOrUpdateDeployment(hostedServiceName, new DeploymentCreateParameters { Name = deploymentName, Label = Base64EncodingHelper.EncodeToBase64String(AzureServiceConstants.DefaultLabel) }); var vmRole = new Role { RoleName = virtualMachineName, RoleType = "PersistentVMRole", OSVirtualHardDisk = osVirtualHardDisk, ConfigurationSets = configurationSets, DataVirtualHardDisks = dataVirtualHardDisks }; vmDeployment.Roles.Add(vmRole); return(CreateVirtualMachine(hostedServiceName, vmDeployment, virtualMachineName)); }
private void CleanupHostedServices(AzureResourceType type, Dictionary <string, object> resources) { SafeExecute(() => { var manager = new AzureCloudServiceManager(); foreach (var obj in resources.Values) { var service = obj as string; if (service == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetHostedService(service) != null) { manager.DeleteHostedService(service); } } resources.Clear(); }, type.ToString()); }
private void CleanupDeployments(AzureResourceType type, Dictionary <string, object> resources) { SafeExecute(() => { var manager = new AzureCloudServiceManager(); foreach (var obj in resources.Values) { var deployment = obj as DeploymentInfo; if (deployment == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetDeployment(deployment.HostedService, deployment.Deployment.Name) != null) { manager.DeleteDeployment(deployment.HostedService, deployment.Deployment.Name); } } resources.Clear(); }, type.ToString()); }
/// <summary> /// Create virtual machine /// </summary> /// <param name="hostedServiceName"></param> /// <param name="osVirtualHardDisk"></param> /// <param name="configurationSets"></param> /// <param name="dataVirtualHardDisks"></param> /// <param name="virtualMachineName"></param> /// <param name="deploymentName"></param> /// <returns></returns> public string CreateVirtualMachine( string hostedServiceName, OSVirtualHardDisk osVirtualHardDisk, IList<ConfigurationSet> configurationSets, IList<DataVirtualHardDisk> dataVirtualHardDisks = null, string virtualMachineName = "", string deploymentName = "") { if (string.IsNullOrEmpty(deploymentName)) { deploymentName = Dependencies.TestResourcesCollector.GetUniqueDeploymentName(); } if (string.IsNullOrEmpty(virtualMachineName)) { virtualMachineName = Dependencies.TestResourcesCollector.GetUniqueVirtualMachineName(); } var csm = new AzureCloudServiceManager(); csm.CreateOrUpdateDeployment(hostedServiceName, new DeploymentCreateParameters { Name = deploymentName }); var vmDeployment = csm.CreateOrUpdateDeployment(hostedServiceName, new DeploymentCreateParameters { Name = deploymentName, Label = Base64EncodingHelper.EncodeToBase64String(AzureServiceConstants.DefaultLabel) }); var vmRole = new Role { RoleName = virtualMachineName, RoleType = "PersistentVMRole", OSVirtualHardDisk = osVirtualHardDisk, ConfigurationSets = configurationSets, DataVirtualHardDisks = dataVirtualHardDisks }; vmDeployment.Roles.Add(vmRole); return CreateVirtualMachine(hostedServiceName, vmDeployment, virtualMachineName); }
private void CleanupHostedServices(AzureResourceType type, Dictionary<string, object> resources) { SafeExecute(() => { var manager = new AzureCloudServiceManager(); foreach (var obj in resources.Values) { var service = obj as string; if (service == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetHostedService(service) != null) { manager.DeleteHostedService(service); } } resources.Clear(); }, type.ToString()); }
private void CleanupDeployments(AzureResourceType type, Dictionary<string, object> resources) { SafeExecute(() => { var manager = new AzureCloudServiceManager(); foreach (var obj in resources.Values) { var deployment = obj as DeploymentInfo; if (deployment == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetDeployment(deployment.HostedService, deployment.Deployment.Name) != null) { manager.DeleteDeployment(deployment.HostedService, deployment.Deployment.Name); } } resources.Clear(); }, type.ToString()); }