client: Fix minor issues in D-Bus path name checking
[platform/upstream/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 make_byte_variant(string):
10     return dbus.Byte(int(string), variant_level=1)
11
12 def print_usage():
13         print "Usage: %s <service> off|manual|auto [<address> [prefixlen] [gateway]] [<privacy>]" % (sys.argv[0])
14
15 if (len(sys.argv) < 3):
16         print_usage()
17         sys.exit(1)
18
19 bus = dbus.SystemBus()
20 path = "/net/connman/service/" + sys.argv[1]
21 service = dbus.Interface(bus.get_object('net.connman', path),
22                                         'net.connman.Service')
23
24 properties = service.GetProperties()
25
26 print "Setting method %s for %s" % (sys.argv[2], sys.argv[1])
27
28 ipv6_configuration = { "Method": make_variant(sys.argv[2])}
29 if sys.argv[2] == "auto":
30         if (len(sys.argv) > 3):
31                 ipv6_configuration["Privacy"] = make_variant(sys.argv[3])
32 else:
33         if (len(sys.argv) > 3):
34                 ipv6_configuration["Address"] = make_variant(sys.argv[3])
35         if (len(sys.argv) > 4):
36                 ipv6_configuration["PrefixLength"] = make_byte_variant(sys.argv[4])
37         if (len(sys.argv) > 5):
38                 ipv6_configuration["Gateway"] = make_variant(sys.argv[5])
39
40 service.SetProperty("IPv6.Configuration", ipv6_configuration)
41 print "New IPv6.Configuration: ", ipv6_configuration
42
43 print