public SetVMOtherConfigAction(IXenConnection connection, VM vm, string key, string val)
     : base(connection, Messages.ACTION_SET_VM_OTHER_CONFIG_TITLE, true)
 {
     VM = vm;
     Key = key;
     Val = val;
 }
        public static new bool CanExecute(VM vm, Host preSelectedHost)
        {
            if (vm == null || !vm.is_a_template || vm.DefaultTemplate || vm.Locked)
                return false;

            return CrossPoolMigrateCommand.CanExecute(vm, preSelectedHost);
        }
Beispiel #3
0
        protected VMProblem(Check check, VM vm)
            : base(check)
        {
            _vm = vm;

            ResidentOn = VM.Connection.Resolve(VM.resident_on);
        }
        public new static bool CanExecute(VM vm, Host preSelectedHost)
        {
            if (vm == null || vm.is_a_template || vm.Locked || vm.power_state == vm_power_state.Running)
                return false;

            return CrossPoolMigrateCommand.CanExecute(vm, preSelectedHost);
        }
 public RevertToSnapshotCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selection, VM snapshot)
     : base(mainWindow, selection)
 {
     Util.ThrowIfParameterNull(snapshot, "snapshot");
     _snapshot = snapshot;
     _VM = _snapshot.Connection.Resolve(_snapshot.snapshot_of);
 }
Beispiel #6
0
 public VNCPasswordDialog(Exception error, VM vm)
     : base(vm.Connection)
 {
     InitializeComponent();
     Icon = Properties.Resources.AppIcon;
     passwordFailure1.Visible = error is VNCAuthenticationException || error is CryptographicException;
 }
 public ChangeVCPUSettingsAction(VM vm, long VCPUs_max, long VCPUs_at_startup)
     : base(vm.Connection, "", true)
 {
     m_VM = vm;
     m_VCPUs_max = VCPUs_max;
     m_VCPUs_at_startup = VCPUs_at_startup;
 }
Beispiel #8
0
        public MoveVMDialog(VM vm)
        {
            InitializeComponent();
            this.vm = vm;
            srPicker1.ItemSelectionNotNull += srPicker1_ItemSelectionNotNull;
            srPicker1.ItemSelectionNull += srPicker1_ItemSelectionNull;
            srPicker1.DoubleClickOnRow += srPicker1_DoubleClickOnRow;
            srPicker1.SrHint.Visible = false;
            Host affinity = vm.Home();
            srPicker1.Usage = SrPicker.SRPickerType.MoveOrCopy;
            //this has to be set after ImportTemplate, otherwise the usage will be reset to VM
            var vdis = (from VBD vbd in vm.Connection.ResolveAll(vm.VBDs)
                                           where vbd.IsOwner
                                           let vdi = vm.Connection.Resolve(vbd.VDI)
                                           where vdi != null
                                           select vdi).ToArray();
            srPicker1.SetExistingVDIs(vdis);
            srPicker1.Connection = vm.Connection;
            srPicker1.DiskSize = vm.TotalVMSize;
            srPicker1.SetAffinity(affinity);
            srPicker1.srListBox.Invalidate();
            srPicker1.selectDefaultSROrAny();

            EnableMoveButton();
        }
 public RevertToSnapshotCommand(IMainWindow mainWindow, VM vm, VM snapshot)
     : base(mainWindow, vm)
 {
     Util.ThrowIfParameterNull(snapshot, "snapshot");
     _snapshot = snapshot;
     _VM = vm;
 }
Beispiel #10
0
 public MockVMBuilder(string opaqueref, Mock<IXenConnection> mockConnection)
 {
     _mockConnection = mockConnection;
     _vm = new VM { Connection = mockConnection.Object, opaque_ref = opaqueref, VBDs = new List<XenRef<VBD>>() };
     _mockConnection.Setup(x => x.ResolveAll(It.IsAny<IEnumerable<XenRef<VBD>>>()))
        .Returns(_vbds);
 }
Beispiel #11
0
 public GpuAssignAction(VM vm, GPU_group gpu_group, VGPU_type vgpuType)
     : base(vm.Connection, "Set GPU", true)
 {
     this.vm = vm;
     this.gpu_group = gpu_group;
     this.vgpuType = vgpuType;
 }
