Example #1
0
def cmd_handler_device_image_delete(args) -> int:
    """Delete an image given its ID

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()
    api.images_deleteimage(args.device_id, args.image_id)
    logging.info("Image %s has been successfully deleted.", args.image_id)
    return 0
Example #2
0
def cmd_handler_device_ip(args) -> int:
    """Sync a local folder with a folder on the device

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()
    ip = api.device_current_ip(args.device_id)
    logging.info(ip)
    return 0
Example #3
0
def cmd_handler_device_key(args) -> int:
    """Returns path of the device private key file

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()
    keypath = api.device_getprivatekey(args.device_id)
    logging.info(keypath)
    return 0
Example #4
0
def cmd_handler_device_delete(args) -> int:
    """Dump information about a specific platform, given its id

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()
    device = api.device_delete(args.device_id)
    logging.info("Device %s has been successfully deleted.", args.device_id)
    return 0
Example #5
0
def cmd_handler_device_container_stop(args) -> int:
    """Stops a container given its ID

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()
    api.container_stop(args.device_id, args.container_id)
    logging.info("Container %s has been successfully started.",
                 args.container_id)
    return 0
Example #6
0
def cmd_handler_device_container_ps(args) -> int:
    """Dumps a list of the processes currently running inside a container

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()
    processes = api.container_getprocesses(args.device_id, args.container_id)
    processeslist = map(generate_process_list_item, processes)
    logging.info(
        tabulate.tabulate(processeslist, headers="keys", tablefmt="plain"))
    return 0
Example #7
0
def cmd_handler_device_containers(args) -> int:
    """Dump a list of images on the target device

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()
    containers = api.device_getcontainers(args.device_id)
    containerslist = map(generate_container_list_item, containers)
    logging.info(
        tabulate.tabulate(containerslist, headers="keys", tablefmt="plain"))
    return 0
Example #8
0
def cmd_handler_device_storage(args) -> int:
    """Returns information about mountpoints on the host OS

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()
    mountpoints = api.device_getmountpoints(args.device_id)
    mountpointslist = map(generate_mountpoint_list_item, mountpoints)
    logging.info(
        tabulate.tabulate(mountpointslist, headers="keys", tablefmt="plain"))
    return 0
Example #9
0
def cmd_handler_devices(args) -> int:
    """Dumps out a list of configured devices

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()
    devices = api.devices_get()
    deviceslist = map(generate_device_list_item, devices)
    logging.info(
        tabulate.tabulate(deviceslist, headers="keys", tablefmt="plain"))
    return 0
Example #10
0
def cmd_handler_device_container_mem(args) -> int:
    """Returns information about memory usage of a specific container

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()
    meminfo = api.container_getmemory(args.device_id, args.container_id)
    logging.info(
        tabulate.tabulate(generate_prop_list(meminfo),
                          headers=["Property", "Value"],
                          tablefmt="plain"))
    return 0
Example #11
0
def cmd_handler_device_image_info(args) -> int:
    """Dump information about a specific image, given its id

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()
    image = api.images_getimage(args.device_id, args.image_id)
    logging.info(
        tabulate.tabulate(generate_prop_list(image),
                          headers=["Property", "Value"],
                          tablefmt="plain"))
    return 0
Example #12
0
def cmd_handler_device_sync(args) -> int:
    """Sync a local folder with a folder on the device

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()

    progress_id = handle_progress(args)

    device = api.device_syncfolders(
        args.device_id,
        os.path.abspath(args.source_folder),
        args.destination_folder,
        progress_id=progress_id,
    )
    return 0
Example #13
0
def cmd_handler_detect(args) -> int:
    """Detects a new serial or network device

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()

    device = None

    if args.network:
        logging.info(
            "Attepting to detect network device, this may take a couple of minutes."
        )
        logging.info(
            "Check that your device is turned on and connected to the network."
        )
        logging.info("At the end of detection your device will reboot.")
        device = api.devices_networkdetect(args.target, args.username,
                                           args.password)
    else:
        logging.info(
            "Attepting to detect serial device, this may take a couple of minutes, after detection the device will reboot."
        )
        logging.info(
            "Check that your device is powered on an connected to your PC via serial/USB cable."
        )
        logging.info("At the end of detection your device will reboot.")
        device = api.devices_serialdetect(args.target, args.username,
                                          args.password)

    logging.info("Device successfully detected.")
    logging.info(
        tabulate.tabulate(generate_prop_list(device),
                          headers=["Property", "Value"],
                          tablefmt="plain"))

    return 0
Example #14
0
def cmd_handler_device_container_logs(args) -> int:
    """Returns information about mountpoints in a container

    Arguments:
        args -- parsed command line arguments

    Returns:
        int -- 0 for success
    """
    api = moses_client.DevicesApi()

    restart = True

    while True:
        line = api.container_getlogs(args.device_id,
                                     args.container_id,
                                     restart=restart)
        restart = False
        logging.info(line)

    return 0