Octavia amphora image handles updates and symlinks
This patch adds logic to the octavia image upload to update the
amphora image if a glance image of the same name already exists but has
a different checksum. It also adds some logic for distro specific
default behavior.
Closes-Bug: #1754039
Change-Id: I48ad8971e34ddebd50f5eb36e22a3d072e011d14
(cherry picked from commit 549f9e004c
)
This commit is contained in:
parent
ee9ace2087
commit
675587eeeb
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
- hosts: undercloud[0]
|
||||
remote_user: stack
|
||||
gather_facts: False
|
||||
gather_facts: True
|
||||
vars:
|
||||
amp_ssh_key_name: "{{ amp_ssh_key_name }}"
|
||||
amp_ssh_key_path: "{{ amp_ssh_key_path }}"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
amp_image_name: "octavia-amphora"
|
||||
amp_image_filename: "/usr/share/openstack-octavia-amphora-images/amphora-x64-haproxy.qcow2"
|
||||
amp_image_name: ""
|
||||
amp_image_filename: ""
|
||||
amp_image_tag: "amphora-image"
|
||||
amp_ssh_key_name: "octavia-ssh-key"
|
||||
amp_ssh_key_path: "/home/stack/.ssh/id_rsa.pub"
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
---
|
||||
- name: check if name is a symlink
|
||||
stat:
|
||||
path: "{{ image_filename }}"
|
||||
register: symlnk_check
|
||||
|
||||
- name: bypass image naming logic if image name is provided (backwards-compatibility)
|
||||
set_fact:
|
||||
amphora_image: "{{ amphora_image_name }}"
|
||||
when: amphora_image_name is defined and not amphora_image_name == ''
|
||||
|
||||
- name: set the actual glance image name if it is a symlink
|
||||
set_fact:
|
||||
amphora_image: "{{ (symlnk_check.stat.lnk_target | basename | splitext)[0] }}"
|
||||
when: amphora_image is not defined and symlnk_check is defined and symlnk_check.stat.islnk
|
||||
|
||||
- name: set the actual glance image name if it is not a symlink
|
||||
set_fact:
|
||||
amphora_image: "{{ (image_file_result.stat.path | basename | splitext)[0] }}"
|
||||
when: amphora_image is not defined and image_file_result.stat.exists and not symlnk_check.stat.islnk
|
||||
|
||||
- name: check there an image in glance already
|
||||
shell: |
|
||||
openstack image show {{ amphora_image }} -c checksum -f value
|
||||
register: glance_results
|
||||
ignore_errors: true
|
||||
|
||||
- name: get md5 from glance if image already exists there
|
||||
set_fact:
|
||||
current_md5: "{{ glance_results.stdout }}"
|
||||
when: glance_results.rc == 0
|
||||
|
||||
- name: determine if the image needs to be replaced
|
||||
set_fact:
|
||||
replace_image: "{{ current_md5 != image_file_result.stat.md5 }}"
|
||||
when: current_md5 is defined
|
||||
|
||||
- name: move existing image if the names match and the md5s are not the same
|
||||
shell: |
|
||||
ts=`openstack image show {{ amphora_image }} -f value -c created_at`
|
||||
ts=${ts//:/}
|
||||
ts=${ts//-/}
|
||||
openstack image set {{ amphora_image }} --name "{{ amphora_image }}_$ts"
|
||||
when: replace_image is defined and replace_image
|
||||
|
||||
- name: decide whether to upload new image
|
||||
set_fact:
|
||||
upload_image: true
|
||||
when: current_md5 is not defined or replace_image
|
||||
|
||||
- name: upload image to glance
|
||||
shell: |
|
||||
openstack image create --disk-format qcow2 --container-format bare --tag {{ amp_image_tag }} \
|
||||
--file {{ image_filename }} {{ amphora_image }}
|
||||
register: image_result
|
||||
changed_when: "image_result.stdout != ''"
|
||||
when: image_file_result.stat.exists and upload_image is defined
|
|
@ -1,18 +1,28 @@
|
|||
---
|
||||
- name: set file if already set by heat variable (backwards-compatibility)
|
||||
set_fact:
|
||||
image_filename: "{{ amp_image_filename }}"
|
||||
when: amp_image_filename is defined and not amp_image_filename == ''
|
||||
|
||||
- name: set location if CentOS
|
||||
set_fact:
|
||||
image_filename: "/usr/share/openstack-octavia-amphora-images/amphora-x64-haproxy.qcow2"
|
||||
when: ansible_distribution == 'CentOS' and not image_filename is defined
|
||||
|
||||
- name: set location if Red Hat
|
||||
set_fact:
|
||||
image_filename: "/usr/share/rhosp-director-images/octavia-amphora.qcow2"
|
||||
when: ansible_distribution == 'RedHat' and not image_filename is defined
|
||||
|
||||
- name: check if amphora image file exists
|
||||
stat:
|
||||
path: "{{ amp_image_filename }}"
|
||||
register: amp_image_file_result
|
||||
- name: upload image to glance
|
||||
shell: |
|
||||
if [[ $(openstack image show {{ amp_image_name }} > /dev/null; echo $?) -eq 1 ]]; then
|
||||
glance image-create --name {{ amp_image_name }} --disk-format qcow2 \
|
||||
--container-format bare --tags {{ amp_image_tag }} --file {{ amp_image_filename }}
|
||||
fi
|
||||
register: image_result
|
||||
changed_when: "image_result.stdout != ''"
|
||||
when: amp_image_file_result.stat.exists == True
|
||||
path: "{{ image_filename }}"
|
||||
follow: true
|
||||
get_md5: true
|
||||
register: image_file_result
|
||||
|
||||
- include_tasks: image_mgmt.yml
|
||||
when: image_file_result.stat.exists
|
||||
|
||||
- name: check if pub key file exists
|
||||
stat: path="{{ amp_ssh_key_path }}"
|
||||
|
|
Loading…
Reference in New Issue