Beispiel #12
0
 public CreateVIFAction(VM vm, Proxy_VIF proxyVIF)
     : base(vm.Connection, String.Format(Messages.ACTION_VIF_CREATING_TITLE, vm.Name))
 {
     _proxyVIF = proxyVIF;
     VM = vm;
     XmlRpcMethods.ForEach( method => ApiMethodsToRoleCheck.Add( method ) );
 }
        public HAUnprotectVMAction(VM vm)
            : base(vm.Connection, string.Format(Messages.ACTION_HA_UNPROTECT_VM_TITLE, Helpers.GetName(vm),
            Helpers.RestartPriorityI18n(XenAPI.VM.HA_Restart_Priority.DoNotRestart)), Messages.ACTION_HA_UNPROTECT_VM_DESCRIPTION)
        {
            VM = vm;

        }
 private void Execute(VM snapshot)
 {
     if (snapshot != null)
     {
         new ExportVMCommand(MainWindowCommandInterface, new SelectedItem(snapshot, snapshot.Connection, null, null)).Execute();
     }
 }
        public ChangeMemorySettingsAction(VM vm, string title,
            long static_min, long dynamic_min, long dynamic_max, long static_max, Action<VM, bool> warningDialogHAInvalidConfig, Action<VMStartAbstractAction, Failure> startDiagnosticForm, bool suppressHistory)
            : base(vm.Connection, title, suppressHistory)
        {
            _warningDialogHAInvalidConfig = warningDialogHAInvalidConfig;
            _startDiagnosticForm = startDiagnosticForm;
            VM = vm;
            this.static_min = static_min;
            this.dynamic_min = dynamic_min;
            this.dynamic_max = dynamic_max;
            this.static_max = static_max;

            #region RBAC Dependencies

            if (staticChanged)
                ApiMethodsToRoleCheck.Add("vm.set_memory_limits");
            else
                ApiMethodsToRoleCheck.Add("vm.set_memory_dynamic_range");

            if (needReboot)
            {
                if (VM.allowed_operations.Contains(XenAPI.vm_operations.clean_shutdown))
                    ApiMethodsToRoleCheck.Add("vm.clean_shutdown");
                else
                    ApiMethodsToRoleCheck.Add("vm.hard_shutdown");
                ApiMethodsToRoleCheck.Add("vm.start_on");
            }

            #endregion
        }
 public SetVMOtherConfigAction(IXenConnection connection, VM vm, string key, string val)
     : base(connection, "Set VM other_config", true)
 {
     VM = vm;
     Key = key;
     Val = val;
 }
Beispiel #17
0
 public RevertDialog(VM vm,string snapshotName)
 {
     InitializeComponent();
     this.questionLabel.Text = string.Format(questionLabel.Text, snapshotName.Ellipsise(40));
     this.takeSnapshotBeforeCheckBox.Enabled = vm.allowed_operations.Contains(vm_operations.snapshot);
     this.takeSnapshotBeforeCheckBox.Checked = this.takeSnapshotBeforeCheckBox.Enabled;
 }
Beispiel #18
0
        protected override void Run()
        {
            Description = Messages.STARTING_IN_RECOVERY_MODE;
            string oldPolicy = VM.HVM_boot_policy;
            string oldOrder  = VM.BootOrder;

            vmCopy = (VM)VM.Clone();
            vmCopy.HVM_boot_policy = "BIOS order";
            vmCopy.BootOrder = "DN";

            VM.Locked = true;
            vmCopy.SaveChanges(Session);
            VM.Locked = false;

            XenAPI.VM.start(Session, VM.opaque_ref, false, false);

            vmCopy.HVM_boot_policy = oldPolicy;
            vmCopy.BootOrder = oldOrder;

            VM.Locked = true;
            vmCopy.SaveChanges(Session);
            VM.Locked = false;

            Description = Messages.STARTED_IN_RECOVERY_MODE;
        }
Beispiel #19
0
 public UpdateVIFCommand(IMainWindow mainWindow, VM vm, VIF vif, Proxy_VIF proxyVIF)
     : base(mainWindow, vm)
 {
     _vm = vm;
     _vif = vif;
     _proxyVIF = proxyVIF;
 }
        protected override void Run()
        {
            // get the VM from the cache again, to check its vCPU fields before trying to change them
            m_VM = Connection.Resolve(new XenRef<VM>(m_VM.opaque_ref));
            if (m_VM == null) // VM has disappeared
                return;

            if (m_VM.power_state == vm_power_state.Running) // if the VM is running, we can only change the vCPUs number, not the max.
            {
                if (m_VM.VCPUs_at_startup > m_VCPUs_at_startup) // reducing VCPU_at_startup is not allowed for live VMs
                {
                    throw new Exception(string.Format(Messages.VM_VCPU_CANNOT_UNPLUG_LIVE, m_VM.VCPUs_at_startup));
                }
                VM.set_VCPUs_number_live(Session, m_VM.opaque_ref, m_VCPUs_at_startup);
                return;
            }

            if (m_VM.VCPUs_at_startup > m_VCPUs_at_startup) // reducing VCPUs_at_startup: we need to change this value first, and then the VCPUs_max
            {
                VM.set_VCPUs_at_startup(Session, m_VM.opaque_ref, m_VCPUs_at_startup);
                VM.set_VCPUs_max(Session, m_VM.opaque_ref, m_VCPUs_max);
            }
            else // increasing VCPUs_at_startup: we need to change the VCPUs_max first
            {
                VM.set_VCPUs_max(Session, m_VM.opaque_ref, m_VCPUs_max);
                VM.set_VCPUs_at_startup(Session, m_VM.opaque_ref, m_VCPUs_at_startup);
            }
        }
Beispiel #21
0
        public override void PageLoaded(PageLoadedDirection direction)
        {
            base.PageLoaded(direction);
            VM template = SelectedTemplate;
            bool installMethodIsNetwork = SelectedInstallMethod == InstallMethod.Network;

            if (template == Template && InstallMethodIsNetwork == installMethodIsNetwork)
                return;

            Template = template;

            InstallMethodIsNetwork = installMethodIsNetwork;
            if ((!Template.DefaultTemplate && !Template.HasAtLeastOneDisk)
                || (Template.IsHVM && InstallMethodIsNetwork)) // CA-46213 The default should be "diskless" if the install method is "boot from network"
            {
                DisklessVMRadioButton.Checked = true;
            }
            else
                DisksRadioButton.Checked = true;
            DisksGridView.Rows.Clear();
            LoadDisks();
            UpdateEnablement();
            UpdateCloneCheckboxEnablement(true);
            DisksGridView.Select();
        }
        public override void PageLoaded(PageLoadedDirection direction)
        {
            base.PageLoaded(direction);

            VM template = SelectedTemplate;
            
            if (!template.Equals(_template))
            {
                _template = template;
                ServersGridView.Rows.Clear();

                if (Helpers.MidnightRideOrGreater(Connection) && template.DefaultTemplate)
                {
                    List<Host> hosts = new List<Host>(Connection.Cache.Hosts);
                    hosts.Sort();
                    foreach (Host host in hosts)
                    {
                        ServerGridRow row = new ServerGridRow(host, false);
                        ServersGridView.Rows.Add(row);

                        if (host == _affinity)
                        {
                            row.Selected = true;
                        }
                    }
                }
                ServersGridView.Enabled = template.DefaultTemplate;
            }
        }
 public VMSnapshotRevertAction(VM snapshot)
     : base(snapshot.Connection, String.Format(Messages.ACTION_VM_REVERT_SNAPSHOT_TITLE, snapshot.Name))
 {
     this.VM = Connection.Resolve<VM>(snapshot.snapshot_of);
     this.m_Snapshot = snapshot;
     Description = String.Format(Messages.VM_REVERTING, m_Snapshot.Name);
 }
Beispiel #24
0
        private static string GetTitle(VM vm, Host toHost)
        {
            Host residentOn = vm.Connection.Resolve(vm.resident_on);

            return residentOn == null
                ? string.Format(Messages.ACTION_VM_MIGRATING_NON_RESIDENT, vm.Name, toHost.Name)
                : string.Format(Messages.ACTION_VM_MIGRATING_RESIDENT, vm.Name, Helpers.GetName(residentOn), toHost.Name);
        }
 protected VMShutdownAction(VM vm,string title)
     : base(vm.Connection, title)
 {
     this.Description = Messages.ACTION_PREPARING;
     this.VM = vm;
     this.Host = vm.Home();
     this.Pool = Core.Helpers.GetPool(vm.Connection);
 }
Beispiel #26
0
 protected override bool CanExecute(VM vm)
 {
     if (!vm.is_a_template && vm.power_state == vm_power_state.Running && vm.allowed_operations != null && vm.allowed_operations.Contains(vm_operations.suspend))
     {
         return true;
     }
     return false;
 }
Beispiel #27
0
 public VMMigrateAction(VM vm, Host destinationHost)
     : base(vm.Connection, GetTitle(vm, destinationHost))
 {
     this.Description = Messages.ACTION_PREPARING;
     this.VM = vm;
     this.Host = destinationHost;
     this.Pool = Core.Helpers.GetPool(vm.Connection);
 }
Beispiel #28
0
 public VMToTemplateAction(VM vm)
     : base(vm.Connection, string.Format(Messages.ACTION_VM_TEMPLATIZING_TITLE, vm.Name))
 {
     this.Description = Messages.ACTION_PREPARING;
     this.VM = vm;
     this.Host = vm.Home();
     this.Pool = Core.Helpers.GetPool(vm.Connection);
 }
        public LiveMigrateOptionsVmMapping(VmMapping vmMapping, IXenObject vm)
        {
            this.vmMapping = vmMapping;
            this.vm = vm as VM;

            if(vm==null)
                throw new NullReferenceException("VM passed to ctor was null");
        }
Beispiel #30
0
 public BallooningDialog(VM vm)
     : base(vm, false)
 {
     InitializeComponent();
     rubric.Text = is_a_template ? Messages.BALLOONING_RUBRIC_TEMPLATE : Messages.BALLOONING_RUBRIC;
     memoryControls = memoryControlsBasic;
     Initialize();
 }
