bnr restore wirh Ironic

This patch automatize the restoration of the node when is integrated with ironic.

Change-Id: I73a7b9588b888d7092eca39e45ce5582d6c4f030
This commit is contained in:
Juan Badia Payno 2021-09-29 15:14:10 +02:00
parent 3818dc35d8
commit ce56a61c67
3 changed files with 190 additions and 0 deletions

View File

@ -0,0 +1,23 @@
---
# Copyright 2021 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: TripleO Restore a node
hosts: Undercloud
remote_user: "{{ tripleo_target_user | default(lookup('env', 'USER')) }}"
tasks:
- name: Restore one node
include_role:
name: backup_and_restore
tasks_from: restore_node.yml

View File

@ -126,3 +126,18 @@ tripleo_backup_and_restore_cephadm_path: "/usr/sbin/cephadm"
# of the partition (the whatever), i.e: sda2, sda1, vda2, sdb3, sdc1...
tripleo_backup_and_restore_boot_mount: replaceme
tripleo_backup_and_restore_boot_efi_mount: replaceme
# The name of the node to restore
tripleo_backup_and_restore_overcloud_restore_name: undercloud
# Ironic images path
tripleo_backup_and_restore_ironic_images_path: "/var/lib/ironic/images"
# Restore retries
tripleo_backup_and_restore_restore_retries: 300
# Restore delay
tripleo_backup_and_restore_restore_delay: 10
# Ironic ubdirectory where the kernel and initrd are uploaded
backup_and_restore_history_path: ""

View File

@ -0,0 +1,152 @@
---
# Copyright 2021 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: Get the name of the node
environment:
OS_CLOUD: undercloud
command: metalsmith -f value -c Hostname show {{ tripleo_backup_and_restore_overcloud_restore_name }}
register: instance_name
tags:
- bar_restore_image
- name: Get metalsmith instance informartion
environment:
OS_CLOUD: undercloud
command: metalsmith -f json show {{ instance_name.stdout }}
register: instance_information
tags:
- bar_restore_image
- name: Parse instance informatation
set_fact:
instance_information_json: "{{ instance_information.stdout | from_json }}"
tags:
- bar_restore_image
- name: Get node name
set_fact:
node_name: "{{ instance_information_json[instance_name.stdout]['node']['name'] }}"
node_hostname: "{{ instance_name.stdout }}"
tags:
- bar_restore_image
- name: Set kernel and initrd
set_fact:
restore_kernel: "{{ (backup_and_restore_history_path == '') | ternary(node_hostname, backup_and_restore_history_path+'/'+node_hostname) + '.kernel' }}"
restore_initrd: "{{ (backup_and_restore_history_path == '') | ternary(node_hostname, backup_and_restore_history_path+'/'+node_hostname) + '.initrd.cgz' }}"
tags:
- bar_restore_image
- name: Power off node
environment:
OS_CLOUD: undercloud
command: openstack baremetal node power off {{ node_name }}
tags:
- bar_restore_image
- name: Set node in maintenance
environment:
OS_CLOUD: undercloud
command: openstack baremetal node maintenance set {{ node_name }}
tags:
- bar_restore_image
- name: Change node settings
environment:
OS_CLOUD: undercloud
command: openstack baremetal node set \
--instance-info kernel=file://{{ tripleo_backup_and_restore_ironic_images_path }}/{{ restore_kernel }} \
--instance-info ramdisk=file://{{ tripleo_backup_and_restore_ironic_images_path }}/{{ restore_initrd }} \
--instance-info kernel_append_params="unattended" \
--deploy-interface ramdisk \
{{ node_name }}
tags:
- bar_restore_image
- name: Unset node from maintenance
environment:
OS_CLOUD: undercloud
command: openstack baremetal node maintenance unset {{ node_name }}
tags:
- bar_restore_image
- name: Rebuild node
environment:
OS_CLOUD: undercloud
command: openstack baremetal node rebuild {{ node_name }}
tags:
- bar_restore_image
- name: Wait node is active
environment:
OS_CLOUD: undercloud
command: openstack baremetal node show {{ node_name }} --fields provision_state -f value
register: node_provision_state
retries: "{{ tripleo_backup_and_restore_restore_retries }}"
until: node_provision_state.stdout == 'active'
delay: "{{ tripleo_backup_and_restore_restore_delay }}"
tags:
- bar_restore_image
- name: Wait node is power off
environment:
OS_CLOUD: undercloud
command: openstack baremetal node show {{ node_name }} --fields power_state -f value
register: node_power_status
retries: "{{ tripleo_backup_and_restore_restore_retries }}"
until: '"off" in node_power_status.stdout'
delay: "{{ tripleo_backup_and_restore_restore_delay }}"
tags:
- bar_restore_image
- name: Set node to maintenance
environment:
OS_CLOUD: undercloud
command: openstack baremetal node maintenance set {{ node_name }}
tags:
- bar_restore_image
- name: Change back configuration node
environment:
OS_CLOUD: undercloud
command: openstack baremetal node set \
--instance-info kernel="file://{{ tripleo_backup_and_restore_ironic_images_path }}/overcloud-full.vmlinuz" \
--instance-info ramdisk="file://{{ tripleo_backup_and_restore_ironic_images_path }}/overcloud-full.initrd" \
--deploy-interface direct \
{{ node_name }}
tags:
- bar_restore_image
- name: Change boot device to disk
environment:
OS_CLOUD: undercloud
command: openstack baremetal node boot device set {{ node_name }} disk
tags:
- bar_restore_image
- name: Unset maintenance from node
environment:
OS_CLOUD: undercloud
command: openstack baremetal node maintenance unset {{ node_name }}
tags:
- bar_restore_image
- name: Power on instance
environment:
OS_CLOUD: undercloud
command: openstack baremetal node power on {{ node_name }}
tags:
- bar_restore_image