Cloud and virtualization provisioning

Provision systems on cloud providers or hypervisors and immediately bring the resources under management.

Cloud provisioning

The first step is to add the credentials for your cloud host. Credentials and other settings provided by the cloud host are stored in provider configuration files. Provider configurations contain the details needed to connect to a cloud host such as EC2, GCE, Rackspace, etc., and any global options that you want set on your cloud minions (such as the location of your Salt Master).

my-ec2:
  driver: ec2
  # Set the EC2 access credentials (see below)
  #
  id: 'HJGRYCILJLKJYG'
  key: 'kdjgfsgm;woormgl/aserigjksjdhasdfgn'
  # Make sure this key is owned by root with permissions 0400.
  #
  private_key: /etc/salt/my_test_key.pem
  keyname: my_test_key
  securitygroup: default
  # Optional: Set up the location of the Salt Master
  #
  minion:
    master: saltmaster.example.com

VM profiles creation

On your Salt master, browse to /etc/salt/cloud.profiles.d/ and create a file called <provider>.profiles.conf, replacing <provider> with ec2, softlayer, and so on. The file must end in .conf.

You can now add any custom profiles you’d like to define to this file. Here are a few examples:

micro_ec2:
  provider: my-ec2
  image: ami-d514f291
  size: t1.micro

medium_ec2:
  provider: my-ec2
  image: ami-d514f291
  size: m3.medium

VM operations

VMs are created by calling salt-cloud with the following options:

salt-cloud -p <profile> <name1> <name2> ...

For example:

salt-cloud -p micro_ec2 minion1 minion2

Add a -d and the minion name you provided to destroy:

salt-cloud -d minion1 minion2

Salt-virt provisioning

The main goal of Salt Virt is to facilitate a very fast and simple cloud. The cloud that can scale and fully featured. Salt Virt comes with the ability to set up and manage complex virtual machine networking, powerful image, and disk management, as well as virtual machine migration with and without shared storage.

Setting up hypervisors

The first step to set up the hypervisors involves getting the correct software installed and setting up the hypervisor network interfaces.

This sls will set up the needed software for a hypervisor, and run the routines to set up the libvirt pki keys.

libvirt:
  pkg.installed: []
  file.managed:
    - name: /etc/sysconfig/libvirtd
    - contents: 'LIBVIRTD_ARGS="--listen"'
    - require:
      - pkg: libvirt
  libvirt.keys:
    - require:
      - pkg: libvirt
  service.running:
    - name: libvirtd
    - require:
      - pkg: libvirt
      - network: br0
      - libvirt: libvirt
    - watch:
      - file: libvirt

libvirt-python:
  pkg.installed: []

libguestfs:
  pkg.installed:
    - pkgs:
      - libguestfs
      - libguestfs-tools

The hypervisors will need to be running a network bridge to serve up network devices for virtual machines, this formula will set up a standard bridge on a hypervisor connecting the bridge to eth0:

eth0:
  network.managed:
    - enabled: True
    - type: eth
    - bridge: br0

br0:
  network.managed:
    - enabled: True
    - type: bridge
    - proto: dhcp
    - require:
      - network: eth0

Note

You can use the salt-formula-libvirt

Using salt-virt

Start by running a Salt Virt hypervisor info command:

salt-run virt.hyper_info

This will query what the running hypervisor stats are and display information for all configured hypervisors. This command will also validate that the hypervisors are properly configured.

Now that hypervisors are available a virtual machine can be provisioned. The virt.init routine will create a new virtual machine:

salt-run virt.init ubuntu01 2 512 salt://ubuntu.img

Lab: Salt-virt example setup

Physical nodes for salt-virt testing.

node020
  - salt-master
  - ip: 10.0.174.176
node021
  - salt-minion
  - ip: 10.0.174.90
node022
  - salt-minion
  - ip: 10.0.174.82

Init the for creating new virtual instance on node021.

salt 'node021*' virt.init test01 2 1028 salt://ubuntu-14-04-x64-1455277409.qcow2

Detailed information about this new virtual instance can be obtain by folowing command:

salt 'node021*' virt.vm_info test01

Finally instance can deleted

salt 'node021*' virt.purge test01