- def upload_cirros_image(deployment_info, context)
- #FIXME: update context status to multirole support: possible situation where one of the
- # roles of node fail but if last status - success, we try to run code below.
- if context.status.has_value?('error')
- Astute.logger.warn "Disabling the upload of disk image because deploy ended with an error"
- return
- end
- controller = deployment_info.find { |n| n['role'] == 'primary-controller' }
- controller = deployment_info.find { |n| n['role'] == 'controller' } unless controller
- if controller.nil?
- Astute.logger.debug("Could not find controller! Possible adding a new node to the existing cluster?")
- return
- end
- cirros_path = case controller['cobbler']['profile']
- when 'centos-x86_64'
- '/opt/vm/cirros-x86_64-disk.img'
- when 'rhel-x86_64'
- '/opt/vm/cirros-x86_64-disk.img'
- when 'ubuntu_1204_x86_64'
- '/usr/share/cirros-testvm/cirros-x86_64-disk.img'
- else
- raise CirrosError, "Unknown system #{controller['cobbler']['profile']}"
- end
- ubuntu_simple_path = 'https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img'
- for image in [{'img_name': 'TestVM', 'img_path': cirros_path, 'disk_format': 'qcow2'},
- {'img_name': 'Ubuntu 14.04 LTS', 'img_path': ubuntu_simple_path, 'disk_format': 'img'}]
- os = {
- 'os_tenant_name' => Shellwords.escape("#{controller['access']['tenant']}"),
- 'os_username' => Shellwords.escape("#{controller['access']['user']}"),
- 'os_password' => Shellwords.escape("#{controller['access']['password']}"),
- 'os_auth_url' => "http://#{controller['management_vip'] || '127.0.0.1'}:5000/v2.0/",
- 'disk_format' => image['disk_format'],
- 'container_format' => 'bare',
- 'public' => 'true',
- 'img_name' => image['img_name'],
- 'os_name' => 'cirros',
- 'img_path' => image['img_path']
- }
- auth_params = "-N #{os['os_auth_url']} \
- -T #{os['os_tenant_name']} \
- -I #{os['os_username']} \
- -K #{os['os_password']}"
- cmd = "/usr/bin/glance #{auth_params} \
- index && \
- (/usr/bin/glance #{auth_params} \
- index | grep #{os['img_name']})"
- response = run_shell_command(context, Array(controller['uid']), cmd)
- if response[:data][:exit_code] == 0
- Astute.logger.debug "Image already added to stack"
- else
- cmd = "/usr/bin/glance #{auth_params} \
- image-create \
- --name \'#{os['img_name']}\' \
- --is-public #{os['public']} \
- --container-format=\'#{os['container_format']}\' \
- --disk-format=\'#{os['disk_format']}\' \
- --property murano_image_info=\'{\"title\": \"Murano Demo\", \"type\": \"cirros.demo\"}\' \
- --file \'#{os['img_path']}\' \
- "
- response = run_shell_command(context, Array(controller['uid']), cmd)
- if response[:data][:exit_code] == 0
- Astute.logger.info("#{context.task_id}: Upload cirros image is done")
- else
- msg = 'Upload cirros image failed'
- Astute.logger.error("#{context.task_id}: #{msg}")
- context.report_and_update_status('nodes' => [
- {'uid' => controller['uid'],
- 'status' => 'error',
- 'error_type' => 'deploy',
- 'role' => controller['role']
- }
- ]
- )
- raise CirrosError, msg
- end
- end
- end
- end