private void UnsetStaticIpv6Setting() { string macaddr = mac.value; resetError(); foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration) { if (!(bool)nic["ipEnabled"]) { continue; } if (nic["macAddress"].ToString().ToUpper() != macaddr.ToUpper()) { continue; } IpSettingItem settings = new IpSettingItem(nic["macAddress"].ToString(), "IPV6", "", "", "", ""); if (IpSettings.getIPseting(nic["macAddress"].ToString(), "IPV6", ref settings) == false) { return; } try{ string argument = "interface ipv6 reset"; netshInvoke(argument); IpSettings.removeIPseting(nic["macAddress"].ToString(), "IPV6"); } catch (Exception e) { errorCode.value = "1"; errorMsg.value = e.ToString(); wmisession.Log("Exception " + e.ToString()); return; } } }
private void UnsetStaticIpv4Setting() { string macaddr = mac.value; resetError(); foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration) { if (!(bool)nic["ipEnabled"]) { continue; } if (!NicUtil.macsMatch(macaddr, nic["macAddress"].ToString())) { continue; } IpSettingItem settings = new IpSettingItem(nic["macAddress"].ToString(), "IPV4", "", "", "", ""); if (IpSettings.getIPseting(nic["macAddress"].ToString(), "IPV4", ref settings) == false) { return; } try{ setIpv4Network(nic, "EnableDHCP", null, "set back to dhcp"); IpSettings.removeIPseting(nic["macAddress"].ToString(), "IPV4"); } catch (Exception e) { errorCode.value = "1"; errorMsg.value = e.ToString(); wmisession.Log("Exception " + e.ToString()); return; } } }
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 (nic["macAddress"].ToString().ToUpper() != macaddr.ToUpper()) { 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; } } }
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 (nic["macAddress"].ToString().ToUpper() != macaddr.ToUpper()) { 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; } } }
public FeatureStaticIpSetting(IExceptionHandler exceptionhandler) : base("StaticIpSetting", "control/feature-static-ip-setting", "xenserver/device/vif", false, exceptionhandler) { IpSettings.load(); staticIpSetting = wmisession.GetXenStoreItem("xenserver/device/vif"); }
/// <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); }