public VMOperationToolStripMenuItem(Command command, bool inContextMenu, vm_operations operation)
            : base(command, inContextMenu)
        {
            if (operation != vm_operations.start_on && operation != vm_operations.resume_on && operation != vm_operations.pool_migrate)
            {
                throw new ArgumentException("Invalid operation", "operation");
            }

            _operation = operation;
            base.DropDownItems.Add(new ToolStripMenuItem());
        }
Example #2
0
        public MeddlingAction(Task task)
            : base(task.Name(), task.Description(), false, false)
        {
            RelatedTask = new XenRef <Task>(task.opaque_ref);

            Host = task.Connection.Resolve(task.resident_on) ?? Helpers.GetMaster(task.Connection);

            Started = (task.created + task.Connection.ServerTimeOffset).ToLocalTime();
            SetAppliesToData(task);
            Connection  = task.Connection;
            VM          = GetVm(task);
            vmOperation = GetVmOperation(task);
            UpdateActionTitleAndDescription(task);
            Update(task, false);
        }
        public VMOperationHostCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> vms, GetHostForVM getHostForVM, string text, vm_operations operation, Session session)
            : base(mainWindow, vms, operation)
        {
            Util.ThrowIfParameterNull(session, "session");
            Util.ThrowIfParameterNull(getHostForVM, "getHostForVM");
            Util.ThrowIfParameterNull(text, "text");
            _text = text;
            _getHostForVM = getHostForVM;

            foreach (SelectedItem item in vms)
            {
                VM vm = (VM)item.XenObject;

                string reason = GetVmCannotBootOnHostReason(vm, GetHost(vm), session, operation);
                _cantBootReasons[vm] = reason;

                if (reason == null)
                    _noneCanBoot = false;
            }
        }
        public VMOperationWlbHostCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> vms, Host host, vm_operations operation, WlbRecommendations.WlbRecommendation recommendation)
            : base(mainWindow, vms, operation)
        {
            Util.ThrowIfParameterNull(recommendation, "recommendation");
            Util.ThrowIfParameterNull(host, "host");

            _host = host;
            _menuText = _host.Name.EscapeAmpersands();

            //Default or failure case, there is no score/star rating actually, just don't display star
            _secondImage = null;
            _menuImage = Images.StaticImages._000_ServerDisconnected_h32bit_16;
            _recommendation = recommendation;

            if (CanExecute())
            {
                _starRating = _recommendation.StarRating;
                _menuImage = Images.StaticImages._000_TreeConnected_h32bit_16;
                _secondImage = GetWLBStarImage(_starRating);
            }
            else
            {
                // get the failure reason if the dictionary is populated with reasons that are all the same.
                // otherwise don't display a reason - leave this to the error dialog.

                string reason = null;
                foreach (string r in _recommendation.CantExecuteReasons.Values)
                {
                    if (reason != null && r != reason)
                    {
                        return;
                    }
                    reason = r;
                }

                if (!string.IsNullOrEmpty(reason))
                {
                    _menuText = string.Format(Messages.MAINWINDOW_CONTEXT_REASON, _menuText, reason);
                }
            }
        }
Example #5
0
        internal static Dictionary <vm_operations, string> convert_from_proxy_vm_operations_string(object o)
        {
            Hashtable hashtable = (Hashtable)o;
            Dictionary <vm_operations, string> dictionary = new Dictionary <vm_operations, string>();

            if (hashtable != null)
            {
                foreach (string str in hashtable.Keys)
                {
                    try
                    {
                        vm_operations _operations = (vm_operations)Helper.EnumParseDefault(typeof(vm_operations), str);
                        string        str2        = (hashtable[str] == null) ? null : ((string)hashtable[str]);
                        dictionary[_operations] = str2;
                    }
                    catch
                    {
                    }
                }
            }
            return(dictionary);
        }
Example #6
0
        internal static Dictionary <string, vm_operations> convert_from_proxy_string_vm_operations(object o)
        {
            Hashtable hashtable = (Hashtable)o;
            Dictionary <string, vm_operations> dictionary = new Dictionary <string, vm_operations>();

            if (hashtable != null)
            {
                foreach (string str in hashtable.Keys)
                {
                    try
                    {
                        string        str2        = str;
                        vm_operations _operations = (hashtable[str] == null) ? vm_operations.snapshot : ((vm_operations)Helper.EnumParseDefault(typeof(vm_operations), (string)hashtable[str]));
                        dictionary[str2] = _operations;
                    }
                    catch
                    {
                    }
                }
            }
            return(dictionary);
        }
Example #7
0
        convert_from_proxy_vm_operations_string(Object o)
        {
            Hashtable table = (Hashtable)o;
            Dictionary <vm_operations, string> result = new Dictionary <vm_operations, string>();

            if (table != null)
            {
                foreach (string key in table.Keys)
                {
                    try
                    {
                        vm_operations k = (vm_operations)Helper.EnumParseDefault(typeof(vm_operations), (string)key);
                        string        v = table[key] == null ? null : (string)table[key];
                        result[k] = v;
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
            return(result);
        }
Example #8
0
        convert_from_proxy_string_vm_operations(Object o)
        {
            Hashtable table = (Hashtable)o;
            Dictionary <string, vm_operations> result = new Dictionary <string, vm_operations>();

            if (table != null)
            {
                foreach (string key in table.Keys)
                {
                    try
                    {
                        string        k = key;
                        vm_operations v = table[key] == null ? (vm_operations)0 : (vm_operations)Helper.EnumParseDefault(typeof(vm_operations), (string)table[key]);
                        result[k] = v;
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
            return(result);
        }
        internal static string GetVmCannotBootOnHostReason(VM vm, Host host, Session session, vm_operations operation)
        {
            Host residentHost = vm.Connection.Resolve(vm.resident_on);

            if (host == null)
            {
                return(Messages.NO_HOME_SERVER);
            }

            if (vm.power_state == vm_power_state.Running && residentHost != null &&
                Helpers.productVersionCompare(Helpers.HostProductVersion(host), Helpers.HostProductVersion(residentHost)) < 0)
            {
                // This will be a migrate menu if powerstate if running
                return(Messages.OLDER_THAN_CURRENT_SERVER);
            }

            if (vm.power_state == vm_power_state.Running && residentHost != null && host.opaque_ref == residentHost.opaque_ref)
            {
                return(Messages.HOST_MENU_CURRENT_SERVER);
            }

            if ((operation == vm_operations.pool_migrate || operation == vm_operations.resume_on) && VmCpuFeaturesIncompatibleWithHost(host, vm))
            {
                return(FriendlyErrorNames.VM_INCOMPATIBLE_WITH_THIS_HOST);
            }

            try
            {
                VM.assert_can_boot_here(session, vm.opaque_ref, host.opaque_ref);
            }
            catch (Failure f)
            {
                if (f.ErrorDescription.Count > 2 && f.ErrorDescription[0] == Failure.VM_REQUIRES_SR)
                {
                    SR sr = host.Connection.Resolve((new XenRef <SR>(f.ErrorDescription[2])));

                    if (sr != null && sr.content_type == SR.Content_Type_ISO)
                    {
                        return(Messages.MIGRATE_PLEASE_EJECT_YOUR_CD);
                    }
                }
                return(f.ShortMessage);
            }
            catch (Exception e)
            {
                log.ErrorFormat("There was an error calling assert_can_boot_here on host {0}", host.Name());
                log.Error(e, e);
                return(Messages.HOST_MENU_UNKNOWN_ERROR);
            }

            return(null);
        }
Example #10
0
 public VMOperationWlbOptimalServerCommand(IMainWindow mainWindow, IEnumerable <SelectedItem> selection, vm_operations operation, WlbRecommendations recommendations)
     : base(mainWindow, selection, operation)
 {
     Util.ThrowIfParameterNull(recommendations, "recommendations");
     _recommendations = recommendations;
 }
Example #11
0
 public VMOperationCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selection)
     : base(mainWindow, selection)
 {
     _operation = vm_operations.unknown;
 }
Example #12
0
 public VMOperationCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selection, vm_operations operation)
     : base(mainWindow, selection)
 {
     _operation = operation;
     AssertOperationIsSupported();
 }
        public VMOperationWlbHostCommand(IMainWindow mainWindow, IEnumerable <SelectedItem> vms, Host host, vm_operations operation, WlbRecommendations.WlbRecommendation recommendation)
            : base(mainWindow, vms, operation)
        {
            Util.ThrowIfParameterNull(recommendation, "recommendation");
            Util.ThrowIfParameterNull(host, "host");

            _host     = host;
            _menuText = _host.Name().EscapeAmpersands();

            //Default or failure case, there is no score/star rating actually, just don't display star
            _secondImage    = null;
            _menuImage      = Images.StaticImages._000_ServerDisconnected_h32bit_16;
            _recommendation = recommendation;

            if (CanExecute())
            {
                _starRating  = _recommendation.StarRating;
                _menuImage   = Images.StaticImages._000_TreeConnected_h32bit_16;
                _secondImage = GetWLBStarImage(_starRating);
            }
            else
            {
                // get the failure reason if the dictionary is populated with reasons that are all the same.
                // otherwise don't display a reason - leave this to the error dialog.

                string reason = null;
                foreach (string r in _recommendation.CantExecuteReasons.Values)
                {
                    if (reason != null && r != reason)
                    {
                        return;
                    }
                    reason = r;
                }

                if (!string.IsNullOrEmpty(reason))
                {
                    _menuText = string.Format(Messages.MAINWINDOW_CONTEXT_REASON, _menuText, reason);
                }
            }
        }
Example #14
0
        public static string ToString(vm_operations x)
        {
            switch (x)
            {
            case vm_operations.snapshot:
                return("snapshot");

            case vm_operations.clone:
                return("clone");

            case vm_operations.copy:
                return("copy");

            case vm_operations.create_template:
                return("create_template");

            case vm_operations.revert:
                return("revert");

            case vm_operations.checkpoint:
                return("checkpoint");

            case vm_operations.snapshot_with_quiesce:
                return("snapshot_with_quiesce");

            case vm_operations.provision:
                return("provision");

            case vm_operations.start:
                return("start");

            case vm_operations.start_on:
                return("start_on");

            case vm_operations.pause:
                return("pause");

            case vm_operations.unpause:
                return("unpause");

            case vm_operations.clean_shutdown:
                return("clean_shutdown");

            case vm_operations.clean_reboot:
                return("clean_reboot");

            case vm_operations.hard_shutdown:
                return("hard_shutdown");

            case vm_operations.power_state_reset:
                return("power_state_reset");

            case vm_operations.hard_reboot:
                return("hard_reboot");

            case vm_operations.suspend:
                return("suspend");

            case vm_operations.csvm:
                return("csvm");

            case vm_operations.resume:
                return("resume");

            case vm_operations.resume_on:
                return("resume_on");

            case vm_operations.pool_migrate:
                return("pool_migrate");

            case vm_operations.migrate_send:
                return("migrate_send");

            case vm_operations.get_boot_record:
                return("get_boot_record");

            case vm_operations.send_sysrq:
                return("send_sysrq");

            case vm_operations.send_trigger:
                return("send_trigger");

            case vm_operations.query_services:
                return("query_services");

            case vm_operations.shutdown:
                return("shutdown");

            case vm_operations.call_plugin:
                return("call_plugin");

            case vm_operations.changing_memory_live:
                return("changing_memory_live");

            case vm_operations.awaiting_memory_live:
                return("awaiting_memory_live");

            case vm_operations.changing_dynamic_range:
                return("changing_dynamic_range");

            case vm_operations.changing_static_range:
                return("changing_static_range");

            case vm_operations.changing_memory_limits:
                return("changing_memory_limits");

            case vm_operations.changing_shadow_memory:
                return("changing_shadow_memory");

            case vm_operations.changing_shadow_memory_live:
                return("changing_shadow_memory_live");

            case vm_operations.changing_VCPUs:
                return("changing_VCPUs");

            case vm_operations.changing_VCPUs_live:
                return("changing_VCPUs_live");

            case vm_operations.assert_operation_valid:
                return("assert_operation_valid");

            case vm_operations.data_source_op:
                return("data_source_op");

            case vm_operations.update_allowed_operations:
                return("update_allowed_operations");

            case vm_operations.make_into_template:
                return("make_into_template");

            case vm_operations.import:
                return("import");

            case vm_operations.export:
                return("export");

            case vm_operations.metadata_export:
                return("metadata_export");

            case vm_operations.reverting:
                return("reverting");

            case vm_operations.destroy:
                return("destroy");

            case vm_operations.xenprep:
                return("xenprep");
            }
            return("unknown");
        }
Example #15
0
        private static string GetVmCannotBootOnHostReason(VM vm, Host host, Session session, vm_operations operation)
        {
            Host residentHost = vm.Connection.Resolve(vm.resident_on);

            if (host == null)
                return Messages.NO_HOME_SERVER;

            if (vm.power_state == vm_power_state.Running && residentHost != null
                && Helpers.productVersionCompare(Helpers.HostProductVersion(host), Helpers.HostProductVersion(residentHost)) < 0)
            {
                // This will be a migrate menu if powerstate if running
                return Messages.OLDER_THAN_CURRENT_SERVER;
            }

            if (vm.power_state == vm_power_state.Running && residentHost != null && host.opaque_ref == residentHost.opaque_ref)
                return Messages.HOST_MENU_CURRENT_SERVER;

            if ((operation == vm_operations.pool_migrate || operation == vm_operations.resume_on) && VmCpuFeaturesIncompatibleWithHost(host, vm))
            {
                return FriendlyErrorNames.VM_INCOMPATIBLE_WITH_THIS_HOST;
            }

            try
            {
                VM.assert_can_boot_here(session, vm.opaque_ref, host.opaque_ref);
            }
            catch (Failure f)
            {
                if (f.ErrorDescription.Count > 2 && f.ErrorDescription[0] == Failure.VM_REQUIRES_SR)
                {
                    SR sr = host.Connection.Resolve((new XenRef<SR>(f.ErrorDescription[2])));

                    if (sr != null && sr.content_type == SR.Content_Type_ISO)
                        return Messages.MIGRATE_PLEASE_EJECT_YOUR_CD;
                }
                return f.ShortMessage;
            }
            catch (Exception e)
            {
                log.ErrorFormat("There was an error calling assert_can_boot_here on host {0}", host.Name);
                log.Error(e, e);
                return Messages.HOST_MENU_UNKNOWN_ERROR;
            }

            return null;
        }
Example #16
0
 public static string ToString(vm_operations x)
 {
     return(x.StringOf());
 }
        public VMOperationHostCommand(IMainWindow mainWindow, IEnumerable <SelectedItem> vms, GetHostForVM getHostForVM, string text, vm_operations operation, Session session)
            : base(mainWindow, vms, operation)
        {
            Util.ThrowIfParameterNull(session, "session");
            Util.ThrowIfParameterNull(getHostForVM, "getHostForVM");
            Util.ThrowIfParameterNull(text, "text");
            _text         = text;
            _getHostForVM = getHostForVM;

            foreach (SelectedItem item in vms)
            {
                VM vm = (VM)item.XenObject;

                string reason = GetVmCannotBootOnHostReason(vm, GetHost(vm), session, operation);

                if (reason == null)
                {
                    _noneCanBoot = false;
                }
                else
                {
                    _cantBootReasons[vm] = reason;
                }
            }
        }
Example #18
0
 public VMOperationCommand(IMainWindow mainWindow, IEnumerable <SelectedItem> selection)
     : base(mainWindow, selection)
 {
     _operation = vm_operations.unknown;
 }
Example #19
0
 public VMOperationCommand(IMainWindow mainWindow, IEnumerable <SelectedItem> selection, vm_operations operation)
     : base(mainWindow, selection)
 {
     _operation = operation;
     AssertOperationIsSupported();
 }
Example #20
0
 public static string ToString(vm_operations x)
 {
     switch (x)
     {
         case vm_operations.snapshot:
             return "snapshot";
         case vm_operations.clone:
             return "clone";
         case vm_operations.copy:
             return "copy";
         case vm_operations.create_template:
             return "create_template";
         case vm_operations.revert:
             return "revert";
         case vm_operations.checkpoint:
             return "checkpoint";
         case vm_operations.snapshot_with_quiesce:
             return "snapshot_with_quiesce";
         case vm_operations.provision:
             return "provision";
         case vm_operations.start:
             return "start";
         case vm_operations.start_on:
             return "start_on";
         case vm_operations.pause:
             return "pause";
         case vm_operations.unpause:
             return "unpause";
         case vm_operations.clean_shutdown:
             return "clean_shutdown";
         case vm_operations.clean_reboot:
             return "clean_reboot";
         case vm_operations.hard_shutdown:
             return "hard_shutdown";
         case vm_operations.power_state_reset:
             return "power_state_reset";
         case vm_operations.hard_reboot:
             return "hard_reboot";
         case vm_operations.suspend:
             return "suspend";
         case vm_operations.csvm:
             return "csvm";
         case vm_operations.resume:
             return "resume";
         case vm_operations.resume_on:
             return "resume_on";
         case vm_operations.pool_migrate:
             return "pool_migrate";
         case vm_operations.migrate_send:
             return "migrate_send";
         case vm_operations.get_boot_record:
             return "get_boot_record";
         case vm_operations.send_sysrq:
             return "send_sysrq";
         case vm_operations.send_trigger:
             return "send_trigger";
         case vm_operations.query_services:
             return "query_services";
         case vm_operations.shutdown:
             return "shutdown";
         case vm_operations.changing_memory_live:
             return "changing_memory_live";
         case vm_operations.awaiting_memory_live:
             return "awaiting_memory_live";
         case vm_operations.changing_dynamic_range:
             return "changing_dynamic_range";
         case vm_operations.changing_static_range:
             return "changing_static_range";
         case vm_operations.changing_memory_limits:
             return "changing_memory_limits";
         case vm_operations.changing_shadow_memory:
             return "changing_shadow_memory";
         case vm_operations.changing_shadow_memory_live:
             return "changing_shadow_memory_live";
         case vm_operations.changing_VCPUs:
             return "changing_VCPUs";
         case vm_operations.changing_VCPUs_live:
             return "changing_VCPUs_live";
         case vm_operations.assert_operation_valid:
             return "assert_operation_valid";
         case vm_operations.data_source_op:
             return "data_source_op";
         case vm_operations.update_allowed_operations:
             return "update_allowed_operations";
         case vm_operations.make_into_template:
             return "make_into_template";
         case vm_operations.import:
             return "import";
         case vm_operations.export:
             return "export";
         case vm_operations.metadata_export:
             return "metadata_export";
         case vm_operations.reverting:
             return "reverting";
         case vm_operations.destroy:
             return "destroy";
         default:
             return "unknown";
     }
 }
 public VMOperationHomeServerCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> vms, vm_operations operation, Session session)
     : base(mainWindow, vms, v => v.Connection.Resolve(v.affinity), Messages.HOME_SERVER_MENU_ITEM, operation, session)
 {
 }
Example #22
0
 public VMOperationHomeServerCommand(IMainWindow mainWindow, IEnumerable <SelectedItem> vms, vm_operations operation, Session session)
     : base(mainWindow, vms, v => v.Connection.Resolve(v.affinity), Messages.HOME_SERVER_MENU_ITEM, operation, session)
 {
 }
 public VMOperationWlbOptimalServerCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selection, vm_operations operation, WlbRecommendations recommendations)
     : base(mainWindow, selection, operation)
 {
     Util.ThrowIfParameterNull(recommendations, "recommendations");
     _recommendations = recommendations;
 }