New version of salt-formula from Saltstack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.1KB

  1. {% from "salt/map.jinja" import control with context %}
  2. {%- if control.enabled and control.virt_enabled is defined %}
  3. include:
  4. - salt.minion
  5. salt_control_virt_packages:
  6. pkg.installed:
  7. - names: {{ control.virt_pkgs }}
  8. {% if grains.oscodename == 'trusty' %}
  9. {#- This tool is not available in newer releases #}
  10. update-guestfs-appliance:
  11. cmd.wait:
  12. - watch:
  13. - pkg: salt_control_virt_packages
  14. {%- endif %}
  15. {%- for cluster_name, cluster in control.cluster.iteritems() %}
  16. {%- if cluster.engine == "virt" %}
  17. salt_libvirt_service:
  18. service.running:
  19. - name: {{ control.virt_service }}
  20. - enable: true
  21. {%- if grains.get('noservices') %}
  22. - onlyif: /bin/false
  23. {%- endif %}
  24. ##Posibility to disable rng device globally for old libvirt version
  25. {%- if cluster.rng is defined %}
  26. {%- set rng = cluster.rng %}
  27. {%- endif %}
  28. {%- for node_name, node in cluster.node.iteritems() %}
  29. {%- if node.name is defined %}
  30. {%- set node_name = node.name %}
  31. {%- endif %}
  32. {%- if node.provider == grains.id %}
  33. {%- set size = control.size.get(node.size) %}
  34. {%- set cluster_cloud_init = cluster.get('cloud_init', {}) %}
  35. {%- set node_cloud_init = node.get('cloud_init', {}) %}
  36. {%- set cloud_init = salt['grains.filter_by']({'default': cluster_cloud_init}, merge=node_cloud_init) %}
  37. salt_control_virt_{{ cluster_name }}_{{ node_name }}:
  38. module.run:
  39. - name: virtng.init
  40. - m_name: {{ node_name }}.{{ cluster.domain }}
  41. - cpu: {{ size.cpu }}
  42. - mem: {{ size.ram }}
  43. - image: {{ node.image }}
  44. - start: True
  45. - disk: {{ size.disk_profile }}
  46. - nic: {{ size.net_profile }}
  47. {%- if node.rng is defined %}
  48. - rng: {{ node.rng }}
  49. {%- elif rng is defined %}
  50. - rng: {{ rng }}
  51. {%- endif %}
  52. {%- if node.loader is defined %}
  53. - loader: {{ node.loader }}
  54. {%- endif %}
  55. {%- if node.machine is defined %}
  56. - machine: {{ node.machine }}
  57. {%- endif %}
  58. {%- if node.cpu_mode is defined %}
  59. - cpu_mode: {{ node.cpu_mode }}
  60. {%- endif %}
  61. - kwargs:
  62. {%- if cloud_init is defined %}
  63. cloud_init: {{ cloud_init }}
  64. {%- endif %}
  65. seed: True
  66. serial_type: pty
  67. console: True
  68. {%- if node.img_dest is defined %}
  69. img_dest: {{ node.img_dest }}
  70. {%- endif %}
  71. {%- if node.mac is defined %}
  72. {%- for mac_name, mac in node.mac.items() %}
  73. {{ mac_name }}_mac: {{ mac }}
  74. {%- endfor %}
  75. {%- endif %}
  76. - unless: virsh list --all --name| grep -E "^{{ node_name }}.{{ cluster.domain }}$"
  77. - require:
  78. - salt_libvirt_service
  79. #salt_control_seed_{{ cluster_name }}_{{ node_name }}:
  80. # module.run:
  81. # - name: seed.apply
  82. # - path: /srv/salt-images/{{ node_name }}.{{ cluster.domain }}/system.qcow2
  83. # - id_: {{ node_name }}.{{ cluster.domain }}
  84. # - unless: virsh list | grep {{ node_name }}.{{ cluster.domain }}
  85. {%- if node.get("autostart", True) %}
  86. salt_virt_autostart_{{ cluster_name }}_{{ node_name }}:
  87. module.run:
  88. - name: virt.set_autostart
  89. - vm_: {{ node_name }}.{{ cluster.domain }}
  90. - state: true
  91. - unless: virsh list --autostart --name| grep -E "^{{ node_name }}.{{ cluster.domain }}$"
  92. {%- endif %}
  93. {%- endif %}
  94. {%- endfor %}
  95. {%- endif %}
  96. {%- endfor %}
  97. {%- endif %}