stevedoreize the drivers
I don't expect these to be plugable, mostly just wrapping my head around stevedores codebase. Of note, because of the stevedore-ness, we _must_ install ekko to use it. No longer will it work in the local dir, it must be installed on the system (or in a venv) Change-Id: I5037f6877e623614ef7ecf991b0009f49824ec0a
This commit is contained in:
parent
94bf4209b2
commit
e2ee32ed82
0
ekko/manifest/_drivers/__init__.py
Normal file
0
ekko/manifest/_drivers/__init__.py
Normal file
@ -20,10 +20,10 @@
|
||||
import os
|
||||
from struct import pack
|
||||
|
||||
from ekko.manifest import driver
|
||||
from ekko.manifest import drivers
|
||||
|
||||
|
||||
class OSDKDriver(driver.ManifestDriver):
|
||||
class OSDKManifest(drivers.BaseManifest):
|
||||
|
||||
def initialize(self):
|
||||
with open(self.manifest_file, 'wb', 4096) as f:
|
@ -17,11 +17,11 @@ from contextlib import closing
|
||||
from contextlib import contextmanager
|
||||
import sqlite3
|
||||
|
||||
from ekko.manifest import driver
|
||||
from ekko.manifest import drivers
|
||||
from ekko.manifest import structure
|
||||
|
||||
|
||||
class SQLiteDriver(driver.ManifestDriver):
|
||||
class SQLiteManifest(drivers.BaseManifest):
|
||||
|
||||
def initialize(self):
|
||||
with self.get_conn() as conn:
|
@ -13,35 +13,53 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from oslo_utils import importutils
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
|
||||
def load_manifest_driver(manifest_location, manifest_driver=None):
|
||||
if not manifest_driver:
|
||||
manifest_driver = 'sqlite.SQLiteDriver'
|
||||
|
||||
return importutils.import_object_ns('ekko.manifest',
|
||||
manifest_driver,
|
||||
manifest_location)
|
||||
|
||||
|
||||
class ManifestDriver(object):
|
||||
"""Base class for manifest drivers
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class BaseManifest(object):
|
||||
"""Base class for Manifest drivers
|
||||
|
||||
:params manifest_file: File location for manifest
|
||||
"""
|
||||
|
||||
def __init__(self, manifest_file):
|
||||
self.conn = None
|
||||
self.manifest_file = manifest_file
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_metadata(self):
|
||||
"""Get segments from manifest
|
||||
|
||||
:returns: An object of class manifest.structure.Metadata
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_segments(self):
|
||||
"""Get segments from manifest
|
||||
|
||||
:returns: A generator of with objects of class
|
||||
manifest.structure.Segment
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
@abc.abstractmethod
|
||||
def put_metadata(self, metadata):
|
||||
"""Puts given metadata into manifest
|
||||
|
||||
:params metadata: An object of class manifest.structure.Metadata
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
@abc.abstractmethod
|
||||
def put_segments(self, segments, metadata):
|
||||
"""Puts given segment information into manifest
|
||||
|
||||
:params segments: An interable with objects of class
|
||||
manifest.structure.Segment
|
||||
:params metadata: An object of class manifest.structure.Metadata
|
||||
"""
|
||||
raise NotImplementedError()
|
@ -5,3 +5,4 @@
|
||||
pbr>=1.6
|
||||
six>=1.9.0
|
||||
oslo.utils>=3.2.0 # Apache-2.0
|
||||
stevedore>=1.5.0 # Apache-2.0
|
||||
|
@ -19,6 +19,11 @@ classifier =
|
||||
Programming Language :: Python :: 3.3
|
||||
Programming Language :: Python :: 3.4
|
||||
|
||||
[entry_points]
|
||||
ekko.manifest.drivers =
|
||||
osdk = ekko.manifest._drivers.osdk:OSDKManifest
|
||||
sqlite = ekko.manifest._drivers.sqlite:SQLiteManifest
|
||||
|
||||
[files]
|
||||
packages =
|
||||
ekko
|
||||
|
@ -21,16 +21,9 @@ import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, '/root/ekko/')
|
||||
from ekko.manifest import driver as manifest_driver
|
||||
from ekko.manifest import structure as manifest_structure
|
||||
from six.moves import range
|
||||
|
||||
|
||||
DRIVERS = {
|
||||
'osdk': 'osdk.OSDKDriver',
|
||||
'sqlite': 'sqlite.SQLiteDriver'
|
||||
}
|
||||
from stevedore import driver
|
||||
|
||||
|
||||
def parse_args():
|
||||
@ -68,8 +61,12 @@ def main():
|
||||
print('manifest exists; exiting')
|
||||
return
|
||||
|
||||
manifest = manifest_driver.load_manifest_driver(args.manifest,
|
||||
DRIVERS[args.driver])
|
||||
manifest = driver.DriverManager(
|
||||
namespace='ekko.manifest.drivers',
|
||||
name=args.driver,
|
||||
invoke_on_load=True,
|
||||
invoke_args=[args.manifest]
|
||||
).driver
|
||||
|
||||
size_of_disk = args.backupsize * 1024**3 # Convert GB to B
|
||||
num_of_sectors = int(size_of_disk / 512)
|
||||
|
Loading…
x
Reference in New Issue
Block a user