# Copyright (c) 2020, JINGROW
# For license information, please see license.txt


import jingrow


def execute():
	pagetypes = ["Server", "Proxy Server", "Database Server"]
	for pagetype in pagetypes:
		jingrow.reload_pg("jcloud", "pagetype", jingrow.scrub(pagetype))
		servers = jingrow.get_all(pagetype, {"hostname": ("is", "not set")})
		domain = jingrow.db.get_single_value("Jcloud Settings", "domain")
		for server in servers:
			hostname = server.name.replace(f".{domain}", "")
			jingrow.db.set_value(pagetype, server.name, "hostname", hostname)
			jingrow.db.set_value(pagetype, server.name, "domain", domain)
