def authenticate_with_access_token(access_token): """Authenticate using an existing access token.""" credentials = Credentials(access_token=access_token) client = YamcsClient('localhost:8090', credentials=credentials) for link in client.list_data_links('simulator'): print(link)
def authenticate_with_username_password(): """Authenticate by directly providing username/password to Yamcs.""" credentials = Credentials(username="******", password="******") client = YamcsClient("localhost:8090", credentials=credentials) for link in client.list_links("simulator"): print(link)
def authenticate_with_username_password(): """Authenticate in by directly providing username/password to Yamcs.""" credentials = Credentials(username='******', password='******') client = YamcsClient('localhost:8090', credentials=credentials) for link in client.list_data_links('simulator'): print(link)
def do_login(self, args): opts = utils.CommandOptions(args) address = args.address or self.read_address(opts) client = YamcsClient(address) auth_info = client.get_auth_info() if auth_info.require_authentication: credentials = self.read_credentials() client = YamcsClient(address, credentials=credentials) print('Login succeeded') else: user_info = client.get_user_info() print('Anonymous login succeeded (username: {})'.format( user_info.username)) self.save_client_config(client, opts.config)
def impersonate_with_client_credentials(): credentials = Credentials(client_id='cf79cfbd-ed01-4ae2-93e1-c606a2ebc36f', client_secret='!#?hgbu1*3', become='admin') client = YamcsClient('localhost:8090', credentials=credentials) print('have', client.get_user_info().username) while True: print(client.get_time('simulator')) sleep(1)
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) rows = [['NAME']] for table in archive.list_tables(): rows.append([ table.name, ]) utils.print_table(rows)
def impersonate_with_client_credentials(): credentials = Credentials( client_id="cf79cfbd-ed01-4ae2-93e1-c606a2ebc36f", client_secret="!#?hgbu1*3", become="admin", ) client = YamcsClient("localhost:8090", credentials=credentials) print("have", client.get_user_info().username) while True: print(client.get_time("simulator")) sleep(1)
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) mdb = client.get_mdb(opts.instance) rows = [['NAME', 'DESCRIPTION']] for algorithm in mdb.list_algorithms(): rows.append([ algorithm.qualified_name, algorithm.description, ]) utils.print_table(rows)
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) rows = [['NAME', 'STATE', 'MISSION TIME']] for instance in client.list_instances(): rows.append([ instance.name, instance.state, instance.mission_time, ]) utils.print_table(rows)
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) mdb = client.get_mdb(opts.instance) rows = [['NAME', 'DATA SOURCE']] for parameter in mdb.list_parameters(): rows.append([ parameter.qualified_name, parameter.data_source, ]) utils.print_table(rows)
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) rows = [['NAME', 'CLASS', 'STATUS']] for service in client.list_services(opts.instance): rows.append([ service.name, service.class_name, service.state, ]) utils.print_table(rows)
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) mdb = client.get_mdb(opts.instance) rows = [['NAME', 'DESCRIPTION', 'ABSTRACT']] for command in mdb.list_commands(): rows.append([ command.qualified_name, command.description, command.abstract, ]) utils.print_table(rows)
def subscribe(self, args): def on_data(stream_data): print(stream_data._proto) #pylint: disable=protected-access opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) try: subscription = archive.create_stream_subscription(args.stream, on_data=on_data) subscription.result() except KeyboardInterrupt: pass
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) rows = [['ID', 'USER', 'APPLICATION', 'LOGIN']] for client in client.list_clients(): rows.append([ client.id, client.username, client.application_name, client.login_time, ]) utils.print_table(rows)
def load(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) for table in args.tables: path = table + '.dump' if args.dir: path = os.path.join(args.dir, path) with gzip.open(path, 'rb') as f: stdout.write(table) stdout.flush() n = archive.load_table(table, data=f) stdout.write('\r{}: loaded {} rows'.format(table, n)) stdout.write('\n')
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) rows = [['NAME', 'CLASS', 'STATUS', 'IN', 'OUT']] for link in client.list_data_links(opts.instance): rows.append([ link.name, link.class_name, link.status, link.in_count, link.out_count, ]) utils.print_table(rows)
def load(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) for table in args.tables: path = table + '.dump.gz' if args.gzip else table + '.dump' if args.dir: path = os.path.join(args.dir, path) if args.gzip: with gzip.open(path, 'rb') as f: self.read_dump(f, archive, table, path) else: with open(path, 'rb') as f: self.read_dump(f, archive, table, path)
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) rows = [[ 'NAME', 'TYPE', 'OWNER', 'PERSISTENT', 'MISSION TIME', 'STATE' ]] for processor in client.list_processors(opts.instance): rows.append([ processor.name, processor.type, processor.owner, processor.persistent, processor.mission_time, processor.state, ]) utils.print_table(rows)
def launch(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) shell = DbShell(client) shell.do_use(opts.instance) if args.command: shell.onecmd(args.command) else: server_info = client.get_server_info() intro = ('Yamcs DB Shell\n' 'Server version: {} - ID: {}\n\n' 'Type ' 'help' ' or ' '?' ' for help.\n').format(server_info.version, server_info.id) shell.cmdloop(intro)
def dump(self, args): if args.dir: if not os.path.exists(args.dir): os.makedirs(args.dir) opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) for table in args.tables: path = table + '.dump.gz' if args.gzip else table + '.dump' if args.dir: path = os.path.join(args.dir, path) if args.gzip: with gzip.open(path, 'wb', compresslevel=1) as f: self.write_dump(f, archive, table, path) else: with open(path, 'wb') as f: self.write_dump(f, archive, table, path)
def dump(self, args): if args.dir: if not os.path.exists(args.dir): os.makedirs(args.dir) opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) for table in args.tables: path = table + '.dump' if args.dir: path = os.path.join(args.dir, path) with gzip.open(path, 'wb') as f: size = 0 t1 = time.time() for chunk in archive.dump_table(table): size += f.write(chunk) t2 = time.time() rate = (size / 1024 / 1024) / (t2 - t1) stdout.write('\r{}: {} MB/s'.format(table, round(rate, 2))) stdout.flush() if size > 0: stdout.write('\n')
def describe(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) mdb = client.get_mdb(opts.instance) parameter = mdb.get_parameter(args.parameter) print(parameter._proto) #pylint: disable=protected-access
processor.set_default_calibrator("/YSS/SIMULATOR/BatteryVoltage2", "polynomial", [1, 0.1]) def reset_calibrator(): """Reset the calibrator to the original MDB value.""" processor.reset_calibrators("/YSS/SIMULATOR/BatteryVoltage2") def clear_calibrator(): """Clear(remove) the calibrator.""" processor.clear_calibrators("/YSS/SIMULATOR/BatteryVoltage2") if __name__ == "__main__": client = YamcsClient("localhost:8090") processor = client.get_processor(instance="simulator", processor="realtime") subscribe_param() sleep(5) print("Set calibrator") set_calibrator() sleep(10) print("Remove calibrator") clear_calibrator() sleep(10) print("reset calibrator to original MDB value") reset_calibrator() sleep(10)
def describe(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) table = archive.get_table(args.table) print(table._proto) #pylint: disable=protected-access
def set_alarms(): """Set the default (i.e. non-contextual) limits for the parameter.""" processor.set_default_alarm_ranges('/YSS/SIMULATOR/BatteryVoltage2', watch=(-10, 10), critical=(-100, None)) def clear_alarm_ranges(): """Clear(remove) all limits for the parameter. Note that if the is an alarm being triggered, it is not automatically acknowledged.""" processor.clear_alarm_ranges('/YSS/SIMULATOR/BatteryVoltage2') def reset_alarms(): """Reset the alarm limits for the parameter to the original MDB value.""" processor.reset_alarm_ranges('/YSS/SIMULATOR/BatteryVoltage2') if __name__ == '__main__': client = YamcsClient('localhost:8090') processor = client.get_processor(instance='simulator', processor='realtime') subscribe_param() sleep(5) print('Set alarms') set_alarms() sleep(10) print('Clear(remove) all alarms') clear_alarm_ranges() sleep(10) print('reset alarms to their MDB value')
def describe(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) mdb = client.get_mdb(opts.instance) algorithm = mdb.get_algorithm(args.algorithm) print(algorithm._proto) #pylint: disable=protected-access
def describe(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) link = client.get_data_link(opts.instance, args.link) print(link._proto) #pylint: disable=protected-access
def describe(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) mdb = client.get_mdb(opts.instance) command = mdb.get_command(args.command) print(command._proto) #pylint: disable=protected-access
def stop(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) for instance in args.instances: client.stop_instance(instance)
def stop(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) for service in args.services: client.stop_service(opts.instance, service=service)