def __init__(self, conf): self.volumes = VolumeHelper(conf) self.exports = ExportHelper(conf) self.backups = BackupHelper(conf) self.cgroups = CgroupHelper(conf) self.api_server = conf.string('storage', 'api_server', "http://localhost:8080") self.api_retry = conf.int('storage', 'api_retry', 1) # name of node registration self.name = conf.string('storage', 'name', socket.gethostname()) self.affinity_group = conf.string('storage', 'affinity_group', '') # management interface self.management_host = conf.string('server:main', 'host', '0.0.0.0') if self.management_host == '0.0.0.0': self.management_host = my_ip(self.api_server) self.management_port = conf.int('server:main', 'port', 8081) # storage interface self.storage_host = conf.string('storage', 'host', '127.0.0.1') self.storage_port = conf.int('storage', 'port', 3260) self.volume_type = conf.string('storage', 'volume_type', 'vtype') # cinder self.cinder_args = cinderclient.get_args(conf) self.rax_auth = conf.bool('cinder', 'rax_auth', True) if self.rax_auth: self.client = cinderclient.CinderClient(**self.cinder_args) self.cinder_host = conf.string('storage', 'cinder_host', self.management_host)
def __init__(self): # Give our sub command a name self._name = 'tools' # Create a volume helper with our local storage config self.volume = VolumeHelper(LunrConfig.from_storage_conf()) # let the base class setup methods in our class SubCommand.__init__(self) self.total = defaultdict(float)
def backup(self, id=None, src=None, timestamp=None): """ This runs a backup job outside of the storage api, which is useful for performance testing backups """ # Set basic Logging logging.basicConfig() # Get the lunr logger log = logger.get_logger() # Output Debug level info log.logger.setLevel(logging.DEBUG) # Load the local storage configuration conf = LunrConfig.from_storage_conf() # If no time provided, use current time timestamp = timestamp or time() # Init our helpers volume = VolumeHelper(conf) backup = BackupHelper(conf) try: # Create the snapshot snapshot = volume.create_snapshot(src, id, timestamp) # For testing non-snapshot speeds #snapshot = volume.get(src) #snapshot['backup_id'] = id #snapshot['origin'] = src #snapshot['timestamp'] = 1338410885.0 #del snapshot['volume'] print("Created snap-shot: ", pprint(snapshot)) with self.timeit(snapshot['size']): # Backup the snapshot print("Starting Backup") backup.save(snapshot, id) finally: # Delete the snapshot if it was created if 'snapshot' in locals(): self._remove_volume(snapshot['path'])
def clone(self, id=None, src=None, backup=None, size=None): """ This runs a clone job outside of the storage api, which is useful for performance testing backup restores (Example: storage tools clone volume-clone --backup volume-backup --src volume-original) """ # Set basic Logging logging.basicConfig() # Get the lunr logger log = logger.get_logger() # Output Debug level info log.logger.setLevel(logging.DEBUG) # Load the local storage configuration conf = LunrConfig.from_storage_conf() # Init the volume helper volume = VolumeHelper(conf) # Attempt to figure out the original volume size size = size or str(volume.get(src)['size'] / 1073741824) # Size is in gigs if not re.match('G', size): size = size + 'G' # Create a tag to apply to the lvm volume tag = encode_tag(source_volume_id=src, backup_id=backup) # Create the volume execute('lvcreate', volume.volume_group, name=id, size=size, addtag=tag) # Get info for the newly created volume new = volume.get(id) with self.timeit(): print("Starting Backup") # Restore volume from the backup volume.clone(new, src, backup)
def setUp(self): IetTest.setUp(self) self.tempdir = mkdtemp() self.conf = self.config(self.tempdir) self.volume = VolumeHelper(self.conf)