diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..b0082cb825739e2d6c145c676ba266e0368e32e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +/config.py diff --git a/backup.py b/backup.py new file mode 100755 index 0000000000000000000000000000000000000000..669a31199543d987866ad09b9915d68aab5d6493 --- /dev/null +++ b/backup.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import argparse +import urllib3 + +import config +import pyone +import functions + +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + +# ---------------------------- +# Define parser +# ---------------------------- +parser = argparse.ArgumentParser(description='OpenNebula Backup Tool') + +parser.add_argument('-i', '--image', help='Image id or comma separated list of image ids to backup.' + 'Omit for backup all images', type=functions.list_of_int_arg) +parser.add_argument('-S', '--startImage', help='Image id to start backup from. Backups all following images' + 'including defined one', type=int) +parser.add_argument('-a', '--datastore', help='Datastore id or comma separated list of datastore ids to backup' + 'from. Omit to backup from all datastores to backup', + type=functions.list_of_int_arg) +parser.add_argument('-l', '--label', help='Label or comma separated list of labels of tagged images or datastores', + type=functions.list_arg) +parser.add_argument('-e', '--exclude', help='Skip (exclude) by label or comma separated list of labels of tagged' + 'images or datastores', type=functions.list_arg) +parser.add_argument('-D', '--deployments', help='Backup also deployments files from system datastores') +parser.add_argument('-d', '--dryRun', help='Dry run - not execute any commands, all cmds will be just printed') +parser.add_argument('-v', '--verbose', help='Verbose mode') + +# ------------------------------------- +# Parse args and proceed with execution +# ------------------------------------- +args = parser.parse_args() + +# ----------------------- +# Connect to OpenNebula +# ----------------------- +one = pyone.OneServer(config.ONE['address'], session='%s:%s' % (config.ONE['username'], config.ONE['password'])) + +imagepool = one.imagepool.info(-2, -1, -1) + +for image in imagepool.IMAGE: + print image.PERSISTENT diff --git a/config.sample.py b/config.sample.py new file mode 100644 index 0000000000000000000000000000000000000000..9311ade6cc76efde9f2255b3af6d8a391e0582a9 --- /dev/null +++ b/config.sample.py @@ -0,0 +1,22 @@ +# OpenNebula XML-RPC API connection details +ONE = { + 'address': 'https://opennebula:2633/RPC2', + 'username': 'user', + 'password': 'pass' +} + +# Path where to save backups on backup server +BACKUP_DIR = '/var/data/backups/' + +# Lock Image and VM during backup +# OpenNebula 5.6+ required +LOCK_RESOURCES = True + +# 3PAR connection details +_3PAR = { + 'api': 'https://3par:8080/api/v1', + 'ip': '3par_ip', + 'username': '3paradm', + 'password': '3pardata', + 'secure': True +} diff --git a/drivers/3par.py b/drivers/3par.py new file mode 100644 index 0000000000000000000000000000000000000000..200fd7c36ad4020f872caff726e5f7b575ac6b6a --- /dev/null +++ b/drivers/3par.py @@ -0,0 +1,16 @@ +from hpe3parclient import client, exceptions +import config + +# ------------------ +# Login to 3PAR +# ------------------ + +cl = client.HPE3ParClient(config._3PAR['api'], config._3PAR['secure']) +cl.setSSHOptions(config._3PAR['ip'], config._3PAR['username'], config._3PAR['password']) + +try: + cl.login(config._3PAR['username'], config._3PAR['password']) +except exceptions.HTTPUnauthorized as ex: + print "Login failed." + +cl.logout() \ No newline at end of file diff --git a/functions.py b/functions.py new file mode 100644 index 0000000000000000000000000000000000000000..d853e497fb9dd2d15ab57577dfca7df94bb007ca --- /dev/null +++ b/functions.py @@ -0,0 +1,10 @@ +def bool_arg(string): + if string != True and string != '1' and string != 'YES': + return False + return True + +def list_of_int_arg(string): + return map(int, string.split(',')) + +def list_arg(string): + return string.split(',') \ No newline at end of file