Skip to content
Snippets Groups Projects
Commit 185f2e43 authored by František Řezníček's avatar František Řezníček
Browse files

feat: Detect and assign same MAC address as in source cloud

parent 6bf955bd
No related branches found
No related tags found
1 merge request!7feat: Detect and assign same MAC address as in source cloud
Pipeline #451537 passed with stage
in 29 seconds
""" OpenStack migrator - OpenStack library """
import copy
import inspect
import math
import os.path
......@@ -508,22 +509,35 @@ def describe_server_network_connection(args, dst_ostack_conn, netaddr_dict):
# netaddr_dict{ 'dst-network': Network,
# 'src-network-addresses': {'network-name': <source-network-name>,
# 'addresses': [ ... ]} }
func_name = inspect.currentframe().f_code.co_name
msg_suffix = "Carefully check whether migrated VM is accessible and can communicate with outside world."
fixed_port = None
dst_network = netaddr_dict['dst-network']
source_server_fixed_addresses = [i_addr['addr'] for i_addr in netaddr_dict['src-network-addresses']['addresses'] if i_addr.get('OS-EXT-IPS:type') == 'fixed']
source_server_mac_addresses = [i_addr.get('OS-EXT-IPS-MAC:mac_addr', None) for i_addr in netaddr_dict['src-network-addresses']['addresses'] if i_addr.get('OS-EXT-IPS:type') == 'fixed']
if len(source_server_fixed_addresses) == 1 and len(dst_network.subnet_ids) == 1:
if source_server_fixed_addresses[0] and source_server_mac_addresses[0] is None:
args.logger.warning(f"{func_name}() MAC address detection failed! " \
f"Migrated VM will have same internal IP address, but different MAC address. {msg_suffix}")
try:
port_desc = "A part of workload migration: created to get same server fixed-ips"
port_desc = "A part of workload migration: created to get same server fixed-ip / MAC addresses"
fixed_port = dst_ostack_conn.network.create_port(name=get_dst_resource_name(args),
description=port_desc,
network_id=dst_network.id,
mac_address=source_server_mac_addresses[0],
fixed_ips=[{"ip_address": source_server_fixed_addresses[0],
"subnet_id": dst_network.subnet_ids[0]}])
except:
pass
except Exception as ex:
args.logger.error(f"{func_name}() throws exception while creating an ostack port.",
exc_info=True)
else:
args.logger.warning(f"{func_name}() detected multiple ports which is NOT implemented yet! " \
f"Migrated VM will not have same internal IP address / MAC address. {msg_suffix}")
if fixed_port:
return {'port': fixed_port.id}
args.logger.warning(f"{func_name}() Creation of dedicated network port failed! " \
f"Migrated VM will not have same internal IP address / MAC address. {msg_suffix}")
return {'uuid': dst_network.id}
......
......@@ -245,6 +245,7 @@ def main(args):
args.logger.info(f"F.42 Source OpenStack VM server (name:{i_source_server_detail.name}) became ACTIVE already.")
# EXPLICIT OpenStack volume migration
# ---------------------------------------------------------------------------------------------
if args.explicit_volume_names:
for i_source_volume_name in args.explicit_volume_names:
i_source_volume = source_project_conn.block_storage.find_volume(i_source_volume_name)
......@@ -279,7 +280,7 @@ def main(args):
# main() call (argument parsing)
# ---------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
if __name__ == "__main__":
AP = argparse.ArgumentParser(epilog=globals().get('__doc__'),
formatter_class=argparse.RawDescriptionHelpFormatter)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment