def run(self, **kwargs): search_opts, search_opts_img, search_opts_tenant = {}, {}, {} search_opts_vol = {} filter_path = self.cfg.migrate.filter_path if (utils.read_yaml_file(filter_path) and not self.cfg.migrate.migrate_whole_cloud): filter_config = utils.read_yaml_file(filter_path) if utils.INSTANCES_TYPE in filter_config: search_opts = filter_config[utils.INSTANCES_TYPE] if utils.IMAGES_TYPE in filter_config: search_opts_img = filter_config[utils.IMAGES_TYPE] if utils.VOLUMES_TYPE in filter_config: search_opts_vol = filter_config[utils.VOLUMES_TYPE] if utils.TENANTS_TYPE in filter_config: search_opts_tenant = filter_config[utils.TENANTS_TYPE] filtered_tenant = search_opts_tenant.get('tenant_id', ['INVALID'])[0] for r in self.src_cloud.resources.values(): if hasattr(r, 'filter_tenant_id') and filtered_tenant != 'INVALID': r.filter_tenant_id = filtered_tenant return { 'search_opts': search_opts, 'search_opts_img': search_opts_img, 'search_opts_vol': search_opts_vol, 'search_opts_tenant': search_opts_tenant }
def run(self, **kwargs): search_opts, search_opts_img, search_opts_tenant = {}, {}, {} search_opts_vol = {} filter_path = self.cfg.migrate.filter_path if (utils.read_yaml_file(filter_path) and not self.cfg.migrate.migrate_whole_cloud): filter_config = utils.read_yaml_file(filter_path) if utils.INSTANCES_TYPE in filter_config: search_opts = filter_config[utils.INSTANCES_TYPE] if utils.IMAGES_TYPE in filter_config: search_opts_img = filter_config[utils.IMAGES_TYPE] if utils.VOLUMES_TYPE in filter_config: search_opts_vol = filter_config[utils.VOLUMES_TYPE] if utils.TENANTS_TYPE in filter_config: search_opts_tenant = filter_config[utils.TENANTS_TYPE] return { 'search_opts': search_opts, 'search_opts_img': search_opts_img, 'search_opts_vol': search_opts_vol, 'search_opts_tenant': search_opts_tenant }
def run(self, **kwargs): if self.raw: filters = utils.read_yaml_file(cfglib.CONF.migrate.filter_path) if filters: LOG.info('Filters: %s', pprint.pformat(filters)) else: self._print_options('Filter by instances', kwargs.get('search_opts', {})) self._print_options('Filter by images', kwargs.get('search_opts_img', {})) self._print_options('Filter by volumes', kwargs.get('search_opts_vol', {})) self._print_options('Filter by tenants', kwargs.get('search_opts_tenant', {}))
def take_action(self, parsed_args): self.override_config('migrate', scenario=parsed_args.scenario, filter_path=parsed_args.filter_path, copy_backend=parsed_args.copy_backend) self.config.log_opt_values(LOG, logging.DEBUG) filters = utils.read_yaml_file(self.config.migrate.filter_path) LOG.debug('Filters: %s', pprint.pformat(filters)) env.key_filename = self.config.migrate.key_filename env.connection_attempts = self.config.migrate.ssh_connection_attempts env.cloud = os2os.OS2OSFerry(self.config) status_error = env.cloud.migrate(scenario.Scenario( path_scenario=self.config.migrate.scenario, path_tasks=self.config.migrate.tasks_mapping)) if status_error != errorcodes.NO_ERROR: raise RuntimeError("Migration failed")
def run(self, **kwargs): if self.cfg.migrate.migrate_whole_cloud: LOG.info("Whole cloud migration is enabled. Ignore filtering...") return filter_path = self.cfg.migrate.filter_path if not utils.check_file(filter_path): raise exception.AbortMigrationError( "Filter file '%s' has not been found. Please check filter file" " path in the CloudFerry configuration file." % filter_path) if not utils.read_yaml_file(filter_path): raise exception.AbortMigrationError("Filter file '%s' is empty." % filter_path) try: tenant_opts = kwargs['search_opts_tenant'] instance_opts = kwargs['search_opts'] volume_opts = kwargs['search_opts_vol'] image_opts = kwargs['search_opts_img'] except KeyError: raise exception.AbortMigrationError( "Action 'act_get_filter' should be specified prior this action" " in the scenario file. Aborting migration...") tenant = Tenant(self.cloud, tenant_opts) instance = Instance(self.cloud, instance_opts) volume = Volume(self.cloud, volume_opts) image = Image(self.cloud, image_opts) invalid_data = {} for filter_object in [tenant, instance, volume, image]: invalid_data.update(filter_object.check()) # Filter only non-empty values invalid_data = {k: v for k, v in invalid_data.iteritems() if v} if invalid_data: msg = "\n\nInvalid Filter Data:\n\n%s" % yaml.dump(invalid_data) LOG.critical(msg) raise exception.AbortMigrationError( "There is a number of invalid data specified in the filter " "file '%s', so migration process can not be continued. Please " "update your filter config file and try again. %s" % (filter_path, msg))
def __init__(self, config, group_file, cloud_id): self.config = config if group_file is None: message = "Grouping config is not provided." LOG.error(message) raise ValueError(message) self.group_config = utils.read_yaml_file(group_file) resources = {'identity': keystone.KeystoneIdentity, 'network': neutron.NeutronNetwork, 'compute': nova_compute.NovaCompute} self.cloud = cloud.Cloud(resources, cloud_id, config) self.network = self.cloud.resources['network'] self.compute = self.cloud.resources['compute'] self.identity = self.cloud.resources['identity'] self.groups = {}
def take_action(self, parsed_args): self.override_config('migrate', scenario=parsed_args.scenario, filter_path=parsed_args.filter_path, copy_backend=parsed_args.copy_backend) self.config.log_opt_values(LOG, logging.DEBUG) filters = utils.read_yaml_file(self.config.migrate.filter_path) LOG.debug('Filters: %s', pprint.pformat(filters)) env.key_filename = self.config.migrate.key_filename env.connection_attempts = self.config.migrate.ssh_connection_attempts env.cloud = os2os.OS2OSFerry(self.config) status_error = env.cloud.migrate(scenario.Scenario( path_scenario=self.config.migrate.scenario, path_tasks=self.config.migrate.tasks_mapping)) if status_error != errorcodes.NO_ERROR: raise RuntimeError("Migration failed with exit code {code}".format( code=status_error))
def test_group_by_network(self): group_rules = """ group_by: - network """ self.make_group_file(group_rules) group = grouping.Grouping(FAKE_CONFIG, FILE_NAME, 'src') group.compute.get_instances_list.return_value = [ self.fake_instance1, self.fake_instance2, self.fake_instance3 ] group.group() expected_result = {'net1_id': ['s1', 's3'], 'net3_id': ['s2']} result = utils.read_yaml_file(RESULT_FILE) self.assertEquals(expected_result, result)
def test_group_by_network(self): group_rules = """ group_by: - network """ self.make_group_file(group_rules) group = grouping.Grouping(FAKE_CONFIG, FILE_NAME, 'src') group.compute.get_instances_list.return_value = [self.fake_instance1, self.fake_instance2, self.fake_instance3] group.group() expected_result = {'net1_id': ['s1', 's3'], 'net3_id': ['s2']} result = utils.read_yaml_file(RESULT_FILE) self.assertEquals(expected_result, result)
def run(self, **kwargs): LOG.debug("Checking networks...") overlapping_resources = {} invalid_resources = {} src_net = self.src_cloud.resources[utils.NETWORK_RESOURCE] dst_net = self.dst_cloud.resources[utils.NETWORK_RESOURCE] src_compute = self.src_cloud.resources[utils.COMPUTE_RESOURCE] search_opts = kwargs.get('search_opts_tenant', {}) search_opts.update({'search_opts': kwargs.get('search_opts', {})}) LOG.debug("Retrieving Network information from Source cloud...") ports = src_net.get_ports_list() src_net_info = NetworkInfo(src_net.read_info(**search_opts), ports) LOG.debug("Retrieving Network information from Destination cloud...") dst_net_info = NetworkInfo(dst_net.read_info()) LOG.debug("Retrieving Compute information from Source cloud...") src_compute_info = ComputeInfo(src_compute, search_opts) ext_net_map = utils.read_yaml_file(self.cfg.migrate.ext_net_map) or {} # Check external networks mapping if ext_net_map: LOG.info("Check external networks mapping...") invalid_ext_net_ids = src_net_info.get_invalid_ext_net_ids( dst_net_info, ext_net_map) if invalid_ext_net_ids: invalid_resources.update( {"invalid_external_nets_ids_in_map": invalid_ext_net_ids}) # Check networks' segmentation IDs overlap LOG.info("Check networks' segmentation IDs overlapping...") nets_overlapping_seg_ids = ( src_net_info.get_overlapping_seg_ids(dst_net_info)) if nets_overlapping_seg_ids: LOG.warning("Networks with segmentation IDs overlapping:\n%s", nets_overlapping_seg_ids) # Check external subnets overlap LOG.info("Check external subnets overlapping...") overlapping_external_subnets = ( src_net_info.get_overlapping_external_subnets( dst_net_info, ext_net_map)) if overlapping_external_subnets: overlapping_resources.update( {"overlapping_external_subnets": overlapping_external_subnets}) # Check floating IPs overlap LOG.info("Check floating IPs overlapping...") floating_ips = src_net_info.list_overlapping_floating_ips( dst_net_info, ext_net_map) if floating_ips: overlapping_resources.update( {'overlapping_floating_ips': floating_ips}) # Check busy physical networks on DST of FLAT network type LOG.info("Check busy physical networks for FLAT network type...") busy_flat_physnets = src_net_info.busy_flat_physnets(dst_net_info) if busy_flat_physnets: overlapping_resources.update( {'busy_flat_physnets': busy_flat_physnets}) # Check physical networks existence on DST for VLAN network type LOG.info("Check physical networks existence for VLAN network type...") dst_neutron_client = dst_net.neutron_client missing_vlan_physnets = src_net_info.missing_vlan_physnets( dst_net_info, dst_neutron_client) if missing_vlan_physnets: overlapping_resources.update( {'missing_vlan_physnets': missing_vlan_physnets}) # Check VMs spawned directly in external network LOG.info("Check VMs spawned directly in external networks...") devices = src_net_info.get_devices_from_external_networks() vms_list = src_compute_info.list_vms_in_external_network(devices) if vms_list: overlapping_resources.update({'vms_in_external_network': vms_list}) # Print LOG message with all overlapping stuff and abort migration if overlapping_resources or invalid_resources: if overlapping_resources: LOG.critical('Network overlapping list:\n%s', overlapping_resources) if invalid_resources: LOG.critical('Invalid Network resources list:\n%s', invalid_resources) raise exception.AbortMigrationError( "There is a number of overlapping/invalid Network resources, " "so migration process can not be continued. Resolve it please " "and try again")
def run(self, **kwargs): LOG.debug("Checking networks...") overlapping_resources = {} invalid_resources = {} src_net = self.src_cloud.resources[utils.NETWORK_RESOURCE] dst_net = self.dst_cloud.resources[utils.NETWORK_RESOURCE] src_compute = self.src_cloud.resources[utils.COMPUTE_RESOURCE] search_opts = kwargs.get('search_opts_tenant', {}) search_opts.update({'search_opts': kwargs.get('search_opts', {})}) LOG.debug("Retrieving Network information from Source cloud...") ports = src_net.get_ports_list() src_net_info = NetworkInfo(src_net.read_info(**search_opts), ports) LOG.debug("Retrieving Network information from Destination cloud...") dst_net_info = NetworkInfo(dst_net.read_info()) LOG.debug("Retrieving Compute information from Source cloud...") src_compute_info = ComputeInfo(src_compute, search_opts) ext_net_map = utils.read_yaml_file(self.cfg.migrate.ext_net_map) or {} # Check external networks mapping if ext_net_map: LOG.info("Check external networks mapping...") invalid_ext_net_ids = src_net_info.get_invalid_ext_net_ids( dst_net_info, ext_net_map) if invalid_ext_net_ids: invalid_resources.update( {"invalid_external_nets_ids_in_map": invalid_ext_net_ids}) # Check networks' segmentation IDs overlap LOG.info("Check networks' segmentation IDs overlapping...") nets_overlapping_seg_ids = (src_net_info.get_overlapping_seg_ids( dst_net_info)) if nets_overlapping_seg_ids: LOG.warning("Networks with segmentation IDs overlapping:\n%s", nets_overlapping_seg_ids) # Check external subnets overlap LOG.info("Check external subnets overlapping...") overlapping_external_subnets = ( src_net_info.get_overlapping_external_subnets(dst_net_info, ext_net_map)) if overlapping_external_subnets: overlapping_resources.update( {"overlapping_external_subnets": overlapping_external_subnets}) # Check floating IPs overlap LOG.info("Check floating IPs overlapping...") floating_ips = src_net_info.list_overlapping_floating_ips(dst_net_info, ext_net_map) if floating_ips: overlapping_resources.update( {'overlapping_floating_ips': floating_ips}) # Check busy physical networks on DST of FLAT network type LOG.info("Check busy physical networks for FLAT network type...") busy_flat_physnets = src_net_info.busy_flat_physnets(dst_net_info) if busy_flat_physnets: overlapping_resources.update( {'busy_flat_physnets': busy_flat_physnets}) # Check physical networks existence on DST for VLAN network type LOG.info("Check physical networks existence for VLAN network type...") dst_neutron_client = dst_net.neutron_client missing_vlan_physnets = src_net_info.missing_vlan_physnets( dst_net_info, dst_neutron_client) if missing_vlan_physnets: overlapping_resources.update( {'missing_vlan_physnets': missing_vlan_physnets}) # Check VMs spawned directly in external network LOG.info("Check VMs spawned directly in external networks...") devices = src_net_info.get_devices_from_external_networks() vms_list = src_compute_info.list_vms_in_external_network(devices) if vms_list: overlapping_resources.update({'vms_in_external_network': vms_list}) # Print LOG message with all overlapping stuff and abort migration if overlapping_resources or invalid_resources: if overlapping_resources: LOG.critical('Network overlapping list:\n%s', overlapping_resources) if invalid_resources: LOG.critical('Invalid Network resources list:\n%s', invalid_resources) raise exception.AbortMigrationError( "There is a number of overlapping/invalid Network resources, " "so migration process can not be continued. Resolve it please " "and try again")