// https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/ /// <summary> /// Used to construct the command to create a virtual machine deployment including the creation of a role /// </summary> // https://management.core.windows.net/<subscription-id>/services/hostedservices/<cloudservice-name>/deployments/<deploymentname>/roles internal AddLinuxVirtualMachineToDeploymentCommand(LinuxVirtualMachineProperties properties, string cloudServiceName) { AdditionalHeaders["x-ms-version"] = "2012-03-01"; OperationId = "hostedservices"; ServiceType = "services"; Properties = properties; HttpCommand = (CloudServiceName = cloudServiceName) + "/deployments/" + properties.DeploymentName + "/roles"; }
public void Execute() { var linuxClient = new LinuxVirtualMachineClient(_applicationFactory.SubscriptionId, _applicationFactory.ManagementCertificate); var images = linuxClient.ListImages("Ubuntu Server 12.04 LTS"); images.ForEach(image => System.Console.WriteLine(image.Label)); var props = new List <LinuxVirtualMachineProperties>(); for (int i = 1; i < 2; i++) { var properties = new LinuxVirtualMachineProperties() { CloudServiceName = "asos-yarn-spark4", HostName = "spark-node" + i, RoleName = "spark-node" + i, UserName = "******", AdministratorPassword = "******", DeploymentName = "spark-master", CustomTemplateName = images[0].Name, StorageAccountName = "mtlytics", PublicEndpoints = new List <InputEndpoint>() { new InputEndpoint() { EndpointName = "SSL", LocalPort = 22, Port = 21 + i, Protocol = Protocol.TCP } }, VmSize = VmSize.Small }; //var linux1 = new LinuxVirtualMachineClient(_applicationFactory.SubscriptionId, _applicationFactory.ManagementCertificate) //{ // Properties = new List<LinuxVirtualMachineProperties>() { properties } //}; //linux1.DeleteVirtualMachine(true, true, false, false); props.Add(properties); } var service = new ServiceClient(_applicationFactory.SubscriptionId, _applicationFactory.ManagementCertificate, "asos-yarn-spark4"); var certificate = service.CreateServiceCertificateExportToFileSystem("elastacert", "AsosSp@rk20148yJed", "C:\\Projects\\cert_export"); //var settings = // new PublishSettingsExtractor(@"C:\Projects\ASOS Big Compute-12-30-2013-credentials.publishsettings"); //var cert = settings.AddPublishSettingsToPersonalMachineStore(); var linux = new LinuxVirtualMachineClient(_applicationFactory.SubscriptionId, _applicationFactory.ManagementCertificate); //linux.AddRolesToExistingDeployment(props, "asos-yarn-spark", null); linux.CreateNewVirtualMachineDeploymentFromTemplateGallery(props, "asos-yarn-spark4", new ServiceCertificateModel() { Password = "******", ServiceCertificate = certificate.DerEncodedCertificate }); }
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"); } }