1. def upload_cirros_image(deployment_info, context)
  2. #FIXME: update context status to multirole support: possible situation where one of the
  3. # roles of node fail but if last status - success, we try to run code below.
  4. if context.status.has_value?('error')
  5. Astute.logger.warn "Disabling the upload of disk image because deploy ended with an error"
  6. return
  7. end
  8. controller = deployment_info.find { |n| n['role'] == 'primary-controller' }
  9. controller = deployment_info.find { |n| n['role'] == 'controller' } unless controller
  10. if controller.nil?
  11. Astute.logger.debug("Could not find controller! Possible adding a new node to the existing cluster?")
  12. return
  13. end
  14. cirros_path = case controller['cobbler']['profile']
  15. when 'centos-x86_64'
  16. '/opt/vm/cirros-x86_64-disk.img'
  17. when 'rhel-x86_64'
  18. '/opt/vm/cirros-x86_64-disk.img'
  19. when 'ubuntu_1204_x86_64'
  20. '/usr/share/cirros-testvm/cirros-x86_64-disk.img'
  21. else
  22. raise CirrosError, "Unknown system #{controller['cobbler']['profile']}"
  23. end
  24. ubuntu_simple_path = 'https://cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img'
  25. for image in [{'img_name': 'TestVM', 'img_path': cirros_path, 'disk_format': 'qcow2'},
  26. {'img_name': 'Ubuntu 14.04 LTS', 'img_path': ubuntu_simple_path, 'disk_format': 'img'}]
  27. os = {
  28. 'os_tenant_name' => Shellwords.escape("#{controller['access']['tenant']}"),
  29. 'os_username' => Shellwords.escape("#{controller['access']['user']}"),
  30. 'os_password' => Shellwords.escape("#{controller['access']['password']}"),
  31. 'os_auth_url' => "http://#{controller['management_vip'] || '127.0.0.1'}:5000/v2.0/",
  32. 'disk_format' => image['disk_format'],
  33. 'container_format' => 'bare',
  34. 'public' => 'true',
  35. 'img_name' => image['img_name'],
  36. 'os_name' => 'cirros',
  37. 'img_path' => image['img_path']
  38. }
  39. auth_params = "-N #{os['os_auth_url']} \
  40. -T #{os['os_tenant_name']} \
  41. -I #{os['os_username']} \
  42. -K #{os['os_password']}"
  43. cmd = "/usr/bin/glance #{auth_params} \
  44. index && \
  45. (/usr/bin/glance #{auth_params} \
  46. index | grep #{os['img_name']})"
  47. response = run_shell_command(context, Array(controller['uid']), cmd)
  48. if response[:data][:exit_code] == 0
  49. Astute.logger.debug "Image already added to stack"
  50. else
  51. cmd = "/usr/bin/glance #{auth_params} \
  52. image-create \
  53. --name \'#{os['img_name']}\' \
  54. --is-public #{os['public']} \
  55. --container-format=\'#{os['container_format']}\' \
  56. --disk-format=\'#{os['disk_format']}\' \
  57. --property murano_image_info=\'{\"title\": \"Murano Demo\", \"type\": \"cirros.demo\"}\' \
  58. --file \'#{os['img_path']}\' \
  59. "
  60. response = run_shell_command(context, Array(controller['uid']), cmd)
  61. if response[:data][:exit_code] == 0
  62. Astute.logger.info("#{context.task_id}: Upload cirros image is done")
  63. else
  64. msg = 'Upload cirros image failed'
  65. Astute.logger.error("#{context.task_id}: #{msg}")
  66. context.report_and_update_status('nodes' => [
  67. {'uid' => controller['uid'],
  68. 'status' => 'error',
  69. 'error_type' => 'deploy',
  70. 'role' => controller['role']
  71. }
  72. ]
  73. )
  74. raise CirrosError, msg
  75. end
  76. end
  77. end
  78. end