Citrix XenServer: How XenStore information

2:21 PM
Citrix XenServer: How XenStore information -

Some time ago I wrote a Knowledge Base article (CTX136426) documentation of the Windows Management Instrumentation (WMI) in XenServer to access transfer data between the hypervisor and operating system in a virtual machine as a XenDesktop or XenApp VD. I still receive many inquiries about our SDK Forum which are basically looking to see if such an interface exists, so my articles here I am republishing hoping that google it easier Index

finds warning :! This article is for the technical heart

the WMI interface in XenServer uses the underlying Xen hypervisor XenStore data storage. It is particularly useful for developers looking for products for the XenServer platform to build, such as anti-virus or backup products for XenDesktop or management / monitoring solutions. However, it could also be used by an experienced system administrator to develop their own scripts and tools. WMI provides a mechanism information about a Windows virtual machine from the guest virtual machine (VM), such as access to the VM name or its IP address.

I. From a very helpful, a lot of help had XenServer developer (Ben Chalmers) to write in their Windows Tools team this article, he even wrote under several code examples, others to get started

The information quite technical, but we have a lot of requests for more technical blogs had recently, as feedback from the UK User Group. We try every taste 😉

The history of this functionality

The XenStore_Client.exe is to hear and receive a small executable program that was ( in earlier versions of XenServer) distributed with the XenServer Tools and users allows the value of the parameter in XenStore contained access. This program has been removed from XenServer 6.1.0, since it was not aware of dependencies or other consumers. However, after the program has been removed, remarked Citrix that there were users rely on this unsupported tool. XenStore_Client.exe was never officially supported or tested.

XenServer 6.1.0 introduced an alternative mechanism for extracting XenStore information by using Windows Management Instrumentation (WMI), which provides a much richer interface. This article contains information about WMI to extract for XenStore information.

developers who use XenServer 6.2.0 and CTX136422 outlines above and the Windows guest WMI interface as with XenStore and other hypervisor interfaces communication should read its use and deployment of code examples. The WMI interface can be used in XenServer 6.1.0 as an alternative to XenStore_Client.exe which was in earlier versions of XenServer available.

Summary

The XenStore_Client.exe is a small executable program that was (in previous versions of XenServer) distributed with the XenServer Tools and allows users to value the parameter access in XenStore contained. This program has been removed from XenServer 6.1.0, since it was not aware of dependencies or other consumers. However, after the program has been removed, remarked Citrix that there were users rely on this unsupported tool. XenStore_Client.exe was never officially supported or tested.

XenServer 6.1.0 provides an alternative mechanism for extracting XenStore information by using Windows Management Instrumentation (WMI), which provides a much richer interface. This article contains information about WMI to extract for XenStore information.

Background

This item is for (XenServer 6.1.0 and later) clients that use the Windows guest WMI interface as for communication with XenStore and other hypervisor interfaces. The WMI interface can be used in XenServer 6.1.0 as an alternative to XenStore_Client.exe which was in earlier versions of XenServer available.
WMI provides a mechanism for information on a Windows virtual machine to access from the guest virtual machine (VM), such as the name of the VM or its IP address.

Windows host WMI interface

Windows host WMI interface is provided by the device driver xeniface.sys, the part forms the XenServer Tools (Windows paravirtualized drivers). This interface is available for users who are granted access to the root wmi namespace (that is, the device driver namespace). By default, this is only available administrators .

The WMI interface provides a basis singleton object (CitrixXenStoreBase), which can be used to generate unique session objects (CitrixXenStoreSession). This session objects represent individual applications (or functions of an application) and are the objects that have been used to interact with XenStore; Reading, writing, set, and unset watches.

Sessions can also take advantage of the transaction semantics take indivisibility of XenStore operations to ensure. The life of watches and transactions are limited by the lifetime of the session object that it creates. On the driver load, an object CitrixXenStoreBase is WMI, provided that represents a singleton object xenstore properties: UInt64 XenTime. Local Time as Windows set for the VM, and then adjusted by the hypervisor Watch

WMI objects

CitrixXenStoreBase

A singleton object represents XenStore :

