from parallels.core.utils.common import cached
from parallels.core.connections.connections import Connections
from parallels.plesk.source.cpanel.server import CpanelSourceServer
from parallels.plesk.source.cpanel import settings


class MigratorConnections(Connections):
	def __init__(self, global_context, target_panel):
		super(MigratorConnections, self).__init__(global_context, target_panel)
		self.source_settings = settings.init(global_context.config)
		self.cpanel = CpanelSourceServer('cpanel', self.source_settings)

	def get_information_servers(self):
		return {'cpanel': self.cpanel.node_settings}

	@cached
	def get_source_node(self, node_id):
		return CpanelSourceServer(node_id, self.get_information_servers()[node_id])
