Exemplo n.º 1
0
 def _make_dir(self, method, *args, **kwargs):
     """Creates a directory in the datastore."""
     ds_path = kwargs.get("name")
     if _db_content.get("files", None) is None:
         raise exception.NoFilesFound()
     if get_file(ds_path):
         raise error_util.FileAlreadyExistsException()
     _db_content["files"].append('%s/' % ds_path)
Exemplo n.º 2
0
 def _search_ds(self, method, *args, **kwargs):
     """Searches the datastore for a file."""
     ds_path = kwargs.get("datastorePath")
     if _db_content.get("files", None) is None:
         raise exception.NoFilesFound()
     for file in _db_content.get("files"):
         if file.find(ds_path) != -1:
             task_mdo = create_task(method, "success")
             return task_mdo.obj
     task_mdo = create_task(method, "error")
     return task_mdo.obj
Exemplo n.º 3
0
def _remove_file(file_path):
    """Removes a file reference from the db."""
    if _db_content.get("files") is None:
        raise exception.NoFilesFound()
    # Check if the remove is for a single file object or for a folder
    if file_path.find(".vmdk") != -1:
        if file_path not in _db_content.get("files"):
            raise exception.FileNotFound(file_path=file_path)
        _db_content.get("files").remove(file_path)
    else:
        # Removes the files in the folder and the folder too from the db
        for file in _db_content.get("files"):
            if file.find(file_path) != -1:
                lst_files = _db_content.get("files")
                if lst_files and lst_files.count(file):
                    lst_files.remove(file)
Exemplo n.º 4
0
 def _search_ds(self, method, *args, **kwargs):
     """Searches the datastore for a file."""
     # TODO(garyk): add support for spec parameter
     ds_path = kwargs.get("datastorePath")
     if _db_content.get("files", None) is None:
         raise exception.NoFilesFound()
     matched_files = set()
     # Check if we are searching for a file or a directory
     directory = False
     dname = '%s/' % ds_path
     for file in _db_content.get("files"):
         if file == dname:
             directory = True
             break
     # A directory search implies that we must return all
     # subdirectories
     if directory:
         for file in _db_content.get("files"):
             if file.find(ds_path) != -1:
                 if not file.endswith(ds_path):
                     path = file.lstrip(dname).split('/')
                     if path:
                         matched_files.add(path[0])
         if not matched_files:
             matched_files.add('/')
     else:
         for file in _db_content.get("files"):
             if file.find(ds_path) != -1:
                 matched_files.add(ds_path)
     if matched_files:
         result = DataObject()
         result.path = ds_path
         result.file = []
         for file in matched_files:
             matched = DataObject()
             matched.path = file
             result.file.append(matched)
         task_mdo = create_task(method, "success", result=result)
     else:
         task_mdo = create_task(method, "error", error_fault=FileNotFound())
     return task_mdo.obj
Exemplo n.º 5
0
def get_file(file_path):
    """Check if file exists in the db."""
    if _db_content.get("files") is None:
        raise exception.NoFilesFound()
    return file_path in _db_content.get("files")
Exemplo n.º 6
0
 def _make_dir(self, method, *args, **kwargs):
     """Creates a directory in the datastore."""
     ds_path = kwargs.get("name")
     if _db_content.get("files", None) is None:
         raise exception.NoFilesFound()
     _db_content["files"].append(ds_path)