def set(session, vtrqid, path, spec): """Creates or overwrites a workspace. Args: session (:class:`~velstor.restapi.Session`): Provides security information. vtrqid (int): ID of the vTRQ. path (str): Fully-qualified workspace name. spec (Iterable[str]): Workspace definition Returns: The return value of :func:`~velstor.restapi.fulfill202.fulfill202` """ # validate vtrqid is an int # validate path is a string and is absolute # url = '/'.join([session.base_url(), 'vtrq', 'workspaces', str(vtrqid)]) try: spec = spec if isinstance(spec, str) else ' '.join(spec) r = requests.post(url, json={'name': path, 'spec': json.loads(spec)}) return fulfill202(session, r) except ValueError as e: message = 'Invalid workspace specification: ' + str(e) return synthetic_response(400, 'EINVAL', message)
def list(session): """Retrieves a list of existing jobs. Args: session (:class:`~velstor.restapi.Session`): Provides security information. Returns: The return value of :func:`~velstor.restapi.fulfill202.fulfill202` """ # url = '/'.join([session.base_url(), 'grid/jobs']) r = requests.get(url) return fulfill202(session, r)
def get(session, jobid): """Retrieves details about a grid job. Args: session (:class:`~velstor.restapi.Session`): Provides security information. jobid (str): The job's identifying string. Returns: The return value of :func:`~velstor.restapi.fulfill202.fulfill202` """ # url = '/'.join([session.base_url(), 'grid/job', urlencode(jobid)]) r = requests.get(url) return fulfill202(session, r)
def shutdown(session, vtrqid): """Gracefully shuts down a vTRQ. Args: session (:class:`~velstor.restapi.Session`): Provides security information. vtrqid (int): ID of the vTRQ. Returns: The return value of :func:`~velstor.restapi.fulfill202.fulfill202` """ # validate vtrqid is an integer url = '/'.join([session.base_url(), 'vtrq', 'service', str(vtrqid)]) r = requests.delete(url) return fulfill202(session, r)
def post(session, jobid, vtrq_id, workspace_name): """Posts information about a grid job. Args: session (:class:`~velstor.restapi.Session`): Provides security information. jobid (str): The job's identifying string. vtrq_id (int): The vTRQ of the worksapce name. workspace_name (str): The PeerCache workspace employed by the job. Returns: The return value of :func:`~velstor.restapi.fulfill202.fulfill202` """ # url = '/'.join([session.base_url(), 'grid/job', urlencode(jobid)]) r = requests.post(url, json={ 'workspace_name': workspace_name, 'vtrq_id': vtrq_id }) return fulfill202(session, r)
def get(session, vtrqid, vpid): """Retrieves details about a mounted client file system. Args: session (:class:`~velstor.restapi.Session`): Provides security information. vtrqid (int): ID of the vTRQ. vpid (str): An opaque VP (mounted client file system) identifier. Returns: The return value of :func:`~velstor.restapi.fulfill202.fulfill202` """ # validate vtrqid is an int # validate vpid # url = '/'.join([session.base_url(), 'vtrq/vp', str(vtrqid), vpid]) r = requests.get(url) return fulfill202(session, r)
def get(session, vtrqid, path): """Retrieves a workspace specification. Args: session (:class:`~velstor.restapi.Session`): Provides security information. vtrqid (int): ID of the vTRQ. path (str): Fully-qualified workspace name. Returns: The return value of :func:`~velstor.restapi.fulfill202.fulfill202` """ # validate vtrqid is an int # validate path is a string and is absolute # url = '/'.join([session.base_url(), 'vtrq', 'workspaces', str(vtrqid), urlencode(path)]) r = requests.get(url) return fulfill202(session, r)
def list(session, vtrqid, path): """Returns names of the child nodes of a vtrq path. Args: session (:class:`~velstor.restapi.Session`): Provides security information. vtrqid (int): ID of the vTRQ. path (str): Fully-qualified namespace path. Returns: The return value of :func:`~velstor.restapi.fulfill202.fulfill202` """ # validate vtrqid is an int # validate path is a string and is absolute url = '/'.join([session.base_url(), 'vtrq', 'namespace', str(vtrqid), urlencode(path), 'children']) r = requests.get(url, timeout=5.0) return fulfill202(session, r)
def delete(session, vtrqid, path, recursive): """Removes a namespace node. Args: session (:class:`~velstor.restapi.Session`): Provides security information. vtrqid (int): ID of the vTRQ. path (str): Fully-qualified namespace path. recursive (bool): When True, a subtree will removed. Otherwise, only leafs will be removed. Returns: The return value of :func:`~velstor.restapi.fulfill202.fulfill202` """ # validate vtrqid is an int # validate path is a string and is absolute url = '/'.join([session.base_url(), 'vtrq', 'namespace', str(vtrqid), urlencode(path)]) r = requests.delete(url, params={'recursive': recursive}) return fulfill202(session, r)
def mkdir(session, vtrqid, mode, parents, path): """Creates a directory on the vtrq. Args: session (:class:`~velstor.restapi.Session`): Provides security information. vtrqid (int): ID of the vTRQ. path (str): Fully-qualified namespace path. Returns: The return value of :func:`~velstor.restapi.fulfill202.fulfill202` """ # validate vtrqid is an int # validate path is a string and is absolute # validate recursive is boolean url = '/'.join([session.base_url(), 'vtrq', 'namespace', str(vtrqid), urlencode(path), 'mkdir']) r = requests.post(url, params={'mode': mode, 'parents': parents}) return fulfill202(session, r)
def find(session, vtrqid, vp_host, mount_point): """Returns a filtered list of VP identifiers. Args: session (:class:`~velstor.restapi.Session`): Provides security information. vtrqid (int): ID of the vTRQ. vp_host (str): The client hostname to match. mount_point (str): The path on the client host at which the VP is mounted. Returns: The return value of :func:`~velstor.restapi.fulfill202.fulfill202` """ # validate vtrqid is an int # validate vpid # url = '/'.join([session.base_url(), 'vtrq/vp', str(vtrqid)]) r = requests.get(url, params={'vp_host': vp_host, 'mount_point': mount_point}) return fulfill202(session, r)
def list(session, vtrqid, path): """Returns the names at a workspace path. The names may represent workspaces or nodes of the hierarchy. Args: session (:class:`~velstor.restapi.Session`): Provides security information. vtrqid (int): ID of the vTRQ. path (str): Fully-qualified workspace path. Returns: The return value of :func:`~velstor.restapi.fulfill202.fulfill202` """ # validate vtrqid is an int # validate path is a string and is absolute # url = '/'.join([session.base_url(), 'vtrq', 'workspaces', str(vtrqid), urlencode(path), 'children']) r = requests.get(url) return fulfill202(session, r)
def copy_vector(session, vtrqid, pairs, overwrite): """Performs one or more meta-data copies on the vtrq. Args: session (:class:`~velstor.restapi.Session`): Provides security information. vtrqid (int): ID of the vTRQ. pairs (list): A list of (source, destination) pairs. overwrite (bool): When true, an existing destination is overwritten with 'cp -r' semantics; otherwise, the pair is skipped. Returns: The return value of :func:`~velstor.restapi.fulfill202.fulfill202` """ # validate vtrqid is an int # validate pairs is an array # validate overwrite is boolean url = '/'.join([session.base_url(), 'vtrq', 'meta_copy', str(vtrqid)]) r = requests.post(url, params={'overwrite': overwrite}, json={'copy_paths': pairs}) return fulfill202(session, r)