Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
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)
Exemple #4
0
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)
Exemple #5
0
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)
Exemple #6
0
    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)
Exemple #7
0
    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)
Exemple #8
0
    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)
Exemple #9
0
    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', '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', 'DESCRIPTION', 'ABSTRACT']]
        for command in mdb.list_commands():
            rows.append([
                command.qualified_name,
                command.description,
                command.abstract,
            ])
        utils.print_table(rows)
Exemple #12
0
    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
Exemple #13
0
    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)
Exemple #14
0
 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')
Exemple #15
0
    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)
Exemple #17
0
    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)
Exemple #18
0
 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)
Exemple #20
0
    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')
Exemple #21
0
    def do_login(self, args):
        opts = utils.CommandOptions(args)

        address = args.address or self.read_address(opts)
        client = YamcsClient(address)

        if args.kerberos:
            credentials = KerberosCredentials()
            client = YamcsClient(address, credentials=credentials)
            print('Login succeeded')
        elif client.get_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)
Exemple #22
0
    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)
Exemple #23
0
 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
from yamcs.client import YamcsClient


def enable_all_links():
    """Enable all links."""
    for link in client.list_data_links(instance='simulator'):
        client.enable_data_link(instance=link.instance, link=link.name)


def callback(message):
    print('Link Event: {}'.format(message))


if __name__ == '__main__':
    client = YamcsClient('localhost:8090')

    print('Enabling all links')
    enable_all_links()

    subscription = client.create_data_link_subscription('simulator', callback)

    sleep(10)

    print('-----')
    # You don't have to use the on_data callback. You could also
    # directly retrieve the latest data link state from a local cache:
    print('Last values from cache:')
    for link in subscription.list_data_links():
        print(link)
def print_commands():
    """Print all commands."""
    for command in mdb.list_commands():
        print(command)


def find_parameter():
    """Find one parameter."""
    p1 = mdb.get_parameter("/YSS/SIMULATOR/BatteryVoltage2")
    print("Via qualified name:", p1)

    p2 = mdb.get_parameter("MDB:OPS Name/SIMULATOR_BatteryVoltage2")
    print("Via domain-specific alias:", p2)


if __name__ == "__main__":
    client = YamcsClient("localhost:8090")
    mdb = client.get_mdb(instance="simulator")

    print("\nSpace systems:")
    print_space_systems()

    print("\nParameters:")
    print_parameters()

    print("\nCommands:")
    print_commands()

    print("\nFind a specific parameter using different names")
    find_parameter()
Exemple #26
0
 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
                event_count += rec.count
        print(f"  {source: <40} {event_count: >20}")


def print_command_count():
    """Print the number of commands grouped by name."""
    mdb = client.get_mdb(instance="simulator")
    for command in mdb.list_commands():
        total = 0
        for group in archive.list_command_histogram(command.qualified_name):
            for rec in group.records:
                total += rec.count
        print(f"  {command.qualified_name: <40} {total: >20}")


if __name__ == "__main__":
    client = YamcsClient("localhost:8090")
    archive = client.get_archive(instance="simulator")

    print("Packets:")
    print_packet_count()

    print("\nProcessed Parameter Groups:")
    print_pp_groups()

    print("\nEvents:")
    print_event_count()

    print("\nCommands:")
    print_command_count()
from yamcs.client import YamcsClient


def print_buckets():
    for bucket in storage_client.list_buckets():
        print(
            f" {bucket} ({bucket.object_count} objects, {bucket.size} bytes)")
        listing = bucket.list_objects()
        print("  prefixes:", listing.prefixes)
        for obj in listing.objects:
            print("  object:", obj)


if __name__ == "__main__":
    client = YamcsClient("localhost:8090")
    storage_client = client.get_storage_client()

    print("Buckets:")
    print_buckets()
Exemple #29
0

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')
from __future__ import print_function

from time import sleep

from yamcs.client import YamcsClient


def callback(dt):
    print('Mission time:', dt)


if __name__ == '__main__':
    client = YamcsClient('localhost:8090')
    subscription = client.create_time_subscription('simulator', callback)

    sleep(6)

    print('-----')
    # You don't have to use the on_data callback. You could also
    # directly retrieve the latest state from a local cache:
    print('Last time from cache:', subscription.time)

    # But then maybe you don't need a subscription, so do simply:
    time = client.get_time('simulator')
    print('Mission time (fresh from server)', time)