public static void ShutdownRoles(this IServiceManagement proxy,
                                  string subscriptionId,
                                  string serviceName,
                                  string deploymentName,
                                  ShutdownRolesOperation shutdownRolesOperation)
 {
     proxy.EndExecuteRoleSetOperation(proxy.BeginExecuteRoleSetOperation(
                                          subscriptionId,
                                          serviceName,
                                          deploymentName,
                                          shutdownRolesOperation,
                                          null,
                                          null));
 }
Beispiel #2
0
        internal override void ExecuteCommand()
        {
            base.ExecuteCommand();

            if (CurrentDeployment == 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(CurrentDeployment.RoleInstanceList, 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, Name));
            }

            // Insure the Force switch is specified for wildcard operations when StayProvisioned is not specified.
            if (WildcardPattern.ContainsWildcardCharacters(roleName) && (!StayProvisioned.IsPresent) && (!Force.IsPresent))
            {
                throw new ArgumentException(Resources.MustSpecifyForceParameterWhenUsingWildcards);
            }

            if (roleNames.Count == 1)
            {
                if (StayProvisioned.IsPresent)
                {
                    ExecuteClientActionInOCS(
                        null,
                        CommandRuntime.ToString(),
                        s => this.Channel.ShutdownRole(s, this.ServiceName, CurrentDeployment.Name, roleNames[0], PostShutdownAction.Stopped));
                }
                else
                {
                    if (!Force.IsPresent && IsLastVmInDeployment(roleNames.Count))
                    {
                        ConfirmAction(false,
                                      Resources.DeploymentVIPLossWarning,
                                      string.Format(Resources.DeprovisioningVM, roleName),
                                      String.Empty,
                                      () => ExecuteClientActionInOCS(
                                          null,
                                          CommandRuntime.ToString(),
                                          s => this.Channel.ShutdownRole(s, this.ServiceName, CurrentDeployment.Name, roleNames[0], PostShutdownAction.StoppedDeallocated)));
                    }
                    else
                    {
                        ExecuteClientActionInOCS(
                            null,
                            CommandRuntime.ToString(),
                            s => this.Channel.ShutdownRole(s, this.ServiceName, CurrentDeployment.Name, roleNames[0], PostShutdownAction.StoppedDeallocated));
                    }
                }
            }
            else
            {
                var shutdownRolesOperation = new ShutdownRolesOperation()
                {
                    Roles = roleNames
                };

                if (StayProvisioned.IsPresent)
                {
                    shutdownRolesOperation.PostShutdownAction = PostShutdownAction.Stopped;
                    ExecuteClientActionInOCS(
                        null,
                        CommandRuntime.ToString(),
                        s => this.Channel.ShutdownRoles(s, this.ServiceName, CurrentDeployment.Name, shutdownRolesOperation));
                }
                else
                {
                    shutdownRolesOperation.PostShutdownAction = PostShutdownAction.StoppedDeallocated;
                    if (!Force.IsPresent && IsLastVmInDeployment(shutdownRolesOperation.Roles.Count))
                    {
                        ConfirmAction(false,
                                      Resources.DeploymentVIPLossWarning,
                                      string.Format(Resources.DeprovisioningVM, roleName),
                                      String.Empty,
                                      () => ExecuteClientActionInOCS(
                                          null,
                                          CommandRuntime.ToString(),
                                          s => this.Channel.ShutdownRoles(s, this.ServiceName, CurrentDeployment.Name, shutdownRolesOperation)));
                    }
                    else
                    {
                        ExecuteClientActionInOCS(
                            null,
                            CommandRuntime.ToString(),
                            s => this.Channel.ShutdownRoles(s, this.ServiceName, CurrentDeployment.Name, shutdownRolesOperation));
                    }
                }
            }
        }
 public static void ShutdownRoles(this IServiceManagement proxy,
     string subscriptionId,
     string serviceName,
     string deploymentName,
     ShutdownRolesOperation shutdownRolesOperation)
 {
     proxy.EndExecuteRoleSetOperation(proxy.BeginExecuteRoleSetOperation(
         subscriptionId,
         serviceName,
         deploymentName,
         shutdownRolesOperation,
         null,
         null));
 }
Beispiel #4
0
        internal override void ExecuteCommand()
        {
            base.ExecuteCommand();

            if (CurrentDeployment == 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(CurrentDeployment.RoleInstanceList, 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, Name));
            }

            // Insure the Force switch is specified for wildcard operations when StayProvisioned is not specified.
            if (WildcardPattern.ContainsWildcardCharacters(roleName) && (!StayProvisioned.IsPresent) && (!Force.IsPresent))
            {
                throw new ArgumentException(Resources.MustSpecifyForceParameterWhenUsingWildcards);
            }

            if (roleNames.Count == 1)
            {
                if (StayProvisioned.IsPresent)
                {
                    ExecuteClientActionInOCS(
                        null,
                        CommandRuntime.ToString(),
                        s => this.Channel.ShutdownRole(s, this.ServiceName, CurrentDeployment.Name, roleNames[0], PostShutdownAction.Stopped));
                }
                else
                {
                    if (!Force.IsPresent && IsLastVmInDeployment(roleNames.Count))
                    {
                        ConfirmAction(false,
                            Resources.DeploymentVIPLossWarning,
                            string.Format(Resources.DeprovisioningVM, roleName),
                            String.Empty,
                            () => ExecuteClientActionInOCS(
                                null,
                                CommandRuntime.ToString(),
                                s => this.Channel.ShutdownRole(s, this.ServiceName, CurrentDeployment.Name, roleNames[0], PostShutdownAction.StoppedDeallocated)));
                    }
                    else
                    {
                        ExecuteClientActionInOCS(
                            null,
                            CommandRuntime.ToString(),
                            s => this.Channel.ShutdownRole(s, this.ServiceName, CurrentDeployment.Name, roleNames[0], PostShutdownAction.StoppedDeallocated));
                    }
                }

            }
            else
            {
                var shutdownRolesOperation = new ShutdownRolesOperation() { Roles = roleNames };

                if (StayProvisioned.IsPresent)
                {
                    shutdownRolesOperation.PostShutdownAction = PostShutdownAction.Stopped;
                    ExecuteClientActionInOCS(
                        null,
                        CommandRuntime.ToString(),
                        s => this.Channel.ShutdownRoles(s, this.ServiceName, CurrentDeployment.Name, shutdownRolesOperation));
                }
                else
                {
                    shutdownRolesOperation.PostShutdownAction = PostShutdownAction.StoppedDeallocated;
                    if (!Force.IsPresent && IsLastVmInDeployment(shutdownRolesOperation.Roles.Count))
                    {
                        ConfirmAction(false,
                            Resources.DeploymentVIPLossWarning,
                            string.Format(Resources.DeprovisioningVM, roleName),
                            String.Empty,
                            () => ExecuteClientActionInOCS(
                                null,
                                CommandRuntime.ToString(),
                                s => this.Channel.ShutdownRoles(s, this.ServiceName, CurrentDeployment.Name, shutdownRolesOperation)));
                    }
                    else
                    {
                        ExecuteClientActionInOCS(
                            null,
                            CommandRuntime.ToString(),
                            s => this.Channel.ShutdownRoles(s, this.ServiceName, CurrentDeployment.Name, shutdownRolesOperation));
                    }
                }
            }
        }