def wifi_remove(path): service = connman.get_service_interface(path) try: service.Remove() except dbus.DBusException, e: print('DBusException removing') connected = False
def wifi_connect(path, password=None, ssid=None): connected = False if password or ssid: print('Starting Wireless Agent') keyfile = open('/tmp/preseed_data', 'w') if password: print('Setting password') keyfile.write(password) keyfile.write('\n') if ssid: print('Setting password') keyfile.write(ssid) keyfile.close() process = subprocess.Popen( [sys.executable, WIRELESS_AGENT, 'fromfile']) count = 0 while not os.path.exists('/tmp/agent_started'): count += 1 time.sleep(1) if count > 10: print('Agent had not started after 10 seconds') break if os.path.exists('/tmp/agent_started'): os.remove('/tmp/agent_started') print('Attempting connection to ' + path) service = connman.get_service_interface(path) try: service.Connect(timeout=15000) connected = True except dbus.DBusException, e: print('DBusException connecting ' + str(e)) connected = False
def wifi_disconnect(path): service = connman.get_service_interface(path) try: service.Disconnect() except dbus.DBusException, e: print('DBusException disconnecting') connected = False
def wifi_disconnect(path): service = connman.get_service_interface(path) try: service.Disconnect() except dbus.DBusException, e: print ('DBusException disconnecting') connected = False
def apply_network_changes(settings_dict): if settings_dict['Method'] in ['manual', 'dhcp']: # non NFS setup path = settings_dict['path'] service = connman.get_service_interface(path) ipv4_configuration = { 'Method': make_variant(settings_dict['Method']), 'Address': make_variant(settings_dict['Address']), 'Netmask': make_variant(settings_dict['Netmask']) } if 'Gateway' in settings_dict: ipv4_configuration['Gateway'] = make_variant( settings_dict['Gateway']) service.SetProperty('IPv4.Configuration', ipv4_configuration) time.sleep(2) dns = [] if 'DNS_1' in settings_dict: dns.append(settings_dict['DNS_1']) if 'DNS_2' in settings_dict: dns.append(settings_dict['DNS_2']) # duplicate SetProperty message works around connman dns forwarder bug service.SetProperty('Nameservers.Configuration', dbus.Array(dns, signature=dbus.Signature('s'))) service.SetProperty('Nameservers.Configuration', dbus.Array(dns, signature=dbus.Signature('s'))) elif settings_dict['Method'].startswith('nfs_'): ip_value = None if settings_dict['Method'] == 'nfs_dhcp': ip_value = 'dhcp' if settings_dict['Method'] == 'nfs_manual': ip_value = create_cmdline_nfs_manual_string(settings_dict) update_cmdline_file(UPDATE_NETWORK_DETAILS_FILE, 'ip', ip_value)
def wifi_remove(path): service = connman.get_service_interface(path) try: service.Remove() except dbus.DBusException, e: print ('DBusException removing') connected = False
def apply_network_changes(settings_dict): if settings_dict['Method'] in ['manual', 'dhcp']: # non NFS setup path = settings_dict['path'] service = connman.get_service_interface(path) ipv4_configuration = {'Method': make_variant(settings_dict['Method']), 'Address': make_variant(settings_dict['Address']), 'Netmask': make_variant(settings_dict['Netmask'])} if 'Gateway' in settings_dict: ipv4_configuration['Gateway'] = make_variant(settings_dict['Gateway']) service.SetProperty('IPv4.Configuration', ipv4_configuration) time.sleep(2) dns = [] if 'DNS_1' in settings_dict: dns.append(settings_dict['DNS_1']) if 'DNS_2' in settings_dict: dns.append(settings_dict['DNS_2']) # duplicate SetProperty message works around connman dns forwarder bug service.SetProperty('Nameservers.Configuration', dbus.Array(dns, signature=dbus.Signature('s'))) service.SetProperty('Nameservers.Configuration', dbus.Array(dns, signature=dbus.Signature('s'))) elif settings_dict['Method'].startswith('nfs_'): ip_value = None if settings_dict['Method'] == 'nfs_dhcp': ip_value = 'dhcp' if settings_dict['Method'] == 'nfs_manual': ip_value = create_cmdline_nfs_manual_string(settings_dict) update_cmdline_file(UPDATE_NETWORK_DETAILS_FILE, 'ip', ip_value)
def wifi_connect(path, password=None, ssid=None): connected = False if password or ssid: print('Starting Wireless Agent') keyfile = open('/tmp/preseed_data', 'w') if password: print('Setting password') keyfile.write(password) keyfile.write('\n') if ssid: print('Setting password') keyfile.write(ssid) keyfile.close() process = subprocess.Popen([sys.executable, WIRELESS_AGENT, 'fromfile']) count = 0 while not os.path.exists('/tmp/agent_started'): count += 1 time.sleep(1) if count > 10: print('Agent had not started after 10 seconds') break if os.path.exists('/tmp/agent_started'): os.remove('/tmp/agent_started') print ('Attempting connection to ' + path ) service = connman.get_service_interface(path) try: service.Connect(timeout=15000) connected = True except dbus.DBusException, e: print ('DBusException connecting ' + str(e)) connected = False
def wifi_connect(path, password=None, ssid=None): agentNeeded = False if password or ssid: agentNeeded = True print('Starting Wireless Agent') keyfile = open('/tmp/preseed_data', 'w') if password: print('Setting password') keyfile.write(password) keyfile.write('\n') if ssid: print('Setting SSID') keyfile.write(ssid) keyfile.close() process = subprocess.Popen([sys.executable, WIRELESS_AGENT, 'fromfile']) print ('Attempting connection to ' + path ) service = connman.get_service_interface(path) connected = 1 connectionAttempts = 15 while connected != 0 and connected < (connectionAttempts + 1): try: service.Connect(timeout=15000) connected = 0 except dbus.DBusException, e: if len(e.args) > 0 and e.args[0] == 'Not registered' and agentNeeded: connected += 1 time.sleep(1) print 'Connection agent not started yet, waiting a second' else: # another type of exception jump out of the loop connected = (connectionAttempts+1) print 'DBusException Raised: ' + str(e)
def wifi_connect(path, password=None, ssid=None, script_base_path = None): agentNeeded = False if password or ssid: agentNeeded = True print('Starting Wireless Agent') keyfile = open('/tmp/preseed_data', 'w') if password: print('Setting password') keyfile.write(password) keyfile.write('\n') if ssid: print('Setting SSID') keyfile.write(ssid) keyfile.close() agent_script = script_base_path + WIRELESS_AGENT process = subprocess.Popen([sys.executable, agent_script, 'fromfile']) print ('Attempting connection to ' + path ) service = connman.get_service_interface(path) connected = 1 connectionAttempts = 20 while connected != 0 and connected < (connectionAttempts + 1): try: service.Connect(timeout=15000) connected = 0 except dbus.DBusException, e: if len(e.args) > 0 and e.args[0] == 'Not registered' and agentNeeded: connected += 1 time.sleep(1) print 'Connection agent not started yet, waiting a second' else: # another type of exception jump out of the loop connected = (connectionAttempts+1) print 'DBusException Raised: ' + str(e)
def wifi_connect(path, password=None, ssid=None, script_base_path=None): agentNeeded = False if password or ssid: agentNeeded = True print ("Starting Wireless Agent") keyfile = open("/tmp/preseed_data", "w") if password: print ("Setting password") keyfile.write(password) keyfile.write("\n") if ssid: print ("Setting SSID") keyfile.write(ssid) keyfile.close() agent_script = script_base_path + WIRELESS_AGENT process = subprocess.Popen([sys.executable, agent_script, "fromfile"]) print ("Attempting connection to " + path) service = connman.get_service_interface(path) connected = 1 connectionAttempts = 20 while connected != 0 and connected < (connectionAttempts + 1): try: service.Connect(timeout=15000) connected = 0 except dbus.DBusException, e: if len(e.args) > 0 and e.args[0] == "Not registered" and agentNeeded: connected += 1 time.sleep(1) print "Connection agent not started yet, waiting a second" else: # another type of exception jump out of the loop connected = connectionAttempts + 1 print "DBusException Raised: " + str(e)
def apply_network_changes(settings_dict, internet_protocol): if settings_dict[internet_protocol]["Method"] in ["manual", "dhcp"]: # non NFS setup path = settings_dict["path"] service = connman.get_service_interface(path) ipv4_configuration = { "Method": make_variant(settings_dict[internet_protocol]["Method"]), "Address": make_variant(settings_dict[internet_protocol]["Address"]), "Netmask": make_variant(settings_dict[internet_protocol]["Netmask"]), } if settings_dict[internet_protocol]["Gateway"]: ipv4_configuration["Gateway"] = make_variant(settings_dict[internet_protocol]["Gateway"]) service.SetProperty("IPv4.Configuration", ipv4_configuration) time.sleep(2) if settings_dict[internet_protocol]["Method"] == "dhcp": dns = ["", ""] else: namesevers = settings_dict["Nameservers"] dns = [] if "DNS_1" in namesevers and namesevers["DNS_1"]: dns.append(namesevers["DNS_1"]) if "DNS_2" in namesevers and namesevers["DNS_2"]: dns.append(namesevers["DNS_2"]) # duplicate SetProperty message works around connman dns forwarder bug service.SetProperty("Nameservers.Configuration", dbus.Array(dns, signature=dbus.Signature("s"))) service.SetProperty("Nameservers.Configuration", dbus.Array(dns, signature=dbus.Signature("s"))) elif settings_dict[internet_protocol]["Method"].startswith("nfs_"): ip_value = None if settings_dict[internet_protocol]["Method"] == "nfs_dhcp": ip_value = "dhcp" if settings_dict[internet_protocol]["Method"] == "nfs_manual": ip_value = create_cmdline_nfs_manual_string(settings_dict, internet_protocol) update_cmdline_file(UPDATE_NETWORK_DETAILS_FILE, "ip", ip_value)
def wifi_connect(path, password=None): connected = False if password: keyfile = open("/tmp/key", "w") keyfile.write(password) keyfile.close() process = subprocess.Popen([sys.executable, WIRELESS_AGENT, 'keyfile']) time.sleep(2) print('Attempting connection to ' + path) service = connman.get_service_interface(path) try: service.Connect(timeout=15000) connected = True except dbus.DBusException, e: print('DBusException connecting') connected = False
def wifi_connect(path, password=None): connected = False if password: keyfile = open("/tmp/key", "w") keyfile.write(password) keyfile.close() process = subprocess.Popen([sys.executable, WIRELESS_AGENT, 'keyfile']) time.sleep(2) print ('Attempting connection to ' + path ) service = connman.get_service_interface(path) try: service.Connect(timeout=15000) connected = True except dbus.DBusException, e: print ('DBusException connecting') connected = False