service: Simplify nameserver route adding and removing
[framework/connectivity/connman.git] / test / set-ipv6-method
1 #!/usr/bin/python
2
3 import sys
4 import dbus
5
6 def make_variant(string):
7         return dbus.String(string, variant_level=1)
8
9 def print_usage():
10         print "Usage: %s <service> off|manual|auto [<address> [prefixlen] [gateway]] [<privacy>]" % (sys.argv[0])
11
12 if (len(sys.argv) < 3):
13         print_usage()
14         sys.exit(1)
15
16 bus = dbus.SystemBus()
17 path = "/net/connman/service/" + sys.argv[1]
18 service = dbus.Interface(bus.get_object('net.connman', path),
19                                         'net.connman.Service')
20
21 properties = service.GetProperties()
22
23 print "Setting method %s for %s" % (sys.argv[2], sys.argv[1])
24
25 ipv6_configuration = { "Method": make_variant(sys.argv[2])}
26 if sys.argv[2] == "auto":
27         if (len(sys.argv) > 3):
28                 ipv6_configuration["Privacy"] = make_variant(sys.argv[3])
29 else:
30         if (len(sys.argv) > 3):
31                 ipv6_configuration["Address"] = make_variant(sys.argv[3])
32         if (len(sys.argv) > 4):
33                 ipv6_configuration["PrefixLength"] = make_variant(sys.argv[4])
34         if (len(sys.argv) > 5):
35                 ipv6_configuration["Gateway"] = make_variant(sys.argv[5])
36
37 service.SetProperty("IPv6.Configuration", ipv6_configuration)
38 print "New IPv6.Configuration: ", ipv6_configuration
39
40 print