Beispiel #31
0
        public bool Connect(string server, int port, string vm_uuid, string username, string password, int width, int height, bool show_border)
        {
            // reinitiailize the VNC Control
            initSubControl(width, height, true, show_border);
            m_vncClient.ErrorOccurred += ConnectionErrorHandler;

            try {
                // Create a new XenAPI session
                m_session = new Session(Session.STANDARD_TIMEOUT, server, port);

                // Authenticate with username and password passed in.
                // The third parameter tells the server which API version we support.
                m_session.login_with_password(username, password, API_Version.LATEST);
                m_vncPassword = password.ToCharArray();

                // Find the VM in question
                XenRef <VM> vmRef = VM.get_by_uuid(m_session, vm_uuid);
                m_sourceVM = VM.get_record(m_session, vmRef);

                // Check if this VM is PV or HVM
                m_sourceIsPV = (m_sourceVM.PV_bootloader.Length != 0); /* No PV bootloader specified implies HVM */

                // Get the console that uses the RFB (VNC) protocol
                List <XenRef <XenAPI.Console> > consoleRefs = VM.get_consoles(m_session, vmRef);
                XenAPI.Console console = null;
                foreach (XenRef <XenAPI.Console> consoleRef in consoleRefs)
                {
                    console = XenAPI.Console.get_record(m_session, consoleRef);
                    if (console.protocol == console_protocol.rfb)
                    {
                        break;
                    }
                    console = null;
                }

                if (console != null)
                {
                    //ThreadPool.QueueUserWorkItem(new WaitCallback(ConnectToConsole), new KeyValuePair<VNCGraphicsClient, XenAPI.Console>(m_vncClient, console));
                    ConnectHostedConsole(m_vncClient, console, m_session.uuid);
                }

                // done with this session, log it out
                m_session.logout();
            }
            catch (Exception exn)
            {
                // call the expcetion handler directly
                this.ConnectionErrorHandler(this, exn);
            }
            return(m_vncClient.Connected);
        }
        private void ProcessRecordVM(string console)
        {
            RunApiCall(() =>
            {
                string objRef = XenAPI.Console.get_VM(session, console);

                XenAPI.VM obj = null;

                if (objRef != "OpaqueRef:NULL")
                {
                    obj            = XenAPI.VM.get_record(session, objRef);
                    obj.opaque_ref = objRef;
                }

                WriteObject(obj, true);
            });
        }
        private void ProcessRecordControlDomain(string host)
        {
            RunApiCall(() =>
            {
                string objRef = XenAPI.Host.get_control_domain(session, host);

                XenAPI.VM obj = null;

                if (objRef != "OpaqueRef:NULL")
                {
                    obj            = XenAPI.VM.get_record(session, objRef);
                    obj.opaque_ref = objRef;
                }

                WriteObject(obj, true);
            });
        }
        private void ProcessRecordBackend(string vtpm)
        {
            RunApiCall(() =>
            {
                string objRef = XenAPI.VTPM.get_backend(session, vtpm);

                XenAPI.VM obj = null;

                if (objRef != "OpaqueRef:NULL")
                {
                    obj            = XenAPI.VM.get_record(session, objRef);
                    obj.opaque_ref = objRef;
                }

                WriteObject(obj, true);
            });
        }
Beispiel #35
0
        // Test API for the harness
        public Dictionary <String, String> ListConsoles(String server, int port, String username, String password)
        {
            XenAPI.Session session           = new Session(Session.STANDARD_TIMEOUT, server, port);
            Dictionary <String, String> dict = new Dictionary <String, String>();

            // Authenticate with username and password. The third parameter tells the server which API version we support.
            session.login_with_password(username, password, API_Version.LATEST);
            List <XenRef <XenAPI.Console> > consoleRefs = XenAPI.Console.get_all(session);

            foreach (XenRef <XenAPI.Console> consoleRef in consoleRefs)
            {
                XenAPI.Console console = XenAPI.Console.get_record(session, consoleRef);
                XenAPI.VM      vm      = XenAPI.VM.get_record(session, console.VM);
                dict.Add(vm.uuid, vm.name_label);
            }

            return(dict);
        }
Beispiel #36
0
        protected override void Run()
        {
            // First, save changes to the VBD.

            string vbdServerRef = vbd.SaveChanges(Session, null, null);

            if (!VM.IsHVM && vbd.empty)
            {
                // PV guest require no further action
                return;
            }

            // Then if we can plug the vbd in, do so...
            if (vbdServerRef != null &&
                XenAPI.VBD.get_allowed_operations(Session, vbdServerRef).Contains(XenAPI.vbd_operations.plug))
            {
                log.DebugFormat("Attempting to hot plug VBD {0}.", vbd.uuid);
                this.RelatedTask = XenAPI.VBD.async_plug(Session, vbdServerRef);
                PollToCompletion();
                this.Description = Messages.ATTACHDISKWIZARD_ATTACHED;
            }
            else
            {
                XenAPI.VM vm = this.Connection.Resolve <XenAPI.VM>(vbd.VM);
                if (vm != null && vm.power_state != XenAPI.vm_power_state.Halted)
                {
                    if (InstallingTools)
                    {
                        //Program.Invoke(Program.MainWindow, ShowMustRebootBox);
                        // this is now done inside InstallToolsCommand
                    }
                    else if (vbd.type == XenAPI.vbd_type.CD)
                    {
                        _ShowMustRebootBoxCD();
                    }
                    else
                    {
                        // Plug could not happen straight away: show warning.
                        _ShowVBDWarningBox();
                    }
                }
            }
        }
