Imported Upstream connman version 1.38
[platform/upstream/connman.git] / test / set-ipv4-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|dhcp|manual <address> [netmask] [gateway]]" % (sys.argv[0]))
11
12
13 if (len(sys.argv) < 3):
14         print_usage()
15         sys.exit(1)
16
17 bus = dbus.SystemBus()
18 path = "/net/connman/service/" + sys.argv[1]
19 service = dbus.Interface(bus.get_object('net.connman', path),
20                                         'net.connman.Service')
21
22 properties = service.GetProperties()
23
24 print("Setting method %s for %s" % (sys.argv[2], sys.argv[1]))
25
26 ipv4_configuration = { "Method": make_variant(sys.argv[2]) }
27 if (len(sys.argv) > 3):
28         ipv4_configuration["Address"] = make_variant(sys.argv[3])
29 if (len(sys.argv) > 4):
30         ipv4_configuration["Netmask"] = make_variant(sys.argv[4])
31 if (len(sys.argv) > 5):
32         ipv4_configuration["Gateway"] = make_variant(sys.argv[5])
33
34 service.SetProperty("IPv4.Configuration", ipv4_configuration)
35 print("New IPv4.Configuration: ", ipv4_configuration)
36
37 print()