def set_unmanaged_by_network_manager(cls, interface): Logger.debug( "Adding interface \"%s-%s\" as an unmanaged interface to network manager", interface, cls.get_mac(interface)) with open(constants.PATH_CONF_NETWORK_MANAGER, "r") as conf_read: conf = conf_read.read().splitlines() added = False entry = cls.get_device_unmanaged_entry(interface) # Add Entry for line in range(0, len(conf)): # Add keyfile plugin if it's not enabled if conf[line].startswith( "plugins=") and "keyfile" not in conf[line]: conf[line] += ",keyfile" # Add unmanaged device if conf[line].startswith( "unmanaged-devices=") and entry not in conf[line]: conf[line] += ";" + entry added = True # Add the initial unmanaged entry if it was not present if not added: conf.append("[keyfile]") conf.append("unmanaged-devices=" + entry) # Write with open(constants.PATH_CONF_NETWORK_MANAGER, "w") as conf_write: for line in conf: conf_write.write(line + "\n") # Deprecating init.d service calls and using Systemd ProcessUtil.call(["systemctl", "stop", "NetworkManager"]) ProcessUtil.call(["systemctl", "restart", "wpa_supplicant"]) ProcessUtil.call(["systemctl", "start", "NetworkManager"])
def is_managed_by_network_manager(cls, interface): if not os.path.exists(constants.PATH_CONF_NETWORK_MANAGER): Logger.debug("Network manager config not found.") return False conf = open(constants.PATH_CONF_NETWORK_MANAGER) conf_data = conf.readlines() conf.close() managed = False for line in conf_data: if line.startswith("unmanaged-devices=") and "mac:" + cls.get_mac( interface) not in line: managed = True # Ensure configs with duplicates raise an unmanaged prompt if "unmanaged-devices=" not in " ".join(conf_data): managed = True Logger.debug("Interface \"%s\" managed by network manager: %s", interface, managed) return managed
def __init__(self, in_path): pre = "resources/" Logger.debug("Loading resource \"%s\"", join(pre, in_path)) current_dir = os.path.dirname(__file__).split(os.sep) # Check local files first file_path = "/" if len(current_dir) >= 3: for path in range(0, len(current_dir) - 3): file_path = join(file_path, current_dir[path]) file_path = join(file_path, pre, in_path) if os.path.exists(file_path): try: with open(file_path) as f: self.resource = f.read() except UnicodeDecodeError: Logger.debug("Opening resource as binary.") with open(file_path, "rb") as f: self.resource = f.read() Logger.extra("Found resource in local resource directory.") return # Check /usr/local - pip installs to here file_path = "/usr/local/resources/" + in_path if os.path.exists(file_path): try: with open(file_path) as f: self.resource = f.read() except UnicodeDecodeError: Logger.debug("Opening resource as binary.") with open(file_path, "rb") as f: self.resource = f.read() Logger.extra( "Found resource in /usr/local/ resource directory.") return # Attempt to get from package - setup.py installs here try: self.resource = pkg_resources.resource_string( pkg_resources.Requirement.parse("drcsim"), join(pre, in_path)) Logger.extra("Found resource in package.") except FileNotFoundError: Logger.throw("Could not find resource: %s" % join(pre, in_path)) sys.exit()