Beispiel #37
0
 protected override void ProcessRecord()
 {
     XenAPI.Session session = XenObject as XenAPI.Session;
     if (session != null)
     {
         WriteObject(new XenRef <XenAPI.Session>(session));
         return;
     }
     XenAPI.Auth auth = XenObject as XenAPI.Auth;
     if (auth != null)
     {
         WriteObject(new XenRef <XenAPI.Auth>(auth));
         return;
     }
     XenAPI.Subject subject = XenObject as XenAPI.Subject;
     if (subject != null)
     {
         WriteObject(new XenRef <XenAPI.Subject>(subject));
         return;
     }
     XenAPI.Role role = XenObject as XenAPI.Role;
     if (role != null)
     {
         WriteObject(new XenRef <XenAPI.Role>(role));
         return;
     }
     XenAPI.Task task = XenObject as XenAPI.Task;
     if (task != null)
     {
         WriteObject(new XenRef <XenAPI.Task>(task));
         return;
     }
     XenAPI.Event evt = XenObject as XenAPI.Event;
     if (evt != null)
     {
         WriteObject(new XenRef <XenAPI.Event>(evt));
         return;
     }
     XenAPI.Pool pool = XenObject as XenAPI.Pool;
     if (pool != null)
     {
         WriteObject(new XenRef <XenAPI.Pool>(pool));
         return;
     }
     XenAPI.Pool_patch pool_patch = XenObject as XenAPI.Pool_patch;
     if (pool_patch != null)
     {
         WriteObject(new XenRef <XenAPI.Pool_patch>(pool_patch));
         return;
     }
     XenAPI.Pool_update pool_update = XenObject as XenAPI.Pool_update;
     if (pool_update != null)
     {
         WriteObject(new XenRef <XenAPI.Pool_update>(pool_update));
         return;
     }
     XenAPI.VM vm = XenObject as XenAPI.VM;
     if (vm != null)
     {
         WriteObject(new XenRef <XenAPI.VM>(vm));
         return;
     }
     XenAPI.VM_metrics vm_metrics = XenObject as XenAPI.VM_metrics;
     if (vm_metrics != null)
     {
         WriteObject(new XenRef <XenAPI.VM_metrics>(vm_metrics));
         return;
     }
     XenAPI.VM_guest_metrics vm_guest_metrics = XenObject as XenAPI.VM_guest_metrics;
     if (vm_guest_metrics != null)
     {
         WriteObject(new XenRef <XenAPI.VM_guest_metrics>(vm_guest_metrics));
         return;
     }
     XenAPI.VMPP vmpp = XenObject as XenAPI.VMPP;
     if (vmpp != null)
     {
         WriteObject(new XenRef <XenAPI.VMPP>(vmpp));
         return;
     }
     XenAPI.VMSS vmss = XenObject as XenAPI.VMSS;
     if (vmss != null)
     {
         WriteObject(new XenRef <XenAPI.VMSS>(vmss));
         return;
     }
     XenAPI.VM_appliance vm_appliance = XenObject as XenAPI.VM_appliance;
     if (vm_appliance != null)
     {
         WriteObject(new XenRef <XenAPI.VM_appliance>(vm_appliance));
         return;
     }
     XenAPI.DR_task dr_task = XenObject as XenAPI.DR_task;
     if (dr_task != null)
     {
         WriteObject(new XenRef <XenAPI.DR_task>(dr_task));
         return;
     }
     XenAPI.Host host = XenObject as XenAPI.Host;
     if (host != null)
     {
         WriteObject(new XenRef <XenAPI.Host>(host));
         return;
     }
     XenAPI.Host_crashdump host_crashdump = XenObject as XenAPI.Host_crashdump;
     if (host_crashdump != null)
     {
         WriteObject(new XenRef <XenAPI.Host_crashdump>(host_crashdump));
         return;
     }
     XenAPI.Host_patch host_patch = XenObject as XenAPI.Host_patch;
     if (host_patch != null)
     {
         WriteObject(new XenRef <XenAPI.Host_patch>(host_patch));
         return;
     }
     XenAPI.Host_metrics host_metrics = XenObject as XenAPI.Host_metrics;
     if (host_metrics != null)
     {
         WriteObject(new XenRef <XenAPI.Host_metrics>(host_metrics));
         return;
     }
     XenAPI.Host_cpu host_cpu = XenObject as XenAPI.Host_cpu;
     if (host_cpu != null)
     {
         WriteObject(new XenRef <XenAPI.Host_cpu>(host_cpu));
         return;
     }
     XenAPI.Network network = XenObject as XenAPI.Network;
     if (network != null)
     {
         WriteObject(new XenRef <XenAPI.Network>(network));
         return;
     }
     XenAPI.VIF vif = XenObject as XenAPI.VIF;
     if (vif != null)
     {
         WriteObject(new XenRef <XenAPI.VIF>(vif));
         return;
     }
     XenAPI.VIF_metrics vif_metrics = XenObject as XenAPI.VIF_metrics;
     if (vif_metrics != null)
     {
         WriteObject(new XenRef <XenAPI.VIF_metrics>(vif_metrics));
         return;
     }
     XenAPI.PIF pif = XenObject as XenAPI.PIF;
     if (pif != null)
     {
         WriteObject(new XenRef <XenAPI.PIF>(pif));
         return;
     }
     XenAPI.PIF_metrics pif_metrics = XenObject as XenAPI.PIF_metrics;
     if (pif_metrics != null)
     {
         WriteObject(new XenRef <XenAPI.PIF_metrics>(pif_metrics));
         return;
     }
     XenAPI.Bond bond = XenObject as XenAPI.Bond;
     if (bond != null)
     {
         WriteObject(new XenRef <XenAPI.Bond>(bond));
         return;
     }
     XenAPI.VLAN vlan = XenObject as XenAPI.VLAN;
     if (vlan != null)
     {
         WriteObject(new XenRef <XenAPI.VLAN>(vlan));
         return;
     }
     XenAPI.SM sm = XenObject as XenAPI.SM;
     if (sm != null)
     {
         WriteObject(new XenRef <XenAPI.SM>(sm));
         return;
     }
     XenAPI.SR sr = XenObject as XenAPI.SR;
     if (sr != null)
     {
         WriteObject(new XenRef <XenAPI.SR>(sr));
         return;
     }
     XenAPI.LVHD lvhd = XenObject as XenAPI.LVHD;
     if (lvhd != null)
     {
         WriteObject(new XenRef <XenAPI.LVHD>(lvhd));
         return;
     }
     XenAPI.VDI vdi = XenObject as XenAPI.VDI;
     if (vdi != null)
     {
         WriteObject(new XenRef <XenAPI.VDI>(vdi));
         return;
     }
     XenAPI.VBD vbd = XenObject as XenAPI.VBD;
     if (vbd != null)
     {
         WriteObject(new XenRef <XenAPI.VBD>(vbd));
         return;
     }
     XenAPI.VBD_metrics vbd_metrics = XenObject as XenAPI.VBD_metrics;
     if (vbd_metrics != null)
     {
         WriteObject(new XenRef <XenAPI.VBD_metrics>(vbd_metrics));
         return;
     }
     XenAPI.PBD pbd = XenObject as XenAPI.PBD;
     if (pbd != null)
     {
         WriteObject(new XenRef <XenAPI.PBD>(pbd));
         return;
     }
     XenAPI.Crashdump crashdump = XenObject as XenAPI.Crashdump;
     if (crashdump != null)
     {
         WriteObject(new XenRef <XenAPI.Crashdump>(crashdump));
         return;
     }
     XenAPI.VTPM vtpm = XenObject as XenAPI.VTPM;
     if (vtpm != null)
     {
         WriteObject(new XenRef <XenAPI.VTPM>(vtpm));
         return;
     }
     XenAPI.Console console = XenObject as XenAPI.Console;
     if (console != null)
     {
         WriteObject(new XenRef <XenAPI.Console>(console));
         return;
     }
     XenAPI.User user = XenObject as XenAPI.User;
     if (user != null)
     {
         WriteObject(new XenRef <XenAPI.User>(user));
         return;
     }
     XenAPI.Data_source data_source = XenObject as XenAPI.Data_source;
     if (data_source != null)
     {
         WriteObject(new XenRef <XenAPI.Data_source>(data_source));
         return;
     }
     XenAPI.Blob blob = XenObject as XenAPI.Blob;
     if (blob != null)
     {
         WriteObject(new XenRef <XenAPI.Blob>(blob));
         return;
     }
     XenAPI.Message message = XenObject as XenAPI.Message;
     if (message != null)
     {
         WriteObject(new XenRef <XenAPI.Message>(message));
         return;
     }
     XenAPI.Secret secret = XenObject as XenAPI.Secret;
     if (secret != null)
     {
         WriteObject(new XenRef <XenAPI.Secret>(secret));
         return;
     }
     XenAPI.Tunnel tunnel = XenObject as XenAPI.Tunnel;
     if (tunnel != null)
     {
         WriteObject(new XenRef <XenAPI.Tunnel>(tunnel));
         return;
     }
     XenAPI.PCI pci = XenObject as XenAPI.PCI;
     if (pci != null)
     {
         WriteObject(new XenRef <XenAPI.PCI>(pci));
         return;
     }
     XenAPI.PGPU pgpu = XenObject as XenAPI.PGPU;
     if (pgpu != null)
     {
         WriteObject(new XenRef <XenAPI.PGPU>(pgpu));
         return;
     }
     XenAPI.GPU_group gpu_group = XenObject as XenAPI.GPU_group;
     if (gpu_group != null)
     {
         WriteObject(new XenRef <XenAPI.GPU_group>(gpu_group));
         return;
     }
     XenAPI.VGPU vgpu = XenObject as XenAPI.VGPU;
     if (vgpu != null)
     {
         WriteObject(new XenRef <XenAPI.VGPU>(vgpu));
         return;
     }
     XenAPI.VGPU_type vgpu_type = XenObject as XenAPI.VGPU_type;
     if (vgpu_type != null)
     {
         WriteObject(new XenRef <XenAPI.VGPU_type>(vgpu_type));
         return;
     }
     XenAPI.PVS_site pvs_site = XenObject as XenAPI.PVS_site;
     if (pvs_site != null)
     {
         WriteObject(new XenRef <XenAPI.PVS_site>(pvs_site));
         return;
     }
     XenAPI.PVS_server pvs_server = XenObject as XenAPI.PVS_server;
     if (pvs_server != null)
     {
         WriteObject(new XenRef <XenAPI.PVS_server>(pvs_server));
         return;
     }
     XenAPI.PVS_proxy pvs_proxy = XenObject as XenAPI.PVS_proxy;
     if (pvs_proxy != null)
     {
         WriteObject(new XenRef <XenAPI.PVS_proxy>(pvs_proxy));
         return;
     }
     XenAPI.PVS_cache_storage pvs_cache_storage = XenObject as XenAPI.PVS_cache_storage;
     if (pvs_cache_storage != null)
     {
         WriteObject(new XenRef <XenAPI.PVS_cache_storage>(pvs_cache_storage));
         return;
     }
     XenAPI.Feature feature = XenObject as XenAPI.Feature;
     if (feature != null)
     {
         WriteObject(new XenRef <XenAPI.Feature>(feature));
         return;
     }
     XenAPI.SDN_controller sdn_controller = XenObject as XenAPI.SDN_controller;
     if (sdn_controller != null)
     {
         WriteObject(new XenRef <XenAPI.SDN_controller>(sdn_controller));
         return;
     }
     XenAPI.Vdi_nbd_server_info vdi_nbd_server_info = XenObject as XenAPI.Vdi_nbd_server_info;
     if (vdi_nbd_server_info != null)
     {
         WriteObject(new XenRef <XenAPI.Vdi_nbd_server_info>(vdi_nbd_server_info));
         return;
     }
     XenAPI.PUSB pusb = XenObject as XenAPI.PUSB;
     if (pusb != null)
     {
         WriteObject(new XenRef <XenAPI.PUSB>(pusb));
         return;
     }
     XenAPI.USB_group usb_group = XenObject as XenAPI.USB_group;
     if (usb_group != null)
     {
         WriteObject(new XenRef <XenAPI.USB_group>(usb_group));
         return;
     }
     XenAPI.VUSB vusb = XenObject as XenAPI.VUSB;
     if (vusb != null)
     {
         WriteObject(new XenRef <XenAPI.VUSB>(vusb));
         return;
     }
 }
