/// <summary> /// Gets a list of hosts, internal ip addresses and other things /// </summary> public List <VmHost> GetHostDetails(string cloudServiceName) { var hosts = new List <VmHost>(); var command = new GetVirtualMachineContextCommand(cloudServiceName) { SubscriptionId = SubscriptionId, Certificate = ManagementCertificate }; command.Execute(); if (command.PersistentVm == null && command.ResponseStackTrace != null) { throw new FluentManagementException(command.ResponseStackTrace, "LinuxVirtualMachineClient"); } var persistentHosts = command.PersistentVm.ToList(); persistentHosts.ForEach(vm => hosts.Add(new VmHost() { HostName = vm.RoleName, IpAddress = vm.IPAddress, RoleName = vm.RoleName, Endpoints = vm.NetworkConfigurationSet.InputEndpoints.Endpoints.AsReadOnly() })); return(hosts); }
private void CheckVmDeploymentIsRunning(List <LinuxVirtualMachineProperties> properties) { // 1. Get the number of vms in the role and create a binary list var linuxProperties = new Dictionary <string, RoleInstanceStatus>(); properties.ForEach(property => linuxProperties.Add(property.HostName, RoleInstanceStatus.RoleStateUnknown)); var vmProperties = new LinuxVirtualMachineProperties() { CloudServiceName = properties[0].CloudServiceName }; // 2. Set the value to if the vm is running or not int index = 0; // time this out just in case after an hour? while (linuxProperties.Any(role => role.Value != RoleInstanceStatus.ReadyRole) || index == 360) { var command = new GetVirtualMachineContextCommand(vmProperties) { SubscriptionId = SubscriptionId, Certificate = ManagementCertificate }; command.Execute(); command.PersistentVm.ForEach(vm => { if (linuxProperties[vm.RoleName] == vm.Status) { return; } // raise the event with the old and new status LinuxVirtualMachineStatusEvent(this, new VirtualMachineStatus() { NewStatus = vm.Status, OldStatus = linuxProperties[vm.RoleName], VirtualMachineInstanceName = vm.RoleName, CloudService = vmProperties.CloudServiceName }); // update the status in the dictionary linuxProperties[vm.RoleName] = vm.Status; }); index++; // TODO: advice from Zak on the best way to use task.delay instead Thread.Sleep(TimeSpan.FromSeconds(10)); } if (index == 360) { throw new FluentManagementException("timed out listening for status changes - check vms are running correctly", "LinuxVirtualMachineClient"); } }
/// <summary> /// Executes the query performing the underlying operation /// </summary> /// <typeparam name="T">The type used to define the query - CloudService or StorageAccount</typeparam> /// <param name="inputs">The Authentication inputs needed to fulfil the operation</param> /// <returns>An IQueryable interface</returns> public IQueryable <T> Execute <T>(LinqToAzureInputs inputs) { if (typeof(T) != GetValidType()) { throw new InvalidQueryException("Mismatch between generic types StorageAccount type expected"); } // Get the place name(s) to query the Web service with. var sf = new VirtualMachineFinder(_expression != null ? _expression.Body : null); string cloudServiceName = sf.CloudServiceName; if (String.IsNullOrEmpty(cloudServiceName)) { throw new InvalidQueryException("You must specify a single cloud service in your query"); } // Call the Web service and get the results. if (_roles == null) { // get the cert in the form of an x509v3 var certificate = PublishSettingsExtractor.FromStore(inputs.ManagementCertificateThumbprint); try { var properties = new WindowsVirtualMachineProperties() { CloudServiceName = cloudServiceName }; var command = new GetVirtualMachineContextCommand(properties) { SubscriptionId = inputs.SubscriptionId, Certificate = certificate }; command.Execute(); _roles = command.PersistentVm; } catch (Exception ex) { throw new ApplicationException("Unable to query Windows Azure", ex); } } //return _roles.AsQueryable(); return((IQueryable <T>)_roles.AsQueryable()); }