from parallels.common.actions.base.subscription_action \
	import SubscriptionAction

class SubscriptionBackupAction(SubscriptionAction):
	"""Action performed to change subscription's backup"""

	def __init__(self, subscription_backup):
		"""Class constructor

		Arguments:
		- subscription_backup - object that can retrieve subscription backup
		  object for each subscription, list of servers with backups
		"""
		self._subscription_backup = subscription_backup

	def filter_subscription(self, global_context, subscription):
		return True

	def run(self, global_context, subscription):
		"""Run action on given subscription

		Arguments:
		- global_context - registry with different objects that reused among
		  different actions
		- subscription - object with information about single subscription,
		  instance of
		  parallels.common.migrated_subscription.MigrationSubscription
		"""
		subscription_backup = self._subscription_backup.get(subscription)

		if subscription_backup is None:
			# subscription does not exist in backup - simply skip it
			return

		self._run_subscription_backup(global_context, subscription, subscription_backup)

	def _run_subscription_backup(
		self, global_context, subscription, subscription_backup
	):
		"""Run action on single subscription on provided backup"""
		raise NotImplementedError()