def run(self, context, args, kwargs, opargs): volume = self.parent.entity result = list(iterate_vdevs(volume['topology'])) return Table(result, [ Table.Column('Name', 'path'), Table.Column('Status', 'status') ])
def run(self, context, args, kwargs, opargs): result = context.call_sync('vm.guest_ls', self.parent.entity['id'], args[0]) return Table(result, [ Table.Column('Name', 'name'), Table.Column('Type', 'type'), Table.Column('Size', 'size', ValueType.SIZE) ])
def update_check_utility(context): """ A small helper function that checks for updates and returns the update operations to be performed if any else None """ context.call_task_sync('update.check') updates = context.call_sync('update.get_update_ops') if updates: for update in updates: update['previous_version'] = ( get_short_version(update['previous_version']) if update['previous_version'] else '-' ) update['new_version'] = ( get_short_version(update['new_version']) if update['new_version'] else '-' ) return Table(updates, [ Table.Column('Name', 'new_name'), Table.Column('Operation', 'operation'), Table.Column('Current Version', 'previous_version'), Table.Column('New Version', 'new_version') ]) else: return None
def run(self, context, args, kwargs, opargs): # Enclose ipv6 urls in '[]' according to ipv6 url spec my_ips = [ wrap_address(ip) for ip in context.call_sync('network.config.get_my_ips', timeout=60) ] my_protocols = context.call_sync('system.ui.get_config', timeout=60) urls = [] for proto in my_protocols['webui_protocol']: proto_port = my_protocols['webui_{0}_port'.format(proto.lower())] if proto_port is not None: if proto_port in [80, 443]: for x in my_ips: urls.append( {'url': '{0}://{1}'.format(proto.lower(), x)}) else: for x in my_ips: urls.append({ 'url': '{0}://{1}:{2}'.format(proto.lower(), x, proto_port) }) return Sequence( _("You may try the following URLs to access the web user interface:" ), Table(urls, [Table.Column(_('URLs (url)'), 'url')]))
def run(self, context, args, kwargs, opargs): if len(kwargs) > 0: raise CommandException( _("Invalid syntax {0}. For help see 'help <command>'".format( kwargs))) if len(args) == 0: var_dict_list = [] for k, v in self.variables.get_all_printable(): var_dict = { 'varname': k, 'vardescr': self.variables.variable_doc.get(k, ''), 'varvalue': v, } var_dict_list.append(var_dict) return Table(var_dict_list, [ Table.Column('Variable', 'varname', ValueType.STRING), Table.Column('Description', 'vardescr', ValueType.STRING), Table.Column('Value', 'varvalue') ]) if len(args) == 1: try: return format_value(self.variables.variables[args[0]]) except KeyError: raise CommandException( _("No such Environment Variable exists")) else: raise CommandException( _("Invalid syntax {0}. For help see 'help <command>'".format( args)))
def run(self, context, args, kwargs, opargs): volume = context.call_sync('zfs.pool.get_boot_pool') result = list(iterate_vdevs(volume['groups'])) return Table( result, [Table.Column('Name', 'path'), Table.Column('Status', 'status')])
def output_object(obj, file=sys.stdout, **kwargs): values = [] editable_column = False for item in obj: value = { 'name': item.name, 'descr': item.descr, 'value': AsciiOutputFormatter.format_value(item.value, item.vt) } if item.editable is not None: value['editable'] = AsciiOutputFormatter.format_value( item.editable, ValueType.BOOLEAN) editable_column = True values.append(value) cols = [] cols.append(Table.Column("Property", 'name')) cols.append(Table.Column("Description", 'descr')) cols.append(Table.Column("Value", 'value')) if editable_column: cols.append(Table.Column("Editable", 'editable')) table = AsciiOutputFormatter.format_table(Table(values, cols)) six.print_(table.draw(), file=file, end=('\n' if kwargs.get('newline', True) else ' '))
def run(self, context, args, kwargs, opargs): files = context.call_sync('filesystem.get_open_files', self.parent.entity['mountpoint']) return Table(files, [ Table.Column('Process name', 'process_name'), Table.Column('PID', 'pid', ValueType.NUMBER), Table.Column('File path', 'path') ])
def run(self, context, args, kwargs, opargs): if not args: raise CommandException( _("'chdir' requires 1 argument. For help see 'help chdir'")) name = args[0] if name == '..': dest = self.parent.curr_obj.parent elif name == '.': dest = self.parent.curr_obj else: dest = self.parent.curr_obj.get_child(name) if not dest.is_dir: raise CommandException( 'Cannot "cd" into object of type: {0}'.format(dest.type.name)) else: self.parent.curr_obj = dest output_msg(_(">{0}".format(str(self.parent.curr_obj)))) contents = [{ 'name': o.name, 'type': o.type.name } for o in self.parent.curr_obj.readdir()] return Table(contents, [ Table.Column('Name', 'name'), Table.Column('Type', 'type'), ])
def run(self, context, args, kwargs, opargs): vols = context.call_sync('volume.find') return Table(vols, [ Table.Column('ID', 'id', vt=ValueType.STRING), Table.Column('Volume name', 'name'), Table.Column('Status', 'status') ])
def run(self, context, args, kwargs, opargs, input=None): if len(args) != 1: raise CommandException('Please specify exactly one field name') if isinstance(input, Table): result = Table(None, [Table.Column('Result', 'result')]) result.data = ({'result': x.get(args[0])} for x in input) return result
def run(self, context, args, kwargs, opargs): devices = sorted(self.parent.entity['devices'], key=lambda d: d['index']) return Table(devices, [ Table.Column('Index', 'index', width=10), Table.Column('Disk name', 'disk_name', width=20), Table.Column('Slot description', 'name'), Table.Column('Slot status', 'status') ])
def run(self, context, args, kwargs, opargs): media = context.call_sync('volume.find_media') return Table(media, [ Table.Column('Path', 'path'), Table.Column('Label', 'label'), Table.Column('Size', 'size'), Table.Column('Filesystem type', 'fstype') ])
def run(self, context, args, kwargs, opargs): return Table([{ 'var': k, 'val': v.value } for k, v in self.current_env.items()], [ Table.Column(_("Variable (var)"), 'var'), Table.Column(_("Value (val)"), 'val') ])
def run(self, context, args, kwargs, opargs): return Sequence( _("These are the active ips from all the configured network interfaces" ), Table([{ 'ip': x } for x in context.call_sync('network.config.get_my_ips')], [Table.Column(_("IP Addresses (ip)"), 'ip')]))
def run(self, context, args, kwargs, opargs): result = context.call_sync('share.get_connected_clients', self.parent.entity['id']) return Table(result, [ Table.Column(_("IP address"), 'host', ValueType.STRING), Table.Column(_("User"), 'user', ValueType.STRING), Table.Column(_("Connected at"), 'connected_at', ValueType.TIME) ])
def run(self, context, args, kwargs, opargs): sessions = context.call_sync('session.get_live_user_sessions') return Table(sessions, [ Table.Column('Session ID', 'id'), Table.Column('User name', 'username'), Table.Column('Address', 'address'), Table.Column('Started at', 'started_at', ValueType.TIME) ])
def run(self, context, args, kwargs, opargs): return Table( [{ 'name': k, 'value': v } for k, v in os.environ.items()], [Table.Column('Name', 'name'), Table.Column('Value', 'value')])
def run(self, context, args, kwargs, opargs): if len(args) != 1 and 'name' not in kwargs: raise CommandException("Please specify fragment of the image name") name = kwargs.get('name') or args[0] return Table(context.call_sync('docker.image.search', name), [ Table.Column('Name', 'name', width=30), Table.Column('Description', 'description') ])
def run(self, context, args, kwargs, opargs): if not kwargs: data = [{'label': k, 'value': v} for k, v in context.ml.aliases.items()] return Table(data, [ Table.Column('Alias name', 'label'), Table.Column('Alias value', 'value') ]) for name, value in kwargs.items(): context.ml.aliases[name] = value
def run(self, context, args, kwargs, opargs): pending = list(filter( lambda t: t['session'] == context.session_id, context.pending_tasks.values() )) return Table(pending, [ Table.Column('Task ID', 'id'), Table.Column('Task description', lambda t: translate_task(context, t['name'], t['args'])), Table.Column('Task status', describe_task_state) ])
def run(self, context, args, kwargs, opargs): trains = context.call_sync('update.trains') if trains is None: return _( "Could not fetch Available Trains from the Update Server. " "Please Check internet connectivity and try again.") else: return Table(trains, [ Table.Column('Name', 'name'), Table.Column('Description', 'description'), Table.Column('Sequence', 'sequence'), Table.Column('Current', 'current', vt=ValueType.BOOLEAN) ])
def run(self, context, args, kwargs, opargs): result = context.call_task_sync('backup.query', self.parent.entity['id']) manifest = result['result'] return Sequence( Object( Object.Item('Hostname', 'hostname', manifest['hostname']), Object.Item('Dataset', 'dataset', manifest['dataset']), ), Table(manifest['snapshots'], [ Table.Column('Snapshot name', 'name', ValueType.STRING), Table.Column('Incremental', 'incremental', ValueType.BOOLEAN), Table.Column('Created at', 'created_at', ValueType.TIME) ]))
def run(self, context, args, kwargs, opargs): if not args: raise CommandException( _("'mkdir' requires 1 argument. For help see 'help mkdir'")) self.parent.curr_obj.mkdir(args[0]) output_msg(_(">{0}".format(str(self.parent.curr_obj)))) contents = [{ 'name': o.name, 'type': o.type.name } for o in self.parent.curr_obj.readdir()] return Table(contents, [ Table.Column('Name', 'name'), Table.Column('Type', 'type'), ])
def run(self, context, args, kwargs, opargs): codes = list(context.call_sync('peer.freenas.get_auth_codes')) for c in codes: remaining_time = c['expires_at'] - datetime.now() remaining_time = int(remaining_time.total_seconds()) if remaining_time < 0: c['lifetime'] = 'Expired {0} seconds ago'.format( abs(remaining_time)) else: c['lifetime'] = 'Expires in {0} seconds'.format(remaining_time) return Table(codes, [ Table.Column('Token', 'code', ValueType.STRING), Table.Column('Lifetime', 'lifetime', ValueType.STRING) ])
def run(self, context, args, kwargs, opargs, filtering=None): cols = [] params = [] options = {} if filtering: for k, v in filtering['params'].items(): if k == 'limit': options['limit'] = int(v) continue if k == 'reverse': options['reverse'] = v continue if k == 'sort': for sortkey in v: neg = '' if sortkey.startswith('-'): sortkey = sortkey[1:] neg = '-' prop = self.parent.get_mapping(sortkey) if not prop: raise CommandException( 'Unknown field {0}'.format(sortkey)) if not isinstance(prop.get, six.string_types): raise CommandException( 'Cannot sort on field {0}'.format(sortkey)) options.setdefault('sort', []).append(neg + prop.get) continue raise CommandException('Unknown field {0}'.format(k)) params = list(self.__map_filter_properties(filtering['filter'])) for col in self.parent.property_mappings: if not col.list: continue cols.append( Table.Column(col.descr, col.do_get, col.type, col.width, col.name)) return Table(self.parent.query(params, options), cols)
def run(self, context, args, kwargs, opargs): if not args: raise CommandException( _("Open requires 1 argument. For help see 'help open'")) self.parent.curr_obj = FileProvider.open( args[0], remote_logpass=self.parent.remote_logpass) output_msg( _("Connection opened: {0}".format(str(self.parent.curr_obj)))) contents = [{ 'name': o.name, 'type': o.type.name } for o in self.parent.curr_obj.readdir()] return Table(contents, [ Table.Column('Name', 'name'), Table.Column('Type', 'type'), ])
def run(self, context, args, kwargs, opargs): result = context.call_task_sync('backup.query', self.parent.entity['id']) if result['state'] != 'FINISHED': raise CommandException('Failed to query backup: {0}'.format( q.get(result, 'error.message'))) manifest = result['result'] return Sequence( Object( Object.Item('Hostname', 'hostname', manifest['hostname']), Object.Item('Dataset', 'dataset', manifest['dataset']), ), Table(manifest['snapshots'], [ Table.Column('Snapshot name', 'name', ValueType.STRING), Table.Column('Incremental', 'incremental', ValueType.BOOLEAN), Table.Column('Created at', 'created_at', ValueType.TIME) ]))
def run(self, context, args, kwargs, opargs): desired_range = None if args: if len(args) != 1: raise CommandException(_( "Invalid Syntax for history command. For help see 'help <command>'" )) try: desired_range = int(args[0]) except ValueError: raise CommandException(_("Please specify an integer for the history range")) histroy_range = readline.get_current_history_length() if desired_range is not None and desired_range < histroy_range: histroy_range = desired_range + 1 return Table( [{'cmd': readline.get_history_item(i)} for i in range(1, histroy_range)], [Table.Column('Command History', 'cmd', ValueType.STRING)] )
def run(self, context, args, kwargs, opargs): incremental = read_value(kwargs.pop('incrementasl', 'yes'), ValueType.BOOLEAN) snapshot = read_value(kwargs.pop('snapshot', 'yes'), ValueType.BOOLEAN) dry_run = read_value(kwargs.pop('dry_run', 'no'), ValueType.BOOLEAN) if dry_run: def describe(row): if row['type'] == 'SEND_STREAM': return '{localfs}@{snapshot} -> {remotefs}@{snapshot} ({incr})'.format( incr='incremental' if row.get('incremental') else 'full', **row) if row['type'] == 'DELETE_SNAPSHOTS': return 'reinitialize remote dataset {remotefs}'.format( **row) if row['type'] == 'DELETE_DATASET': return 'delete remote dataset {remotefs} (because it has been deleted locally)'.format( **row) result = context.call_task_sync('backup.sync', self.parent.entity['id'], snapshot, True) if result['state'] != 'FINISHED': raise CommandException('Failed to query backup: {0}'.format( q.get(result, 'error.message'))) return Sequence( Table(result['result'], [ Table.Column('Action type', 'type', ValueType.STRING), Table.Column('Description', describe, ValueType.STRING) ]), "Estimated backup stream size: {0}".format( format_value( sum(a.get('send_size', 0) for a in result['result']), ValueType.SIZE))) else: tid = context.submit_task('backup.sync', self.parent.entity['id'], snapshot) return TaskPromise(context, tid)