# Path: cirque/common/cirquelog.py
# class CirqueLog:
# 
#   logger = None
# 
#   @classmethod
#   def setup_cirque_logger(cls, level=logging.INFO):
#     if cls.logger:
#       return
#     cls.logger = logging.getLogger('cirque')
#     cls.logger.setLevel(level)
#     sh = logging.StreamHandler()
#     sh.setFormatter(
#         logging.Formatter('%(asctime)s [%(name)s] %(levelname)s %(message)s'))
#     cls.logger.addHandler(sh)
# 
#   @classmethod
#   def get_cirque_logger(cls, name=None):
#     name = 'cirque' if not name else 'cirque.{}'.format(name)
#     return logging.getLogger(name)
# 
# Path: cirque/common/utils.py
# def sleep_time(logger, seconds, reason=None):
#   if reason:
#     reason = 'for ' + reason
#   logger.debug('sleeps {}s {}'.format(seconds, reason))
#   time.sleep(seconds)


import argparse
import time
import logging
import os
import grpc
import cirque.proto.capability_pb2 as capability_pb2
import cirque.proto.device_pb2 as device_pb2
import cirque.proto.service_pb2_grpc as service_pb2_grpc
import cirque.proto.service_pb2 as service_pb2
from google.rpc import code_pb2, status_pb2
from cirque.proto.device_pb2 import DeviceSpecification
from cirque.common.cirquelog import CirqueLog
from cirque.common.utils import sleep_time
from cirque.proto.capability_pb2 import (WeaveCapability, ThreadCapability,
                                         WiFiCapability, XvncCapability,
                                         InteractiveCapability,
                                         LanAccessCapability, MountPair,
                                         MountCapability,
                                         TrafficControlCapability)
    mount_capability.mount_pairs.append(
        MountPair(
            host_path=os.path.abspath(os.path.relpath(__file__)),
            target_path='/tmp/test'))
    device_0_id = stub.CreateCirqueDevice(
        service_pb2.CreateCirqueDeviceRequest(
            home_id=home_id,
            specification=device_pb2.DeviceSpecification(
                device_type='test',
                base_image='sdk_border_router',
                weave_capability=WeaveCapability(
                    weave_certificate_path=weave_cert_path),
                thread_capability=ThreadCapability(),
                wifi_capability=WiFiCapability(),
                xvnc_capability=XvncCapability(localhost=True),
                mount_capability=mount_capability))).device.device_id
    device_1_id = stub.CreateCirqueDevice(
        service_pb2.CreateCirqueDeviceRequest(
            home_id=home_id,
            specification=device_pb2.DeviceSpecification(
                device_type='mobile',
                base_image='mobile_node_image',
                interactive_capability=InteractiveCapability(),
                lan_access_capability=LanAccessCapability(),
            ))).device.device_id
    device_info = stub.QueryCirqueDevice(
        service_pb2.QueryCirqueDeviceRequest(
            home_id=home_id, device_id=device_1_id))
    logger.info(device_info)
    logger.info('Waiting for device to fully launch')

# Path: cirque/common/cirquelog.py
# class CirqueLog:
# 
#   logger = None
# 
#   @classmethod
#   def setup_cirque_logger(cls, level=logging.INFO):
#     if cls.logger:
#       return
#     cls.logger = logging.getLogger('cirque')
#     cls.logger.setLevel(level)
#     sh = logging.StreamHandler()
#     sh.setFormatter(
#         logging.Formatter('%(asctime)s [%(name)s] %(levelname)s %(message)s'))
#     cls.logger.addHandler(sh)
# 
#   @classmethod
#   def get_cirque_logger(cls, name=None):
#     name = 'cirque' if not name else 'cirque.{}'.format(name)
#     return logging.getLogger(name)
# 
# Path: cirque/common/utils.py
# def sleep_time(logger, seconds, reason=None):
#   if reason:
#     reason = 'for ' + reason
#   logger.debug('sleeps {}s {}'.format(seconds, reason))
#   time.sleep(seconds)


# Path: cirque/grpc/client.py
import argparse
import time
import logging
import os
import grpc
import cirque.proto.capability_pb2 as capability_pb2
import cirque.proto.device_pb2 as device_pb2
import cirque.proto.service_pb2_grpc as service_pb2_grpc
import cirque.proto.service_pb2 as service_pb2
from google.rpc import code_pb2, status_pb2
from cirque.proto.device_pb2 import DeviceSpecification
from cirque.common.cirquelog import CirqueLog
from cirque.common.utils import sleep_time
from cirque.proto.capability_pb2 import (WeaveCapability, ThreadCapability,
                                         WiFiCapability, XvncCapability,
                                         InteractiveCapability,
                                         LanAccessCapability, MountPair,
                                         MountCapability,
                                         TrafficControlCapability)

    mount_capability.mount_pairs.append(
        MountPair(
            host_path=os.path.abspath(os.path.relpath(__file__)),
            target_path='/tmp/test'))
    device_0_id = stub.CreateCirqueDevice(
        service_pb2.CreateCirqueDeviceRequest(
            home_id=home_id,
            specification=device_pb2.DeviceSpecification(
                device_type='test',
                base_image='sdk_border_router',
                weave_capability=WeaveCapability(
                    weave_certificate_path=weave_cert_path),
                thread_capability=ThreadCapability(),
                wifi_capability=WiFiCapability(),
                xvnc_capability=XvncCapability(localhost=True),
                mount_capability=mount_capability))).device.device_id
    device_1_id = stub.CreateCirqueDevice(
        service_pb2.CreateCirqueDeviceRequest(
            home_id=home_id,
            specification=device_pb2.DeviceSpecification(
                device_type='mobile',
                base_image='mobile_node_image',
                interactive_capability=InteractiveCapability(),
                lan_access_capability=LanAccessCapability(),
            ))).device.device_id
    device_info = stub.QueryCirqueDevice(
        service_pb2.QueryCirqueDeviceRequest(
            home_id=home_id, device_id=device_1_id))
    logger.info(device_info)
    logger.info('Waiting for device to fully launch')

    sleep_time(logger, 10)