private bool ConsoleSuperceded(Console old_console) { if (old_console == null) { return(true); } List <Console> consoles; lock (hostedConsolesLock) { consoles = Source.Connection.ResolveAll(hostedConsoles); } bool good_console = false; foreach (Console console in consoles) { if (console.opaque_ref == old_console.opaque_ref && console.location == old_console.location) { return(false); } else if (console.protocol == console_protocol.rfb) { good_console = true; } } return(good_console); }
private void ConnectHostedConsole(VNCGraphicsClient v, Console console) { Program.AssertOffEventThread(); Host host = console.Connection.Resolve(Source.resident_on); if (host == null) { throw new Failure(Failure.INTERNAL_ERROR, Messages.VNC_HOST_GONE); } Uri uri = new Uri(console.location); String SessionUUID; lock (activeSessionLock) { // use the elevated credentials, if provided, for connecting to the console (CA-91132) activeSession = (string.IsNullOrEmpty(ElevatedUsername) || string.IsNullOrEmpty(ElevatedPassword)) ? console.Connection.DuplicateSession() : console.Connection.ElevatedSession(ElevatedUsername, ElevatedPassword); SessionUUID = activeSession.uuid; } Stream stream = HTTPHelper.CONNECT(uri, console.Connection, SessionUUID, false, true); InvokeConnection(v, stream, console); }
protected override void ProcessRecord() { GetSession(); if (Record == null && HashTable == null) { Record = new XenAPI.Console(); Record.other_config = CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(OtherConfig); } else if (Record == null) { Record = new XenAPI.Console(HashTable); } if (!ShouldProcess(session.Url, "Console.create")) { return; } RunApiCall(() => { var contxt = _context as XenServerCmdletDynamicParameters; if (contxt != null && contxt.Async) { taskRef = XenAPI.Console.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.Console.create(session, Record); if (PassThru) { XenAPI.Console obj = null; if (objRef != "OpaqueRef:NULL") { obj = XenAPI.Console.get_record(session, objRef); obj.opaque_ref = objRef; } WriteObject(obj, true); } } }); UpdateSessions(); }
private void ConnectHostedConsole(VNCGraphicsClient v, XenAPI.Console console, string session_uuid) { //Program.AssertOffEventThread(); Uri uri = new Uri(console.location); Stream stream = HTTP.CONNECT(uri, null, session_uuid, 0); InvokeConnection(v, stream, console, m_vncPassword); }
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); }
// 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); }
private void InvokeConnection(VNCGraphicsClient v, Stream stream, Console console) { Program.Invoke(this, delegate() { // This is the last chance that we have to make sure that we've not already // connected this VNCGraphicsClient. Now that we are back on the event thread, // we're guaranteed that no-one will beat us to the v.connect() call. We // hand over responsibility for closing the stream at that point, so we have to // close it ourselves if the client is already connected. if (v.Connected || v.Terminated) { stream.Close(); } else { v.SendScanCodes = UseSource && !this.sourceIsPV; v.SourceVM = sourceVM; v.Console = console; v.connect(stream, this.vncPassword); } }); }
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); }
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; } }
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; }