# Copyright (C) 2015 Kristoffer Gronlund
#
# License: GNU General Public License (GPL)
version: 2.2
shortdesc: STONITH for libvirt (kvm / Xen)
longdesc: >
  Uses libvirt as a STONITH device to fence a guest node.
  Create a separate resource for each guest node in the cluster.

  Note that the recommended fencing mechanism is SBD whenever
  a shared storage device (like a SAN) is available.
category: Stonith
parameters:
  - name: id
    shortdesc: Resource ID (Name)
    example: stonith-libvirt
    required: true
    type: resource
  - name: target
    shortdesc: Node to Manage With STONITH Device
    type: resource
    required: true
  - name: hostlist
    shortdesc: "List of controlled hosts: hostname[:domain_id].."
    longdesc: >
      The optional domain_id defaults to the hostname.
    type: string
    required: true
  - name: hypervisor_uri
    longdesc: >
      URI for connection to the hypervisor.
      driver[+transport]://[username@][hostlist][:port]/[path][?extraparameters]
      e.g.
      qemu+ssh://my_kvm_server.mydomain.my/system   (uses ssh for root)
      xen://my_kvm_server.mydomain.my/              (uses TLS for client)

      virsh must be installed (e.g. libvirt-client package) and access control must
      be configured for your selected URI.
    example: qemu+ssh://my_kvm_server.example.com/system
    required: true
  - name: reset_method
    required: false
    example: power_cycle
    type: string
    shortdesc: Guest Reset Method
    longdesc: >
      A guest reset may be done by a sequence of off and on commands
      (power_cycle) or by the reboot command. Which method works
      depend on the hypervisor and guest configuration management.
  - name: install
    shortdesc: Enable to Install Required Packages
    type: boolean
    required: false
    value: false
actions:
  - install: cluster-glue libvirt-client
    nodes: all
    when: install
  - cib: |
      primitive {{id}}-{{target}} stonith:external/libvirt
        params
          hostlist="{{hostlist}}"
          hypervisor_uri="{{hypervisor_uri}}"
          {{#reset_method}}reset_method="{{reset_method}}"{{/reset_method}}
        op start timeout=60s
      location l-{{id}}-{{target}} {{id}}-{{target}} -inf: {{target}}
