def enable_connections(enable): """Activate all connections and set them to auto-connect.""" setting_name = nm.SETTING_WIREGUARD_SETTING_NAME client = network.get_nm_client() for connection in client.get_connections(): if connection.get_connection_type() != setting_name: continue network.edit_connection(connection, {'common': { 'autoconnect': enable }}) if enable: network.activate_connection(connection.get_uuid()) else: try: network.deactivate_connection(connection.get_uuid()) except network.ConnectionNotFound: pass # Connection is already inactive
def activate(request, uuid): """Activate the connection.""" try: connection = network.activate_connection(uuid) name = connection.get_id() messages.success(request, _("Activated connection %s.") % name) except network.ConnectionNotFound: messages.error(request, _("Failed to activate connection: " "Connection not found.")) except network.DeviceNotFound as exception: name = exception.args[0].get_id() messages.error(request, _("Failed to activate connection %s: " "No suitable device is available.") % name) return redirect(reverse_lazy("networks:index"))
def activate(request, uuid): """Activate the connection.""" try: connection = network.activate_connection(uuid) name = connection.get_id() messages.success(request, _('Activated connection %s.') % name) except network.ConnectionNotFound: messages.error(request, _('Failed to activate connection: ' 'Connection not found.')) except network.DeviceNotFound as exception: name = exception.args[0].get_id() messages.error(request, _('Failed to activate connection %s: ' 'No suitable device is available.') % name) return redirect(reverse_lazy('networks:index'))
def activate(request, uuid): """Activate the connection.""" try: connection = network.activate_connection(uuid) name = connection.GetSettings()['connection']['id'] messages.success(request, _('Activated connection %s.') % name) except network.ConnectionNotFound: messages.error(request, _('Failed to activate connection: ' 'Connection not found.')) except network.DeviceNotFound as exception: name = exception.args[0].GetSettings()['connection']['id'] messages.error(request, _('Failed to activate connection %s: ' 'No suitable device is available.') % name) return redirect(reverse_lazy('networks:index'))
def activate(request, uuid): """Activate the connection.""" try: connection = network.activate_connection(uuid) name = connection.get_id() messages.success(request, _('Activated connection {name}.') .format(name=name)) except network.ConnectionNotFound: messages.error(request, _('Failed to activate connection: ' 'Connection not found.')) except network.DeviceNotFound as exception: name = exception.args[0].get_id() messages.error(request, _('Failed to activate connection {name}: ' 'No suitable device is available.') .format(name=name)) return redirect(reverse_lazy('networks:index'))