Beispiel #38
0
        public Dictionary <VM, Dictionary <VDI, String> > GetMultiPathStatusLunPerVDI()
        {
            Dictionary <VM, Dictionary <VDI, String> > result =
                new Dictionary <VM, Dictionary <VDI, String> >();

            if (Connection == null)
            {
                return(result);
            }

            foreach (PBD pbd in Connection.ResolveAll(PBDs))
            {
                if (!pbd.MultipathActive())
                {
                    continue;
                }

                foreach (KeyValuePair <String, String> kvp in pbd.other_config)
                {
                    if (!kvp.Key.StartsWith(MPATH))
                    {
                        continue;
                    }

                    int current;
                    int max;
                    if (!PBD.ParsePathCounts(kvp.Value, out current, out max))
                    {
                        continue;
                    }

                    String scsiIdKey = String.Format("scsi-{0}", kvp.Key.Substring(MPATH.Length + 1));
                    if (!sm_config.ContainsKey(scsiIdKey))
                    {
                        continue;
                    }

                    String vdiUUID = sm_config[scsiIdKey];
                    VDI    vdi     = null;

                    foreach (VDI candidate in Connection.ResolveAll(VDIs))
                    {
                        if (candidate.uuid != vdiUUID)
                        {
                            continue;
                        }

                        vdi = candidate;
                        break;
                    }

                    if (vdi == null)
                    {
                        continue;
                    }

                    foreach (VBD vbd in Connection.ResolveAll(vdi.VBDs))
                    {
                        VM vm = Connection.Resolve(vbd.VM);
                        if (vm == null)
                        {
                            continue;
                        }

                        if (vm.power_state != vm_power_state.Running)
                        {
                            continue;
                        }

                        if (!result.ContainsKey(vm))
                        {
                            result[vm] = new Dictionary <VDI, String>();
                        }

                        result[vm][vdi] = kvp.Value;
                    }
                }
            }

            return(result);
        }
        protected override void ProcessRecord()
        {
            GetSession();
            if (Record == null && HashTable == null)
            {
                Record                           = new XenAPI.VM();
                Record.name_label                = NameLabel;
                Record.name_description          = NameDescription;
                Record.user_version              = UserVersion;
                Record.is_a_template             = IsATemplate;
                Record.affinity                  = Affinity == null ? null : new XenRef <XenAPI.Host>(Affinity.opaque_ref);
                Record.memory_target             = MemoryTarget;
                Record.memory_static_max         = MemoryStaticMax;
                Record.memory_dynamic_max        = MemoryDynamicMax;
                Record.memory_dynamic_min        = MemoryDynamicMin;
                Record.memory_static_min         = MemoryStaticMin;
                Record.VCPUs_params              = CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(VCPUsParams);
                Record.VCPUs_max                 = VCPUsMax;
                Record.VCPUs_at_startup          = VCPUsAtStartup;
                Record.actions_after_shutdown    = ActionsAfterShutdown;
                Record.actions_after_reboot      = ActionsAfterReboot;
                Record.actions_after_crash       = ActionsAfterCrash;
                Record.PV_bootloader             = PVBootloader;
                Record.PV_kernel                 = PVKernel;
                Record.PV_ramdisk                = PVRamdisk;
                Record.PV_args                   = PVArgs;
                Record.PV_bootloader_args        = PVBootloaderArgs;
                Record.PV_legacy_args            = PVLegacyArgs;
                Record.HVM_boot_policy           = HVMBootPolicy;
                Record.HVM_boot_params           = CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(HVMBootParams);
                Record.HVM_shadow_multiplier     = HVMShadowMultiplier;
                Record.platform                  = CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(Platform);
                Record.PCI_bus                   = PCIBus;
                Record.other_config              = CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(OtherConfig);
                Record.recommendations           = Recommendations;
                Record.xenstore_data             = CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(XenstoreData);
                Record.ha_always_run             = HaAlwaysRun;
                Record.ha_restart_priority       = HaRestartPriority;
                Record.tags                      = Tags;
                Record.blocked_operations        = CommonCmdletFunctions.ConvertHashTableToDictionary <vm_operations, string>(BlockedOperations);
                Record.protection_policy         = ProtectionPolicy == null ? null : new XenRef <XenAPI.VMPP>(ProtectionPolicy.opaque_ref);
                Record.is_snapshot_from_vmpp     = IsSnapshotFromVmpp;
                Record.snapshot_schedule         = SnapshotSchedule == null ? null : new XenRef <XenAPI.VMSS>(SnapshotSchedule.opaque_ref);
                Record.is_vmss_snapshot          = IsVmssSnapshot;
                Record.appliance                 = Appliance == null ? null : new XenRef <XenAPI.VM_appliance>(Appliance.opaque_ref);
                Record.start_delay               = StartDelay;
                Record.shutdown_delay            = ShutdownDelay;
                Record.order                     = Order;
                Record.suspend_SR                = SuspendSR == null ? null : new XenRef <XenAPI.SR>(SuspendSR.opaque_ref);
                Record.version                   = Version;
                Record.generation_id             = GenerationId;
                Record.hardware_platform_version = HardwarePlatformVersion;
                Record.has_vendor_device         = HasVendorDevice;
                Record.reference_label           = ReferenceLabel;
            }
            else if (Record == null)
            {
                Record = new XenAPI.VM(HashTable);
            }

            if (!ShouldProcess(session.Url, "VM.create"))
            {
                return;
            }

            RunApiCall(() =>
            {
                var contxt = _context as XenServerCmdletDynamicParameters;

                if (contxt != null && contxt.Async)
                {
                    taskRef = XenAPI.VM.async_create(session, Record);

                    if (PassThru)
                    {
                        XenAPI.Task taskObj = null;
                        if (taskRef != "OpaqueRef:NULL")
                        {
                            taskObj            = XenAPI.Task.get_record(session, taskRef.opaque_ref);
                            taskObj.opaque_ref = taskRef.opaque_ref;
                        }

                        WriteObject(taskObj, true);
                    }
                }
                else
                {
                    string objRef = XenAPI.VM.create(session, Record);

                    if (PassThru)
                    {
                        XenAPI.VM obj = null;

                        if (objRef != "OpaqueRef:NULL")
                        {
                            obj            = XenAPI.VM.get_record(session, objRef);
                            obj.opaque_ref = objRef;
                        }

                        WriteObject(obj, true);
                    }
                }
            });

            UpdateSessions();
        }
