Update test scripts for IPv6 support
[platform/upstream/connman.git] / test / set-address
1 #!/usr/bin/python
2
3 import sys
4 import dbus
5
6 if (len(sys.argv) < 3):
7         print "Usage: %s <address> <netmask | prefix length> <gateway> [version]" % (sys.argv[0])
8         sys.exit(1)
9
10 bus = dbus.SystemBus()
11
12 manager = dbus.Interface(bus.get_object('org.moblin.connman', "/"),
13                                         'org.moblin.connman.Manager')
14
15 properties = manager.GetProperties()
16
17 for path in properties["Services"]:
18         service = dbus.Interface(bus.get_object('org.moblin.connman', path),
19                                                 'org.moblin.connman.Service')
20
21         properties = service.GetProperties()
22
23
24
25         if (len(sys.argv) == 5 and sys.argv[4] == "ipv6"):
26                 ipv = 6
27         else:
28                 ipv = 4
29
30         print "Setting IPv%d address %s for %s" % (ipv, sys.argv[1], path)
31
32         if (ipv == 4):
33                 service.SetProperty("IPv4.Configuration",
34                                         { "Method": "manual",
35                                                 "Address": sys.argv[1],
36                                                 "Netmask": sys.argv[2],
37                                                         "Gateway": sys.argv[3]})
38         else:
39                 service.SetProperty("IPv6.Configuration",
40                                         { "Method": "manual",
41                                                 "Address": sys.argv[1],
42                                                 "PrefixLength": sys.argv[2],
43                                                         "Gateway": sys.argv[3]})
44
45         print