protected override void ExecuteCommand() { ServiceManagementProfile.Initialize(); base.ExecuteCommand(); if (this.CurrentDeploymentNewSM == null) { return; } string[] inputRoleNames = (this.ParameterSetName == "ByName") ? this.Name : this.VM.Select(vm => vm.GetInstance().RoleName).ToArray(); // Generate a list of role names matching wildcard patterns or // the exact name specified in the -Name parameter. var roleNames = PersistentVMHelper.GetRoleNames(this.CurrentDeploymentNewSM.RoleInstances, inputRoleNames); // Insure at least one of the role name instances can be found. if ((roleNames == null) || (!roleNames.Any())) { throw new ArgumentOutOfRangeException(String.Format(Resources.RoleInstanceCanNotBeFoundWithName, Name)); } var parameters = new VirtualMachineStartRolesParameters(); foreach(var r in roleNames) { parameters.Roles.Add(r); } this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.StartRoles(this.ServiceName, this.CurrentDeploymentNewSM.Name, parameters)); }
protected PSArgument[] CreateVirtualMachineStartRolesParameters() { string serviceName = string.Empty; string deploymentName = string.Empty; VirtualMachineStartRolesParameters parameters = new VirtualMachineStartRolesParameters(); return ConvertFromObjectsToArguments(new string[] { "ServiceName", "DeploymentName", "Parameters" }, new object[] { serviceName, deploymentName, parameters }); }
/// <summary> /// The Start Roles operation starts the specified set of virtual /// machines. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.Compute.IVirtualMachineOperations. /// </param> /// <param name='serviceName'> /// The name of your service. /// </param> /// <param name='deploymentName'> /// The name of your deployment. /// </param> /// <param name='parameters'> /// The set of virtual machine roles to start. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static OperationResponse BeginStartingRoles(this IVirtualMachineOperations operations, string serviceName, string deploymentName, VirtualMachineStartRolesParameters parameters) { try { return operations.BeginStartingRolesAsync(serviceName, deploymentName, parameters).Result; } catch (AggregateException ex) { if (ex.InnerExceptions.Count > 1) { throw; } else { throw ex.InnerException; } } }
/// <summary> /// The Start Roles operation starts the specified set of virtual /// machines. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.Compute.IVirtualMachineOperations. /// </param> /// <param name='serviceName'> /// The name of your service. /// </param> /// <param name='deploymentName'> /// The name of your deployment. /// </param> /// <param name='parameters'> /// The set of virtual machine roles to start. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task<OperationResponse> BeginStartingRolesAsync(this IVirtualMachineOperations operations, string serviceName, string deploymentName, VirtualMachineStartRolesParameters parameters) { return operations.BeginStartingRolesAsync(serviceName, deploymentName, parameters, CancellationToken.None); }
/// <summary> /// The Begin Starting Roles operation starts the specified set of /// virtual machines. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/dn469419.aspx /// for more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.Compute.IVirtualMachineOperations. /// </param> /// <param name='serviceName'> /// Required. The name of your service. /// </param> /// <param name='deploymentName'> /// Required. The name of your deployment. /// </param> /// <param name='parameters'> /// Required. Parameters to pass to the Begin Starting Roles operation. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static OperationResponse BeginStartingRoles(this IVirtualMachineOperations operations, string serviceName, string deploymentName, VirtualMachineStartRolesParameters parameters) { return Task.Factory.StartNew((object s) => { return ((IVirtualMachineOperations)s).BeginStartingRolesAsync(serviceName, deploymentName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }