Exemple #1
0
 override protected void onFeature()
 {
     if (controlKey.Exists() && !state.Exists())
     {
         try
         {
             if (error.Exists())
             {
                 error.Remove();
             }
             if (!domainName.Exists())
             {
                 error.value = "domainname must be specified";
                 throw new Exception("domainname must be specified");
             }
             if (!userName.Exists())
             {
                 error.value = "username must be specified";
                 throw new Exception("username must be specified");
             }
             if (!password.Exists())
             {
                 error.value = "password must be specified";
                 throw new Exception("password must be specified");
             }
             if (controlKey.value.Equals("joindomain"))
             {
                 JoinDomain();
             }
             else if (controlKey.value.Equals("unjoindomain"))
             {
                 UnjoinDomain();
             }
             // If completed, remove the arguments, to avoid
             // them hanging around in xenstore.
             domainName.Remove();
             userName.Remove();
             password.Remove();
         }
         catch (Exception e)
         {
             if (!error.Exists())
             {
                 error.value = e.ToString();
             }
             state.value = "Failed";
         }
         finally
         {
             // We always want to remove the controlKey, so that
             // it can be set again
             controlKey.Remove();
         }
     }
 }
Exemple #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);
                }
            }
        }
            void onServerClipboard()
            {
                string newclipboard = null;

                try
                {
                    if (xsSetClipboard.Exists())
                    {
                        newclipboard = xsSetClipboard.value;
                        Debug.Print("get new clipboard " + newclipboard);
                        xsSetClipboard.Remove();
                    }
                    else
                    {
                        return;
                    }
                }
                catch
                {
                    return;
                }

                if (newclipboard == null)
                {
                    currentclipboard = totalclipboard;
                    setClientClipboard(totalclipboard);
                    totalclipboard = "";
                }
                else
                {
                    totalclipboard += newclipboard;
                }
            }
Exemple #4
0
 void onFeatureWrapper(object nothing, EventArrivedEventArgs args)
 {
     // If this session is already in a transaction we must
     // wait for it to finish, otherwise we may not correctly
     // read the controlKey
     wmisession.AwaitTransactionCompletion();
     try
     {
         if (enabled && ((!controlmustexist) || controlKey.Exists()))
         {
             onFeature();
         }
     }
     catch (System.Management.ManagementException e) {
         enabled = false;
         if (e.ErrorCode == ManagementStatus.AccessDenied)
         {
             wmisession.Log("Feature " + name + " disabled");
         }
         else
         {
             throw e;
         }
     }
     catch (Exception e)
     {
         enabled = false; //Don't want to call the feature if it causes an exception
         exceptionhandler.HandleException("Feature " + name, e);
     }
 }
Exemple #5
0
        override protected void onFeature()
        {
            if (controlKey.Exists() && !state.Exists())
            {
                try {
                    if (error.Exists())
                    {
                        error.Remove();
                    }
                    if (warn.Exists())
                    {
                        warn.Remove();
                    }

                    if (state.Exists())
                    {
                        error.value = "Setting name already in progress";
                        state.value = "Failed";
                        return;
                    }
                    if (controlKey.value.Equals("set"))
                    {
                        SetComputerName();
                    }
                    else
                    {
                        error.value = "Unknown action : " + controlKey.value;
                        state.value = "Failed";
                    }
                }
                catch (Exception e) {
                    if (!error.Exists())
                    {
                        error.value = e.ToString();
                    }
                    state.value = "Failed";
                }
                finally {
                    // We always want to remove the controlKey, so that
                    // it can be set again
                    controlKey.Remove();
                }
            }
        }
Exemple #6
0
 protected override void onFeature()
 {
     if (!datats.Exists())
     {
         bool   enabled    = query();
         string newtsvalue = (enabled ? "1" : "0");
         wmisession.Log("Setting data/ts to " + newtsvalue);
         datats.value = newtsvalue;
     }
 }
