#SAMWeb Client Python API
Return a list of applications
Arguments:
- SAMWeb Instance
- queryCriteria: A dictionary of key, value pairs
def listApplications(samweb, **queryCriteria)
POST a new application to the SAMWeb instance
Arguments:
- SAMWeb Instance
- family: Application family
- name: Application name
- version: Application version
def addApplication(samweb, family, name, version)
Return a list of all users registered to the SAMWeb instance
Arguments:
- SAMWeb Instance
def listUsers(samweb)
Return details of user from argument 'username' in JSON format
Arguments:
- SAMWeb Instance
- username: SAM username of user registered in SAMWeb Instance
def describeUser(samweb, username)
Return details of users from argument 'username' in text format
Arguments:
- SAMWeb Instance
- username: SAM username of user registered in SAMWeb Instance
def describeUserText(samweb, username)
Add a new user to the SAMWeb Instance
Arguments:
- SAMWeb Instance
- username: SAM username of user to be registered in SAMWeb Instance
- firstname: First name of new user (Default: None)
- lastname: Last name of new user (Default: None)
- email: Email address of new user (Default: None)
- uid: Identification number of new user (Defaults: None)
- groups: Privilege groups the new user is to be registered into (Default: None)
def addUser(samweb, username, firstname=None, lastname=None, email=None, uid=None, groups=None)
Modify an existing SAMWeb user's details
Arguments:
- SAMWeb Instance
- username: SAM username of user to be modified
- **args: Dictionary of key, value pairs corresponding to user options to be modified
def modifyUser(samweb, username, **args)
Returns the names that may be used in calls to listValues() and addValues()
Arguments:
- SAMWeb Instance
def getAvailableValues(samweb)
List values contained in the database
Arguments:
- SAMWeb Instance
- vtype: String with values to return (i.e. data_tiers, groups)
def listValues(samweb, vtype)
Add a new value to the database
Arguments:
- SAMWeb Instance
- vtype: String giving the type of value to add (i.e. data_tiers, groups)
- *args: Arguments to be passed to server
- **kwargs: Keyword arguments to be passed to server
def addValue(samweb, vtype, *args, **kwargs)
Returns a list of the defined parameters
Arguments:
- SAMWeb Instance
def listParameters(samweb)
Lists all the values for a particular parameter
Arguments:
- SAMWeb Instance
- param: Name of the parameter having its values queried
def listParameterValues(samweb, param)
Add a new parameter to the database
Arguments:
- SAMWeb Instance
- name: String that contains name of the new parameter
- data_type: Data type of new parameter
- category: Category of the new parameter (Default: None)
def addParameter(samweb, name, data_type, category=None)
Returns a list of defined data disks
Arguments:
- SAMWeb Instance
def listDataDisks(samweb)
Add a new data disk to the database
Arguments:
- SAMWeb Instance
- mount_point: The path mount point for the new disk
def addDataDisk(samweb, mount_point)
List definitions matching given query parameters
Arguments:
- SAMWeb Instance
- stream: Boolean indicating if results should be returned progressively
- **queryCriteria: Dictionary of key, value pairs containing the terms of the definition query
def listDefinitions(samweb, stream=False, **queryCriteria)
Returns a dictionary with a description of a dataset definition
Arguments:
- SAMWeb Instance
- defname: Name of the definition to be described
def descDefinitionDict(samweb, defname)
Returns a textual description of a dataset definition
Arguments:
- SAMWeb Instance
- defname: Name of the definition to be described
def descDefinition(samweb, defname)
Create a new dataset definition
Arguments:
- SAMWeb Instance
- defname: Name to be assigned to the new dataset definition
- dims: String containg the dimensions of the new definition
- user: Username to be attached to new definition (Default: None)
- group: Group name for the new definition to be assigned to (Default: None)
- description: Description of the new definition (Default: None)
def createDefinition(samweb, defname, dims, user=None, group=None, description=None)
Modify a dataset definition
Arguments:
- SAMWeb Instance
- existing_defname: Name of the definition to be modified
- defname: String containing new name for the modified definition (Default: None)
- description: String containg new description for the definition (Default: None)
def modifyDefinition(samweb, existing_defname, defname=None, description=None)
Delete a dataset definition from the database
Arguments:
- SAMWeb Instance
- defname: Name of the definition to be deleted
def deleteDefinition(samweb, defname)
Create a snapshot of an existing definition
Arguments:
- SAMWeb Instance
- defname: Name of the definition to be snapshotted
- group: Group for the snapshot (Internally defaults to experiment name if none provided)
def takeSnapshot(samweb, defname, group=None)
Return a list of the available dimensions
Arguments:
- SAMWeb Instance
def getAvailableDimensions(samweb)
List files matching either a dataset definition or a dimensions string
Arguments:
- SAMWeb Instance
- dimensions: String containing the dimension to have its files listed (Default: None)
- defname: String containing definition to have its files listed (Default: None)
- fileinfo: Boolean where True indicates file_id, file_size and event_count should be returned
- stream: Boolean with True indicating that files should be delivered progressively
def listFiles(samweb, dimensions=None, defname=None, fileinfo=False, stream=False)
Returns a summary of files matching either a dataset definition or a dimensions string
Arguments:
- SAMWeb Instance
- dimensions: String designating the dimension to be summarized (Default: None)
- defname: String containg the name of the definition to be summarized (Default: None)
def listFilesSummary(samweb, dimensions=None, defname=None)
Expand the given dimensions
Arguments:
- SAMWeb Instance
- dimensions: Dimension to be expanded
def expandDims(samweb, dimensions)
Parse through the given dimensions for debugging purposes
Arguments:
- SAMWeb Instance
- dimensions: A dimensions string
- mode: A string that selects the behavior from 'count', 'summary', 'fileinfo' or 'list'
def parseDims(samweb, dimensions, mode=False)
Return a count of files matching either a dataset definition or a dimensisons string
Arguments:
- SAMWeb Instance
- dimensions: Dimensions to have files counted (Default: None)
- defname: Defintion to have files counted (Default: None)
def countFiles(samweb, dimensions=None, defname=None)
List files and their locations based on location path, dimensions, or defname arguments
Arguments:
- SAMWeb Instance
- filter_path: String or list of strings (Default: None) 3: dimensions: String containg dimensions to be returned (Default: None)
- defname: String containing name of definition to be returned (Default: None)
def listFilesAndLocations(samweb, filter_path=None, dimensions=None, defname=None,
checksums=False, schema=None, structured_output=True)
Return locations for this file
Arguments:
- SAMWeb Instance
- filenameorid: Name or id number of file to be located
def locateFile(samweb, filenameorid)
Returns the locations of multiple files in the form { filenameorid : location }
Arguments:
- SAMWeb Instance
- filenameorids: List of file names or id numbers to be located
def locateFiles(samweb, filenameorids)
Given an iterable of file names or ids, return an iterable object with (name or id, locations) pairs. Convienient wrapper for locateFiles
Arguments:
- SAMWeb Instance
- iterable: Iterable object of file names or identification numbers
- chunksize: The number of files to be queried on each pass
def locateFilesIterator(samweb, iterable, chunksize=50)
Add a SAM location for a file
Arguments:
- SAMWeb Instance
- filenameorid: Name or id number of the file to be added
- location: Location to be added for the file specified by filenameorid
def addFileLocation(samweb, filenameorid, location)
Remove a SAM location for a file
Arguments:
- SAMWeb Instance
- filenameorid: Filename or id number of the file to have its location removed
- location: SAM location to be removed for this file
def removeFileLocation(samweb, filenameorid, location)
Return all the URL's by which the specified file may be accessed
Arguments:
- SAMWeb Instance
- filenameorid: Filename or id number of the file
- schema: A comma seperated list of acceptable protocols (ex. gsiftp, xrootd, ...)
- locationfilter: Only return URL's for files that are contained in the filtered location (Default: None)
def getFileAccessUrls(samweb, filenameorid, schema, locationfilter=None)
Return metadata as a dictionary
Arguments:
- SAMWeb Instance
- filenameorid: Filename or id number of the file having its metadata queried
- locations: Boolean with True value indicating that the location of this file should also be returned (Default: None)
- basic: Boolean with True indicating that only basic metadata should be returned (Default: False)
def getMetadata(samweb, filenameorid, locations=False, basic=False)
Return a list of metadata dictionaries. Returns no result for non-existent files
Arguments:
- SAMWeb Instance
- filenameorids: Filenames or id numbers of files having their metadata queried
- locations: Boolean with True indicating that location data should be included (Default: None)
- asJSON: Boolean with True indicating that the unencoded JSON string should be returned (Default: False) 5: basic: Boolean with True indicating that only basic metadata should be returned (Default: None)
def getMultipleMetadata(samweb, filenameorids, locations=False, asJSON=False, basic=False)
Given an iterable of file names or id numbers, return an iterable object with their metadata. Convenience wrapper around getMultipleMetadata.
Arguments:
- SAMWeb Instance
- iterable: Iterable object of filenames or id numbers.
- locations: Boolean with True indicating that location data should be included (Default: None)
- basic: Boolean with True indicating that only basic metadata should be returned (Default: None)
- chunksize: The number of files to query on each pass (Default: 50)
def getMetadataIterator(samweb, iterable, locations=False, basic=False, chunksize=50)
Return metadata for a file as a string
Arguments:
- SAMWeb Instance
- filenameorid: Filename or id number of the file having its metadata queried
- format: A format string to have return output mapped into (Default: None)
- locations: Boolean with True indicating that location data should be included (Default: None)
- basic: Boolean with True indicating that only basic metadata should be returned (Default: None)
def getMetadataText(samweb, filenameorid, format=None, locations=False, basic=False)
Return lineage information for a file
Arguments:
- SAMWeb Instance
- lineagetype: Options are 'parents' or 'children'
- filenameorid: Filename or id number of the file having its metadata queried
def getFileLineage(samweb, lineagetype, filenameorid)
Check the validity of the metadata
Arguments:
- SAMWeb Instance
- md: Dictionary containing the metadata to be validated (Default: None)
- mdfile: File object containing metadata (Default: None)
def validateFileMetadata(samweb, md=None, mdfile=None)
Declare a new file to this SAMWeb instance
Arguments:
- SAMWeb Instance
- md: Dictionary containing the metadata to be validated (Default: None)
- mdfile: File object containing metadata (Default: None)
def declareFile(samweb, md=None, mdfile=None)
Modify the file metadata for a given file
Arguments:
- SAMWeb Instance
- filename: Name of the file having its file metadata modified
- md: Dictionary containing the metadata to be validated (Default: None)
- mdfile: File object containing metadata (Default: None)
def modifyFileMetadata(samweb, filename, md=None, mdfile=None)
Modify metadata for one or more files. The metadata must be in the form of a list of metadata objects containing the file_name and the fields to change the arguments
Arguments:
- SAMWeb Instance
- md: Dictionary containing the metadata to be validated (Default: None)
- mdfile: File object containing metadata (Default: None)
- continue_on_error: Boolean with True indicating an error in a files metadata will not prevent the other files metadata from being processed (Default: False)
def modifyMetadata(samweb, md=None, mdfile=None, continue_on_error=False)
Retire a file
Arguments:
- SAMWeb Instance
- filename: Name of the file to be retired
def retireFile(samweb, filename)
Verify checksum of local file against what is stored in SAM
Arguments:
- SAMWeb Instance
- path: Either the filename or the path to the physical file. The path must be given if checksum is None
- checksum: A list of checksums to verify against. If given the file will not be opened (Default: None)
- algorithms: A list of preferred algorithms in order (Default: None)
def verifyFileChecksum(samweb, path, checksum=None, algorithms=None)
List projects matching query parameters
Arguments:
- SAMWeb Instance
- stream: Boolean with True indicating that results should be delivered progressively
- queryCriteria: Dictionary containing arguments for project query
def listProjects(samweb, stream=False, **queryCriteria)
Make a suitable project name from the provided string
Arguments:
- SAMWeb Instance
- description: Project description to be using in making a project name
def makeProjectName(samweb, description)
Start a SAM project on the station. Either defname or snapshot_id must be given
Arguments:
- SAMWeb Instance
- project: Project name
- defname: Definition name (Default: None)
- station: Station name (Defaults to experiment name) (Default: None)
- group: Group name (Defaults to experiment name) (Default: None)
- user: User name (Defaults to user name from certificate) (Default: None)
- snapshot_id: ID number of snapshot (Default: None)
def startProject(samweb, project, defname=None, station=None, group=None, user=None, snapshot_id=None)
Return details about a specified project
Arguments:
- SAMWeb Instance
- project: The name of the project to be returned
- station: The station to be queried for the project (Default: None)
def findProject(samweb, project, station=None)
Start a new process
Arguments:
- SAMWeb Instance
- projecturl: The URL of the SAM Project to be started
- appfamily: Application family
- appname: Application name
- appversion: Application version
- deliveryLocation: Location that files will be delivered (Default: None)
- node: Name of node that process will be run on (Default: None)
- user: Name of user (Default: User that owns the certificate being used for authentication)
- maxFiles: Maximum number of files to be delivered to the process (Default: None)
- description: String containing description of the process (Default: None)
- schemas: Comma seperated list of acceptable protocols (ex. gsiftp, xrootd, ...) (Default: None)
def startProcess(samweb, projecturl, appfamily, appname, appversion, deliveryLocation=None,
node=None,user=None, maxFiles=None, description=None, schemas=None)
Make the process URL from a project URL and process ID
Arguments:
- SAMWeb Instance
- projecturl: Project URL
- processid: Process ID
def makeProcessUrl(samweb, projecturl, processid)
Get the next file from the project
Arguments:
- SAMWeb Instance
- processurl: The process URL
- timeout: Timeout after obtaining no files in number of seconds. -1 to disable, 0 to return immediately. (Default: None)
def getNextFile(samweb, processurl, timeout=None)
Release a file that has been processed
Arguments:
- SAMWeb Instance
- processurl: URL for the process that has completed use of the file
- filename: Name of the file that processing has been completed on
- status: If status is 'ok', the file was successfully processed (Default: 'ok')
def releaseFile(samweb, processurl, filename, status="ok")
Sets the status of a file to the value of status
Arguments:
- SAMWeb Instance
- processurl: URL for the process the file belongs to
- filename: Name of the file that is having its status updated
- status: Value containing the new status for the file
def setProcessFileStatus(samweb, processurl, filename, status="consumed")
End an existing process
Arguments:
- SAMWeb Instance
- processurl: The URL of the process that is being ended
def stopProcess(samweb, processurl)
Ends a project
Arguments:
- SAMWeb Instance
- projecturl: URL of the project to be stopped
def stopProject(samweb, projecturl)
Returns a summary of the project in JSON format
Arguments:
- SAMWeb Instance
- projecturl: URL of the project to be summarized
def projectSummary(samweb, projecturl)
Returns a summary of the project in text format
Arguments:
- SAMWeb Instance
- projecturl: URL of the project to be summarized
def projectSummaryText(samweb, projecturl)
Get the dimensions to create a recovery dataset
Arguments:
- SAMWeb Instance
- projectnameorurl: Project name or URL
- useFileStatus: Use the status of the last file seen by a process (Default: None, Valid: [0|1])
- useProcessStatus: Use the status of the process (Default: None, Valid: [0|1])
def projectRecoveryDimension(samweb, projectnameorurl, useFileStatus=None, useProcessStatus=None)
Mark the final status of a process
Arguments:
- SAMWeb Instance
- status: Must be either 'completed' or 'bad'
- projectnameorurl: Project name or URL
- processid: Process identifier (Default: None)
- process_desc: Description of the process (Default: None)
def setProcessStatus(samweb, status, projectnameorurl, processid=None, process_desc=None)
Run a SAM project
Arguments:
- SAMWeb Instance
- projectname: The name for the project (Default: None)
- defname: The definition name to use (Default: None)
- snapshot_id: The ID number of the snapshot to use (Default: None)
- callback: A single argument function invoked on each file (Default: None)
- deliveryLocation: Location that files will be delivered to (Default: None)
- node: Where the job will run (Default: None)
- station: Station that the project will be served files from (Default: None)
- maxFiles: Maximum number of files to be used in the project (Default: 0)
- schemas: Comma seperated list of transfer protocols to be used (ex. gsiftp, xrootd, ...)
- application: A three element sequence of (family, name, version) (Default: ('runproject','runproject',get_version()))
- nparallel: The number of processes to be run in parallel (Default: 1)
- quiet: Boolean with True indicating normal output should be suppressed (Default: False)
def runProject(samweb, projectname=None, defname=None, snapshot_id=None, callback=None,
deliveryLocation=None, node=None, station=None, maxFiles=0, schemas=None,
application=('runproject','runproject',get_version()), nparallel=1, quiet=False )
Prestage the given dataset: Prestaging is not complete until the command exits, so it must continue to run until then
Arguments:
- SAMWeb Instance
- projectname: Name of the project (Default: None)
- defname: Name of the definition (Default: None)
- snapshot_id: ID number of the snapshot to be used (Default: None)
- maxFiles: Maximum number of files to be prestaged (Default: 0)
- station: Station that the files should be staged for (Default: None)
- deliveryLocation: Location that files will be delivered to (Default: None)
- node: Node that the data will be staged on (Default: None)
- nparallel: Number of processes to be run in parallel (Default: 1)
def prestageDataset(samweb, projectname=None, defname=None, snapshot_id=None, maxFiles=0,
station=None, deliveryLocation=None, node=None, nparallel=1)
Returns information about the server
Arguments:
- SAMWeb Instance
- authenticate
- False: Default
- True: Force an SSL connection
def serverInfo(samweb, authenticate=False)