Beispiel #40
0
        public bool ConnectConsole(string consoleuri, int width, int height, bool show_border)
        {
            //reinitialise the VNC Control
            initSubControl(width, height, true, show_border);
            m_vncClient.ErrorOccurred += ConnectionErrorHandler;

            try {
                XenAPI.Console console = new XenAPI.Console();
                console.protocol = console_protocol.rfb;
                console.location = consoleuri;

                Uri    uri         = new Uri(consoleuri);
                char[] delims      = { '&', '=', '?' };
                string qargs       = uri.Query;
                string session_id  = "";
                string vm_Opref    = "";
                string console_ref = "";

                string[] args  = qargs.Split(delims);
                int      x     = -1;
                int      y     = -1;
                int      z     = -1;
                int      count = 0;

                foreach (string s in args)
                {
                    if (String.Equals(s, "session_id", StringComparison.Ordinal))
                    {
                        //The session_id value must be one greater in array
                        x = count + 1;
                    }
                    else if (String.Equals(s, "ref", StringComparison.Ordinal))
                    {
                        //The OpaqueRef for vnc console must be one greater in array
                        y = count + 1;
                    }
                    else if (String.Equals(s, "uuid", StringComparison.Ordinal))
                    {
                        //The uuid was passed for the vnc console - it must be one
                        //greater in the array.
                        z = count + 1;
                    }
                    count++;
                }

                //Checks for incorrect parsing of the console URL
                if (x == -1 || x == count)
                {
                    this.ConnectionErrorHandler(this, new System.ApplicationException("Error: The session ID has been incorrectly parsed."));
                }
                else
                {
                    session_id = args[x];
                }

                if (console != null)
                {
                    try {
                        m_session = new Session("http://" + uri.Host, session_id);
                    }
                    catch (XenAPI.Failure f) {
                        if (f.ErrorDescription[0] == HOST_IS_SLAVE)
                        {
                            string m_address = f.ErrorDescription[1];
                            m_session = new Session("http://" + m_address, session_id);
                        }
                    }


                    if ((y == -1 && z == -1) || (y == count && z == count))
                    {
                        //Check for the error case where neither uuid or vm_reference have been supplied.
                        this.ConnectionErrorHandler(this, new System.ApplicationException("Error: The console reference has been incorrectly parsed."));
                    }
                    else if (y != -1 && y != count)
                    {
                        //The console reference has been provided.
                        console_ref = args[y];
                    }

                    else if (z != -1 && z != count)
                    {
                        //The console uuid has been supplied instead, we must get the VM reference.
                        console_ref = XenAPI.Console.get_by_uuid(m_session, args[z]);
                    }

                    vm_Opref   = XenAPI.Console.get_VM(m_session, console_ref);
                    m_sourceVM = VM.get_record(m_session, vm_Opref);

                    // Check if this VM is PV or HVM
                    m_sourceIsPV = (m_sourceVM.PV_bootloader.Length != 0);
                    ConnectHostedConsole(m_vncClient, console, session_id);
                }
            }

            catch (Exception exn) {
                //call the exception handler directly
                this.ConnectionErrorHandler(this, exn);
            }
            return(m_vncClient.Connected);
        }