Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2322,6 +2322,8 @@ The following parameters are available in the `peadm::migrate` plan:

* [`old_primary_host`](#-peadm--migrate--old_primary_host)
* [`new_primary_host`](#-peadm--migrate--new_primary_host)
* [`upgrade_version`](#-peadm--migrate--upgrade_version)
* [`replica_host`](#-peadm--migrate--replica_host)

##### <a name="-peadm--migrate--old_primary_host"></a>`old_primary_host`

Expand All @@ -2335,6 +2337,22 @@ Data type: `Peadm::SingleTargetSpec`

The new server that will become the PE primary server

##### <a name="-peadm--migrate--upgrade_version"></a>`upgrade_version`

Data type: `Optional[String]`

Optional version to upgrade to after migration is complete

Default value: `undef`

##### <a name="-peadm--migrate--replica_host"></a>`replica_host`

Data type: `Optional[Peadm::SingleTargetSpec]`



Default value: `undef`

### <a name="peadm--modify_certificate"></a>`peadm::modify_certificate`

Certificates can be modified by adding extensions, removing extensions, or
Expand Down
63 changes: 60 additions & 3 deletions plans/migrate.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,35 @@
# The existing PE primary server that will be migrated from
# @param new_primary_host
# The new server that will become the PE primary server
# @param upgrade_version
# Optional version to upgrade to after migration is complete
#
plan peadm::migrate (
Peadm::SingleTargetSpec $old_primary_host,
Peadm::SingleTargetSpec $new_primary_host,
Optional[String] $upgrade_version = undef,
Optional[Peadm::SingleTargetSpec] $replica_host = undef,
) {
peadm::assert_supported_bolt_version()

$backup_file = run_plan('peadm::backup', $old_primary_host, {
backup_type => 'migration',
})

download_file($backup_file['path'], 'backup', $old_primary_host)
$download_results = download_file($backup_file['path'], 'backup', $old_primary_host)
$download_path = $download_results[0]['path']

$backup_filename = basename($backup_file['path'])
$remote_backup_path = "/tmp/${backup_filename}"
$current_dir = system::env('PWD')

upload_file("${current_dir}/downloads/backup/${old_primary_host}/${backup_filename}", $remote_backup_path, $new_primary_host)
upload_file($download_path, $remote_backup_path, $new_primary_host)

$old_primary_target = get_targets($old_primary_host)[0]
$old_primary_password = peadm::get_pe_conf($old_primary_target)['console_admin_password']
$old_pe_conf = run_task('peadm::get_peadm_config', $old_primary_target).first.value

out::message("old_pe_conf:${old_pe_conf}.")

run_plan('peadm::install', {
primary_host => $new_primary_host,
console_password => $old_primary_password,
Expand All @@ -40,4 +46,55 @@
restore_type => 'migration',
input_file => $remote_backup_path,
})

$node_types = {
'primary_host' => $old_pe_conf['params']['primary_host'],
'replica_host' => $old_pe_conf['params']['replica_host'],
'primary_postgresql_host' => $old_pe_conf['params']['primary_postgresql_host'],
'replica_postgresql_host' => $old_pe_conf['params']['replica_postgresql_host'],
'compilers' => $old_pe_conf['params']['compilers'],
'legacy_compilers' => $old_pe_conf['params']['legacy_compilers'],
}

$nodes_to_purge = $node_types.reduce([]) |$memo, $entry| {
$value = $entry[1]

if empty($value) {
$memo
}
elsif $value =~ Array {
$memo + $value.filter |$node| { !empty($node) }
}
else {
$memo + [$value]
}
}

out::message("Nodes to purge: ${nodes_to_purge}")

if !empty($nodes_to_purge) {
out::message('Purging nodes from old configuration individually')
$nodes_to_purge.each |$node| {
out::message("Purging node: ${node}")
run_command("/opt/puppetlabs/bin/puppet node purge ${node}", $new_primary_host)
}
} else {
out::message('No nodes to purge from old configuration')
}

if $replica_host {
run_plan('peadm::add_replica', {
primary_host => $new_primary_host,
replica_host => $replica_host,
})
}

if $upgrade_version and $upgrade_version != '' and !empty($upgrade_version) {
run_plan('peadm::upgrade', {
primary_host => $new_primary_host,
version => $upgrade_version,
download_mode => 'direct',
replica_host => $replica_host,
})
}
}
Loading