Exemple #7
0
        void addLicenseInfoToStore()
        {
            try
            {
                if (oslicense.Exists())
                {
                    oslicense.Remove();
                }
                switch (Win32Impl.IsGenuineWindows())
                {
                case Win32Impl.SL_GENUINE_STATE.SL_GEN_STATE_INVALID_LICENSE:
                    oslicense.value = licenseinvalid;
                    break;

                case Win32Impl.SL_GENUINE_STATE.SL_GEN_STATE_IS_GENUINE:
                    oslicense.value = licensegenuine;
                    break;

                case Win32Impl.SL_GENUINE_STATE.SL_GEN_STATE_TAMPERED:
                    oslicense.value = licensetampered;
                    break;

                default:
                    break;
                }
            }
            catch { //Do nothing if IsGenuineWindows doesn't exist
            };
            try
            {
                if (osvirtualxp.Exists())
                {
                    osvirtualxp.Remove();
                }
                if (Win32Impl.GetWindowsInformation("VirtualXP-licensing-Enabled") != 0)
                {
                    osvirtualxp.value = "1";
                }
                else
                {
                    osvirtualxp.value = "0";
                }
            }
            catch (Exception e)
            {
                WmiBase.Singleton.DebugMsg("GetWindowsInformation failed: \n" + e.ToString());
            }
        }
            void onClientClipboard()
            {
                if (xsReportClipboard.Exists())
                {
                    string newclipboard = xsReportClipboard.value;
                }
                else
                {
                    // There is nothing set
                    if (totalclientclipboard != null)
                    {
                        string tempclip;
                        if (totalclientclipboard.Length > 1024)
                        {
                            tempclip             = totalclientclipboard.Substring(0, 1024);
                            totalclientclipboard = totalclientclipboard.Substring(1024, totalclientclipboard.Length - 1024);
                        }
                        else
                        {
                            tempclip             = totalclientclipboard;
                            totalclientclipboard = "";
                        }

                        xsReportClipboard.value = tempclip;
                        if (tempclip.Equals(""))
                        {
                            if (currentclipboardchanged)
                            {
                                currentclipboardchanged = false;
                                totalclientclipboard    = currentclipboard;
                            }
                            else
                            {
                                totalclientclipboard = null;
                            }
                        }
                    }
                }
            }
Exemple #9
0
        void snapshotThreadHandler()
        {
            try
            {
                WmiBase.Singleton.DebugMsg("SnapshotThread");


                if (!typeKey.Exists())
                {
                    type = VssSnapshot.Type.VM;
                }
                else
                {
                    switch (typeKey.value)
                    {
                    case "volume":
                        type = VssSnapshot.Type.VOLUME;
                        break;

                    case "vm":
                    default:
                        type = VssSnapshot.Type.VM;
                        break;
                    }
                }

                List <String> volumeNames;

                if (type == VssSnapshot.Type.VM)
                {
                    volumeNames = ListXenVolumes();
                }
                else
                {
                    volumeNames = ListXenStoreVolumes();
                }

                using (VssSnapshot vss = new VssSnapshot(type, volumeNames))
                {
                    Debug.Print("Create snapshot");

                    vss.CreateSnapshotSet();

                    Debug.Print("Created snapshot");
                    statusKey.value = "snapshot-created";
                }
            }
            catch (VssSnapshotException vsse)
            {
                Debug.Print(vsse.ToString());
                try {
                    wmisession.GetXenStoreItem("control/snapshot/error/message").value = GetHresult(vsse.code);
                    wmisession.GetXenStoreItem("control/snapshot/error/code").value    = vsse.code.ToString();
                    wmisession.GetXenStoreItem("control/snapshot/error").value         = vsse.state;
                    statusKey.value = "snapshot-error";
                }
                catch {}
            }
            catch (Exception e)
            {
                Debug.Print(e.ToString());
                try {
                    wmisession.GetXenStoreItem("control/snapshot/error").value = "Unknown Error";
                    statusKey.value = "snapshot-error";
                }
                catch {}
            }

            Debug.Print("Snapshot done");
        }
Exemple #10
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
            }
        }
Exemple #11
0
        private void SetStaticIpv6Setting()
        {
            string macaddr = mac.value;

            resetError();

            if ((address6.Exists() && address6.value.Length != 0) || (gateway6.Exists() && gateway6.value.Length != 0))
            {
                bool FoundDevice = false;
                foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration)
                {
                    if (!(bool)nic["ipEnabled"])
                    {
                        continue;
                    }

                    if (!NicUtil.macsMatch(macaddr, nic["macAddress"].ToString()))
                    {
                        continue;
                    }

                    FoundDevice = true;

                    IpSettings.addIpSeting(nic["macAddress"].ToString(), nic["DHCPEnabled"].ToString(), "IPV6", "", "", "");

                    try{
                        if (address6.Exists() && address6.value.Length != 0)
                        {
                            string argument = "interface ipv6 set address {0} {1}";
                            argument = string.Format(argument, nic["interfaceIndex"], address6.value);

                            if (netshInvoke(argument) != 0)
                            {
                                return;
                            }
                        }

                        if (gateway6.Exists() && gateway6.value.Length != 0)
                        {
                            string argument = "interface ipv6 add route ::/0 {0} {1}";
                            argument = string.Format(argument, nic["interfaceIndex"], gateway6.value);

                            if (netshInvoke(argument) != 0)
                            {
                                resetError();
                                argument = "interface ipv6 set route ::/0 {0} {1}";
                                argument = string.Format(argument, nic["interfaceIndex"], gateway6.value);

                                if (netshInvoke(argument) != 0)
                                {
                                    return;
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        errorCode.value = "1";
                        errorMsg.value  = e.ToString();

                        wmisession.Log("Exception " + e.ToString());
                        return;
                    }
                }
                if (!FoundDevice)
                {
                    errorCode.value = "101";
                    errorMsg.value  = "Device not ready to use or ipEnabled not been set";
                    wmisession.Log("Device not ready to use or ipEnabled not been set");
                    return;
                }
            }
        }
Exemple #12
0
        private void SetStaticIpv4Setting()
        {
            string macaddr = mac.value;

            resetError();

            if ((address.Exists() && address.value.Length != 0) || (gateway.Exists() && gateway.value.Length != 0))
            {
                bool FoundDevice = false;
                foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration)
                {
                    if (!(bool)nic["ipEnabled"])
                    {
                        continue;
                    }

                    if (!NicUtil.macsMatch(macaddr, nic["macAddress"].ToString()))
                    {
                        continue;
                    }

                    FoundDevice = true;
                    IpSettings.addIpSeting(nic["macAddress"].ToString(), nic["DHCPEnabled"].ToString(), "IPV4", "", "", "");

                    try{
                        if (address.Exists() && address.value.Length != 0)
                        {
                            string ipv4, netmask;
                            convertIpv4Mask(address.value, out ipv4, out netmask);

                            ManagementBaseObject objNewIP = nic.GetMethodParameters("EnableStatic");
                            objNewIP["IPAddress"]  = new string[] { ipv4 };
                            objNewIP["SubnetMask"] = new string[] { netmask };

                            if (setIpv4Network(nic, "EnableStatic", objNewIP, "ipv4 address setting") != 0)
                            {
                                return;
                            }
                        }

                        if (gateway.Exists() && gateway.value.Length != 0)
                        {
                            ManagementBaseObject objNewGate = nic.GetMethodParameters("SetGateways");
                            objNewGate["DefaultIPGateway"] = new string[] { gateway.value };

                            if (setIpv4Network(nic, "SetGateways", objNewGate, "ipv4 gateway setting") != 0)
                            {
                                return;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        errorCode.value = "1";
                        errorMsg.value  = e.ToString();

                        wmisession.Log("Exception " + e.ToString());
                        return;
                    }
                }

                if (!FoundDevice)
                {
                    errorCode.value = "101";
                    errorMsg.value  = "Device not ready to use or ipEnabled not been set";
                    wmisession.Log("Device not ready to use or ipEnabled not been set");
                    return;
                }
            }
        }