import settings,os import ng_openstack.openstackRequest def makeBackup(volumeID,name,description,token): pass def listBackups(projectID,marker="",allBackups=[]): if marker=="": returnData= ng_openstack.openstackRequest.openstackRequest("GET", "v3/"+os.getenv("OS_PROJECT_ID")+"/backups" "/detail?all_tenants=True&project_id="+projectID, "", "http://172.25.110.140:8776").json() else: returnData= ng_openstack.openstackRequest.openstackRequest("GET", "v3/"+os.getenv("OS_PROJECT_ID")+"/backups" "/detail?all_tenants=True&project_id="+projectID+"&marker="+marker, "", "http://172.25.110.140:8776").json() allBackups=allBackups+returnData['backups'] # print("Got {} records".format(len(returnData['backups']))) if len(returnData['backups'])>=1000: #We hit the limt, make another request # print("Making another request {} ".format(returnData['backups'][999]['id'])) nextRequestMarker=returnData['backups'][999]['id'] # print("Len now is {}".format(len(allBackups))) allBackups=listBackups(projectID,nextRequestMarker,allBackups) return allBackups def createBackup(volumeID,backupName,backupDescription,projectID,force=False): # In order to create a backup for another project as admin you must scope the token to that project, # if you don't, the backup will be added in the admin project data = { "backup": { "description": backupDescription, "name": backupName, "volume_id": volumeID, # "incremental": True "force": force } } return ng_openstack.openstackRequest.openstackRequest("POST", "v3/" + projectID + "/backups", data, "http://172.25.110.140:8776",projectID).json() def getAllVolumesPerProject(projectID): return ng_openstack.openstackRequest.openstackRequest("GET","v3/"+os.getenv("OS_PROJECT_ID")+ "/volumes/detail?all_tenants=True&project_id="+projectID,"","http://172.25.110.140:8776").json() def getAllSnapshotsPerProject(projectID): return ng_openstack.openstackRequest.openstackRequest("GET","v3/"+os.getenv("OS_PROJECT_ID")+ "/snapshots/detail?all_tenants=True&project_id="+projectID,"","http://172.25.110.140:8776").json() def printAllVolumesForProject(projectID): allVols = getAllVolumesPerProject("5f320f5f187f416794c30772b5fa2a89") for volume in allVols['volumes']: print("{:20} {:10} {:6}".format(volume['name'], volume['size'], volume['volume_type'])) def logCurrentVolumeUsagetoGnocchi(projectID): pass #Get all volumes for the project #Split them up into types #Save to heliostack_meter def getBackupSizeOnDisk(volumeID): # Reach out to MOR # Run rbd du on the volume ID # Return the size in bytes pass