def unparse(self, config, configuration): threads_setting = config_lookup(config, THREADS) if threads_setting is not None: configuration.threads = config_setting_get_int(threads_setting) nbcores_setting = config_lookup(config, NBCORES) if nbcores_setting is not None: configuration.nbcores = config_setting_get_int(nbcores_setting) storio_setting = config_lookup(config, STORIO) if storio_setting is not None: configuration.storio = config_setting_get_string(storio_setting) listen_settings = config_lookup(config, LISTEN) configuration.listens = [] for i in range(config_setting_length(listen_settings)): listen_setting = config_setting_get_elem(listen_settings, i) addr_setting = config_setting_get_member(listen_setting, LISTEN_ADDR) addr = config_setting_get_string(addr_setting) port_setting = config_setting_get_member(listen_setting, LISTEN_PORT) port = config_setting_get_int(port_setting) configuration.listens.append(ListenConfig(addr, port)) storage_settings = config_lookup(config, STORAGES) configuration.storages = {} for i in range(config_setting_length(storage_settings)): storage_setting = config_setting_get_elem(storage_settings, i) cid_setting = config_setting_get_member(storage_setting, STORAGE_CID) cid = config_setting_get_int(cid_setting) sid_setting = config_setting_get_member(storage_setting, STORAGE_SID) sid = config_setting_get_int(sid_setting) root_setting = config_setting_get_member(storage_setting, STORAGE_ROOT) root = config_setting_get_string(root_setting) configuration.storages[(cid, sid)] = StorageConfig(cid, sid, root)
def unparse(self, config, configuration): # layout_setting = config_lookup(config, LAYOUT) # if (layout_setting == None): # raise Exception("Wrong format: no layout defined.") # # configuration.layout = config_setting_get_int(layout_setting) port_settings = config_lookup(config, PORTS) configuration.ports = [] for i in range(config_setting_length(port_settings)): configuration.ports.append(config_setting_get_int_elem(port_settings, i)) storage_settings = config_lookup(config, STORAGES) # if (storage_settings == None): # raise Exception(get_config.error_text) configuration.storages = {} for i in range(config_setting_length(storage_settings)): storage_setting = config_setting_get_elem(storage_settings, i) cid_setting = config_setting_get_member(storage_setting, STORAGE_CID) cid = config_setting_get_int(cid_setting) sid_setting = config_setting_get_member(storage_setting, STORAGE_SID) sid = config_setting_get_int(sid_setting) root_setting = config_setting_get_member(storage_setting, STORAGE_ROOT) root = config_setting_get_string(root_setting) configuration.storages[(cid, sid)] = StorageConfig(cid, sid, root)
def unparse(self, config, configuration): layout_setting = config_lookup(config, LAYOUT) if layout_setting == None: raise Exception("wrong format: no layout defined.") configuration.layout = config_setting_get_int(layout_setting) volumes_setting = config_lookup(config, VOLUMES) # if volumes_setting == None: # raise Exception(config.error_text) configuration.volumes = {} if volumes_setting is not None: for i in range(config_setting_length(volumes_setting)): volume_setting = config_setting_get_elem(volumes_setting, i) vid_setting = config_setting_get_member(volume_setting, VOLUME_VID) vid = config_setting_get_int(vid_setting) clusters_setting = config_setting_get_member(volume_setting, VOLUME_CIDS) clusters = {} for j in range(config_setting_length(clusters_setting)): cluster_setting = config_setting_get_elem(clusters_setting, j) cid_setting = config_setting_get_member(cluster_setting, VOLUME_CID) cid = config_setting_get_int(cid_setting) storages = {} sids_setting = config_setting_get_member(cluster_setting, VOLUME_SIDS) for k in range(config_setting_length(sids_setting)): storage_setting = config_setting_get_elem(sids_setting, k) sid_setting = config_setting_get_member(storage_setting, VOLUME_SID) sid = config_setting_get_int(sid_setting) host_setting = config_setting_get_member(storage_setting, VOLUME_HOST) host = config_setting_get_string(host_setting) storages[sid] = host clusters[cid] = ClusterConfig(cid, storages) configuration.volumes[vid] = VolumeConfig(vid, clusters) export_settings = config_lookup(config, EXPORTS) # if export_settings == None: # raise Exception(config.error_text) configuration.exports = {} if export_settings is not None: for i in range(config_setting_length(export_settings)): export_setting = config_setting_get_elem(export_settings, i) eid_setting = config_setting_get_member(export_setting, EXPORT_EID) eid = config_setting_get_int(eid_setting) vid_setting = config_setting_get_member(export_setting, VOLUME_VID) vid = config_setting_get_int(vid_setting) root_setting = config_setting_get_member(export_setting, EXPORT_ROOT) root = config_setting_get_string(root_setting) md5_setting = config_setting_get_member(export_setting, EXPORT_MD5) md5 = config_setting_get_string(md5_setting) sqt_setting = config_setting_get_member(export_setting, EXPORT_SQUOTA) sqt = config_setting_get_string(sqt_setting) hqt_setting = config_setting_get_member(export_setting, EXPORT_HQUOTA) hqt = config_setting_get_string(hqt_setting) configuration.exports[eid] = ExportConfig(eid, vid, root, md5, sqt, hqt)
def unparse(self, config, configuration): listen_settings = config_lookup(config, LISTEN) configuration.listens = [] for i in range(config_setting_length(listen_settings)): listen_setting = config_setting_get_elem(listen_settings, i) addr_setting = config_setting_get_member(listen_setting, LISTEN_ADDR) addr = config_setting_get_string(addr_setting) port_setting = config_setting_get_member(listen_setting, LISTEN_PORT) port = config_setting_get_int(port_setting) configuration.listens.append(ListenConfig(addr, port)) storage_settings = config_lookup(config, STORAGES) configuration.storages = {} for i in range(config_setting_length(storage_settings)): storage_setting = config_setting_get_elem(storage_settings, i) cid_setting = config_setting_get_member(storage_setting, STORAGE_CID) cid = config_setting_get_int(cid_setting) sid_setting = config_setting_get_member(storage_setting, STORAGE_SID) sid = config_setting_get_int(sid_setting) root_setting = config_setting_get_member(storage_setting, STORAGE_ROOT) root = config_setting_get_string(root_setting) configuration.storages[(cid, sid)] = StorageConfig(cid, sid, root)
def unparse(self, config, configuration): nbcores_setting = config_lookup(config, NBCORES) if nbcores_setting is not None: configuration.nbcores = config_setting_get_int(nbcores_setting) layout_setting = config_lookup(config, LAYOUT) if layout_setting == None: raise Exception("wrong format: no layout defined.") configuration.layout = config_setting_get_int(layout_setting) volumes_setting = config_lookup(config, VOLUMES) # if volumes_setting == None: # raise Exception(config.error_text) configuration.volumes = {} if volumes_setting is not None: for i in range(config_setting_length(volumes_setting)): volume_setting = config_setting_get_elem(volumes_setting, i) vid_setting = config_setting_get_member( volume_setting, VOLUME_VID) vid = config_setting_get_int(vid_setting) layout = None volume_layout_setting = config_setting_get_member( volume_setting, LAYOUT) if volume_layout_setting is not None: layout = config_setting_get_int(volume_layout_setting) clusters_setting = config_setting_get_member( volume_setting, VOLUME_CIDS) clusters = {} for j in range(config_setting_length(clusters_setting)): cluster_setting = config_setting_get_elem( clusters_setting, j) cid_setting = config_setting_get_member( cluster_setting, VOLUME_CID) cid = config_setting_get_int(cid_setting) storages = {} sids_setting = config_setting_get_member( cluster_setting, VOLUME_SIDS) for k in range(config_setting_length(sids_setting)): storage_setting = config_setting_get_elem( sids_setting, k) sid_setting = config_setting_get_member( storage_setting, VOLUME_SID) sid = config_setting_get_int(sid_setting) host_setting = config_setting_get_member( storage_setting, VOLUME_HOST) host = config_setting_get_string(host_setting) storages[sid] = host clusters[cid] = ClusterConfig(cid, storages) configuration.volumes[vid] = VolumeConfig( vid, layout, clusters) export_settings = config_lookup(config, EXPORTS) # if export_settings == None: # raise Exception(config.error_text) configuration.exports = {} if export_settings is not None: for i in range(config_setting_length(export_settings)): export_setting = config_setting_get_elem(export_settings, i) eid_setting = config_setting_get_member( export_setting, EXPORT_EID) eid = config_setting_get_int(eid_setting) vid_setting = config_setting_get_member( export_setting, VOLUME_VID) vid = config_setting_get_int(vid_setting) root_setting = config_setting_get_member( export_setting, EXPORT_ROOT) root = config_setting_get_string(root_setting) md5_setting = config_setting_get_member( export_setting, EXPORT_MD5) md5 = config_setting_get_string(md5_setting) sqt_setting = config_setting_get_member( export_setting, EXPORT_SQUOTA) sqt = config_setting_get_string(sqt_setting) hqt_setting = config_setting_get_member( export_setting, EXPORT_HQUOTA) hqt = config_setting_get_string(hqt_setting) configuration.exports[eid] = ExportConfig( eid, vid, root, md5, sqt, hqt)
def unparse(self, config, configuration): nbcores_setting = config_lookup(config, NBCORES) if nbcores_setting is not None: configuration.nbcores = config_setting_get_int(nbcores_setting) layout_setting = config_lookup(config, LAYOUT) if layout_setting is not None: configuration.layout = config_setting_get_int(layout_setting) else: raise SyntaxError("can't lookup key '%s'" % LAYOUT) volumes_setting = config_lookup(config, VOLUMES) configuration.volumes = {} if volumes_setting is not None: for i in range(config_setting_length(volumes_setting)): volume_setting = config_setting_get_elem(volumes_setting, i) vid_setting = config_setting_get_member( volume_setting, VOLUME_VID) if vid_setting is not None: vid = config_setting_get_int(vid_setting) else: raise SyntaxError( "can't lookup key '%s' in volume idx: %d" % (VOLUME_VID, i)) layout = None volume_layout_setting = config_setting_get_member( volume_setting, LAYOUT) if volume_layout_setting is not None: layout = config_setting_get_int(volume_layout_setting) clusters_setting = config_setting_get_member( volume_setting, VOLUME_CIDS) if clusters_setting is not None: clusters = {} for j in range(config_setting_length(clusters_setting)): cluster_setting = config_setting_get_elem( clusters_setting, j) cid_setting = config_setting_get_member( cluster_setting, VOLUME_CID) if cid_setting is not None: cid = config_setting_get_int(cid_setting) else: raise SyntaxError("can't lookup key '%s'" " for volume idx: %d," " cluster idx: %d" % (VOLUME_CID, i, j)) storages = {} sids_setting = config_setting_get_member( cluster_setting, VOLUME_SIDS) if sids_setting is None: raise SyntaxError("can't lookup key '%s'" " for volume idx: %d," " cluster idx: %d" % (VOLUME_SIDS, i, j)) for k in range(config_setting_length(sids_setting)): storage_setting = config_setting_get_elem( sids_setting, k) sid_setting = config_setting_get_member( storage_setting, VOLUME_SID) if sid_setting is not None: sid = config_setting_get_int(sid_setting) else: raise SyntaxError("can't lookup key '%s' for" " volume idx: %d," " cluster idx: %d," " storage idx: %d" % (VOLUME_SID, i, j, k)) host_setting = config_setting_get_member( storage_setting, VOLUME_HOST) if host_setting is not None: host = config_setting_get_string(host_setting) else: raise SyntaxError("can't lookup key '%s' for" " volume idx: %d," " cluster idx: %d," " storage idx: %d" % (VOLUME_HOST, i, j, k)) storages[sid] = host clusters[cid] = ClusterConfig(cid, storages) configuration.volumes[vid] = VolumeConfig( vid, layout, clusters) else: raise SyntaxError( "can't lookup key '%s' in volume idx: %d" % (VOLUME_CIDS, i)) export_settings = config_lookup(config, EXPORTS) configuration.exports = {} if export_settings is not None: for i in range(config_setting_length(export_settings)): export_setting = config_setting_get_elem(export_settings, i) eid_setting = config_setting_get_member( export_setting, EXPORT_EID) if eid_setting is not None: eid = config_setting_get_int(eid_setting) else: raise SyntaxError( "can't lookup key '%s' in export idx: %d" % (EXPORT_EID, i)) vid_setting = config_setting_get_member( export_setting, VOLUME_VID) if vid_setting is not None: vid = config_setting_get_int(vid_setting) else: raise SyntaxError( "can't lookup key '%s' in export idx: %d" % (VOLUME_VID, i)) root_setting = config_setting_get_member( export_setting, EXPORT_ROOT) if root_setting is not None: root = config_setting_get_string(root_setting) else: raise SyntaxError( "can't lookup key '%s' in export idx: %d" % (EXPORT_ROOT, i)) md5_setting = config_setting_get_member( export_setting, EXPORT_MD5) if md5_setting is not None: md5 = config_setting_get_string(md5_setting) else: md5 = '' sqt_setting = config_setting_get_member( export_setting, EXPORT_SQUOTA) if sqt_setting is not None: sqt = config_setting_get_string(sqt_setting) else: sqt = '' hqt_setting = config_setting_get_member( export_setting, EXPORT_HQUOTA) if hqt_setting is not None: hqt = config_setting_get_string(hqt_setting) else: hqt = '' configuration.exports[eid] = ExportConfig( eid, vid, root, md5, sqt, hqt)
def unparse(self, config, configuration): threads_setting = config_lookup(config, THREADS) if threads_setting is not None: configuration.threads = config_setting_get_int(threads_setting) nbcores_setting = config_lookup(config, NBCORES) if nbcores_setting is not None: configuration.nbcores = config_setting_get_int(nbcores_setting) storio_setting = config_lookup(config, STORIO) if storio_setting is not None: configuration.storio = config_setting_get_string(storio_setting) self_healing_setting = config_lookup(config, SELF_HEALING) if self_healing_setting is not None: configuration.self_healing = config_setting_get_int(self_healing_setting) export_hosts_setting = config_lookup(config, EXPORT_HOSTS) if export_hosts_setting is not None: configuration.export_hosts = config_setting_get_string(export_hosts_setting) crc32c_check_setting = config_lookup(config, CRC32C_CHECK) if crc32c_check_setting is not None: configuration.crc32c_check = config_setting_get_bool(crc32c_check_setting) crc32c_gen_setting = config_lookup(config, CRC32C_GENERATE) if crc32c_gen_setting is not None: configuration.crc32c_generate = config_setting_get_bool(crc32c_gen_setting) crc32c_hw_forced_setting = config_lookup(config, CRC32C_HW_FORCED) if crc32c_hw_forced_setting is not None: configuration.crc32c_hw_forced = config_setting_get_bool(crc32c_hw_forced_setting) listen_settings = config_lookup(config, LISTEN) if listen_settings is not None: nb_io_addr = config_setting_length(listen_settings) if nb_io_addr == 0: raise SyntaxError("no IO listen address defined") if nb_io_addr > STORAGE_PORTS_MAX: raise SyntaxError("too many IO listen addresses defined.%d " "while max is %d." % (nb_io_addr, STORAGE_PORTS_MAX)) configuration.listens = [] for i in range(config_setting_length(listen_settings)): listen_setting = config_setting_get_elem(listen_settings, i) if listen_setting is not None: addr_setting = config_setting_get_member(listen_setting, LISTEN_ADDR) if addr_setting is not None: addr = config_setting_get_string(addr_setting) else: raise SyntaxError("can't lookup key '%s' in IO address " "(idx: %d)" % (LISTEN_ADDR, i)) port_setting = config_setting_get_member(listen_setting, LISTEN_PORT) if port_setting is not None: port = config_setting_get_int(port_setting) else: raise SyntaxError("can't lookup key '%s' in IO address " "(idx: %d)" % (LISTEN_PORT, i)) configuration.listens.append(ListenConfig(addr, port)) else: raise SyntaxError("can't fetch IO listen address(es)" " settings (idx: %d)" % i); else: raise SyntaxError("can't fetch '%s' settings" % LISTEN) storage_settings = config_lookup(config, STORAGES) if storage_settings is not None: configuration.storages = {} for i in range(config_setting_length(storage_settings)): storage_setting = config_setting_get_elem(storage_settings, i) cid_setting = config_setting_get_member(storage_setting, STORAGE_CID) if cid_setting is not None: cid = config_setting_get_int(cid_setting) else: raise SyntaxError("can't lookup key '%s' for " "storage (idx: %d)" % (STORAGE_CID, i)) sid_setting = config_setting_get_member(storage_setting, STORAGE_SID) if sid_setting is not None: sid = config_setting_get_int(sid_setting) else: raise SyntaxError("can't lookup key '%s' for " "storage (idx: %d)" % (STORAGE_SID, i)) root_setting = config_setting_get_member(storage_setting, STORAGE_ROOT) if root_setting is not None: root = config_setting_get_string(root_setting) else: raise SyntaxError("can't lookup key '%s' for " "storage (idx: %d)" % (STORAGE_ROOT, i)) device_t_setting = config_setting_get_member(storage_setting, STORAGE_DEV_T) if device_t_setting is not None: device_t = config_setting_get_int(device_t_setting) else: raise SyntaxError("can't lookup key '%s' for " "storage (idx: %d)" % (STORAGE_DEV_T, i)) device_m_setting = config_setting_get_member(storage_setting, STORAGE_DEV_M) if device_m_setting is not None: device_m = config_setting_get_int(device_m_setting) else: raise SyntaxError("can't lookup key '%s' for " "storage (idx: %d)" % (STORAGE_DEV_M, i)) device_r_setting = config_setting_get_member(storage_setting, STORAGE_DEV_R) if device_r_setting is not None: device_r = config_setting_get_int(device_r_setting) else: raise SyntaxError("can't lookup key '%s' for " "storage (idx: %d)" % (STORAGE_DEV_R, i)) configuration.storages[(cid, sid)] = StorageConfig(cid, sid, root, device_t, device_m, device_r ) else: raise SyntaxError("can't fetch '%s' settings" % STORAGES)
def unparse(self, config, configuration): nbcores_setting = config_lookup(config, NBCORES) if nbcores_setting is not None: configuration.nbcores = config_setting_get_int(nbcores_setting) layout_setting = config_lookup(config, LAYOUT) if layout_setting is not None: configuration.layout = config_setting_get_int(layout_setting) else: raise SyntaxError("can't lookup key '%s'" % LAYOUT) volumes_setting = config_lookup(config, VOLUMES) configuration.volumes = {} if volumes_setting is not None: for i in range(config_setting_length(volumes_setting)): volume_setting = config_setting_get_elem(volumes_setting, i) vid_setting = config_setting_get_member(volume_setting, VOLUME_VID) if vid_setting is not None: vid = config_setting_get_int(vid_setting) else: raise SyntaxError("can't lookup key '%s' in volume idx: %d" % (VOLUME_VID, i)) layout = None volume_layout_setting = config_setting_get_member(volume_setting, LAYOUT) if volume_layout_setting is not None: layout = config_setting_get_int(volume_layout_setting) clusters_setting = config_setting_get_member(volume_setting, VOLUME_CIDS) if clusters_setting is not None: clusters = {} for j in range(config_setting_length(clusters_setting)): cluster_setting = config_setting_get_elem(clusters_setting, j) cid_setting = config_setting_get_member(cluster_setting, VOLUME_CID) if cid_setting is not None: cid = config_setting_get_int(cid_setting) else: raise SyntaxError("can't lookup key '%s'" " for volume idx: %d," " cluster idx: %d" % (VOLUME_CID, i, j)) storages = {} sids_setting = config_setting_get_member(cluster_setting, VOLUME_SIDS) if sids_setting is None: raise SyntaxError("can't lookup key '%s'" " for volume idx: %d," " cluster idx: %d" % (VOLUME_SIDS, i, j)) for k in range(config_setting_length(sids_setting)): storage_setting = config_setting_get_elem(sids_setting, k) sid_setting = config_setting_get_member(storage_setting, VOLUME_SID) if sid_setting is not None: sid = config_setting_get_int(sid_setting) else: raise SyntaxError("can't lookup key '%s' for" " volume idx: %d," " cluster idx: %d," " storage idx: %d" % (VOLUME_SID, i, j, k)) host_setting = config_setting_get_member(storage_setting, VOLUME_HOST) if host_setting is not None: host = config_setting_get_string(host_setting) else: raise SyntaxError("can't lookup key '%s' for" " volume idx: %d," " cluster idx: %d," " storage idx: %d" % (VOLUME_HOST, i, j, k)) storages[sid] = host clusters[cid] = ClusterConfig(cid, storages) configuration.volumes[vid] = VolumeConfig(vid, layout, clusters) else: raise SyntaxError("can't lookup key '%s' in volume idx: %d" % (VOLUME_CIDS, i)) export_settings = config_lookup(config, EXPORTS) configuration.exports = {} if export_settings is not None: for i in range(config_setting_length(export_settings)): export_setting = config_setting_get_elem(export_settings, i) eid_setting = config_setting_get_member(export_setting, EXPORT_EID) if eid_setting is not None: eid = config_setting_get_int(eid_setting) else: raise SyntaxError("can't lookup key '%s' in export idx: %d" % (EXPORT_EID, i)) vid_setting = config_setting_get_member(export_setting, VOLUME_VID) if vid_setting is not None: vid = config_setting_get_int(vid_setting) else: raise SyntaxError("can't lookup key '%s' in export idx: %d" % (VOLUME_VID, i)) root_setting = config_setting_get_member(export_setting, EXPORT_ROOT) if root_setting is not None: root = config_setting_get_string(root_setting) else: raise SyntaxError("can't lookup key '%s' in export idx: %d" % (EXPORT_ROOT, i)) md5_setting = config_setting_get_member(export_setting, EXPORT_MD5) if md5_setting is not None: md5 = config_setting_get_string(md5_setting) else: raise SyntaxError("can't lookup key '%s' in export idx: %d" % (EXPORT_MD5, i)) sqt_setting = config_setting_get_member(export_setting, EXPORT_SQUOTA) if sqt_setting is not None: sqt = config_setting_get_string(sqt_setting) else: raise SyntaxError("can't lookup key '%s' in export idx: %d" % (EXPORT_SQUOTA, i)) hqt_setting = config_setting_get_member(export_setting, EXPORT_HQUOTA) if hqt_setting is not None: hqt = config_setting_get_string(hqt_setting) else: raise SyntaxError("can't lookup key '%s' in export idx: %d" % (EXPORT_HQUOTA, i)) configuration.exports[eid] = ExportConfig(eid, vid, root, md5, sqt, hqt)