from parallels.core import messages
from parallels.core.actions.base.subscription_action import SubscriptionAction
from parallels.core.converter import dns as dns_converter


class DNS(SubscriptionAction):
	def get_description(self):
		return messages.ACTION_CONVERT_DNS_RECORDS

	def get_failure_message(self, global_context, subscription):
		"""
		:type global_context: parallels.core.global_context.GlobalMigrationContext
		:type subscription: parallels.core.migrated_subscription.MigratedSubscription
		"""
		return messages.FAILED_CONVERT_DNS_RECORDS_FOR_SUBSCRIPTION_2 % (subscription.name)

	def filter_subscription(self, global_context, subscription):
		"""
		:type global_context: parallels.core.global_context.GlobalMigrationContext
		:type subscription: parallels.core.migrated_subscription.MigratedSubscription
		"""
		return True

	def run(self, global_context, subscription):
		"""Make subscription DNS records resolve to target server IP.

		:type global_context: parallels.core.global_context.GlobalMigrationContext
		:type subscription: parallels.core.migrated_subscription.MigratedSubscription
		"""
		dns_converter.replace_resource_record_ips(subscription)
