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.

134 lines
3.5KB

  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. {%- if cluster.enable_vnc is defined and cluster.enable_vnc %}
  29. {%- set enable_vnc = True %}
  30. {%- else %}
  31. {%- set enable_vnc = False %}
  32. {%- endif %}
  33. {%- for node_name, node in cluster.node.iteritems() %}
  34. {%- if node.name is defined %}
  35. {%- set node_name = node.name %}
  36. {%- endif %}
  37. {%- if node.provider == grains.id %}
  38. {%- set size = control.size.get(node.size) %}
  39. {%- set cluster_cloud_init = cluster.get('cloud_init', {}) %}
  40. {%- set node_cloud_init = node.get('cloud_init', {}) %}
  41. {%- set cloud_init = salt['grains.filter_by']({'default': cluster_cloud_init}, merge=node_cloud_init) %}
  42. salt_control_virt_{{ cluster_name }}_{{ node_name }}:
  43. module.run:
  44. - name: virtng.init
  45. - m_name: {{ node_name }}.{{ cluster.domain }}
  46. - cpu: {{ size.cpu }}
  47. - mem: {{ size.ram }}
  48. - image: {{ node.image }}
  49. - start: True
  50. - disk: {{ size.disk_profile }}
  51. - nic: {{ size.net_profile }}
  52. {%- if node.rng is defined %}
  53. - rng: {{ node.rng }}
  54. {%- elif rng is defined %}
  55. - rng: {{ rng }}
  56. {%- endif %}
  57. {%- if node.loader is defined %}
  58. - loader: {{ node.loader }}
  59. {%- endif %}
  60. {%- if node.machine is defined %}
  61. - machine: {{ node.machine }}
  62. {%- endif %}
  63. {%- if node.cpuset is defined %}
  64. - cpuset: {{ node.cpuset }}
  65. {%- endif %}
  66. {%- if node.cpu_mode is defined %}
  67. - cpu_mode: {{ node.cpu_mode }}
  68. {%- endif %}
  69. - kwargs:
  70. {%- if cloud_init is defined %}
  71. cloud_init: {{ cloud_init }}
  72. {%- endif %}
  73. seed: True
  74. serial_type: pty
  75. console: True
  76. {%- if node.enable_vnc is defined %}
  77. enable_vnc: {{ node.enable_vnc }}
  78. {%- else %}
  79. enable_vnc: {{ enable_vnc }}
  80. {%- endif %}
  81. {%- if node.img_dest is defined %}
  82. img_dest: {{ node.img_dest }}
  83. {%- endif %}
  84. {%- if node.mac is defined %}
  85. {%- for mac_name, mac in node.mac.items() %}
  86. {{ mac_name }}_mac: {{ mac }}
  87. {%- endfor %}
  88. {%- endif %}
  89. - unless: virsh list --all --name| grep -E "^{{ node_name }}.{{ cluster.domain }}$"
  90. - require:
  91. - salt_libvirt_service
  92. #salt_control_seed_{{ cluster_name }}_{{ node_name }}:
  93. # module.run:
  94. # - name: seed.apply
  95. # - path: /srv/salt-images/{{ node_name }}.{{ cluster.domain }}/system.qcow2
  96. # - id_: {{ node_name }}.{{ cluster.domain }}
  97. # - unless: virsh list | grep {{ node_name }}.{{ cluster.domain }}
  98. {%- if node.get("autostart", True) %}
  99. salt_virt_autostart_{{ cluster_name }}_{{ node_name }}:
  100. module.run:
  101. - name: virt.set_autostart
  102. - vm_: {{ node_name }}.{{ cluster.domain }}
  103. - state: true
  104. - unless: virsh list --autostart --name| grep -E "^{{ node_name }}.{{ cluster.domain }}$"
  105. {%- endif %}
  106. {%- endif %}
  107. {%- endfor %}
  108. {%- endif %}
  109. {%- endfor %}
  110. {%- endif %}