Пример #1
0
def set_state(server: BBBServer, state: str):
    server.state = state
    server.save()

    # Move away all meetings on panic
    if state == BBBServer.PANIC:
        for meeting in Meeting.running.filter(server=server):
            # Try sending the end call, hoping it can still reach the server
            try:
                send_api_request(
                    server, "end", {
                        "meetingID": meeting.meeting_id,
                        "password": meeting.create_query["moderatorPW"]
                    })
            except:
                pass
            finally:
                meeting.ended = True
                meeting.save()

            # Reopen the meeting on a new server
            new_server = get_next_server()
            new_meeting, response = create_meeting(new_server,
                                                   meeting.meeting_id,
                                                   meeting.create_query)
            if response["returncode"] == "SUCCESS":
                print(
                    f"Reopened '{meeting.meeting_id}' on #{new_server.server_id}",
                    file=sys.stdout)
                meeting.moved_to = new_meeting
                meeting.save()
            else:
                print(
                    f"Couldn't reopen '{meeting.meeting_id}': {response['message']}",
                    file=sys.stderr)
Пример #2
0
def create_meeting(server: BBBServer,
                   meeting_id: str,
                   parameters: dict = None) -> Tuple[Meeting, dict]:
    if parameters is None:
        parameters = {}

    if not Meeting.running.filter(meeting_id=meeting_id).exists():
        # Register the meeting to get an id and delete it if the bbb api call fails
        meeting = Meeting.objects.create(
            meeting_id=meeting_id,
            internal_id=Meeting.TEMP_INTERNAL_ID,
            server=server,
            load=parameters["load"] if "load" in parameters else 1,
            create_query=dict(parameters),
        )
    else:
        meeting = Meeting.running.get(meeting_id=meeting_id)

    # Direct logoutURL to us
    parameters["logoutURL"] = build_api_url(Loadbalancer, "rejoin",
                                            {"meetingID": meeting.id})

    # Call bbb's api
    response = send_api_request(server, "create", parameters)

    # Update new meeting
    if meeting.internal_id == Meeting.TEMP_INTERNAL_ID:
        if response["returncode"] == "SUCCESS":
            meeting.internal_id = response["internalMeetingID"]
            meeting.save()
        else:
            meeting.delete()

    return meeting, response
Пример #3
0
    def process(self, parameters: dict, request: HttpRequest):
        # Get a parameters dict without the 'recordID'
        meta_parameters = dict((key, value)
                               for key, value in parameters.items()
                               if key != "recordID")

        # Get a list of meetings to be updated for each server
        meetings_per_server = defaultdict(list)
        for internal_id in map(str.strip, parameters["recordID"].split(",")):
            try:
                meeting = Meeting.objects.get(internal_id=internal_id)
                meetings_per_server[meeting.server].append(internal_id)
            except Meeting.DoesNotExist:
                pass

        # Call update on every server once with all its meetings
        responses = []
        for server, meetings in meetings_per_server.items():
            if not server.enabled:
                continue

            responses.append(
                send_api_request(server, "updateRecordings", {
                    "recordID": ",".join(meetings),
                    **meta_parameters,
                }))

        # If any recording was updated successfully just call everything a success (bbb behaviour)
        for response in responses:
            if response["returncode"] == "SUCCESS":
                break
        else:
            return respond(False, "notFound", "We could not find recordings")
        return respond(True, data={"updated": "true"})
Пример #4
0
    def process(self, parameters: dict, request: HttpRequest):
        meeting = self.get_meeting(parameters)

        response = send_api_request(meeting.server, "end", parameters)
        if response["returncode"] == "SUCCESS":
            meeting.ended = True
            meeting.save()

        return respond(data=response)
Пример #5
0
    def process(self, parameters: dict, request: HttpRequest):
        meeting = self.get_meeting(parameters)

        if "serverID" in parameters:
            try:
                server = BBBServer.objects.get(
                    server_id=parameters["serverID"])
            except BBBServer.DoesNotExist:
                return respond(False, "notFound",
                               "We don't have a server with that server ID")
        else:
            server = get_next_server(
                BBBServer.objects.exclude(id=meeting.server.id))

        if server == meeting.server:
            return respond(False, "sameServer",
                           "Origin and destination server are the same.")

        # End meeting
        response = send_api_request(
            meeting.server, "end", {
                "meetingID": meeting.meeting_id,
                "password": meeting.create_query["moderatorPW"]
            })
        if response["returncode"] == "SUCCESS":
            meeting.ended = True
            meeting.save()
        else:
            return respond(data=response)

        # Create meeting
        new_meeting, response = create_meeting(server, meeting.meeting_id,
                                               meeting.create_query)
        if response["returncode"] == "SUCCESS":
            logger.info(
                f"SUCCESS: moved from {meeting.server} to {new_meeting.server}"
            )
            meeting.moved_to = new_meeting
            meeting.save()

        return respond(data=response)
Пример #6
0
    def from_server(server: BBBServer) -> list:
        """
        Get all meetings on a server

        :param server: server to get meetings from
        :return: list of meetings (meetings are dicts)
        """
        if not server.enabled:
            return []

        response = send_api_request(server, "getMeetings")

        if "messageKey" in response and response["messageKey"] == "noMeetings":
            return []  # No meetings

        meetings_data = response["meetings"]["meeting"]
        if isinstance(meetings_data, XMLDictNode):
            return [meetings_data]  # One meeting

        else:
            return list(meetings_data)  # Multiple meetings
Пример #7
0
 def process(self, parameters: dict, request: HttpRequest):
     meeting = self.get_meeting(parameters)
     response = send_api_request(meeting.server, "getMeetingInfo",
                                 parameters)
     return XmlResponse({"response": response})