Init commit
diff --git a/baremetal_simulator/init.sls b/baremetal_simulator/init.sls
new file mode 100644
index 0000000..9efdd0f
--- /dev/null
+++ b/baremetal_simulator/init.sls
@@ -0,0 +1,141 @@
+{%- from "baremetal_simulator/map.jinja" import baremetal_simulator with context %}
+{%- if baremetal_simulator.enabled %}
+
+simulator_pkgs:
+ pkg.installed:
+ - names: {{ baremetal_simulator.pkgs }}
+
+simulator_pip_pkgs:
+ pip.installed:
+ - names: {{ baremetal_simulator.pip_pkgs }}
+ - require:
+ - pkg: python-pip
+
+libvirt-bin:
+ service.running:
+ - watch:
+ - file: /etc/libvirt/qemu.conf
+
+cgroup:
+ file.append:
+ - name: /etc/libvirt/qemu.conf
+ - source: salt://ironic/files/qemu-cgroup.conf
+
+brbm:
+ openvswitch_bridge.present
+
+brbm-phy:
+ cmd.run:
+ - names:
+ - ip addr add {{ baremetal_simulator.brbm_net.ip }}/{{ baremetal_simulator.brbm_net.prefix }} dev brbm-phy
+ - ip link set dev brbm-phy up || true
+ - ip link set dev ovs-brbm up || true
+ - ip link add ovs-brbm type veth peer name brbm-phy || true
+ - unless: ip addr show dev brbm-phy |grep -q {{ baremetal_simulator.brbm_net.ip }}
+
+ovs-brbm_in_ovs:
+ openvswitch_port.present:
+ - name: ovs-brbm
+ - bridge: brbm
+ - require:
+ - brbm-phy
+
+brbm-to-ovs:
+ cmd.run:
+ - names:
+ - ovs-vsctl --may-exist add-port br-int brint-brbm -- set Interface brint-brbm type=patch options:peer=brbm-brint
+ - ovs-vsctl --may-exist add-port brbm brbm-brint -- set Interface brbm-brint type=patch options:peer=brint-brbm
+ - unless: (ovs-vsctl show |grep -q "Port brint-brbm") && (ovs-vsctl show |grep -q "Port brbm-brint")
+
+default_pool:
+ cmd.run:
+ - name: virsh pool-define-as --name default dir --target /var/lib/libvirt/images && virsh pool-autostart default && virsh pool-start default
+ - unless: virsh pool-info default
+
+/var/log/ironic-bm-logs/:
+ file.directory:
+ - makedirs: true
+
+deploy_ramdisk:
+ file.managed:
+ - name: {{ baremetal_simulator.http_root }}/{{ baremetal_simulator.deploy_ramdisk_file }}
+ - source: {{ baremetal_simulator.deploy_ramdisk_ref }}
+ - skip_verify: true
+
+deploy_kernel:
+ file.managed:
+ - name: {{ baremetal_simulator.http_root }}/{{ baremetal_simulator.deploy_kernel_file }}
+ - source: {{ baremetal_simulator.deploy_kernel_ref }}
+ - skip_verify: true
+
+{%- if baremetal_simulator.cirros_image_ref is defined %}
+
+{{ baremetal_simulator.cirros_image_name }}_file:
+ file.managed:
+ - name: {{ baremetal_simulator.http_root }}/{{ baremetal_simulator.cirros_image_name }}
+ - source: {{ baremetal_simulator.cirros_image_ref }}
+ - skip_verify: true
+
+{%- endif %}
+
+{%- for identity_name, nodes in baremetal_simulator.nodes.iteritems() %}
+ {%- for node in nodes %}
+
+disk_create_node{{ loop.index }}:
+ cmd.run:
+ - name: virsh vol-create-as default {{ node.name }}.qcow2 --capacity {{ node.properties.local_gb }}G --format qcow2
+ - unless: test -f /var/lib/libvirt/images/{{ node.name }}.qcow2
+
+vm_{{ node.name }}_present:
+ cmd.run:
+ - name: virsh undefine {{ node.name }} && sleep 1; virsh define /tmp/{{ node.name }}.xml
+ - onchanges:
+ - file: /tmp/{{ node.name }}.xml
+
+/tmp/{{ node.name }}.xml:
+ file.managed:
+ - source: salt://baremetal_simulator/files/vm.xml
+ - template: jinja
+ - defaults:
+ node: {{ node }}
+
+vbcm_add_{{ node.name }}:
+ cmd.run:
+ - name: vbmc add {{ node.name }} --port {{ node.driver_info.ipmi_port }}
+ - unless: vbmc show {{ node.name }}
+
+vbmc_start_{{ node.name }}:
+ cmd.run:
+ - name: vbmc start {{ node.name }} > /dev/null 2>&1 && sleep 1
+ - unless: vbmc show {{ node.name }} | grep status |grep -q running
+
+node_{{ node.name }}_present:
+ ironicng.node_present:
+ - name: {{ node.name }}
+ - driver: {{ node.driver }}
+ - properties: {{ node.properties }}
+ - profile: {{ identity_name }}
+ - driver_info: {{ node.driver_info }}
+
+{%- for port in node.ports %}
+
+{{ node.name }}_tap_device_{{ loop.index }}:
+ cmd.run:
+ - name: ip tuntap add dev tap-{{ node.name }}i{{ loop.index }} mode tap; ip link set dev tap-{{ node.name }}i{{ loop.index }} up
+ - unless: ip link show tap-{{ node.name }}i{{ loop.index }}
+
+{{ node.name }}_tap{{ loop.index }}_in_ovs:
+ openvswitch_port.present:
+ - name: tap-{{ node.name }}i{{ loop.index }}
+ - bridge: brbm
+
+{{ node.name }}_port{{ loop.index }}_present:
+ ironicng.port_present:
+ - address: {{ port.address }}
+ - node_name: {{ node.name }}
+ - profile: {{ identity_name }}
+{%- endfor %}
+
+{%- endfor %}
+{%- endfor %}
+{%- endif %}