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

import jingrow


def execute():
	jingrow.reload_pg("jcloud", "pagetype", "virtual_machine")

	for machine in jingrow.get_all(
		"Virtual Machine", ["name", "index", "series", "domain"]
	):
		for server_type, series in [
			("Server", "f"),
			("Database Server", "m"),
			("Proxy Server", "n"),
		]:
			server = jingrow.db.get_value(
				server_type, {"virtual_machine": machine.name}, ["name", "domain"], as_dict=True
			)
			if server:
				break
		index = server.name.split("-")[0][1:]
		jingrow.db.set_value("Virtual Machine", machine.name, "series", series)
		jingrow.db.set_value("Virtual Machine", machine.name, "index", index)
		jingrow.db.set_value("Virtual Machine", machine.name, "domain", server.domain)
