Esempio n. 1
0
        /// <summary>
        /// Override method to customize how to report the NIC data
        /// </summary>
        /// <param name="device">The device needs to be reported</param>
        /// <param name="nic">nic object inside VM</param>
        override protected void writeDevice(string device, NetworkInterface nic)
        {
            if (null == device || null == nic)
            {
                return;                                // We trust xenstore, it is a SR-IOV device
            }
            string deviceId = getDeviceIndexFromIndexedDevicePath(device);
            string nameKey  = String.Format("{0}/{1}/name", attrPath, deviceId);
            string macKey   = String.Format("{0}/{1}/mac", attrPath, deviceId);

            // Update the xenstore info
            try
            {
                // Update name
                AXenStoreItem xenName = wmisession.GetXenStoreItem(nameKey);
                xenName.value = nic.Name;

                // Update mac
                AXenStoreItem xenMac  = wmisession.GetXenStoreItem(macKey);
                byte[]        byteMac = nic.GetPhysicalAddress().GetAddressBytes();
                xenMac.value = NicUtil.getMacStringFromByteArray(byteMac);

                // Update ipv4 info
                updateVFIpInfo(deviceId, System.Net.Sockets.AddressFamily.InterNetwork, nic);

                // Update the ipv6 info
                updateVFIpInfo(deviceId, System.Net.Sockets.AddressFamily.InterNetworkV6, nic);
            }
            catch (Exception e)
            {
                Debug.Print("updateVFXenstoreAttrInfo error: {0}", e);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Update all the devices info into xensore
        /// </summary>
        /// <param name="devices">The devices key from xenstore, representing devices from xenopsd, needs to be udpated</param>
        /// <param name="nics">the nic objects representing a NIC inside VM</param>
        virtual protected void updateNicAttr(string[] devices, NetworkInterface[] nics)
        {
            foreach (var device in devices)
            {
                AXenStoreItem macItem = wmisession.GetXenStoreItem(device + "/mac");
                if (!macItem.Exists() || "".Equals(macItem.value))
                {
                    Debug.Print("Warning: xenstored should provide mac address for this vf device");
                    Debug.Print("Warning: ignore device {0}", device);
                    continue;
                }

                string mac = macItem.value;

                NetworkInterface nic = findValidNic(mac, nics);
                if (null != nic)
                {
                    writeDevice(device, nic);
                }
                else
                {
                    Debug.Print("does not find nic for mac: " + mac);
                }
            }
        }
Esempio n. 3
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));
 }
Esempio n. 4
0
 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");
 }
Esempio n. 5
0
 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");
 }
Esempio n. 6
0
            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";
                        AXenStoreItem vdisnap     = wmisession.GetXenStoreItem(rootkeyname);
                        foreach (string entryKey in vdisnap.children)
                        {
                            AXenStoreItem src  = wmisession.GetXenStoreItem(entryKey);
                            AXenStoreItem 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);
            }
Esempio n. 7
0
 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");
 }
Esempio n. 8
0
        /// <summary>
        /// Write Device into xenstore, only update for the first time
        /// </summary>
        /// <param name="device">device key representing a device</param>
        /// <param name="nic">nic object inside VM</param>
        override protected void writeDevice(string device, NetworkInterface nic)
        {
            string        namePath = string.Format("{0}/{1}/name", attrPath, getDeviceIndexFromIndexedDevicePath(device));
            AXenStoreItem name     = wmisession.GetXenStoreItem(namePath);

            name.value = nic.Name;
            if (name.GetStatus() != ManagementStatus.NoError)
            {
                Debug.Print(string.Format("write to {0} error", namePath));
            }
        }
Esempio n. 9
0
 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();
 }
Esempio n. 10
0
        /// <summary>
        /// Update device ip address info into xenstore
        /// </summary>
        /// <param name="deviceId">current device id, specified by xenposd</param>
        /// <param name="addressFamily">System.Net.Sockets.AddressFamily.InterNetwork for ipv4, InterNetworkV6 for ipv6</param>
        /// <param name="nic">current nic info which will be updated into xenstore</param>
        private void updateVFIpInfo(string deviceId, System.Net.Sockets.AddressFamily addressFamily, NetworkInterface nic)
        {
            // Clean the item to avoid zombie record
            string ipKind = addressFamily == System.Net.Sockets.AddressFamily.InterNetwork ? "ipv4" : "ipv6";

            // Fresh the VF info into database
            int index = 0;

            foreach (var item in getAddrInfo(nic, addressFamily))
            {
                string        ipAddrKey  = String.Format("{0}/{1}/{2}/{3}", attrPath, deviceId, ipKind, index++);
                AXenStoreItem ipAddrItem = wmisession.GetXenStoreItem(ipAddrKey);
                ipAddrItem.value = item.ToString();
            }
        }
Esempio n. 11
0
        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");
            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();
            }
        }
Esempio n. 12
0
        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");
        }
Esempio n. 13
0
 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;
     }
 }
Esempio n. 14
0
        /// <summary>
        /// Constructor of the NetInfo class
        /// </summary>
        /// <param name="exceptionhandler">The exception handler, trigger when exception occurs</param>
        /// <param name="devicePath"> xenstore device path of NIC device</param>
        /// <param name="attrPath"> xenstore path NIC device data info report back to</param>
        /// <param name="session"> wmi session, mainly used to access xenstore</param>
        public NetInfo(IExceptionHandler exceptionhandler, string devicePath, string attrPath, AWmiSession session)
        {
            wmisession            = session;
            this.exceptionhandler = exceptionhandler;
            updating = new Object();

            this.devicePath = devicePath;
            this.attrPath   = attrPath;

            netDeviceItem = wmisession.GetXenStoreItem(devicePath);
            netAttrItem   = wmisession.GetXenStoreItem(attrPath);

            netDeviceItem.Watch(onXenstoreNetChanged);

            addrChangeHandler = new NetworkAddressChangedEventHandler(onVmNicAddrChange);
            NetworkChange.NetworkAddressChanged += addrChangeHandler;

            netStaticIpSetting = wmisession.GetXenStoreItem(STATIC_IP_FEATURE_MONITOR_KEY);
            netStaticIpSetting.Watch(onXenstoreStaticIpSettingChanged);

            // trigger the first update
            needsRefresh = true;
        }
Esempio n. 15
0
 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(""))
     {
         this.addAdvert(advertise);
     }
     Disposer.Add(this);
 }
Esempio n. 16
0
        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"))
                    {
                        AXenStoreItem hotfix = wmisession.GetXenStoreItem("attr/os/hotfixes/" + index.ToString());
                        hotfix.value = id;
                        if (hotfix.GetStatus() == ManagementStatus.AccessDenied)
                        {
                            enablehotfixinfo = false;
                        }
                        index++;
                    }
                }
            }
        }
Esempio n. 17
0
        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");
                    AXenStoreItem 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";
        }
Esempio n. 18
0
        protected override void onFeature()
        {
            if (controlKey.Exists())
            {
                try
                {
                    foreach (string nic in staticIpSetting.children)
                    {
                        mac         = wmisession.GetXenStoreItem(nic + "/static-ip-setting/mac");
                        ipenabled   = wmisession.GetXenStoreItem(nic + "/static-ip-setting/enabled");
                        ipv6enabled = wmisession.GetXenStoreItem(nic + "/static-ip-setting/enabled6");
                        errorCode   = wmisession.GetXenStoreItem(nic + "/static-ip-setting/error-code");
                        errorMsg    = wmisession.GetXenStoreItem(nic + "/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(nic + "/static-ip-setting/address");
                                gateway = wmisession.GetXenStoreItem(nic + "/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(nic + "/static-ip-setting/address6");
                                gateway6 = wmisession.GetXenStoreItem(nic + "/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
            }
        }
Esempio n. 19
0
 /// <summary>
 /// PV NIC constructor
 /// </summary>
 /// <param name="exceptionhandler"></param>
 /// <param name="DEVICE_PATH"> xenstore device path of pv device</param>
 /// <param name="ATTR_PATH"> xenstore path pv device data info report back to</param>
 /// <param name="SESSION_NAME"> wmi session name for pv device</param>
 public VifInfo(IExceptionHandler exceptionhandler)
     : base(exceptionhandler, DEVICE_PATH, ATTR_PATH, SESSION_NAME)
 {
     numvif = wmisession.GetXenStoreItem("data/num_vif");
 }
Esempio n. 20
0
 public FeatureTerminalServices(IExceptionHandler exceptionhandler)
     : base("Terminal Services", "control/feature-ts", "control/ts", true, exceptionhandler)
 {
     datats = wmisession.GetXenStoreItem("data/ts");
 }
Esempio n. 21
0
 protected void addAdvert(string advertname)
 {
     advert = wmisession.GetXenStoreItem(advertname);
     features.Add(this);
 }
Esempio n. 22
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="name">Name of the feature </param>
 /// <param name="advertise">Advertise key to xapi</param>
 /// <param name="controlKey">Watch the control key and perform feature when update</param>
 /// <param name="controlmustexist"></param>
 /// <param name="exceptionhandler"></param>
 public FeatureStaticIpSetting(string name, string advertise, string controlKey, bool controlmustexist, IExceptionHandler exceptionhandler)
     : base(name, advertise, controlKey, controlmustexist, exceptionhandler)
 {
     IpSettings.load();
     staticIpSetting = wmisession.GetXenStoreItem(controlKey);
 }