features Description
uint64 XenTime the Local time set by the window for the VM, and then adjusted by the clock of the hypervisor.
method Description
AddSession
(string Id)
Add a CitrixXenStoreSession object to the WMI namespace. The return value (SessionId) is a unique value that can be used to identify the session (at several meetings have the same string ID) .Returns SessionId was created.

CitrixXenStoreSession

Each instance represents a single session of communication with XenStore:

features Description
string ID A string that use the can identify the session and, if any meetings to determine the opening has been left
uint32 SessionID An integer that is unique among all the closed sessions. This integer equal to the integer value returned when AddSession created the session.
[1945017[
Methods Description
StartTransaction until the transaction is completed, all activities at this meeting within a transaction occur (hence activities will not affect on XenStore until the transaction is committed ).
CommitTransaction attempt to commit the current session of the transaction. If this fails, the transaction has been unsuccessful and must be repeated.
EndTransaction Cancel the current transaction without
GetValue (string pathname) Returns string value. Returns the value on the way Pathname in XenStore saved
GetChildren
(String pathname)
Are children {UInt32 NoOfChildNodes, String [NoOfChildNodes] ChildNodes}. For a given node (in pathName), which returns an object containing the number of child nodes, and a set of strings, where each string is the full path name of a child node
RemoveValue
(string pathname):
Removes an entry from XenStore (and, if available, all subordinate entries)
SetValue (string pathname, string value) Set the value to a specific path to value
log (string): Specifies a log message to the hypervisor
SetWatch (string pathname) Watch a specified XenStore entry for changes ,
Note
: Several amendments thereto XenStore entry that come in succession soon, can be merged into a WMI event. The event will be available after all changes indicated by the new event occur.
RemoveWatch (String pathname) to remove the clock, set previously with SetWatch.
EndSession () end this session. Remove the Session object from the WMI namespace. All watches and transactions linked to the session ends

events

CitrixXenStoreWatchEvent

event is raised when a certain changes XenStore entry. Several include changes of XenStore event could be merged into a CitrixXenStoreWatchEvent. You can your interest in receiving such an event by calling CitrixXenStoreSession.SetWatch (pathname)

Features Description register
string EventId , the path name of XenStore value has changed

CitrixXenStoreUnsuspendedEvent

event is triggered when a VM from suspended state again
PowerShell. Example:
The following example uses to demonstrate PowerShell how to script the XenStore WMI interface:

 # find the base object $ base = gwmi -n root  wmi -cl CitrixXenStoreBase # Create a session $ sid = $ base.AddSession ( "MyNewSession") $ session = gwmi -n root  wmi -q "select * from where CitrixXenStoreSession SessionId = $ ($ sid.SessionId)" # value $ session Write .SetValue ( "data / TempValue", "This is a string") # value $ session.GetValue reading ( "data / TempValue"). value # of the current VM name $ session.GetValue read ( "name"). Value # value $ session.RemoveValue remove ( "data / TempValue") #Examine children $ session.GetChildren ( "data"). Children # Set Watch $ pm = register WmiEvent -n root  wmi -q "select * from where CitrixXenStoreWatchEvent EventId = 'data / TempValue'" action {write $ session.getvalue ( "data / TempValue")} $ session .setvalue ( "data / TempValue", "hello") $ session.setvalue ( "data / TempValue", "world") $ watch.action.output # Copyright (c) of Citrix Systems, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification are permitted provided that the following conditions # are true: # # 1) disclosure of the source code has the copyright - # - notice, this list of conditions and the following disclaimer , # # 2) passing in binary form must provided with the distribution for the disposal of the above # copyright notice, this list of conditions and the following disclaimer in the # documentation and / or other materials #. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO THE IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE #. IN NO EVENT SHALL THE # Copyright OR ITS EMPLOYEES LIABLE FOR ANY DIRECT, # INDIRECT, SPECIAL, OR CONSEQUENTIAL DAMAGES # (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES, LOSS OF DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # OF ANY CAUSE OR THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY #, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # ABOUT POSSIBILITY OF SUCH DAMAGE. # 

Visual Basic example:

 rem rem testwmi.vbs a plausibility check for xeniface wmi interface rem can called be cscript.exe rem used is% error-% to 0 on success and 1 set on error rem of text "success" or an error message is also output rem rem This code was developed, should introduce functionality and rem not considered production be quality. Set objWMIService = GetObject ( "winmgmts: \.  Root  wmi") set base = objWmiService.InstancesOf ( "CitrixXenStoreBase") Dim Answer Dim Dim answer2 objItem rem Looking the base object if (base.Count) 1 then wscript.echo ( "too many basic objects found") WScript.Quit (1) end, if for any itementry in rem basis it is a trivial way to get the only element of a collection in vbscript? set objItem = Add itementry next rem two sessions objitem.AddSession "VBSTestSession" reply objitem.AddSession "AnotherVBSTestSession" answer2 rem looking the first session query = "select * from where CitrixXenStoreSession SessionId = '" & answer "'" Set sessions = objWMIService.ExecQuery (query) if (sessions.count) 1 then wscript.echo ( "too many session 1 sessions found") WScript.Quit (1) end, if for any itementry in meetings rem is a trivial way of getting the only element of a collection in vbscript? set session Calculate = itementry next rem te second session query = "select * from where CitrixXenStoreSession SessionId = '" & answer2 & "'" Set sessions2 = objWMIService.ExecQuery (query) if (sessions2.count) 1 then wscript.echo ( "too many session 2 sessions") WScript.Quit (1) end if dim session2 for each ses in sessions2 Set session2 = ses next rem we make sure is the expected session when session.Id "VBSTestSession found" then wscript .echo ( "wrong Sessions found") WScript.Quit (1) end if rem blank session.removevalue a set of entries xenstore "data / wmitestrun" rem and put a known set of values ​​there session.SetValue "data / wmitestrun / test1 "" Testing "session.SetValue" data / wmitestrun / test2 "," 123 Testing "session.SetValue" data / wmitestrun / test3 "," 456 Testing "session.SetValue" data / wmitestrun / test4 "," 789 Testing " rem read value back and xenstore, consider whether it properly session.getvalue "data / wmitestrun / test1" res if res "Testing" is then wscript.echo ( "failed to read or write data / wmitestrun / test1" ) wscript.echo ( "read =" & res) WScript.Quit (1) end when, rem another value of xenstore read back and test them, whether it is right session.getvalue "data / wmitestrun / test2", res if res "123 testing" then wscript.echo ( "failed to read or write data / wmitestrun / test2") wscript.echo ( "read =" & res) WScript.Quit (1) end if rem rem transactions test, the transactions canceled do session.starttransaction nothing () session.SetValue "data / wmitestrun / test1", "weird" session.getvalue "data / wmitestrun / test1" res if res "weird" then wscript.echo ( "failed writing or reading within transaction data / wmitestrun / test1 ") wscript.echo (res) WScript.Quit (1) end when session.aborttransaction () session.getvalue" data / wmitestrun / test1 "res if res" Testing "" = read "then wscript.echo (" failed to read data / wmitestrun / test1 after aborted transaction ") wscript.echo (" read = "& res) WScript.Quit (1) end if rem test, committed that two overlapping transactions honor and breaks and increase error if session.starttransaction required () session2.starttransaction () session.SetValue "data / wmitestrun / test1", "weird" session2.SetValue "data / wmitestrun / test1", "fish" session.getvalue " data / wmitestrun / data / wmitestrun / test1 "res2 if res" weird "then wscript.echo (" failed write or in a transaction to read the data / wmitestrun / test1 session 1 ") wscript test1" res session2.getvalue " .echo ( "read =" & res) WScript.Quit (1) end if if res2 "fish" then wscript.echo ( "failed write or read within the transaction data / wmitestrun / test1 session 2") wscript.echo ( " read = "& res) WScript.Quit (1) end if on error resume next session.committransaction () Err.Clear () when Err.Number 0 then wscript.echo (" could not commit first transaction ") WScript.Quit (1) end if session2.committransaction () when Err.Number = 0 then wscript.echo ( "Both transactions comitted") WScript.Quit (1) end if session2.aborttransaction () session2.getvalue "data / wmitestrun / test1 "res2 if res2" weird "then wscript.echo (" failed commiting the right transaction ") wscript.echo (" read = "& res) WScript.Quit (1) end if rem events an event sink dim rem refsink set up refsink = CreateObject ( "WBemScripting.SWbemSink") wscript.ConnectObject refsink, "EVENTSINK_" stq = "select * from CitrixXenStoreWatchEvent" objwmiservice.ExecNotificationQueryAsync refsink, stq evtcount = 0 rem observe a xenstore entry allEvents = 0 session.setwatch "data / wmitestrun / test1 "session.setvalue" data / wmitestrun / test1 "," MAGIC "session.removevalue" data / wmitestrun / test1 "session.setvalue" data / wmitestrun / test1 "," gold "WScript.Sleep (5000) session.removewatch "data / wmitestrun / test1" rem check we receive an event. Also, because events merged, rem check that if we get our final event, the value we is read by test1 the rem final value, we will set things (note the actual work of counting and control events in rem EVENTSINK_OnObjectready done under the bottom)) when evtcount <= 4 and 1 allEvents then) wscript.echo ( "Failed to catch all the expected events") WScript.Quit (1) end if session.removevalue "data / wmitestrun / test1" rem Check that we read the list of children, an entry has strComputer = "." Set objWMIService = GetObject ( "winmgmts:" _ & "{ImpersonationLevel = impersonate} \" & strComputer & " root  cimv2") Set colOperatingSystems = objWMIService.ExecQuery _ ( "select * from Win32_OperatingSystem") for each operating system in colOperatingSystems rem is a trivial way to get the only element of a collection in vbscript? set myos = os next wscript.echo (myos.Version) if mid (myos.Version, 1, 3) "6.0" then dim children session.getchildren "data / wmitestrun" children when children.noofchildnodes 3 then wscript. ( "check and troubleshoot all of the expected child node") echo WScript.Quit (1) end if end if session.getfirstchild "data / wmitestrun" res res session.getnextsibling end or rem both sessions that we created. session2.EndSession () session.EndSession () WScript.Echo ( "Success") Sub EVENTSINK_OnObjectReady (re, rc) = evtcount evtcount + 1 session.getvalue "data / wmitestrun / test1" res if res = "GOLD" then allEvents = 1 otherwise allEvents = 0 end if end sub rem Copyright (c) Citrix Systems, Inc. All rights reserved rem. rem rem Redistribution and use in source and binary forms, with or without rem modification are permitted provided that the following conditions rem are met: rem rem 1) disclosure of the source code has the copyright rem Note, maintaining this list of conditions and the following disclaimer , rem rem 2) passing in binary form must reproduce the above copyright notice things, this list of conditions and the following disclaimer in the documentation rem and / or other materials reproduce rem with the distribution provided. rem rem THIS SOFTWARE BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE rem rem. IN NO EVENT SHALL rem copyright OR EMPLOYEES BE LIABLE FOR ANY DIRECT, rem INDIRECT, SPECIAL, OR CONSEQUENTIAL DAMAGES rem (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR rem SERVICES, LOSS OF DATA, OR PROFITS; OR BUSINESS INTERRUPTION) rem HOWEVER CAUSED AND ON THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY rem, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING rem IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE rem. rem 

Learn more
The following command line tools that come with Windows, are particularly useful for exploring WMI:
• Wbemtext.exe provides a graphical user interface (GUI)
• Wmic.exe is a command line tool that can be used to access WMI

There are a number of external WMI explorer
• Windows management Instrumentation
• Wikipedia :. Windows Management Instrumentation.

Disclaimer

The sample code is provided to you AS IS without representations, warranties or conditions of any kind. You can use, modify and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES OF ANY KIND, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) may include the sample code errors, design flaws or other problems that may cause data loss or damage to property; (B) it may not be possible to make the sample code fully functional; and (c) Citrix may, without notice or liability to you, no longer available to make the current version and / or future versions of the sample code. In no event should the code to support ultra-hazardous activities, including but not limited to use life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS IN BREACH OF CONTRACT OR ANY OTHER LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THE SAMPLE CODE, INCLUDING DIRECT, SPECIAL, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Although the copyright belongs in the code to Citrix, any distribution of the code should have only your own standard of the owner of the rights, and not by Citrix. You agree to indemnify and defend Citrix against any claims arising from the use, modification or distribution of the code created.

Previous
Next Post »
0 Komentar