Ejemplo n.º 1
0
 def test_get_launch_timeout(self):
     self.init_block()
     settings = get_xblock_settings()
     self.assertEqual(self.block.get_launch_timeout(settings),
                      DEFAULT_SETTINGS["launch_timeout"])
     self.block.launch_timeout = 1800
     self.assertEqual(self.block.get_launch_timeout(settings),
                      self.block.launch_timeout)
Ejemplo n.º 2
0
    def handle(self, *args, **options):
        # Get configuration
        settings = get_xblock_settings()

        # Schedule
        scheduler = BlockingScheduler()
        suspender = SuspenderJob(settings)
        interval = settings.get("suspend_interval", 60)
        scheduler.add_job(suspender.run, 'interval', seconds=interval)
        scheduler.start()
Ejemplo n.º 3
0
    def handle(self, *args, **options):
        # Get configuration
        settings = get_xblock_settings()

        # Schedule
        scheduler = BlockingScheduler()
        job = ReaperJob(settings)
        interval = settings.get("delete_interval", 3600)
        scheduler.add_job(job.run, 'interval', seconds=interval)
        scheduler.start()
Ejemplo n.º 4
0
    def test_get_user_stack_status_first(self):
        self.init_block(False)
        stack = self.create_stack()

        mock_result = Mock()
        mock_result.id = "bogus_task_id"
        mock_result.ready.return_value = False
        mock_launch_stack_task = Mock(return_value=mock_result)

        with patch.multiple(self.block,
                            launch_stack_task=mock_launch_stack_task):
            data = {"initialize": True, "reset": False}
            response = self.call_handler("get_user_stack_status", data)

        mock_launch_stack_task.assert_called_with(get_xblock_settings(), {
            "stack_id": stack.id,
            "reset": False
        })
        self.assertEqual(response["status"], "LAUNCH_PENDING")
Ejemplo n.º 5
0
    async def connect(self):
        """
        Initiate the GuacamoleClient and create a connection to it.
        """
        guacd_hostname = os.getenv('GUACD_SERVICE_HOST', 'guacd')
        guacd_port = int(os.getenv('GUACD_SERVICE_PORT', '4822'))

        settings = get_xblock_settings()

        params = urllib.parse.parse_qs(self.scope['query_string'].decode())
        stack_name = params.get('stack')[0]

        stack = await database_sync_to_async(self.get_stack)(stack_name)
        default_port = 3389 if stack.protocol == 'rdp' else 22

        self.read_only = bool(strtobool(params.get('read_only')[0]))

        self.client = GuacamoleClient(guacd_hostname, guacd_port)
        self.client.handshake(
            protocol=stack.protocol,
            width=params.get('width', [1024])[0],
            height=params.get('height', [768])[0],
            hostname=stack.ip,
            port=params.get('port', [default_port])[0],
            username=stack.user,
            password=stack.password,
            private_key=stack.key,
            color_scheme=settings.get("terminal_color_scheme"),
            font_name=settings.get("terminal_font_name"),
            font_size=settings.get("terminal_font_size"),
        )

        if self.client.connected:
            # start receiving data from GuacamoleClient
            loop = asyncio.get_event_loop()
            self.task = loop.create_task(self.open())

            # Accept connection
            await self.accept(subprotocol='guacamole')
        else:
            await self.close()
Ejemplo n.º 6
0
 def create_stack(self):
     course_id, student_id = self.block.get_block_ids()
     settings = get_xblock_settings()
     return self.block.create_stack(settings, course_id, student_id)