def create(self, dbg, uri, configuration): log.debug( "%s: xcpng.libsbd.sr.SROperations.create: uri: %s configuration %s" % (dbg, uri, configuration)) if 'bindnetaddr' not in configuration: raise Exception( 'Failed to connect to Sheepdog cluster. Parameter \'bindnetaddr\' is not specified' ) elif 'mcastaddr' not in configuration: raise Exception( 'Failed to connect to Sheepdog cluster. Parameter \'mcastaddr\' is not specified' ) elif 'mcastport' not in configuration: raise Exception( 'Failed to connect to Sheepdog cluster. Parameter \'mcastport\' is not specified' ) sr_uuid = get_sr_uuid_by_uri(dbg, uri) create_chroot(dbg, sr_uuid) set_chroot(dbg, sr_uuid) write_corosync_conf( dbg, sr_uuid, gen_corosync_conf(dbg, configuration['bindnetaddr'], configuration['mcastaddr'], configuration['mcastport'])) start_sheepdog_gateway(dbg, get_sheep_port(dbg, sr_uuid), sr_uuid)
def get_size(self, dbg, uri): log.debug("%s: xcpng.libsbd.sr.SROperations.sr_size: uri: %s" % (dbg, uri)) return int( dog_node_info(dbg, get_sheep_port(dbg, get_sr_uuid_by_uri(dbg, uri)))[1])
def dump(self, dbg, uri, json): log.debug("%s: xcpng.libsbd.meta.MetaDBOpeations.dump: uri: %s" % (dbg, uri)) length = len(json) dog_vdi_write(dbg, get_sheep_port(dbg, get_sr_uuid_by_uri(dbg, uri)), '__meta__', pack("!I%ss" % length, length, json), 0, length + 4)
def get_vdi_list(self, dbg, uri): log.debug("%s: xcpng.libsbd.sr.SROperations.get_vdi_list: uri: %s" % (dbg, uri)) vols = [] for vol in dog_vdi_list( dbg, get_sheep_port(dbg, get_sr_uuid_by_uri(dbg, uri))): if vol.startswith(VDI_PREFIXES[get_vdi_type_by_uri(dbg, uri)]): vols.append(vol) return vols
def load(self, dbg, uri): log.debug("%s: xcpng.libsbd.meta.MetaDBOpeations.load: uri: %s" % (dbg, uri)) sr_uuid = get_sr_uuid_by_uri(dbg, uri) sheep_port = get_sheep_port(dbg, sr_uuid) length = unpack('!I', dog_vdi_read(dbg, sheep_port, '__meta__', 0, 4))[0] data = unpack('!%ss' % length, dog_vdi_read(dbg, sheep_port, '__meta__', 4, length))[0] return data
def create(self, dbg, uri): log.debug("%s: xcpng.libsbd.meta.MetaDBOpeations.create: uri: %s" % (dbg, uri)) data = '{"sr": {}}' sr_uuid = get_sr_uuid_by_uri(dbg, uri) sheep_port = get_sheep_port(dbg, sr_uuid) dog_vdi_create(dbg, sheep_port, '__meta__', '8M') length = len(data) dog_vdi_write(dbg, sheep_port, '__meta__', pack("!I%ss" % length, length, data), 0, length + 4)
def unlock(self, dbg, uri, timeout=10): log.debug("%s: xcpng.libsbd.meta.MetaDBOpeations.unlock: uri: %s" % (dbg, uri)) try: dog_vdi_delattr(dbg, get_sheep_port(dbg, get_sr_uuid_by_uri(dbg, uri)), '__meta__', 'locked') except Exception as e: log.debug( "%s: xcpng.libsbd.meta.MetaDBOpeations.unlock: Failed to unlock MetaDB for uri: %s" % (dbg, uri)) raise Exception(e)
def sr_import(self, dbg, uri, configuration): log.debug( "%s: xcpng.libsbd.sr.SROperations.sr_import: uri: %s configuration %s" % (dbg, uri, configuration)) if 'bindnetaddr' not in configuration: raise Exception( 'Failed to connect to Sheepdog cluster. Parameter \'bindnetaddr\' is not specified' ) elif 'mcastaddr' not in configuration: raise Exception( 'Failed to connect to Sheepdog cluster. Parameter \'mcastaddr\' is not specified' ) elif 'mcastport' not in configuration: raise Exception( 'Failed to connect to Sheepdog cluster. Parameter \'mcastport\' is not specified' ) sr_uuid = get_sr_uuid_by_uri(dbg, uri) create_chroot(dbg, sr_uuid) set_chroot(dbg, sr_uuid) write_corosync_conf( dbg, sr_uuid, gen_corosync_conf(dbg, configuration['bindnetaddr'], configuration['mcastaddr'], configuration['mcastport'])) start_sheepdog_gateway(dbg, get_sheep_port(dbg, sr_uuid), sr_uuid) mkdir_p("%s/%s" % (SR_PATH_PREFIX, get_sr_uuid_by_uri(dbg, uri))) call(dbg, [ 'ln', '-s', "%s/%s/var/lib/sheepdog/sock" % (CHROOT_BASE, get_sr_uuid_by_uri(dbg, uri)), "%s/%s/sock" % (SR_PATH_PREFIX, get_sr_uuid_by_uri(dbg, uri)) ])
def lock(self, dbg, uri, timeout=10): log.debug("%s: xcpng.libsbd.meta.MetaDBOpeations.lock: uri: %s" % (dbg, uri)) start_time = time() while True: try: dog_vdi_setattr(dbg, get_sheep_port(dbg, get_sr_uuid_by_uri(dbg, uri)), '__meta__', 'locked', 'locked', exclusive=True) break except Exception as e: if time() - start_time >= timeout: log.debug( "%s: xcpng.libsbd.meta.MetaDBOpeations.lock: Failed to lock MetaDB for uri: %s" % (dbg, uri)) raise Exception(e) pass
def destroy(self, dbg, uri): log.debug("%s: xcpng.libsbd.meta.MetaDBOpeations.destroy: uri: %s" % (dbg, uri)) dog_vdi_delete(dbg, get_sheep_port(dbg, get_sr_uuid_by_uri(dbg, uri)), '__meta__')
def get_phisical_utilization(self, dbg, uri): volume_meta = self.MetadataHandler.get_vdi_meta(dbg, uri) vdi_name = "%s%s" % (VDI_PREFIXES[get_vdi_type_by_uri(dbg, uri)], volume_meta[IMAGE_UUID_TAG]) vdi_info = dog_vdi_info(dbg, get_sheep_port(dbg, get_sr_uuid_by_uri(dbg, uri)), vdi_name) log.debug("%s: get_phisical_utilization: uri: %s: utilization: %s" % (dbg, uri, vdi_info[4])) return int(vdi_info[4])
def resize(self, dbg, uri, new_size): volume_meta = self.MetadataHandler.get_vdi_meta(dbg, uri) dog_vdi_resize(dbg, get_sheep_port(dbg, get_sr_uuid_by_uri(dbg, uri)), "%s%s" % (VDI_PREFIXES[get_vdi_type_by_uri(dbg, uri)], volume_meta[IMAGE_UUID_TAG]), new_size)
def destroy(self, dbg, uri): volume_meta = self.MetadataHandler.get_vdi_meta(dbg, uri) dog_vdi_delete(dbg, get_sheep_port(dbg, get_sr_uuid_by_uri(dbg, uri)), "%s%s" % (VDI_PREFIXES[get_vdi_type_by_uri(dbg, uri)], volume_meta[IMAGE_UUID_TAG]))