--- admin/plib/modules/panel-migrator/backend/lib/python/parallels/core/actions/deploy/domain_aliases.py.orig +++ admin/plib/modules/panel-migrator/backend/lib/python/parallels/core/actions/deploy/domain_aliases.py @@ -1,5 +1,6 @@ import logging +from parallels.core.actions.deploy.utils import remove_coinciding_dns_records from parallels.core.utils.common import is_empty_iterator from parallels.plesk import messages from parallels.core.actions.base.subscription_action import SubscriptionAction @@ -33,6 +34,11 @@ class DeployDomainAliases(SubscriptionAction): )) continue + if global_context.target_panel_obj.is_remove_coinciding_dns_records(): + # if target panel is unable to create add-on domain which name matching one of existing + # DNS records, remove such DNS records first + remove_coinciding_dns_records(global_context, subscription, domain_alias_dump.name) + logger.info(messages.ACTION_DEPLOY_DOMAIN_ALIASES_CREATE_DOMAIN_ALIAS.format( domain_alias_name=domain_alias_dump.name, subscription_name=subscription.name --- admin/plib/modules/panel-migrator/backend/lib/python/parallels/core/actions/deploy/domains.py.orig +++ admin/plib/modules/panel-migrator/backend/lib/python/parallels/core/actions/deploy/domains.py @@ -1,5 +1,6 @@ import logging +from parallels.core.actions.deploy.utils import remove_coinciding_dns_records from parallels.core.utils.common import is_empty_iterator from parallels.plesk import messages from parallels.core.actions.base.subscription_action import SubscriptionAction @@ -26,7 +27,6 @@ class DeployDomains(SubscriptionAction): :type global_context: parallels.core.global_context.GlobalMigrationContext :type subscription: parallels.core.migrated_subscription.MigratedSubscription """ - filter_domain_name = subscription.converted_dump.get_domain_names() for domain_dump in subscription.converted_dump.iter_addon_domains(): if global_context.hosting_repository.domain.is_exists_by_subscription( @@ -41,12 +41,7 @@ class DeployDomains(SubscriptionAction): if global_context.target_panel_obj.is_remove_coinciding_dns_records(): # if target panel is unable to create add-on domain which name matching one of existing # DNS records, remove such DNS records first - self._remove_coinciding_dns_records( - global_context, - subscription.name, - domain_dump.name, - filter_domain_name - ) + remove_coinciding_dns_records(global_context, subscription, domain_dump.name) logger.info(messages.ACTION_DEPLOY_DOMAINS_CREATE_DOMAIN.format( domain_name=domain_dump.name, @@ -124,48 +119,3 @@ class DeployDomains(SubscriptionAction): ) continue - @staticmethod - def _remove_coinciding_dns_records(context, subscription_name, domain_name, filter_domain_name): - """Remove DNS records, which match given domain name - - :type context: parallels.core.global_context.GlobalMigrationContext - :type subscription_name: str - :type domain_name: str - :type filter_domain_name: list[str] - """ - # retrieve DNS records coinciding with the domain name - dns_records = [] - try: - dns_records = context.hosting_repository.dns_record.get_list( - filter_domain_name=filter_domain_name, - filter_name=['%s.' % domain_name] - ) - except Exception: - # unable to retrieve DNS records for some reason, so if such records actually exists, - # they will not be removed and further creation of add-on domain will fail; - # anyway, log an exception and go ahead - logger.debug(messages.LOG_EXCEPTION, exc_info=True) - - if len(dns_records) < 1: - return - - logger.info(messages.ACTION_DEPLOY_DOMAINS_REMOVE_COINCIDING_DNS_RECORDS.format( - subscription_name=subscription_name, - domain_name=domain_name - )) - for dns_record in dns_records: - try: - logger.info(messages.ACTION_DEPLOY_DOMAINS_REMOVE_COINCIDING_DNS_RECORDS_REMOVE.format( - subscription_name=subscription_name, - dns_record_domain_name=dns_record.domain_name, - dns_record_pretty_name=dns_record.pretty_name - )) - context.hosting_repository.dns_record.remove(dns_record) - except Exception: - logger.debug(messages.LOG_EXCEPTION, exc_info=True) - logger.warning(messages.ACTION_DEPLOY_DOMAINS_REMOVE_COINCIDING_DNS_RECORDS_REMOVE_ERROR.format( - subscription_name=subscription_name, - domain_name=domain_name, - dns_record_domain_name=dns_record.domain_name, - dns_record_pretty_name=dns_record.pretty_name - )) --- /dev/null +++ admin/plib/modules/panel-migrator/backend/lib/python/parallels/core/actions/deploy/utils.py @@ -0,0 +1,50 @@ +from parallels.core.utils.common.logging import create_safe_logger +from parallels.plesk import messages + +logger = create_safe_logger(__name__) + + +def remove_coinciding_dns_records(global_context, subscription, domain_name): + """Remove DNS records, which match given domain name + + :type global_context: parallels.core.global_context.GlobalMigrationContext + :type subscription: parallels.core.migrated_subscription.MigratedSubscription + :type domain_name: str + """ + # retrieve DNS records coinciding with the domain name + dns_records = [] + try: + filter_domain_name = subscription.converted_dump.get_domain_names() + dns_records = global_context.hosting_repository.dns_record.get_list( + filter_domain_name=filter_domain_name, + filter_name=['%s.' % domain_name] + ) + except Exception: + # unable to retrieve DNS records for some reason, so if such records actually exists, + # they will not be removed and further creation of add-on domain will fail; + # anyway, log an exception and go ahead + logger.debug(messages.LOG_EXCEPTION, exc_info=True) + + if len(dns_records) < 1: + return + + logger.info(messages.REMOVE_COINCIDING_DNS_RECORDS.format( + subscription_name=subscription.name, + domain_name=domain_name + )) + for dns_record in dns_records: + try: + logger.info(messages.REMOVE_COINCIDING_DNS_RECORDS_REMOVE.format( + subscription_name=subscription.name, + dns_record_domain_name=dns_record.domain_name, + dns_record_pretty_name=dns_record.pretty_name + )) + global_context.hosting_repository.dns_record.remove(dns_record) + except Exception: + logger.debug(messages.LOG_EXCEPTION, exc_info=True) + logger.warning(messages.REMOVE_COINCIDING_DNS_RECORDS_REMOVE_ERROR.format( + subscription_name=subscription.name, + domain_name=domain_name, + dns_record_domain_name=dns_record.domain_name, + dns_record_pretty_name=dns_record.pretty_name + )) --- admin/plib/modules/panel-migrator/backend/lib/python/parallels/plesk/messages/__init__.py +++ admin/plib/modules/panel-migrator/backend/lib/python/parallels/plesk/messages/__init__.py @@ -47,15 +47,15 @@ ACTION_DEPLOY_DOMAINS = single_line_message(""" ACTION_DEPLOY_DOMAINS_FAILED = single_line_message(""" Failed to deploy add-on domains of subscription '{subscription_name}' """) -ACTION_DEPLOY_DOMAINS_REMOVE_COINCIDING_DNS_RECORDS = single_line_message(""" +REMOVE_COINCIDING_DNS_RECORDS = single_line_message(""" There are DNS record(s) within the subscription '{subscription_name}' on the target panel, which coincides with the name of the domain '{domain_name}'; such DNS record(s) will be removed """) -ACTION_DEPLOY_DOMAINS_REMOVE_COINCIDING_DNS_RECORDS_REMOVE = single_line_message(""" +REMOVE_COINCIDING_DNS_RECORDS_REMOVE = single_line_message(""" Remove the DNS record '{dns_record_pretty_name}' for domain '{dns_record_domain_name}' within the subscription '{subscription_name}' from the target panel """) -ACTION_DEPLOY_DOMAINS_REMOVE_COINCIDING_DNS_RECORDS_REMOVE_ERROR = single_line_message(""" +REMOVE_COINCIDING_DNS_RECORDS_REMOVE_ERROR = single_line_message(""" Unable to remove the DNS record '{dns_record_pretty_name}' for domain '{dns_record_domain_name}' within the subscription '{subscription_name}' from the target panel, see debug log for details; it could block the creation of the domain '{domain_name}'; in such case you need to remove this DNS record