def DetectStorage(self): """Detects the storage backend. Only AuFS is currently supported. More info : https://docs.docker.com/engine/userguide/storagedriver/ http://jpetazzo.github.io/assets/2015-06-04-deep-dive-into-docker-storage-drivers.html#60 Returns: Storage: a Storage object. Raises: BadStorageException: If the storage backend couldn't be detected. """ if not os.path.isdir(self.docker_directory): error_msg = ('{0:s} is not a Docker directory\n' 'Please specify the Docker\'s directory path.\n' 'hint: python {1:s} -r /var/lib/docker').format( self.docker_directory, sys.argv[0]) raise BadStorageException(error_msg) if os.path.isfile( os.path.join(self.docker_directory, 'repositories-aufs')): # Handles Docker engine storage versions 1.9 and below. return aufs.AufsStorage(docker_directory=self.docker_directory, docker_version=1) elif os.path.isdir(os.path.join(self.docker_directory, u'overlay2')): return overlay.Overlay2Storage( docker_directory=self.docker_directory) elif os.path.isdir(os.path.join(self.docker_directory, 'overlay')): return overlay.OverlayStorage( docker_directory=self.docker_directory) elif os.path.isdir(os.path.join(self.docker_directory, 'aufs')): return aufs.AufsStorage(docker_directory=self.docker_directory) return None
def _SetDockerDirectory(self, docker_path): """Sets the Docker main directory. Args: docker_path(str): the absolute path to the docker directory. Raises: errors.BadStorageException: If the storage backend couldn't be detected. """ self.docker_directory = docker_path if not os.path.isdir(self.docker_directory): err_message = ( '{0:s} is not a Docker directory\n' 'Please specify the Docker\'s directory path.\n' 'hint: de.py -r /var/lib/docker').format(self.docker_directory) raise errors.BadStorageException(err_message) self.containers_directory = os.path.join( self.docker_directory, 'containers') if os.path.isfile( os.path.join(self.docker_directory, 'repositories-aufs')): # TODO: check this agains other storages in version 1.9 and below self.docker_version = 1 self.storage_object = aufs.AufsStorage( docker_directory=self.docker_directory, docker_version=1) elif os.path.isdir(os.path.join(self.docker_directory, 'overlay2')): self.storage_object = overlay.Overlay2Storage( docker_directory=self.docker_directory) elif os.path.isdir(os.path.join(self.docker_directory, 'overlay')): self.storage_object = overlay.OverlayStorage( docker_directory=self.docker_directory) elif os.path.isdir(os.path.join(self.docker_directory, 'aufs')): self.storage_object = aufs.AufsStorage( docker_directory=self.docker_directory) if self.storage_object is None: err_message = ( 'Could not detect storage system. ' 'Make sure the docker directory ({0:s}) is correct. ' 'If it is correct, you might want to run this script' ' with higher privileges.'.format(self.docker_directory)) raise errors.BadStorageException(err_message)
def testPrettyPrintJSON(self): """Tests the Storage.PrettyPrintJSON function.""" test_storage_object = aufs.AufsStorage() test_dict = {'test': [{'dict1': {'key1': 'val1'}, 'dict2': None}]} test_json = json.dumps(test_dict) expected_string = ( '{\n "test": [\n {\n "dict1": {\n' ' "key1": "val1"\n }, \n' ' "dict2": null\n }\n ]\n}') self.assertEqual(expected_string, test_storage_object._PrettyPrintJSON(test_json))
def DetectStorage(self): """Detects the storage backend. More info : https://docs.docker.com/engine/userguide/storagedriver/ http://jpetazzo.github.io/assets/2015-06-04-deep-dive-into-docker-storage-drivers.html#60 Raises: BadStorageException: If the storage backend couldn't be detected. """ if not os.path.isdir(self.docker_directory): error_msg = ('{0:s} is not a Docker directory\n' 'Please specify the Docker\'s directory path.\n' 'hint: de.py -r /var/lib/docker').format( self.docker_directory) raise BadStorageException(error_msg) if os.path.isfile( os.path.join(self.docker_directory, 'repositories-aufs')): # Handles Docker engine storage versions 1.9 and below. self.storage_object = aufs.AufsStorage( docker_directory=self.docker_directory, docker_version=1) elif os.path.isdir(os.path.join(self.docker_directory, 'overlay2')): self.storage_object = overlay.Overlay2Storage( docker_directory=self.docker_directory) elif os.path.isdir(os.path.join(self.docker_directory, 'overlay')): self.storage_object = overlay.OverlayStorage( docker_directory=self.docker_directory) elif os.path.isdir(os.path.join(self.docker_directory, 'aufs')): self.storage_object = aufs.AufsStorage( docker_directory=self.docker_directory) if self.storage_object is None: err_message = ( 'Could not detect storage system. ' 'Make sure the docker directory ({0:s}) is correct. ' 'If it is correct, you might want to run this script' ' with higher privileges.'.format(self.docker_directory)) raise BadStorageException(err_message)