#!/usr/bin/python

import sys
import dbus

def print_usage():
	print "Usage: %s <service> off|manual|auto [<address> [prefixlen] [gateway]] [<privacy>]" % (sys.argv[0])

if (len(sys.argv) < 3):
	print_usage()
	sys.exit(1)

bus = dbus.SystemBus()
path = "/net/connman/service/" + sys.argv[1]
service = dbus.Interface(bus.get_object('net.connman', path),
					'net.connman.Service')

properties = service.GetProperties()

print "Setting method %s for %s" % (sys.argv[2], sys.argv[1])

ipv6_configuration = { "Method": sys.argv[2] }
if sys.argv[2] == "auto":
	if (len(sys.argv) > 3):
		ipv6_configuration["Privacy"] = sys.argv[3]
else:
	if (len(sys.argv) > 3):
		ipv6_configuration["Address"] = sys.argv[3]
	if (len(sys.argv) > 4):
		ipv6_configuration["PrefixLength"] = sys.argv[4]
	if (len(sys.argv) > 5):
		ipv6_configuration["Gateway"] = sys.argv[5]

service.SetProperty("IPv6.Configuration", ipv6_configuration)
print "New IPv6.Configuration: ", ipv6_configuration

print
