def _gns3UpdateReplySlot(self): network_reply = self.sender() if network_reply.error() != QtNetwork.QNetworkReply.NoError: if not self._silent: QtWidgets.QMessageBox.critical( self._parent, "Check For Update", "Cannot check for update: {}".format( network_reply.errorString())) return try: latest_release = bytes( network_reply.readAll()).decode("utf-8").rstrip() except UnicodeDecodeError: log.warning("Invalid answer from the update server") return if re.match(r"^[a-z0-9\.]+$", latest_release) is None: log.warning("Invalid answer from the update server") return if parse_version(version.__version__) < parse_version(latest_release): reply = QtWidgets.QMessageBox.question( self._parent, "Check For Update", "Newer GNS3 version {} is available, do you want to visit our website to download it?" .format(latest_release), QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No) if reply == QtWidgets.QMessageBox.Yes: QtGui.QDesktopServices.openUrl( QtCore.QUrl("http://www.gns3.net/download/")) elif not self._silent: QtWidgets.QMessageBox.information(self._parent, "Check For Update", "GNS3 is up-to-date!")
def test_get_connected_auth(http_client, http_request, network_manager, response): http_client._connected = True http_client._user = "******" http_client._password = "******" callback = unittest.mock.MagicMock() http_client.createHTTPQuery("GET", "/test", callback) http_request.assert_called_with( QtCore.QUrl("http://[email protected]:3080/v2/test")) http_request.setRawHeader.assert_any_call(b"Content-Type", b"application/json") http_request.setRawHeader.assert_any_call(b"Authorization", b"Basic Z25zMzozc25n") http_request.setRawHeader.assert_any_call( b"User-Agent", "GNS3 QT Client v{version}".format(version=__version__).encode()) assert network_manager.sendCustomRequest.called args, kwargs = network_manager.sendCustomRequest.call_args assert args[0] == http_request assert args[1] == b"GET" # Trigger the completion response.finished.emit() assert callback.called
def openConsole(self, command=None, aux=False): if command is None: if aux: command = self.consoleCommand(console_type="telnet") else: command = self.consoleCommand() console_type = "telnet" if aux: console_port = self.auxConsole() if console_port is None: raise ValueError( "AUX console port not allocated for {}".format( self.name())) # Aux console is always telnet console_type = "telnet" else: console_port = self.console() if "console_type" in self.settings(): console_type = self.settings()["console_type"] if console_type == "telnet": from .telnet_console import nodeTelnetConsole nodeTelnetConsole(self, console_port, command) elif console_type == "vnc": from .vnc_console import vncConsole vncConsole(self.consoleHost(), console_port, command) elif console_type == "http" or console_type == "https": QtGui.QDesktopServices.openUrl( QtCore.QUrl("{console_type}://{host}:{port}{path}".format( console_type=console_type, host=self.consoleHost(), port=console_port, path=self.consoleHttpPath())))
def openConsole(self, command=None, aux=False): """ Opens a console. :param command: console command line :param aux: indicates an auxiliary console """ if command is None: if aux: command = self.consoleCommand(console_type="telnet") else: command = self.consoleCommand() console_type = "telnet" if aux: console_port = self.auxConsole() if console_port is None: raise ValueError( "AUX console port not allocated for {}".format( self.name())) # AUX console is always telnet console_type = "telnet" else: console_port = self.console() if console_port is None: log.debug("No console port allocated for {}".format( self.name())) return if "console_type" in self.settings(): console_type = self.consoleType() if console_type == "telnet": from .telnet_console import nodeTelnetConsole nodeTelnetConsole(self, console_port, command) elif console_type == "vnc": from .vnc_console import vncConsole vncConsole(self.consoleHost(), console_port, command) elif console_type.startswith("spice"): from .spice_console import spiceConsole spiceConsole(self.consoleHost(), console_port, command) elif console_type == "http" or console_type == "https": QtGui.QDesktopServices.openUrl( QtCore.QUrl("{console_type}://{host}:{port}{path}".format( console_type=console_type, host=self.consoleHost(), port=console_port, path=self.consoleHttpPath())))
def _get(self, url, finished_slot, user_attribute=None): """ HTTP get :param url: Url to download :param user_attribute: Param to pass to the finished slot :returns: QNetworkReply """ if self._network_manager is None: self._network_manager = QtNetwork.QNetworkAccessManager() request = QtNetwork.QNetworkRequest(QtCore.QUrl(url)) request.setRawHeader(b'User-Agent', b'GNS3 Check For Update') request.setAttribute(QtNetwork.QNetworkRequest.User, user_attribute) reply = self._network_manager.get(request) reply.finished.connect(finished_slot) log.debug('Download %s', url) return reply
def _get(self, url, finished_slot, user_attribute=None): """ HTTP get :param url: Url to download :param user_attribute: Param to pass to the finished slot :returns: QNetworkReply """ if self._network_manager is None: self._network_manager = QtNetwork.QNetworkAccessManager() request = QtNetwork.QNetworkRequest(QtCore.QUrl(url)) request.setRawHeader(b'User-Agent', b'GNS3 Check For Update') request.setAttribute(QtNetwork.QNetworkRequest.User, user_attribute) if parse_version(QtCore.QT_VERSION_STR) >= parse_version("5.6.0") and parse_version(QtCore.PYQT_VERSION_STR) >= parse_version("5.6.0"): # follow redirects only supported starting with Qt 5.6.0 request.setAttribute(QtNetwork.QNetworkRequest.FollowRedirectsAttribute, True) reply = self._network_manager.get(request) reply.finished.connect(finished_slot) log.debug('Download %s', url) return reply
def test_get_connected(http_client, http_request, network_manager, response): http_client._connected = True callback = unittest.mock.MagicMock() http_client.get("/test", callback) http_request.assert_called_with( QtCore.QUrl("http://127.0.0.1:3080/v1/test")) http_request.setRawHeader.assert_any_call(b"Content-Type", b"application/json") http_request.setRawHeader.assert_any_call( b"User-Agent", "GNS3 QT Client v{version}".format(version=__version__).encode()) assert network_manager.sendCustomRequest.called args, kwargs = network_manager.sendCustomRequest.call_args assert args[0] == http_request assert args[1] == b"GET" # Trigger the completion response.finished.emit() assert callback.called
def _VMwareBannerButtonClickedSlot(self): if sys.platform.startswith("darwin"): url = "http://send.onenetworkdirect.net/z/616461/CD225091/" else: url = "http://send.onenetworkdirect.net/z/616460/CD225091/" QtGui.QDesktopServices.openUrl(QtCore.QUrl(url))
def _browseConfigurationDirectorySlot(self): """ Slot to open a file browser into the configuration directory """ QtGui.QDesktopServices.openUrl( QtCore.QUrl("file://" + LocalConfig.instance().configDirectory()))