protected PSArgument[] CreateVirtualMachineShutdownRolesParameters() { string serviceName = string.Empty; string deploymentName = string.Empty; VirtualMachineShutdownRolesParameters parameters = new VirtualMachineShutdownRolesParameters(); return(ConvertFromObjectsToArguments(new string[] { "ServiceName", "DeploymentName", "Parameters" }, new object[] { serviceName, deploymentName, parameters })); }
protected void ExecuteVirtualMachineShutdownRolesMethod(object[] invokeMethodInputParameters) { string serviceName = (string)ParseParameter(invokeMethodInputParameters[0]); string deploymentName = (string)ParseParameter(invokeMethodInputParameters[1]); VirtualMachineShutdownRolesParameters parameters = (VirtualMachineShutdownRolesParameters)ParseParameter(invokeMethodInputParameters[2]); var result = VirtualMachineClient.ShutdownRoles(serviceName, deploymentName, parameters); WriteObject(result); }
protected override void ExecuteCommand() { base.ExecuteCommand(); ServiceManagementProfile.Initialize(); if (this.CurrentDeploymentNewSM == null) { return; } string roleName = (this.ParameterSetName == "ByName") ? this.Name : this.VM.RoleName; // Generate a list of role names matching regular expressions or // the exact name specified in the -Name parameter. var roleNames = PersistentVMHelper.GetRoleNames(this.CurrentDeploymentNewSM.RoleInstances, roleName); // Insure at least one of the role name instances can be found. if ((roleNames == null) || (!roleNames.Any())) { throw new ArgumentOutOfRangeException(String.Format(Resources.RoleInstanceCanNotBeFoundWithName, this.Name)); } // Insure the Force switch is specified for wildcard operations when StayProvisioned is not specified. if (WildcardPattern.ContainsWildcardCharacters(roleName) && (!this.StayProvisioned.IsPresent) && (!this.Force.IsPresent)) { throw new ArgumentException(Resources.MustSpecifyForceParameterWhenUsingWildcards); } if (roleNames.Count == 1) { if (this.StayProvisioned.IsPresent) { ProcessStaticIPAddressWarningInfo(roleNames[0]); this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.Shutdown( this.ServiceName, this.CurrentDeploymentNewSM.Name, roleNames[0], new VirtualMachineShutdownParameters { PostShutdownAction = PostShutdownAction.Stopped }), (s, response) => this.ContextFactory <OperationStatusResponse, ManagementOperationContext>(response, s)); } else { if (!this.Force.IsPresent && this.IsLastVmInDeployment(roleNames.Count)) { this.ConfirmAction(false, Resources.DeploymentVIPLossWarning, string.Format(Resources.DeprovisioningVM, roleName), String.Empty, () => this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.Shutdown( this.ServiceName, this.CurrentDeploymentNewSM.Name, roleNames[0], new VirtualMachineShutdownParameters { PostShutdownAction = PostShutdownAction.StoppedDeallocated }), (s, response) => ContextFactory <OperationStatusResponse, ManagementOperationContext>(response, s))); } else { this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.Shutdown( this.ServiceName, this.CurrentDeploymentNewSM.Name, roleNames[0], new VirtualMachineShutdownParameters { PostShutdownAction = PostShutdownAction.StoppedDeallocated }), (s, response) => this.ContextFactory <OperationStatusResponse, ManagementOperationContext>(response, s)); } } } else { if (this.StayProvisioned.IsPresent) { var parameter = new VirtualMachineShutdownRolesParameters(); foreach (var role in roleNames) { ProcessStaticIPAddressWarningInfo(role); parameter.Roles.Add(role); } parameter.PostShutdownAction = PostShutdownAction.Stopped; this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.ShutdownRoles(this.ServiceName, this.CurrentDeploymentNewSM.Name, parameter)); } else { var parameter = new VirtualMachineShutdownRolesParameters(); foreach (var role in roleNames) { parameter.Roles.Add(role); } parameter.PostShutdownAction = PostShutdownAction.StoppedDeallocated; if (!this.Force.IsPresent && this.IsLastVmInDeployment(roleNames.Count)) { this.ConfirmAction(false, Resources.DeploymentVIPLossWarning, string.Format(Resources.DeprovisioningVM, roleName), String.Empty, () => this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.ShutdownRoles(this.ServiceName, this.CurrentDeploymentNewSM.Name, parameter))); } else { this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.ShutdownRoles(this.ServiceName, this.CurrentDeploymentNewSM.Name, parameter)); } } } }
protected override void ExecuteCommand() { base.ExecuteCommand(); ServiceManagementProfile.Initialize(); if (this.CurrentDeploymentNewSM == null) { return; } string roleName = (this.ParameterSetName == "ByName") ? this.Name : this.VM.RoleName; // Generate a list of role names matching regular expressions or // the exact name specified in the -Name parameter. var roleNames = PersistentVMHelper.GetRoleNames(this.CurrentDeploymentNewSM.RoleInstances, roleName); // Insure at least one of the role name instances can be found. if ((roleNames == null) || (!roleNames.Any())) { throw new ArgumentOutOfRangeException(String.Format(Resources.RoleInstanceCanNotBeFoundWithName, this.Name)); } // Insure the Force switch is specified for wildcard operations when StayProvisioned is not specified. if (WildcardPattern.ContainsWildcardCharacters(roleName) && (!this.StayProvisioned.IsPresent) && (!this.Force.IsPresent)) { throw new ArgumentException(Resources.MustSpecifyForceParameterWhenUsingWildcards); } if (roleNames.Count == 1) { if (this.StayProvisioned.IsPresent) { this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.Shutdown( this.ServiceName, this.CurrentDeploymentNewSM.Name, roleNames[0], new VirtualMachineShutdownParameters { PostShutdownAction = PostShutdownAction.Stopped }), (s, response) => this.ContextFactory<ComputeOperationStatusResponse, ManagementOperationContext>(response, s)); } else { if (!this.Force.IsPresent && this.IsLastVmInDeployment(roleNames.Count)) { this.ConfirmAction(false, Resources.DeploymentVIPLossWarning, string.Format(Resources.DeprovisioningVM, roleName), String.Empty, () => this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.Shutdown( this.ServiceName, this.CurrentDeploymentNewSM.Name, roleNames[0], new VirtualMachineShutdownParameters { PostShutdownAction = PostShutdownAction.StoppedDeallocated }), (s, response) => ContextFactory<ComputeOperationStatusResponse, ManagementOperationContext>(response, s))); } else { this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.Shutdown( this.ServiceName, this.CurrentDeploymentNewSM.Name, roleNames[0], new VirtualMachineShutdownParameters { PostShutdownAction = PostShutdownAction.StoppedDeallocated }), (s, response) => this.ContextFactory<ComputeOperationStatusResponse, ManagementOperationContext>(response, s)); } } } else { if (this.StayProvisioned.IsPresent) { var parameter = new VirtualMachineShutdownRolesParameters(); foreach (var role in roleNames) { parameter.Roles.Add(role); } parameter.PostShutdownAction = PostShutdownAction.Stopped; this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.ShutdownRoles(this.ServiceName, this.CurrentDeploymentNewSM.Name, parameter)); } else { var parameter = new VirtualMachineShutdownRolesParameters(); foreach (var role in roleNames) { parameter.Roles.Add(role); } parameter.PostShutdownAction = PostShutdownAction.StoppedDeallocated; if (!this.Force.IsPresent && this.IsLastVmInDeployment(roleNames.Count)) { this.ConfirmAction(false, Resources.DeploymentVIPLossWarning, string.Format(Resources.DeprovisioningVM, roleName), String.Empty, () => this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.ShutdownRoles(this.ServiceName, this.CurrentDeploymentNewSM.Name, parameter))); } else { this.ExecuteClientActionNewSM( null, this.CommandRuntime.ToString(), () => this.ComputeClient.VirtualMachines.ShutdownRoles(this.ServiceName, this.CurrentDeploymentNewSM.Name, parameter)); } } } }