def remove_snap(cdb, sdb, rdb, server, system, serial, snap_name, proxy_host, datacenter, include_hosts, exclude_hosts): ''' Removes a snapshot cdb : credentials db sdb : script db rdb : snap name to replay name db server : Netapp hostname/ip address serial : lun serial system : HP EVA systen name snap_name : the snapshot name proxy_host : proxy host datacenter : vCenter datacenter include_hosts : Regex to include hosts in datacenter exclude_hosts : Regex to exclude hosts in datacenter If unsuccessful, exits the process with non-zero error code, else exits with zero error code. If we are removing a protected snapshot, we un-mount and cleanup the cloned snapshot lun and then remove the snapshot. ''' clone_serial, protected_snap, group = sdb.get_clone_info(serial) # Check if we are removing a protected snapshot if protected_snap == snap_name: # Deleting a protected snap. Un-mount the clone from the proxy host if not unmount_proxy_backup(cdb, sdb, serial, proxy_host, datacenter, include_hosts, exclude_hosts): sys.exit(1) # Delete the snapshot cloned lun delete_lun(cdb, sdb, rdb, server, system, serial) # Remove snapshot vdisk_snapname = rdb.get_snap_info(snap_name)[1] if vdisk_snapname == '': script_log( "The snapshot does not exist in handoff server's DB. Nothing to remove\n." ) sys.exit(1) else: script_log("Snapshot name is " + vdisk_snapname + "\n.") command = 'DELETE VDISK "%s" ' % vdisk_snapname user, pwd = cdb.get_enc_info(server) out, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status != 0: print("Snapshot delete operation failed " + str(err)) sys.exit(1) # Wait for disk to be deleted # script_log("Waiting for " + vdisk_snapname + " snapshot to be removed\n.") # command = 'WAIT_UNTIL VDISK "%s" DELETED ' % vdisk_snapname # out, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) # if status != 0: # print ("Failed to remove snapshot " + str(err)) # sys.exit(1) rdb.delete_snap_info(snap_name) script_log("Snapshot removed\n") sys.exit(0)
def delete_lun(cdb, sdb, rdb, server, system, serial): ''' For the given serial, finds the last cloned lun and deletes it. Note that it does not delete the snapshot, the snapshot is left behind. cdb : credentials db sdb : script db lun_serial : the lun serial for which we find the last cloned lun ''' script_log('Starting LUN removal...') lun_serial, snap_name, accessgroup = sdb.get_clone_info(serial) script_log('LUN serial: %s , snap_name: %s, accessgroup: %s' % \ (str(lun_serial.split(':')[-1]), str(snap_name), str(accessgroup))) vdisk_snapname = rdb.get_snap_info(snap_name)[1] if not vdisk_snapname: script_log("No LUN to be removed") return user, pwd = cdb.get_enc_info(server) # Retrieve LUN information command = "ls vdisk %s" % vdisk_snapname objects, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status > 0: print("Failed to query snapshot LUN" + str(err)) return for i in objects: snap_host = i['hostname'] snap_lunnumber = i['lunnumber'] lun_name = snap_host + "\\" + snap_lunnumber # Unmap LUN on the Host command = 'DELETE LUN %s' % lun_name out, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status != 0: print("Failed to unmap snapshot LUN " + str(err)) return script_log("LUN unmap operation succeeded") sdb.delete_clone_info(serial) script_log("LUN %s deleted successfully" % lun_name) return
def delete_lun(cdb, sdb, rdb, server, system, serial): ''' For the given serial, finds the last cloned lun and deletes it. Note that it does not delete the snapshot, the snapshot is left behind. cdb : credentials db sdb : script db lun_serial : the lun serial for which we find the last cloned lun ''' script_log('Starting LUN removal...') lun_serial, snap_name, accessgroup = sdb.get_clone_info(serial) script_log('LUN serial: %s , snap_name: %s, accessgroup: %s' % \ (str(lun_serial.split(':')[-1]), str(snap_name), str(accessgroup))) vdisk_snapname = rdb.get_snap_info(snap_name)[1] if not vdisk_snapname: script_log ("No LUN to be removed") return user, pwd = cdb.get_enc_info(server) # Retrieve LUN information command = "ls vdisk %s" % vdisk_snapname objects, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status > 0: print ("Failed to query snapshot LUN" + str(err)) return for i in objects: snap_host = i['hostname'] snap_lunnumber = i['lunnumber'] lun_name = snap_host + "\\" + snap_lunnumber # Unmap LUN on the Host command = 'DELETE LUN %s' % lun_name out, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status != 0: print ("Failed to unmap snapshot LUN " + str(err)) return script_log("LUN unmap operation succeeded") sdb.delete_clone_info(serial) script_log("LUN %s deleted successfully" % lun_name) return
def remove_snap(cdb, sdb, rdb, server, system, serial, snap_name, proxy_host, datacenter, include_hosts, exclude_hosts): ''' Removes a snapshot cdb : credentials db sdb : script db rdb : snap name to replay name db server : Netapp hostname/ip address serial : lun serial system : HP EVA systen name snap_name : the snapshot name proxy_host : proxy host datacenter : vCenter datacenter include_hosts : Regex to include hosts in datacenter exclude_hosts : Regex to exclude hosts in datacenter If unsuccessful, exits the process with non-zero error code, else exits with zero error code. If we are removing a protected snapshot, we un-mount and cleanup the cloned snapshot lun and then remove the snapshot. ''' clone_serial, protected_snap, group = sdb.get_clone_info(serial) # Check if we are removing a protected snapshot if protected_snap == snap_name: # Deleting a protected snap. Un-mount the clone from the proxy host if not unmount_proxy_backup(cdb, sdb, serial, proxy_host, datacenter, include_hosts, exclude_hosts): sys.exit(1) # Delete the snapshot cloned lun delete_lun(cdb, sdb, rdb, server, system, serial) # Remove snapshot vdisk_snapname = rdb.get_snap_info(snap_name)[1] if vdisk_snapname == '': script_log("The snapshot does not exist in handoff server's DB. Nothing to remove\n.") sys.exit(1) else: script_log("Snapshot name is " + vdisk_snapname + "\n.") command = 'DELETE VDISK "%s" ' % vdisk_snapname user, pwd = cdb.get_enc_info(server) out, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status != 0: print ("Snapshot delete operation failed " + str(err)) sys.exit(1) # Wait for disk to be deleted # script_log("Waiting for " + vdisk_snapname + " snapshot to be removed\n.") # command = 'WAIT_UNTIL VDISK "%s" DELETED ' % vdisk_snapname # out, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) # if status != 0: # print ("Failed to remove snapshot " + str(err)) # sys.exit(1) rdb.delete_snap_info(snap_name) script_log ("Snapshot removed\n") sys.exit(0)
def get_vdisk_name(server, system, wwnid): ''' Gets the volume for the given lun server : HP EVA Management appliance hostname/ip address system : HP EVA Storage System Name wwnid : lun wwn id returns vdisk path ''' command = "find vdisk lunwwid=%s" % wwnid user, pwd = cdb.get_enc_info(server) objects, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status > 0: return "" vdisk_name = "" for i in objects: vdisk_name = i['familyname'] return vdisk_name
def create_snap(cdb, sdb, rdb, server, system, serial, snap_name, access_group, proxy_host, datacenter, include_hosts, exclude_hosts, category, protect_category): ''' Creates a snapshot cdb : credentials db sdb : script db rdb : snap name to replay name db rdb : snap name to replay name db server : hostname/ip address serial : lun serial system : HP EVA systen name snap_name : the snapshot name access_group : the initiator group to which cloned lun is mapped proxy_host : the host on which clone lun is mounted datacenter : VMware Data center include_hosts : Regex for including hosts in datacenter exclude_hosts : Regex for excluding hosts in datacenter category : snapshot category protect_category : the snapshot category for which proxy backup is run Prints the snapshot name on the output if successful and exits the process. If unsuccessful, exits the process with non-zero error code. If the snapshot category matches the protected category, we run data protection for this snapshot. ''' # Check for duplicate requests, these are possible # if Granite Core Crashes or the Handoff host itself crashed script_log('Starting create_snap') rdb_snap_name, replay = rdb.get_snap_info(snap_name) if rdb_snap_name: script_log("Duplicate request") print(snap_name) return wwnid = convert_serial(serial) # Run proxy backup on this snapshot if its category matches # protected snapshot category if category == protect_category: # Un-mount the previously mounted cloned lun from proxy host if unmount_proxy_backup(cdb, sdb, serial, proxy_host, datacenter, include_hosts, exclude_hosts): # Delete the cloned snapshot delete_lun(cdb, sdb, rdb, server, system, serial) # Create a cloned snapshot lun form the snapshot lun_serial = create_lun(cdb, sdb, rdb, server, system, serial, snap_name, access_group) # Mount the snapshot on the proxy host mount_proxy_backup(cdb, sdb, lun_serial, snap_name, access_group, proxy_host, datacenter, include_hosts, exclude_hosts) print(snap_name) return # Else, either the snapshot is not protected # or the proxy unmount operation failed. In such a case # just create the snapshot and do not proxy mount it vdisk_path = get_vdisk_name(server, system, wwnid) if len(vdisk_path) == 0: print("Lun %s not found" % (wwnid)) sys.exit(1) vdisk_snapname = "rvbd_" + snap_name[0:15] #command = 'ADD SNAPSHOT %s VDISK="%s" ALLOCATION_POLICY=DEMAND WORLD_WIDE_LUN_NAME = "%s"' %\ # (vdisk_snapname, vdisk_path, wwnid) command = 'ADD SNAPSHOT %s VDISK="%s" ALLOCATION_POLICY=DEMAND' %\ (vdisk_snapname, vdisk_path) user, pwd = cdb.get_enc_info(server) out, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status != 0: print("Failed to create snapshot " + str(err)) sys.exit(1) rdb.insert_snap_info(snap_name, vdisk_snapname) print(snap_name) sys.exit(0)
def create_lun(cdb, sdb, rdb, server, system, serial, snap_name, accessgroup): ''' Creates a lun out of a snapshot cbd : credentials db sdb : script db server : the storage array serial : the original lun serial snap_name : the name of the snapshot from which lun must be created access_group : initiator group for Netapp, Storage Group for EMC Since this step is run as part of proxy backup, on errors, we exit with status zero so that Granite Core ACKs the Edge. ''' script_log('Starting snapshot LUN mapping') wwnid = convert_serial(serial) # Get VDISK path vdisk_path = get_vdisk_name(server, system, wwnid) if len(vdisk_path) == 0: print("Lun %s not found" % (wwnid)) sys.exit(1) # Take a snapshot vdisk_snapname = "rvbd_" + snap_name[0:15] #command = 'ADD SNAPSHOT %s VDISK="%s" ALLOCATION_POLICY=DEMAND WORLD_WIDE_LUN_NAME = "%s"' %\ # (vdisk_snapname, vdisk_path, wwnid) command = 'ADD SNAPSHOT %s VDISK="%s" ALLOCATION_POLICY=DEMAND' % ( vdisk_snapname, vdisk_path) user, pwd = cdb.get_enc_info(server) out, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status != 0: print("Failed to create snapshot " + str(err)) sys.exit(1) # Wait until Snap is created command = "WAIT_UNTIL VDISK %s GOOD" % vdisk_snapname hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) rdb.insert_snap_info(snap_name, vdisk_snapname) #Get parent Disk LUN number command = "ls vdisk %s" % vdisk_path objects, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status > 0: print("Failed to query parent VDISK LUN #" + str(err)) sys.exit(1) for i in objects: parent_lunnumber = i['lunnumber'] if parent_lunnumber is not None: break if parent_lunnumber is None: print("Failed to query parent VDISK LUN #" + str(err)) sys.exit(1) # Map LUN to the Host command = 'ADD LUN %s VDISK=%s HOST=%s' %\ (parent_lunnumber, vdisk_snapname, accessgroup) user, pwd = cdb.get_enc_info(server) out, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status != 0: print("Failed to map snapshot LUN" + str(err)) sys.exit(1) # Retrieve LUN wwn information command = "ls vdisk %s" % vdisk_snapname objects, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status > 0: print("Failed to query snapshot LUN wwn" + str(err)) sys.exit(1) for i in objects: #snap_host = i['hostname'] #snap_lunnumber = i['lunnumber'] snap_lunid = i['wwlunid'] if snap_lunid is not None: break lun_serial = snap_lunid.strip().replace('-', '') # Store this information in a local database. # This is needed because when you are running cleanup, # the script must find out which cloned lun needs to me un-mapped. script_log('Inserting serial: %s, cloned_lun_serial: %s, snap_name: %s, group: %s' %\ (serial, lun_serial, snap_name, accessgroup)) sdb.insert_clone_info(serial, lun_serial, snap_name, accessgroup) rdb.insert_snap_info(snap_name, vdisk_snapname) return lun_serial
def create_snap(cdb, sdb, rdb, server, system, serial, snap_name, access_group, proxy_host, datacenter, include_hosts, exclude_hosts, category, protect_category): ''' Creates a snapshot cdb : credentials db sdb : script db rdb : snap name to replay name db rdb : snap name to replay name db server : hostname/ip address serial : lun serial system : HP EVA systen name snap_name : the snapshot name access_group : the initiator group to which cloned lun is mapped proxy_host : the host on which clone lun is mounted datacenter : VMware Data center include_hosts : Regex for including hosts in datacenter exclude_hosts : Regex for excluding hosts in datacenter category : snapshot category protect_category : the snapshot category for which proxy backup is run Prints the snapshot name on the output if successful and exits the process. If unsuccessful, exits the process with non-zero error code. If the snapshot category matches the protected category, we run data protection for this snapshot. ''' # Check for duplicate requests, these are possible # if Granite Core Crashes or the Handoff host itself crashed script_log('Starting create_snap') rdb_snap_name, replay = rdb.get_snap_info(snap_name) if rdb_snap_name: script_log("Duplicate request") print (snap_name) return wwnid = convert_serial(serial) # Run proxy backup on this snapshot if its category matches # protected snapshot category if category == protect_category: # Un-mount the previously mounted cloned lun from proxy host if unmount_proxy_backup(cdb, sdb, serial, proxy_host, datacenter, include_hosts, exclude_hosts) : # Delete the cloned snapshot delete_lun(cdb, sdb, rdb, server, system, serial) # Create a cloned snapshot lun form the snapshot lun_serial = create_lun(cdb, sdb, rdb, server, system, serial, snap_name, access_group) # Mount the snapshot on the proxy host mount_proxy_backup(cdb, sdb, lun_serial, snap_name, access_group, proxy_host, datacenter, include_hosts, exclude_hosts) print (snap_name) return # Else, either the snapshot is not protected # or the proxy unmount operation failed. In such a case # just create the snapshot and do not proxy mount it vdisk_path = get_vdisk_name(server, system, wwnid) if len(vdisk_path) == 0: print ("Lun %s not found" % (wwnid)) sys.exit(1) vdisk_snapname = "rvbd_" + snap_name[0:15] #command = 'ADD SNAPSHOT %s VDISK="%s" ALLOCATION_POLICY=DEMAND WORLD_WIDE_LUN_NAME = "%s"' %\ # (vdisk_snapname, vdisk_path, wwnid) command = 'ADD SNAPSHOT %s VDISK="%s" ALLOCATION_POLICY=DEMAND' %\ (vdisk_snapname, vdisk_path) user, pwd = cdb.get_enc_info(server) out, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status != 0: print ("Failed to create snapshot " + str(err)) sys.exit(1) rdb.insert_snap_info(snap_name, vdisk_snapname) print (snap_name) sys.exit(0)
def create_lun(cdb, sdb, rdb, server, system, serial, snap_name, accessgroup): ''' Creates a lun out of a snapshot cbd : credentials db sdb : script db server : the storage array serial : the original lun serial snap_name : the name of the snapshot from which lun must be created access_group : initiator group for Netapp, Storage Group for EMC Since this step is run as part of proxy backup, on errors, we exit with status zero so that Granite Core ACKs the Edge. ''' script_log('Starting snapshot LUN mapping') wwnid = convert_serial(serial) # Get VDISK path vdisk_path = get_vdisk_name(server, system, wwnid) if len(vdisk_path) == 0: print ("Lun %s not found" % (wwnid)) sys.exit(1) # Take a snapshot vdisk_snapname = "rvbd_" + snap_name[0:15] #command = 'ADD SNAPSHOT %s VDISK="%s" ALLOCATION_POLICY=DEMAND WORLD_WIDE_LUN_NAME = "%s"' %\ # (vdisk_snapname, vdisk_path, wwnid) command = 'ADD SNAPSHOT %s VDISK="%s" ALLOCATION_POLICY=DEMAND' % (vdisk_snapname, vdisk_path) user, pwd = cdb.get_enc_info(server) out, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status != 0: print ("Failed to create snapshot " + str(err)) sys.exit(1) # Wait until Snap is created command = "WAIT_UNTIL VDISK %s GOOD" % vdisk_snapname hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) rdb.insert_snap_info(snap_name, vdisk_snapname) #Get parent Disk LUN number command = "ls vdisk %s" % vdisk_path objects, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status > 0: print ("Failed to query parent VDISK LUN #" + str(err)) sys.exit(1) for i in objects: parent_lunnumber = i['lunnumber'] if parent_lunnumber is not None: break if parent_lunnumber is None: print ("Failed to query parent VDISK LUN #" + str(err)) sys.exit(1) # Map LUN to the Host command = 'ADD LUN %s VDISK=%s HOST=%s' %\ (parent_lunnumber, vdisk_snapname, accessgroup) user, pwd = cdb.get_enc_info(server) out, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status != 0: print ("Failed to map snapshot LUN" + str(err)) sys.exit(1) # Retrieve LUN wwn information command = "ls vdisk %s" % vdisk_snapname objects, err, status = hpeva_api.hp_sssu(server, system, user, pwd).run_sssu(command) if status > 0: print ("Failed to query snapshot LUN wwn" + str(err)) sys.exit(1) for i in objects: #snap_host = i['hostname'] #snap_lunnumber = i['lunnumber'] snap_lunid = i['wwlunid'] if snap_lunid is not None: break lun_serial = snap_lunid.strip().replace('-', '') # Store this information in a local database. # This is needed because when you are running cleanup, # the script must find out which cloned lun needs to me un-mapped. script_log('Inserting serial: %s, cloned_lun_serial: %s, snap_name: %s, group: %s' %\ (serial, lun_serial, snap_name, accessgroup)) sdb.insert_clone_info(serial, lun_serial, snap_name, accessgroup) rdb.insert_snap_info(snap_name, vdisk_snapname) return lun_serial