Example #1
0
def RegisterFile(Service=None, FileName=None, ProvisionedSpace="10G"):

    if Service  is None:
	raise StorageError('RegisterFile(): Service can not be None')

    if FileName is None:
	raise StorageError('RegisterFile(): FileName can not be None')

    vfilespace = StringSizeToBytes(ProvisionedSpace)
    
    if Service.freespace - vfilespace > 0:
	NewFile = File()
	NewFile.vfilename 	= FileName
        NewFile.ufid		= GetUniqueFileID(FileName)
	NewFile.pfilesize	= 0
        NewFile.vfilesize	= vfilespace
	NewFile.service		= Service
	NewFile.pfilename	= GetPhysicalFileName(Service.localpath, FileName)
	NewFile.status		= 'O'
	NewFile.save()
	
	SFreeSpace = CalculateFreeSpace(Service)
	Service.freespace = SFreeSpace
	Service.save()

	return NewFile
    else:
	raise StorageError('RegisterFile(): No have left space')
Example #2
0
def TakeOwnership(Service=None, FileName=None):
    if Service is None:
	raise StorageError('TakeOwnership(): Service can not be None')

    if FileName is None:
	raise StorageError('TakeOwnership(): FileName can not be None')

    if FileExist(Service.localpath,FileName,True):
	NewFile = File()
	NewFile.vfilename	= FileName
	NewFile.pfilename	= FileName
	NewFile.ufid		= GetUniqueFileID(FileName)
	NewFile.service		= Service
	NewFile.status		= 'O'
	NewFile.vfilesize	= 0
	NewFile.pfilesize	= 0
	NewFile.save()
	CloseFile(NewFile.ufid)
	return NewFile
    else:
	raise StorageError('TakeOwnership(): File not exit [%s%s]' % (Service.localpath+FileName))