def setUpClass(cls): CirqueLog.setup_cirque_logger(level=logging.DEBUG) docker_client = docker.from_env() cls.trafficcontrol_capability = TrafficControlCapability(latencyMs=200, loss=25) cls.node1 = DockerNode(docker_client, 'generic_node_image', capabilities=[cls.trafficcontrol_capability]) cls.node2 = DockerNode(docker_client, 'generic_node_image') kwargs = {'stdin_open': True, 'privileged': True} cls.node1.run(**kwargs) cls.node2.run(**kwargs)
def client_sample(weave_cert_path): CirqueLog.setup_cirque_logger() logger = CirqueLog.get_cirque_logger() with grpc.insecure_channel('localhost:50051') as channel: stub = service_pb2_grpc.CirqueServiceStub(channel) home_id = stub.CreateCirqueHome( service_pb2.CreateCirqueHomeRequest()).home_id mount_capability = MountCapability() 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) logs = stub.GetCirqueDeviceLog( service_pb2.GetCirqueDeviceLogRequest(home_id=home_id, device_id=device_0_id, tail=10)) logger.info(logs.log) stub.StopCirqueDevice( service_pb2.StopCirqueDeviceRequest(home_id=home_id, device_id=device_0_id)) stub.StopCirqueDevice( service_pb2.StopCirqueDeviceRequest(home_id=home_id, device_id=device_1_id)) stub.StopCirqueHome(service_pb2.StopCirqueHomeRequest(home_id=home_id))
def setUpClass(cls): CirqueLog.setup_cirque_logger(level=logging.DEBUG) docker_client = docker.from_env() # bring up WiFi AP Node cls.ap = WiFiAPNode(docker_client) cls.ap.run() cls.wifi_capability = WiFiCapability() cls.generic_node = DockerNode(docker_client, 'generic_node_image', capabilities=[cls.wifi_capability]) kwargs = {'stdin_open': True, 'privileged': True} cls.generic_node.run(**kwargs) cls.ap_ssid = cls.ap.get_wifi_ssid() cls.ap_psk = cls.ap.get_wifi_password()
def __init__(self, name, internal=False): self.logger = CirqueLog.get_cirque_logger('lan_{}'.format(name)) self.__name = name self.__internal = internal self.subnet = None self.gateway = None self.__create_docker_network() self.__disable_container_mutual_access()
def load_kernel_mac80211_hwsim(radios=DEFAULT_RADIOS): logger = CirqueLog.get_cirque_logger() logger.info( "kernel module mac80211_hwsim is not loaded, loading now...") ret = utils.host_run(logger, "modprobe mac80211_hwsim \ radios={}".format(radios)) if ret.returncode != 0: raise LoadKernelError("unable to load module mac80211_hwsim!!") utils.sleep_time(logger, 5, "loading mac80211_hwsim module")
def __init__(self, node_id, petition_id, daemons=['wpantund', 'otbr-agent'], rcp=False): self.thread_endpoint = ThreadSimPipe(node_id, petition_id, rcp) self.thread_endpoint.open() self.logger = CirqueLog.get_cirque_logger(self.__class__.__name__) self.daemons = daemons for daemon in daemons: if daemon not in {'wpantund', 'otbr-agent'}: self.logger.warning( 'using unkown thread daemon mode: {}'.format(daemon))
def __init__(self, home_id=None): self.docker_client = docker.from_env() if home_id is None: self.home_id = str(uuid.uuid4()) else: self.home_id = home_id self.home = {'home_id': self.home_id, 'devices': {}} self.thread_petitions = {} self.external_lan = HomeLan('{}_external'.format(self.home_id)) self.internal_lan = HomeLan('{}_internal'.format(self.home_id), internal=True) self.logger = CirqueLog.get_cirque_logger('home')
def __init__(self, docker_client, node_type, capabilities=None, base_image=None): self._client = docker_client self.node_type = node_type if base_image: self.image_name = base_image else: self.image_name = node_type self.container = None self.capabilities = [] if capabilities is None else capabilities self.logger = CirqueLog.get_cirque_logger(self.__class__.__name__) self.logger.info('Capabilites: {}'.format( [c.name for c in self.capabilities]))
def setUpClass(cls): CirqueLog.setup_cirque_logger(level=logging.DEBUG) cls.home = CirqueHome() cls.weave_crt_path = os.environ['WEAVE_CRT_PATH'] \ if 'WEAVE_CRT_PATH' in os.environ else None
def main(service_port): global logger CirqueLog.setup_cirque_logger() logger = CirqueLog.get_cirque_logger('grpc_service') serve(service_port)
# limitations under the License. import os import atexit from flask import Flask from flask import jsonify from flask import request from flask import Response from cirque.common.cirquelog import CirqueLog from cirque.home.home import CirqueHome app = Flask(__name__) CirqueLog.setup_cirque_logger() logger = CirqueLog.get_cirque_logger('service') service_mode = os.environ.get("CIRQUE_DEBUG", 0) homes = {} @app.route('/create_home', methods=['POST']) def create_home(): home = CirqueHome() homes[home.home_id] = home return jsonify(home.create_home(request.json)) @app.route('/get_homes', methods=['GET'])
def __init__(self): self.logger = CirqueLog.get_cirque_logger(self.__class__.__name__)
def is_mac80211_hwsim_loaded(): ret = utils.host_run(CirqueLog.get_cirque_logger(), "lsmod | grep mac80211_hwsim") return ret.returncode == 0