New version of salt-formula from Saltstack
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

133 linhas
3.4KB

  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_{{ cluster_name }}:
  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 seed = node.get('seed', cluster.get('seed', True)) %}
  40. {%- set cluster_cloud_init = cluster.get('cloud_init', {}) %}
  41. {%- set node_cloud_init = node.get('cloud_init', {}) %}
  42. {%- set cloud_init = salt['grains.filter_by']({'default': cluster_cloud_init}, merge=node_cloud_init) %}
  43. salt_control_virt_{{ cluster_name }}_{{ node_name }}:
  44. module.run:
  45. - name: virtng.init
  46. - m_name: {{ node_name }}.{{ cluster.domain }}
  47. - cpu: {{ size.cpu }}
  48. - mem: {{ size.ram }}
  49. - image: {{ node.image }}
  50. - start: True
  51. - disk: {{ size.disk_profile }}
  52. - nic: {{ size.net_profile }}
  53. {%- if node.rng is defined %}
  54. - rng: {{ node.rng }}
  55. {%- elif rng is defined %}
  56. - rng: {{ rng }}
  57. {%- endif %}
  58. {%- if node.loader is defined %}
  59. - loader: {{ node.loader }}
  60. {%- endif %}
  61. {%- if node.machine is defined %}
  62. - machine: {{ node.machine }}
  63. {%- endif %}
  64. {%- if node.cpuset is defined %}
  65. - cpuset: {{ node.cpuset }}
  66. {%- endif %}
  67. {%- if node.cpu_mode is defined %}
  68. - cpu_mode: {{ node.cpu_mode }}
  69. {%- endif %}
  70. - kwargs:
  71. {%- if cluster.config is defined %}
  72. config: {{ cluster.config }}
  73. {%- endif %}
  74. {%- if cloud_init and cloud_init.get('enabled', True) %}
  75. cloud_init: {{ cloud_init }}
  76. {%- endif %}
  77. {%- if seed %}
  78. seed: {{ seed }}
  79. {%- endif %}
  80. serial_type: pty
  81. console: True
  82. {%- if node.enable_vnc is defined %}
  83. enable_vnc: {{ node.enable_vnc }}
  84. {%- else %}
  85. enable_vnc: {{ enable_vnc }}
  86. {%- endif %}
  87. {%- if node.img_dest is defined %}
  88. img_dest: {{ node.img_dest }}
  89. {%- endif %}
  90. {%- if node.mac is defined %}
  91. {%- for mac_name, mac in node.mac.items() %}
  92. {{ mac_name }}_mac: {{ mac }}
  93. {%- endfor %}
  94. {%- endif %}
  95. - unless: virsh list --all --name| grep -E "^{{ node_name }}.{{ cluster.domain }}$"
  96. - require:
  97. - salt_libvirt_service_{{ cluster_name }}
  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 %}