Instalar y configurar cliente Openstack en RHEL/CentOS/SL 7

instalar_cliente_openstack

Instalar y configurar cliente Openstack en RHEL/CentOS/SL 7

Instalar pre-requisitos

Para instalar las herramientas de cliente de openstack necesitaremos el comando pip, el cual es proveido por el paquete python-pip:

yum install -y python-pip

Instalar cliente openstack

Para instalar utilizaremos el comando pip e instalaremos los paquetes:
– python-openstackclient

pip install python-openstackclient

– python-neutronclient

pip install python-neutronclient

Configurar las variales de entorno

Los clientes de openstack permiten utilizar variables de entorno para no tener que estar especificando los parametros de conexion con cada comando que utilicemos
Estas variables las podemos cargar en el archivo .bashrc del usuario con el que utilizaremos los clientes de openstack

vi .bashrc
# Nombre de la region de Openstack
export OS_REGION_NAME=dc
# Usuario para conectarse a la API
export OS_USERNAME=dca_admin
# Pasword del usuario a utilizar
export OS_PASSWORD=password
# URL del keystone 
export OS_AUTH_URL="https://identity.example.com:443/identity-admin/v2.0"
# Nombre del tenant
export OS_TENANT_NAME=example
# Definicion de los endpoint
export OS_ENDPOINT_TYPE=publicURL
export NOVA_ENDPOINT_TYPE=publicURL
export NETWORK_ENDPOINT_TYPE=publicURL
export VOLUME_ENDPOINT_TYPE=publicURL

# Se definen los alias para agregar el --insecure, 
# la opcion permite conectarnos sin necesidad de que el certificado de nuestro openstack sea valido
alias nova="nova --insecure"
alias neutron="neutron --insecure"
alias cinder="cinder --insecure"

Finalmente para probar podemos ejecutar los siguientes comandos

source .bashrc

nova list
+--------------------------------------+---------------------+--------+------------+-------------+----------------------------------------------------------------------------------+
| ID                                   | Name                | Status | Task State | Power State | Networks                                                                         |
+--------------------------------------+---------------------+--------+------------+-------------+----------------------------------------------------------------------------------+
| cbba125c-96b3-4601-ba8e-341231211211 | COMPUTE1            | ACTIVE | -          | Running     | external_om=172.21.1.1                                                           |
....
+--------------------------------------+---------------------+--------+------------+-------------+----------------------------------------------------------------------------------+

Create oVirt/RHEV’s VM backup

Create backup of oVirt / RHEV’s VMs

[TOC]

Introduction

I’ve been working with oVirt since version 3.5 as main virtualization platform, from day one i were looking for a tool to create VM backups based on snapshot as many solutions does with VMWARE, after some research i didn’t find a tool that fulfilled my requirements so i decided to create one using oVirt python API.

Requirements

  • oVirt >= 4.0
  • Virtual machine with CentOS 7 with this tools installed, we’ll call this VM bkpvm
  • bkpvm should be on the same oVirt Datacenter of the VM we need to take backup of
  • bkpvm should have enought space to store backups
  • Storage Domain should have enought space to take snapshots

How does it work?

This script should run on bkpvm and it connect to oVirt API to do:
– Create snapshot
– Attach disk to bkpvm
– Create a qcow2 file of the VM’s disk
– Delete snapshot

After finish it creates a qcow2 file for each VM’s disk

Instalation

Prerequisites

Install required repositories on bkpvm:

yum install -y epel-release
yum install -y http://resources.ovirt.org/pub/yum-repo/ovirt-release41.rpm

Install required packages from repositories configured:

yum install -y qemu-img python-ovirt-engine-sdk4 python-requests git ovirt-guest-agent wget

Download

cd /opt
git clone https://github.com/vacosta94/VirtBKP.git

We need to get our oVirt’s CA in order to establish secure connections to oVirt API

cd /opt/VirtBKP
wget --insecure "https://ovirt.infratic.com/ovirt-engine/services/pki-resource?resource=ca-certificate&format=X509-PEM-CA"

Usage

Configure

There is a configuration file default.conf inside VirtBKP folder, that file have all the parameters required by the tool. Should modify this file according your environment as follow:

vim /opt/VirtBKP/default.conf
[bkp]
url             = https://ovirt.example.com/ovirt-engine/api
user            = admin@internal
password        = password
ca_file         = ca.crt
bkpvm           = bkpvm
bckdir          = /mnt/

[restore]
url             = https://ovirt.example.com/ovirt-engine/api
user            = admin@internal
password        = password
ca_file         = ca.crt
storage         = gfs_pool0
proxy           = ovirt.example.com
proxyport       = 54323
  • url: oVirt API URL
  • user: User name
  • password: User password
  • ca_file: Path to ca.crt
  • bkpvm: Name of our bkpvm
  • bckdir: Path to store backups in .qcow2 format
  • storage: Storage domain where we’ll restore our backups
  • proxy: IP or hostname of the ovirt-image-proxy host (Default: ovirt-engine)
  • proxyport: TCP port of the ovirt-image-proxy (Default: 54323)

Create backup

In order to create backups of virtual machines you should use the syntax bellow:

/opt/VirtBKP/backup_vm.py <configuration_file> <vm_name>

Example:

/opt/VirtBKP/backup_vm.py /opt/VirtBKP/default.conf webserver

Restore backup

In order to restore an existing backup you should use the syntax bellow:

/opt/VirtBKP/upload_disk.py <configuration_file> <qcow2_file>

Example

/opt/VirtBKP/upload_disk.py /mnt/webserver_2017-04-28-00h.qcow2