def nfs_add_export( conninfo, credentials, export_path, fs_path, description, restrictions, allow_fs_path_create=False, present_64_bit_fields_as_32_bit=False): method = "POST" allow_fs_path_create_ = "true" if allow_fs_path_create else "false" uri = str(UriBuilder(path="/v2/nfs/exports/", rstrip_slash=False). add_query_param("allow-fs-path-create", allow_fs_path_create_)) share_info = { 'export_path': export_path, 'fs_path': fs_path, 'description': description, 'restrictions': [r.dictionary() for r in restrictions], 'present_64_bit_fields_as_32_bit': present_64_bit_fields_as_32_bit, } return request.rest_request(conninfo, credentials, method, uri, body=share_info)
def nfs_modify_export(conninfo, credentials, id_, export_path, fs_path, description, restrictions, allow_fs_path_create=False, present_64_bit_fields_as_32_bit=False, if_match=None): allow_fs_path_create_ = "true" if allow_fs_path_create else "false" if_match = if_match if if_match is None else if_match method = "PUT" uri = str( UriBuilder(path="/v2/nfs/exports/"). add_path_component(id_). add_query_param("allow-fs-path-create", allow_fs_path_create_)) share_info = { 'id': id_, 'export_path': export_path, 'fs_path': fs_path, 'description': description, 'restrictions': [r.dictionary() for r in restrictions], 'present_64_bit_fields_as_32_bit': present_64_bit_fields_as_32_bit, } return request.rest_request(conninfo, credentials, method, uri, body=share_info, if_match=if_match)
def config_put(conninfo, credentials, install_path, target, override_version=False): ''' Set upgrade config. Warning: override_version allows an unsafe upgrade, which can result in corruption if used improperly. It should never be used on a production system. It is useful when upgrading from a non-release build. ''' req = { 'install_path': str(install_path), 'target': str(target), } method = "PUT" uri = UriBuilder(path="/v1/upgrade/settings") if override_version: uri.add_query_param('override_compatibility_check', 'True') return request.rest_request(conninfo, credentials, method, str(uri), body=req)
def current_activity_get(conninfo, credentials, specific_type=None): method = "GET" uri = UriBuilder(path="/v1/analytics/activity/current") if specific_type: uri.add_query_param('type', specific_type) return request.rest_request(conninfo, credentials, method, str(uri))
def directory(conninfo, credentials, inode_num): method = "GET" uri = str( UriBuilder( path="/v1/debug/inspect/directory").add_path_component(inode_num)) return request.rest_request(conninfo, credentials, method, uri)
def smb_delete_share(conninfo, credentials, id_=None, name=None): assert [id_, name].count(None) == 1 method = "DELETE" uri = str( UriBuilder(path="/v2/smb/shares").add_path_component(id_ or name)) return request.rest_request(conninfo, credentials, method, uri)
def node_specific_quorum(conninfo, credentials, expected_nodes): method = "GET" uri = UriBuilder(path="/v1/node/quorum/specific") uri.add_query_param('nodes', ','.join(expected_nodes)) return request.rest_request(conninfo, credentials, method, str(uri))
def iops_get(conninfo, credentials, specific_type=None): method = 'GET' uri = UriBuilder(path='/v1/analytics/iops') if specific_type: uri.add_query_param('type', specific_type) return request.rest_request(conninfo, credentials, method, str(uri))
def iops_get(conninfo, credentials, specific_type=None): method = "GET" uri = UriBuilder(path="/v1/stats/iops") if specific_type: uri.add_query_param('type', specific_type) return request.rest_request(conninfo, credentials, method, str(uri))
def nfs_delete_export(conninfo, credentials, id_=None, export_path=None): assert [id_, export_path].count(None) == 1 method = "DELETE" uri = str(UriBuilder(path="/v2/nfs/exports/"). add_path_component(id_ or export_path)) return request.rest_request(conninfo, credentials, method, uri)
def delete_quota(conninfo, credentials, id_, if_match=None): method = "DELETE" uri = UriBuilder(path="/v1/files/quotas/{}".format(id_)) return request.rest_request(conninfo, credentials, method, unicode(uri), if_match=if_match)
def get_quota_with_status(conninfo, credentials, id_, if_match=None): method = "GET" uri = UriBuilder(path="/v1/files/quotas/status/{}".format(id_)) return request.rest_request(conninfo, credentials, method, unicode(uri), if_match=if_match)
def __init__(self, initial_url, fn, page_size=None): self.initial_url = initial_url self.rest_request = fn self.page_size = page_size self.uri = UriBuilder(path=initial_url, rstrip_slash=False) if page_size is not None: self.uri.add_query_param("limit", page_size)
def config(conninfo, credentials, use_hex): method = "GET" uri = UriBuilder(path="/v1/debug/inspect/config") if use_hex: uri.add_query_param('hex') return request.rest_request(conninfo, credentials, method, str(uri))
def btree(conninfo, credentials, btree_name, verbose): method = "GET" uri = UriBuilder(path="/v1/debug/inspect/btree") uri.add_path_component(btree_name) if verbose: uri.add_query_param("verbose") return request.rest_request(conninfo, credentials, method, str(uri))
def superblock(conninfo, credentials, use_hex=False): method = "GET" uri = UriBuilder(path="/v1/debug/inspect/superblock") if use_hex: uri.add_query_param('hex') return request.rest_request(conninfo, credentials, method, str(uri))
def paddr(conninfo, credentials, pstore_id, addr): method = "GET" uri = UriBuilder(path="/v1/debug/inspect/paddr") uri.add_path_component(pstore_id) uri.add_path_component(addr) return request.rest_request(conninfo, credentials, method, str(uri))
def dump(conninfo, credentials, file_): method = "GET" uri = str(UriBuilder(path="/v1/debug/trace/dump")) return request.rest_request(conninfo, credentials, method, uri, response_file=file_)
def delete(conninfo, credentials, key, uid): uid = int(uid) method = "DELETE" uri = UriBuilder(path="/v1/kv")\ .add_path_component(uid)\ .add_path_component(key) return request.rest_request(conninfo, credentials, method, str(uri))
def create_quota(conninfo, credentials, id_, limit_in_bytes): body = {'id': str(id_), 'limit': str(limit_in_bytes)} method = "POST" uri = UriBuilder(path="/v1/files/quotas/", rstrip_slash=False) return request.rest_request(conninfo, credentials, method, unicode(uri), body=body)
def config_set(conninfo, credentials, mock, time=None): method = "PUT" uri = str(UriBuilder(path="/v1/debug/mock-clock")) config = { "mock": mock } if mock: config['time'] = time return request.rest_request(conninfo, credentials, method, uri, body=config)
def update_quota(conninfo, credentials, id_, limit_in_bytes, if_match=None): body = {'id': str(id_), 'limit': str(limit_in_bytes)} method = "PUT" uri = UriBuilder(path="/v1/files/quotas/{}".format(id_)) return request.rest_request(conninfo, credentials, method, unicode(uri), body=body, if_match=if_match)
def add_new_disk(conninfo, credentials, slot_id, size): method = "POST" uri = str( UriBuilder(path="/v1/debug/slots").add_path_component( slot_id).add_path_component("add_new_disk")) # size is a 64 bit integer encoded as a string body = { "size": str(size), } return request.rest_request(conninfo, credentials, method, uri, body=body)
def build_files_uri(components, append_slash=False, api_version=1): uri = UriBuilder(path="/v{}/files".format(api_version)) if components: for component in components: uri.add_path_component(component) if append_slash: uri.append_slash() return uri
def point_set(conninfo, credentials, path, program, persist=False): if program: assert program.endswith(';') or program.endswith('}'), \ 'Non-empty program {} must end with ";" or "}}"'.format(program) method = "PUT" uri = str(UriBuilder(path="/v1/debug/fail").add_path_component(path)) config = {'program': program, 'persist': persist} return request.rest_request(conninfo, credentials, method, uri, body=config)
def smb_modify_share(conninfo, credentials, id_=None, old_name=None, share_name=None, fs_path=None, description=None, permissions=None, allow_fs_path_create=False, access_based_enumeration_enabled=None, default_file_create_mode=None, default_directory_create_mode=None, bytes_per_sector=None, if_match=None): assert [id_, old_name].count(None) == 1 allow_fs_path_create_ = "true" if allow_fs_path_create else "false" if_match = None if if_match is None else if_match method = "PATCH" uri = str( UriBuilder(path="/v2/smb/shares/").add_path_component( id_ or old_name).add_query_param("allow-fs-path-create", allow_fs_path_create_)) share_info = {} if share_name is not None: share_info['share_name'] = share_name if fs_path is not None: share_info['fs_path'] = fs_path if description is not None: share_info['description'] = description if permissions is not None: share_info['permissions'] = permissions if access_based_enumeration_enabled is not None: share_info['access_based_enumeration_enabled'] = \ bool(access_based_enumeration_enabled) if default_file_create_mode is not None: share_info['default_file_create_mode'] = \ default_file_create_mode if default_directory_create_mode is not None: share_info['default_directory_create_mode'] = \ default_directory_create_mode if bytes_per_sector is not None: share_info['bytes_per_sector'] = str(bytes_per_sector) return request.rest_request(conninfo, credentials, method, uri, body=share_info, if_match=if_match)
def metatree(conninfo, credentials, inode_num, begin_off=None, end_off=None): method = "GET" uri = UriBuilder(path="/v1/debug/inspect/metatree") uri.add_path_component(inode_num) if begin_off != None: uri.add_query_param('begin', str(begin_off)) if end_off != None: uri.add_query_param('end', str(end_off)) return request.rest_request(conninfo, credentials, method, str(uri))
def put(conninfo, credentials, key, value, uid): uid = int(uid) method = "PUT" uri = UriBuilder(path="/v1/kv").add_path_component(uid)\ .add_path_component(key) config = {'key': key, 'value': value} return request.rest_request(conninfo, credentials, method, str(uri), body=config)
def smb_set_share(conninfo, credentials, id_, share_name, fs_path, description, permissions, allow_fs_path_create=False, access_based_enumeration_enabled=None, default_file_create_mode=None, default_directory_create_mode=None, if_match=None): ''' Replaces all share attributes. The result is a share identical to what would have been produced if the same arguments were given on creation. Note that this means that an unspecified optional argument will result in that attribute being reset to default, even if the share currently has a non-default value. ''' allow_fs_path_create_ = "true" if allow_fs_path_create else "false" id_ = id_ share_info = { 'id': id_, 'share_name': share_name, 'fs_path': fs_path, 'description': description, 'permissions': permissions, } if access_based_enumeration_enabled is not None: share_info['access_based_enumeration_enabled'] = \ bool(access_based_enumeration_enabled) if default_file_create_mode is not None: share_info['default_file_create_mode'] = \ default_file_create_mode if default_directory_create_mode is not None: share_info['default_directory_create_mode'] = \ default_directory_create_mode uri = str( UriBuilder( path="/v2/smb/shares/").add_path_component(id_).add_query_param( "allow-fs-path-create", allow_fs_path_create_)) if_match = None if if_match is None else if_match return request.rest_request(conninfo, credentials, "PUT", uri, body=share_info, if_match=if_match)
def authorize(conninfo, credentials, relationship_id, allow_non_empty_directory=None, allow_fs_path_create=None): method = "POST" uri = UriBuilder(path="/v1/replication/target-relationships/{}/authorize". format(relationship_id)) if allow_non_empty_directory is not None: uri.add_query_param("allow-non-empty-directory", "true" if allow_non_empty_directory else "false") if allow_fs_path_create is not None: uri.add_query_param("allow-fs-path-create", "true" if allow_fs_path_create else "false") return request.rest_request(conninfo, credentials, method, unicode(uri))