def list(platform, args): e_host = platform._active_export_host configurations = platform.get_configurations([e_host], Role.EXPORTD) if configurations[e_host] is None: raise Exception("exportd node is off line.") configuration = configurations[e_host][Role.EXPORTD] export_l = {} list_l = [] for vid, volume in configuration.volumes.items(): volume_l = [] if volume.layout is not None: volume_l.append({'LAYOUT' : volume.layout }) else: volume_l.append({'LAYOUT' : configuration.layout }) for cid, cluster in volume.clusters.items(): cluster_l = [] for sid, storage in cluster.storages.items(): cluster_l.append({'STORAGE ' + str(sid): storage}) volume_l.append({'CLUSTER ' + str(cid): cluster_l}) list_l.append({'VOLUME ' + str(vid): volume_l}) export_l.update({'EXPORTD on ' + str(e_host): list_l}) ordered_puts(export_l)
def get(platform, args): e_host = platform._active_export_host configurations = platform.get_configurations([e_host], Role.EXPORTD) configuration = configurations[e_host][Role.EXPORTD] # Check exception if isinstance(configuration, Exception): raise type(configuration)(str(configuration)) eids_l = [] if not args.eids: eids_l = configuration.exports.keys() else: eids_l = args.eids list_l = {} exports_l = [] for eid in eids_l: if eid not in configuration.exports: raise Exception("Unknown export with eid=%d." % eid) econfig = configuration.exports[eid] export_l = [] export_l.append({'vid': econfig.vid}) export_l.append({'root': econfig.root}) export_l.append({'md5': econfig.md5}) export_l.append({'squota': econfig.squota}) export_l.append({'hquota': econfig.hquota}) exports_l.append({'EXPORT ' + str(eid): export_l}) list_l.update({'EXPORTS': exports_l}) ordered_puts(list_l)
def option_list(platform, args): e_host = platform._active_export_host configurations = platform.get_configurations([e_host], Role.EXPORTD) config = configurations[e_host][Role.EXPORTD] export_l = {} errors_l = {} # Check exception if isinstance(config, Exception): # Get error msg err_str = type(config).__name__ + ' (' + str(config) + ')' # Update standard output dict export_l.update({e_host: err_str}) # Update errors dict errors_l.update({e_host: err_str}) else: options_l = [] options_l.append({'nbcores': config.nbcores}) export_l.update({e_host: {'OPTIONS': options_l}}) ordered_puts(export_l) if errors_l: raise MultipleError(errors_l)
def option_get(platform, args): # Check given option valid_opts = [NBCORES] if args.option not in valid_opts: raise Exception('invalid option: \'%s\' (valid value: %s).' % (args.option, ', '.join(valid_opts))) e_host = platform._active_export_host configurations = platform.get_configurations([e_host], Role.EXPORTD) config = configurations[e_host][Role.EXPORTD] export_l = {} errors_l = {} # Check exception if isinstance(config, Exception): # Get error msg err_str = type(config).__name__ + ' (' + str(config) + ')' # Update standard output dict export_l.update({e_host: err_str}) # Update errors dict errors_l.update({e_host: err_str}) else: options_l = [] if args.option == NBCORES: options_l.append({'nbcores': config.nbcores}) export_l.update({e_host: {'OPTIONS': options_l}}) ordered_puts(export_l) if errors_l: raise MultipleError(errors_l)
def list(platform, args): list_l = {} for h, r in platform.list_nodes(__args_to_roles(args)).items(): role_l = [] role_l.append(__roles_to_strings(r)) list_l.update({h: role_l}) ordered_puts(list_l)
def get(platform, args): layout = platform.get_layout() ordered_puts({ 'layout ' + str(layout): OrderedDict([("inverse", LAYOUT_VALUES[layout][0]), ("forward", LAYOUT_VALUES[layout][1]), ("safe", LAYOUT_VALUES[layout][2])]) })
def layout_get(platform, args): layout = platform.get_layout() ordered_puts({ platform._active_export_host: { 'layout ' + str(layout): OrderedDict([("inverse", LAYOUT_VALUES[layout][0]), ("forward", LAYOUT_VALUES[layout][1]), ("safe", LAYOUT_VALUES[layout][2])]) } })
def stat(platform, args): e_host = platform._active_export_host # Get configuration configurations = platform.get_configurations([e_host], Role.EXPORTD) if configurations[e_host] is None: raise Exception("exportd node is off line.") # Get statuses from storaged nodes statuses = {} for h, n in platform._nodes.items(): if n.has_one_of_roles(Role.STORAGED): statuses[h] = n.get_statuses(Role.STORAGED) # Check if all storaged nodes running for host, status in statuses.items(): try: if not status: print 'WARNING: %s is not reachable' % str(host) continue if not status[Role.STORAGED]: print 'WARNING: storaged is not running on ' + str(host) except KeyError: raise Exception("storaged node is off line.") # configuration of exportd node configuration = configurations[e_host][Role.EXPORTD] if configuration.stats is None: ordered_puts({'EXPORTD on ' + str(args.exportd): "not running"}) return export_l = {} stat_l = [] for vid, vstat in configuration.stats.vstats.items(): volume_l = [] if configuration.volumes[vid].layout is not None: volume_l.append({'layout' : configuration.volumes[vid].layout }) else: volume_l.append({'layout' : configuration.layout }) volume_l.append({'bsize': vstat.bsize}) volume_l.append({'bfree': vstat.bfree}) volume_l.append({'blocks': vstat.blocks}) for cid, cstat in vstat.cstats.items(): cluster_l = [] cluster_l.append({'size': cstat.size}) cluster_l.append({'free': cstat.free}) for sid, sstat in cstat.sstats.items(): storage_l = [] storage_l.append({'host': sstat.host}) storage_l.append({'size': sstat.size}) storage_l.append({'free': sstat.free}) cluster_l.append({'STORAGE ' + str(sid): storage_l}) volume_l.append({'CLUSTER ' + str(cid): cluster_l}) stat_l.append({'VOLUME ' + str(vid): volume_l}) export_l.update({'EXPORTD on ' + str(e_host): stat_l}) ordered_puts(export_l)
def status(platform, args): statuses = platform.get_statuses(args.nodes, __args_to_roles(args)) status_l = {} errors_l = {} for h, s in statuses.items(): role_l = [] role_err_l = [] for role, status in s.items(): # Check exception if isinstance(status, Exception): # Update standard output dict err_str = type(status).__name__ + ' (' + str(status) + ')' role_l.append({ROLES_STR[role]: err_str}) # Update errors dict role_err_l.append({ROLES_STR[role]: err_str}) errors_l.update({'NODE: ' + str(h): role_err_l}) continue if (role & Role.ROZOFSMOUNT == Role.ROZOFSMOUNT): mount_l = [] if not status: role_l.append( {ROLES_STR[role]: 'no mountpoint configured'}) else: for m, s in status.items(): mount_l.append({m: 'mounted' if s else 'unmounted'}) role_l.append({ROLES_STR[role]: mount_l}) else: if status: role_l.append({ROLES_STR[role]: 'running'}) else: role_l.append({ROLES_STR[role]: 'not running'}) if role_l: status_l.update({h: role_l}) # Display output ordered_puts(status_l) # Check errors if errors_l: raise MultipleError(errors_l)
def start(platform, args): changes = platform.start(args.nodes, __args_to_roles(args)) status_l = {} errors_l = {} for h, s in changes.items(): role_l = [] role_err_l = [] for role, change in s.items(): # Check exception if isinstance(change, Exception): # Update standard output dict err_str = type(change).__name__ + ' (' + str(change) + ')' role_l.append({ROLES_STR[role]: 'failed, ' + err_str}) # Update errors dict role_err_l.append({ROLES_STR[role]: err_str}) errors_l.update({'NODE: ' + str(h): role_err_l}) continue if (role & Role.ROZOFSMOUNT == Role.ROZOFSMOUNT): mount_l = [] for m, s in change.items(): mount_l.append({m: 'mounted' if s else 'already mounted'}) role_l.append({ROLES_STR[role]: mount_l}) else: if change: role_l.append({ROLES_STR[role]: 'started'}) else: role_l.append({ROLES_STR[role]: 'already started'}) if role_l: status_l.update({h: role_l}) # Display output ordered_puts(status_l) # Check errors if errors_l: raise MultipleError(errors_l)
def get(platform, args): e_host = platform._active_export_host configurations = platform.get_configurations([e_host], Role.EXPORTD) if configurations[e_host] is None: raise Exception("exportd node is off line.") configuration = configurations[e_host][Role.EXPORTD] get_l = [] for vid in args.vid: if vid not in configuration.volumes: raise Exception("Unknown volume with vid=%d." % vid) vconfig = configuration.volumes[vid] vstat = configuration.stats.vstats[vid] volume_l = [] if vconfig.layout is not None: volume_l.append({'layout' : vconfig.layout }) else: volume_l.append({'layout' : configuration.layout }) volume_l.append({'bsize': vstat.bsize}) volume_l.append({'bfree': vstat.bfree}) volume_l.append({'blocks': vstat.blocks}) for cid, cstat in vstat.cstats.items(): cluster_l = [] cluster_l.append({'size': cstat.size}) cluster_l.append({'free': cstat.free}) for sid, sstat in cstat.sstats.items(): storage_l = [] storage_l.append({'host': sstat.host}) storage_l.append({'size': sstat.size}) storage_l.append({'free': sstat.free}) cluster_l.append({'STORAGE ' + str(sid): storage_l}) volume_l.append({'CLUSTER ' + str(cid): cluster_l}) get_l.append({'VOLUME ' + str(vid): volume_l}) ordered_puts({'' + str(e_host): get_l})
def status(args): (pid, listeners) = AgentServer().status() if not pid: raise Exception("no agent is running.") ordered_puts(OrderedDict([("pid", int(pid)), ("listeners", listeners)]))
def config(platform, args): if not args.roles: args.roles = [EXPORTD_MANAGER, STORAGED_MANAGER, ROZOFSMOUNT_MANAGER] configurations = platform.get_configurations(args.nodes, __args_to_roles(args)) errors_l = {} host_l = {} for h, c in configurations.items(): # Is-it necessary ? if c is None: host_l.update({'NODE: ' + str(h): "not reachable"}) continue role_l = [] role_err_l = [] for role, config in c.items(): # Check exception if isinstance(config, Exception): # Get error msg err_str = type(config).__name__ + ' (' + str(config) + ')' # Update standard output dict role_l.append({ROLES_STR[role]: err_str}) host_l.update({'NODE: ' + str(h): role_l}) # Update errors dict role_err_l.append({ROLES_STR[role]: err_str}) errors_l.update({'NODE: ' + str(h): role_err_l}) continue if (role & Role.EXPORTD == Role.EXPORTD): exportd_l = [] volume_l = [] for v in config.volumes.values(): cluster_l = [] for cluster in v.clusters.values(): s_l = [] for s, hhh in cluster.storages.items(): s_l.append({'sid ' + str(s): hhh}) cluster_l.append({'cluster ' + str(cluster.cid): s_l}) volume_l.append({'volume ' + str(v.vid): cluster_l}) exportd_l.append({'VOLUME': volume_l}) if len(config.exports) != 0: for e in config.exports.values(): export_l = OrderedDict([('vid', e.vid), ('root', e.root), ('md5', e.md5), ('squota', e.squota), ('hquota', e.hquota)]) exportd_l.append({'EXPORT': export_l}) role_l.append({'EXPORTD': exportd_l}) if (role & Role.STORAGED == Role.STORAGED): options_l = [] interface_l = [] storage_l = [] if config.nbcores is not None: options_l.append({'nbcores': config.nbcores}) if config.threads is not None: options_l.append({'threads': config.threads}) if config.storio is not None: options_l.append({'storio': config.storio}) if config.self_healing is not None: options_l.append({'self-healing': config.self_healing}) if config.export_hosts is not None: options_l.append({'export-hosts': config.export_hosts}) options_l.append({'crc32c_check': bool(config.crc32c_check)}) options_l.append( {'crc32c_generate': bool(config.crc32c_generate)}) options_l.append( {'crc32c_hw_forced': bool(config.crc32c_hw_forced)}) storage_l.append({'OPTIONS': options_l}) for lconfig in config.listens: interface_l.append({lconfig.addr: lconfig.port}) storage_l.append({'INTERFACE': interface_l}) keylist = config.storages.keys() keylist.sort() st_l = [] for key in keylist: st = config.storages[key] stor_l = OrderedDict([('root', st.root), ('device-total', st.device_t), ('device-mapper', st.device_m), ('device-redundancy', st.device_r)]) st_l.append({ 'cid ' + str(st.cid) + ', sid ' + str(st.sid): stor_l }) storage_l.append({'STORAGE': st_l}) role_l.append({'STORAGED': storage_l}) if (role & Role.ROZOFSMOUNT == Role.ROZOFSMOUNT): exp_l = [] if config: for c in config: mountdict = {} mountdict["mountpoint"] = c.mountpoint mountdict["export host"] = c.export_host mountdict["export path"] = c.export_path exp_l.append(mountdict) role_l.append({'ZOOFSMOUNT': exp_l}) host_l.update({'NODE: ' + str(h): role_l}) ordered_puts(host_l) if errors_l: raise MultipleError(errors_l)
def create(platform, args): if not args.eids: args.eids = None statuses = platform.mount_export(args.eids, args.exports, args.nodes, args.mountpoints, args.options) host_statuses_l = {} host_errors_l = {} for h, s in statuses.items(): # Check exception if isinstance(s, Exception): # Update standard output dict err_str = type(s).__name__ + ' (' + str(s) + ')' host_statuses_l.update({str(h): err_str}) host_errors_l.update({str(h): err_str}) continue mount_statuses_l = [] mount_errors_l = [] for mountpoint, status in s.items(): mountpoint_status = {} mountpoint_error = {} # Check config status if status['config'] is True: mountpoint_status.update({'configuration': 'added'}) elif status['config'] is None: mountpoint_status.update({'configuration': 'already present'}) else: # Check exception if isinstance(status['config'], Exception): # Update standard output dict err_str = type(status['config']).__name__ + ' (' + str( status['config']) + ')' mountpoint_status.update( {'configuration': 'failed, ' + err_str}) # Update errors dict mountpoint_error.update( {'configuration': 'failed, ' + err_str}) # Check service status if status['service'] is True: mountpoint_status.update({'status': 'mounted'}) elif status['service'] is False: mountpoint_status.update({'status': 'unmounted'}) elif status['service'] is None: mountpoint_status.update({'status': 'already mounted'}) else: # Check exception if isinstance(status['service'], Exception): # Update standard output dict err_str = type(status['service']).__name__ + ' (' + str( status['service']) + ')' mountpoint_status.update({'status': 'failed, ' + err_str}) # Update errors dict mountpoint_error.update({'status': 'failed, ' + err_str}) # Update list of mountpoint statuses export_name = os.path.basename(status['export_root']) mnt_config = { "export " + export_name + ' (eid=' + str(status['eid']) + ') on ' + mountpoint: mountpoint_status } mount_statuses_l.append(mnt_config) if mountpoint_error: mnt_config_err = { "export " + export_name + ' (eid=' + str(status['eid']) + ') on ' + mountpoint: mountpoint_error } mount_errors_l.append(mnt_config_err) # Update host host_statuses_l.update({str(h): mount_statuses_l}) if mount_errors_l: host_errors_l.update({str(h): mount_errors_l}) # Display output ordered_puts(host_statuses_l) # Check errors if host_errors_l: raise MultipleError(host_errors_l)