public Feature(string name, string advertise, string control, bool controlmustexist, IExceptionHandler exceptionhandler) { this.exceptionhandler = exceptionhandler; this.name = name; wmisession = WmiBase.Singleton.GetXenStoreSession("Citrix Xen Service Feature : " + name); wmisession.Log("New Feature"); controlKey = wmisession.GetXenStoreItem(control); this.controlmustexist = controlmustexist; try { if (controlKey.value != "") { wmisession.Log("Control key " + control + ":" + controlKey.value); } } catch {} enabled = true; listener = controlKey.Watch(new EventArrivedEventHandler(onFeatureWrapper)); if (!advertise.Equals("")) { advert = wmisession.GetXenStoreItem(advertise); features.Add(this); } Disposer.Add(this); }
public FeatureShutdown(IExceptionHandler exceptionhandler) : base("Shutdown Provider", "control/feature-shutdown", "control/shutdown", true, exceptionhandler) { controlHibernationState = wmisession.GetXenStoreItem("control/hibernation-state"); controlS3State = wmisession.GetXenStoreItem("control/s3-state"); wmisession.Log("Created feature shutdown"); }
public FeatureTerminalServicesReset(IExceptionHandler exceptionhandler) : base("Terminal Services Reset", "control/feature-ts2", "data/ts", false, exceptionhandler) { datats = wmisession.GetXenStoreItem("data/ts"); Disposer.Add(WmiBase.Singleton.ListenForEvent("__InstanceModificationEvent", new EventArrivedEventHandler(onFeatureWrapper))); onFeature(); }
public FeatureStaticIpSetting(IExceptionHandler exceptionhandler) : base("StaticIpSetting", "control/feature-static-ip-setting", "xenserver/device/vif", false, exceptionhandler) { staticIpSetting = wmisession.GetXenStoreItem("xenserver/device/vif"); last_time_ipenabled_state = 0; last_time_ipv6enabled_state = 0; }
public ClipboardAccess(WmiSession wmisession) { this.wmisession = wmisession; xsSetClipboard = wmisession.GetXenStoreItem("data/set_clipboard"); xsReportClipboard = wmisession.GetXenStoreItem("data/report_clipboard"); serverwatch = xsSetClipboard.Watch(new EventArrivedEventHandler(OnServerClipboard)); clientwatch = xsReportClipboard.Watch(new EventArrivedEventHandler(OnClientClipboard)); }
public FeatureDomainJoin(IExceptionHandler exceptionhandler) : base("Domain Join", "", "control/domainjoin/action", true, exceptionhandler) { domainName = wmisession.GetXenStoreItem("control/domainjoin/domainname"); userName = wmisession.GetXenStoreItem("control/domainjoin/user"); password = wmisession.GetXenStoreItem("control/domainjoin/password"); state = wmisession.GetXenStoreItem("control/domainjoin/state"); error = wmisession.GetXenStoreItem("control/domainjoin/error"); }
public FeatureSetComputerName(IExceptionHandler exceptionhandler) : base(Branding.Instance.getString("BRANDING_setComputerName"), "control/feature-setcomputername", "control/setcomputername/action", true, exceptionhandler) { name = wmisession.GetXenStoreItem("control/setcomputername/name"); state = wmisession.GetXenStoreItem("control/setcomputername/state"); error = wmisession.GetXenStoreItem("control/setcomputername/error"); warn = wmisession.GetXenStoreItem("control/setcomputername/warn"); }
public FeatureSetComputerName(IExceptionHandler exceptionhandler) : base("Set Computer Name", "control/feature-setcomputername", "control/setcomputername/action", true, exceptionhandler) { name = wmisession.GetXenStoreItem("control/setcomputername/name"); state = wmisession.GetXenStoreItem("control/setcomputername/state"); error = wmisession.GetXenStoreItem("control/setcomputername/error"); warn = wmisession.GetXenStoreItem("control/setcomputername/warn"); }
public FeatureSnapshot(IExceptionHandler exceptionhandler) : base("snapshot", "control/feature-snapshot", "control/snapshot/action",true, exceptionhandler) { actionKey = wmisession.GetXenStoreItem("control/snapshot/action"); typeKey = wmisession.GetXenStoreItem("control/snapshot/type"); statusKey = wmisession.GetXenStoreItem("control/snapshot/status"); threadlock = new object(); }
bool backupHandler(IntPtr bstrMem) { try { string backup = Marshal.PtrToStringBSTR(bstrMem); string vm = wmisession.GetXenStoreItemCached("vm").value.Substring(4); if (type == VssSnapshot.Type.VM) { string snapstr = wmisession.GetXenStoreItem("/vss/" + vm + "/snapuuid").value; wmisession.GetXenStoreItem("control/snapshot/snapuuid").value = snapstr; wmisession.GetXenStoreItem("control/snapshot/type").value = "vm"; } else if (type == VssSnapshot.Type.VOLUME) { string rootkeyname = "/vss/" + vm + "/vdisnap"; XenStoreItem vdisnap = wmisession.GetXenStoreItem(rootkeyname); foreach (string entryKey in vdisnap.children) { XenStoreItem src = wmisession.GetXenStoreItem(entryKey); XenStoreItem dest = wmisession.GetXenStoreItem("control/snapshot/vdi/" + entryKey.Substring(rootkeyname.Length + 1)); src.value = dest.value; } string snaptype = wmisession.GetXenStoreItem("/vss/" + vm + "/snaptype").value; wmisession.GetXenStoreItem("control/snapshot/type").value = snaptype; } wmisession.GetXenStoreItem("control/snapshot/snapid").Remove(); int size = backup.Length; int poscount = 0; int pagecount = 0; string substr = ""; while (size > 0) { substr += string.Format("{0:x2}{1:x2}", ((int)backup[poscount]) & 0xff, (((int)backup[poscount]) >> 8) & 0xff); size--; poscount++; if (((poscount % 255) == 0) || (size == 0)) { wmisession.GetXenStoreItem("control/snapshot/snapid/" + pagecount.ToString()).value = substr; substr = ""; pagecount++; } } } catch (Exception e) { try { wmisession.GetXenStoreItem("control/snapshot/snapid").Remove(); WmiBase.Singleton.DebugMsg("Backup failed: " + e.ToString()); } catch {} return(false); } return(true); }
private WmiBase() { debugmsg = new Queue<string>(); syncSingleton = new Object(); xenbaselock = new Object(); wmisession = new WmiSession("Base", this); xsupdated = wmisession.GetXenStoreItem("data/updated"); xsupdatedcount = wmisession.GetXenStoreItem("data/update_cnt"); xserror = wmisession.GetXenStoreItem("control/error"); }
private WmiBase() { debugmsg = new Queue <string>(); syncSingleton = new Object(); xenbaselock = new Object(); wmisession = new WmiSession("Base", this); xsupdated = wmisession.GetXenStoreItem("data/updated"); xsupdatedcount = wmisession.GetXenStoreItem("data/update_cnt"); xserror = wmisession.GetXenStoreItem("control/error"); }
public FeatureTerminalServicesReset(IExceptionHandler exceptionhandler) : base("Terminal Services Reset", "control/feature-ts2", "data/ts", false, exceptionhandler) { datats = wmisession.GetXenStoreItem("data/ts"); try { Disposer.Add(WmiBase.Singleton.ListenForEvent("__InstanceModificationEvent", new EventArrivedEventHandler(onFeatureWrapper))); } catch { Trace.WriteLine("Terminal Services namespace not available on this version of windows"); } onFeature(); }
public NetInfo(IExceptionHandler exceptionhandler) { updating = new Object(); this.exceptionhandler = exceptionhandler; wmisession = WmiBase.Singleton.GetXenStoreSession("Adapters"); devicevif = wmisession.GetXenStoreItem("device/vif"); datavif = wmisession.GetXenStoreItem("data/vif"); numvif = wmisession.GetXenStoreItem("data/num_vif"); needsRefresh = true; onAddrChange(null, null); addrChangeHandler = new NetworkAddressChangedEventHandler(onAddrChange); NetworkChange.NetworkAddressChanged += addrChangeHandler; vifListen = devicevif.Watch(onVifChanged); }
public PVInstallation(IExceptionHandler exceptionhandler) : base("PV Installation", "", "attr/PVAddons/Installed", false, exceptionhandler) { osclass = wmisession.GetXenStoreItem("attr/os/class"); osmajor = wmisession.GetXenStoreItem("attr/os/major"); osminor = wmisession.GetXenStoreItem("attr/os/minor"); osbuild = wmisession.GetXenStoreItem("attr/os/build"); osplatform = wmisession.GetXenStoreItem("attr/os/platform"); osspmajor = wmisession.GetXenStoreItem("attr/os/spmajor"); osspminor = wmisession.GetXenStoreItem("attr/os/spminor"); ossuite = wmisession.GetXenStoreItem("attr/os/suite"); ostype = wmisession.GetXenStoreItem("attr/os/type"); datadistro = wmisession.GetXenStoreItem("data/os_distro"); datamajor = wmisession.GetXenStoreItem("data/os_majorver"); dataminor = wmisession.GetXenStoreItem("data/os_minorver"); guestdotnetframework = wmisession.GetXenStoreItem("data/guest_dotnet_framework"); osboottype = wmisession.GetXenStoreItem("attr/os/boottype"); ossystem32 = wmisession.GetXenStoreItem("attr/os/system32_dir"); oshal = wmisession.GetXenStoreItem("attr/os/hal"); osbootoptions = wmisession.GetXenStoreItem("attr/os_boot/options"); osname = wmisession.GetXenStoreItem("data/os_name"); hostname = wmisession.GetXenStoreItem("data/host_name"); hostnamedns = wmisession.GetXenStoreItem("data/host_name_dns"); domain = wmisession.GetXenStoreItem("data/domain"); oslicense = wmisession.GetXenStoreItem("attr/os/license"); osvirtualxp = wmisession.GetXenStoreItem("attr/os/virtualxp_enabled"); pvmajor = wmisession.GetXenStoreItem("attr/PVAddons/MajorVersion"); pvminor = wmisession.GetXenStoreItem("attr/PVAddons/MinorVersion"); pvmicro = wmisession.GetXenStoreItem("attr/PVAddons/MicroVersion"); pvbuild = wmisession.GetXenStoreItem("attr/PVAddons/BuildVersion"); pvinstalled = wmisession.GetXenStoreItem("attr/PVAddons/Installed"); xdvdapresent = wmisession.GetXenStoreItem("data/xd/present"); xdvdaproductinstalled = wmisession.GetXenStoreItem("data/xd/product_installed"); lock (pvinstalllock) { registered = false; needsinstalling = true; initialised = true; System.Threading.Monitor.PulseAll(pvinstalllock); RefreshXenstore(); } }
public FeatureXSBatchCommand(IExceptionHandler exceptionhandler) : base("XS Batch Command", "", "control/batcmd/state", true, exceptionhandler) { if (wmisession.GetXenStoreItem("control/feature-remote-exec").Exists()) { wmisession.Log("Remote exec found"); this.Dispose(); throw new Exception("remote-exec exists"); } this.state = wmisession.GetXenStoreItem("control/batcmd/state"); this.script = wmisession.GetXenStoreItem("control/batcmd/script"); this.ret = wmisession.GetXenStoreItem("control/batcmd/return"); this.stdout = wmisession.GetXenStoreItem("control/batcmd/stdout"); this.stderr = wmisession.GetXenStoreItem("control/batcmd/stderr"); this.addAdvert("control/feature-xs-batcmd"); }
void writeDevice(string device, NetworkInterface[] nics) { if (enablewritedevice) { string mac = wmisession.GetXenStoreItem(device + "/mac").value; foreach (NetworkInterface nic in nics) { if (macsMatch(mac, nic)) { XenStoreItem name = wmisession.GetXenStoreItem("data/vif/" + device.Substring(vifpath.Length + 1) + "/name"); name.value = nic.Name; if (name.GetStatus() != ManagementStatus.NoError) { enablewritedevice = false; return; } } } } }
protected virtual void Finish() { if (advert != null) { if (advert != null) { try { advert.Remove(); } catch { }; } features.Remove(this); advert = null; } if (listener != null) { listener.Dispose(); listener = null; } }
void addHotFixInfoToStore() { uint index = 0; if (enablehotfixinfo) { foreach (ManagementObject mo in WmiBase.Singleton.Win32_QuickFixEngineering) { // Ignore Hotfixes where the id has been replaced by "File 1" // Because these hotfixes have been replaced string id = (string)mo["HotFixID"]; if (!id.Equals("File 1")) { XenStoreItem hotfix = wmisession.GetXenStoreItem("attr/os/hotfixes/" + index.ToString()); hotfix.value = id; if (hotfix.GetStatus() == ManagementStatus.AccessDenied) { enablehotfixinfo = false; } index++; } } } }
public FeatureTerminalServicesReset(IExceptionHandler exceptionhandler) : base("Terminal Services Reset", "", "data/ts", false, exceptionhandler) { datats = wmisession.GetXenStoreItem("data/ts"); onFeature(); }
public FeatureStaticIpSetting(IExceptionHandler exceptionhandler) : base("StaticIpSetting", "control/feature-static-ip-setting", "xenserver/device/vif", false, exceptionhandler) { IpSettings.load(); staticIpSetting = wmisession.GetXenStoreItem("xenserver/device/vif"); }
protected override void onFeature() { if (controlKey.Exists()) { try { foreach (string vif in staticIpSetting.children) { mac = wmisession.GetXenStoreItem(vif + "/static-ip-setting/mac"); ipenabled = wmisession.GetXenStoreItem(vif + "/static-ip-setting/enabled"); ipv6enabled = wmisession.GetXenStoreItem(vif + "/static-ip-setting/enabled6"); errorCode = wmisession.GetXenStoreItem(vif + "/static-ip-setting/error-code"); errorMsg = wmisession.GetXenStoreItem(vif + "/static-ip-setting/error-msg"); if (ipenabled.Exists() && ipenabled.value.Length != 0) { if (int.Parse(ipenabled.value) == 1) // assign static ip setting { address = wmisession.GetXenStoreItem(vif + "/static-ip-setting/address"); gateway = wmisession.GetXenStoreItem(vif + "/static-ip-setting/gateway"); SetStaticIpv4Setting(); wmisession.Log("Static ip setting is assigned."); } else // remove static ip setting { UnsetStaticIpv4Setting(); wmisession.Log("Static ip setting is unassigned."); } } if (ipenabled.Exists()) ipenabled.Remove(); if (ipv6enabled.Exists() && ipv6enabled.value.Length != 0) { if (int.Parse(ipv6enabled.value) == 1) // assign static ipv6 setting { address6 = wmisession.GetXenStoreItem(vif + "/static-ip-setting/address6"); gateway6 = wmisession.GetXenStoreItem(vif + "/static-ip-setting/gateway6"); SetStaticIpv6Setting(); wmisession.Log("Static ipv6 setting is assigned."); } else // remove static ipv6 setting { UnsetStaticIpv6Setting(); wmisession.Log("Static ipv6 setting is unassigned."); } } if (ipv6enabled.Exists()) ipv6enabled.Remove(); } } catch { }; // Ignore failure, if node does not exist } }
protected void addAdvert(string advertname) { advert = wmisession.GetXenStoreItem(advertname); features.Add(this); }
public XenAppSessionInfo() { wmisession = WmiBase.Singleton.GetXenStoreSession("XenAppSession Reporter"); xenAppSession = wmisession.GetXenStoreItemCached("data/xenapp_session_count"); }
void SetComputerName() { wmisession.Log("Set Computer Name Requested"); state.value = "InProgress"; String defaultname; bool res; try { defaultname = name.value; name.Remove(); } catch { try { wmisession.Log("Setting computer name to default"); XenStoreItem name = wmisession.GetXenStoreItem("name"); defaultname = name.value; } catch (Exception e) { wmisession.Log("Unable to read default name for domain from xenstore: " + e.ToString()); error.value = "Can't read default computer name"; state.value = "Failed"; return; } } if (defaultname.Equals("")) { wmisession.Log("Can't set to empty computer name"); error.value = "Computer name empty"; state.value = "Failed"; return; } if (defaultname.Length > Win32Impl.MAX_COMPUTERNAME_LENGTH) { warn.value = "Computer name exceeds MAX_COMPUTERNAME_LENGTH. The NetBIOS name will be truncated"; } try { wmisession.Log("Setting computer name to " + defaultname); Win32Impl.SetLastError(0); res = Win32Impl.SetComputerNameEx(Win32Impl.COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, defaultname); if (!res) { wmisession.Log("Setting computer name failed " + Marshal.GetLastWin32Error().ToString()); error.value = "Setting name failed (error code " + Marshal.GetLastWin32Error().ToString() + ")"; state.value = "Failed"; return; } wmisession.Log("Setting computer name succceded"); } catch (Exception e) { wmisession.Log("Exception setting computer name : " + e.ToString()); error.value = "Exception calling set computer name"; state.value = "Failed"; return; } try { wmisession.Log("Target hostname " + defaultname); wmisession.Log("Current hostname" + Win32Impl.GetComputerDnsHostname()); if (defaultname.Equals(Win32Impl.GetComputerDnsHostname())) { wmisession.Log("No need to reboot to change computer name, already " + defaultname); state.value = "NoChange"; return; } } catch { } state.value = "SucceededNeedsReboot"; }
public FeatureTerminalServices(IExceptionHandler exceptionhandler) : base("Terminal Services", "control/feature-ts", "control/ts", true, exceptionhandler) { datats = wmisession.GetXenStoreItem("data/ts"); }
protected override void onFeature() { if (controlKey.Exists()) { try { foreach (string vif in staticIpSetting.children) { mac = wmisession.GetXenStoreItem(vif + "/static-ip-setting/mac"); ipenabled = wmisession.GetXenStoreItem(vif + "/static-ip-setting/enabled"); ipv6enabled = wmisession.GetXenStoreItem(vif + "/static-ip-setting/enabled6"); errorCode = wmisession.GetXenStoreItem(vif + "/static-ip-setting/error-code"); errorMsg = wmisession.GetXenStoreItem(vif + "/static-ip-setting/error-msg"); if (ipenabled.Exists() && ipenabled.value.Length != 0) { if (int.Parse(ipenabled.value) == 1) // assign static ip setting { address = wmisession.GetXenStoreItem(vif + "/static-ip-setting/address"); gateway = wmisession.GetXenStoreItem(vif + "/static-ip-setting/gateway"); SetStaticIpv4Setting(); wmisession.Log("Static ip setting is assigned."); } else // remove static ip setting { UnsetStaticIpv4Setting(); wmisession.Log("Static ip setting is unassigned."); } } if (ipenabled.Exists()) { ipenabled.Remove(); } if (ipv6enabled.Exists() && ipv6enabled.value.Length != 0) { if (int.Parse(ipv6enabled.value) == 1) // assign static ipv6 setting { address6 = wmisession.GetXenStoreItem(vif + "/static-ip-setting/address6"); gateway6 = wmisession.GetXenStoreItem(vif + "/static-ip-setting/gateway6"); SetStaticIpv6Setting(); wmisession.Log("Static ipv6 setting is assigned."); } else // remove static ipv6 setting { UnsetStaticIpv6Setting(); wmisession.Log("Static ipv6 setting is unassigned."); } } if (ipv6enabled.Exists()) { ipv6enabled.Remove(); } } } catch { }; // Ignore failure, if node does not exist } }
public MemoryInfo() { wmisession = WmiBase.Singleton.GetXenStoreSession("Memory Reporter"); meminfoFree = wmisession.GetXenStoreItemCached("data/meminfo_free"); meminfoTotal = wmisession.GetXenStoreItemCached("data/meminfo_total"); }
public Feature(string name, string advertise, string control, bool controlmustexist, IExceptionHandler exceptionhandler) { this.exceptionhandler = exceptionhandler; this.name = name; wmisession = WmiBase.Singleton.GetXenStoreSession("Citrix Xen Service Feature : " + name); wmisession.Log("New Feature"); controlKey = wmisession.GetXenStoreItem(control); this.controlmustexist = controlmustexist; try { if (controlKey.value != "") { wmisession.Log("Control key "+control+":"+controlKey.value); } } catch {} enabled = true; listener = controlKey.Watch(new EventArrivedEventHandler(onFeatureWrapper)); if (!advertise.Equals("")) { advert = wmisession.GetXenStoreItem(advertise); features.Add(this); } Disposer.Add(this); }