Commit f5991943 authored by Kristian Feldsam's avatar Kristian Feldsam
Browse files

Added cleanup script

Signed-off-by: Kristian Feldsam's avatarKristian Feldsam <>
parent 28cb12a9
#!/usr/bin/env python3
import os
import subprocess
import sys
import re
from drivers import _3par
import pyone
import config
base_path = os.path.abspath(os.path.dirname(sys.argv[0]))
# reset the multipathd wwids file to include only the current devices
subprocess.check_call('multipath -W', shell=True)
except subprocess.CalledProcessError as ex:
raise Exception('Failed to reset wwids', ex)
# read wwids file
wwns = []
with open('/etc/multipath/wwids') as wwids:
for line in wwids:
match ='^/3([^/]+)/$', line)
if match:
wwn =
# Connect to OpenNebula and 3PAR
one = pyone.OneServer(config.ONE['address'], session='%s:%s' % (config.ONE['username'], config.ONE['password']))
volumes = _3par.get_list_of_exported_volumes()
# iterate over wwns
for wwn in wwns:
if wwn in volumes:
name = volumes.get(wwn).get('name')
# flush volume
print('Flushing LUN...')
subprocess.check_call('%s/sh/ %s' % (base_path, wwn), shell=True)
except subprocess.CalledProcessError as ex:
raise Exception('Can not flush LUN', ex)
# unexport volume
print('Unexporting volume %s from backup server...' % name)
_3par.unexport_vv(name, config.EXPORT_HOST)
match = re.match('feldcloud\.one\.([0-9]+)\.vv\.([0-9]+)', name)
if match:
imageId = int(match[1])
snapId = int(match[2])
image =
vmId = image.VMS.ID[0]
vm =
disks = vm.TEMPLATE.get('DISK')
if isinstance(disks, dict):
disks = [disks]
diskId = None
for disk in disks:
if int(disk.get('IMAGE_ID')) == imageId:
diskId = int(disk.get('DISK_ID'))
if diskId is not None:
print('Deleting disk snapshot: vmID:%d diskId:%d snapId:%d' % (vmId, diskId, snapId))
one.vm.disksnapshotdelete(vmId, diskId, snapId)
import logging
import os
import re
import subprocess
import sys
import time
......@@ -45,6 +46,18 @@ def create_snapshot_name(src_name, snap_id):
return name
def get_list_of_exported_volumes():
cmd = ['showvv', '-showcols', 'VV_WWN,Name,CopyOf', '-host', config.EXPORT_HOST]
result = cl._run(cmd)
volumes = {}
for line in result:
if line.startswith('60002AC'):
volume = line.split(',')
volumes[volume[0].lower()] = {'name': volume[1], 'parent': volume[2]}
return volumes
def export_vv(name, host):
# check if VLUN already exists
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment