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

feat/refactor: source and destination entity names now match except security...

parent fc188f11
No related branches found
No related tags found
1 merge request!14feat/refactor: source and destination entity names now match except security...
......@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [1.2.0] - 2024-06-11
### Changed
- source and destination entity names now match except security groups where prefix migrated- is kept
## [1.1.3] - 2024-05-31
### Fixed
- assert disabled projects
......
......@@ -88,6 +88,10 @@ def normalize_table_data(data):
int_list.append(normalize_table_data_field(i_data_field['field']))
return int_list
def get_dst_secgroup_name(args, name=""):
""" translate original secgroup name to destination one """
return f"{args.destination_secgroup_name_prefix}{name}"
def get_dst_resource_name(args, name=""):
""" translate original name to destination one """
return f"{args.destination_entity_name_prefix}{name}"
......
......@@ -10,7 +10,7 @@ import xmltodict
import openstack
import clib
from lib import log_or_assert, get_dst_resource_name, get_dst_resource_desc, remote_cmd_exec, normalize_table_data, trim_dict, wait_for_ostack_volume_status
from lib import log_or_assert, get_dst_resource_name, get_dst_secgroup_name, get_dst_resource_desc, remote_cmd_exec, normalize_table_data, trim_dict, wait_for_ostack_volume_status
def get_destination_network(source_network):
""" LUT for networks """
......@@ -367,7 +367,7 @@ def get_or_create_dst_server_keypair(args, source_keypairs, src_server, dst_osta
def create_security_groups(args, src_ostack_conn, dst_ostack_conn, src_security_group, dst_project, recursion_stack=None):
""" create openstack security group[s] """
int_recursion_stack = {} if recursion_stack is None else recursion_stack
int_sg = dst_ostack_conn.network.create_security_group(name=get_dst_resource_name(args, src_security_group.name),
int_sg = dst_ostack_conn.network.create_security_group(name=get_dst_secgroup_name(args, src_security_group.name),
description=get_dst_resource_desc(args,
src_security_group.description,
src_security_group.id),
......@@ -386,7 +386,7 @@ def create_security_groups(args, src_ostack_conn, dst_ostack_conn, src_security_
i_mod_rule['remote_group_id'] = int_recursion_stack[i_mod_rule['remote_group_id']]
# get linked source SG
elif _src_sg := src_ostack_conn.network.find_security_group(i_mod_rule['remote_group_id']):
if _dst_sg := dst_ostack_conn.network.find_security_group(get_dst_resource_name(args, _src_sg.name),
if _dst_sg := dst_ostack_conn.network.find_security_group(get_dst_secgroup_name(args, _src_sg.name),
project_id=dst_project.id):
i_mod_rule['remote_group_id'] = _dst_sg.id
else:
......@@ -409,7 +409,7 @@ def duplicate_ostack_project_security_groups(args, src_ostack_conn, dst_ostack_c
for i_src_security_group in src_project_security_groups:
j_dst_security_group_found = False
for j_dst_security_group in tuple(dst_ostack_conn.network.security_groups(project_id=dst_project.id)):
if get_dst_resource_name(args, i_src_security_group.name) == j_dst_security_group.name and \
if get_dst_secgroup_name(args, i_src_security_group.name) == j_dst_security_group.name and \
i_src_security_group.id in j_dst_security_group.description:
j_dst_security_group_found = True
if not j_dst_security_group_found:
......@@ -425,7 +425,7 @@ def get_or_create_dst_server_security_groups(args, src_ostack_conn, dst_ostack_c
i_src_server_security_group = src_ostack_conn.network.find_security_group(i_src_server_security_group_name,
project_id=src_project.id)
i_dst_server_security_group = None
if i_dst_server_security_group := dst_ostack_conn.network.find_security_group(get_dst_resource_name(args,
if i_dst_server_security_group := dst_ostack_conn.network.find_security_group(get_dst_secgroup_name(args,
i_src_server_security_group.name),
project_id=dst_project.id):
log_or_assert(args,
......
......@@ -336,8 +336,10 @@ if __name__ == "__main__":
help='Destination cloud bootable volumes are made on top of public image. Name of destination cloud image.')
AP.add_argument('--destination-ipv4-external-network', default='external-ipv4-general-public',
help='Destination cloud IPV4 external network.')
AP.add_argument('--destination-entity-name-prefix', default='migrated-',
help='Destination cloud entity name prefix.')
AP.add_argument('--destination-secgroup-entity-name-prefix', default='migrated-',
help='Destination cloud security_groups entity name prefix.')
AP.add_argument('--destination-entity-name-prefix', default='',
help='Destination cloud entity name prefix (all except secgroups).')
AP.add_argument('--destination-entity-description-suffix', default=', migrated(id:{})',
help='Destination cloud entity description suffix.')
......
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