예제 #1
0
        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));
        }
예제 #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 wildcard patterns 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));
            }

            if (roleNames.Count == 1)
            {
                ExecuteClientActionInOCS(
                    null,
                    CommandRuntime.ToString(),
                    s => this.Channel.StartRole(s, this.ServiceName, CurrentDeployment.Name, roleNames[0]));
            }
            else
            {
                var startRolesOperation = new StartRolesOperation()
                {
                    Roles = roleNames
                };
                ExecuteClientActionInOCS(
                    null,
                    CommandRuntime.ToString(),
                    s => this.Channel.StartRoles(s, this.ServiceName, CurrentDeployment.Name, startRolesOperation));
            }
        }
예제 #3
0
        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));
                    }
                }
            }
        }
예제 #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));
                    }
                }
            }
        }