Пример #1
0
    def execute(self, options_dict, non_option_args):
        manager = self.Manager()
        current_state = manager.get_state()

        if len(non_option_args) < 1:
            if current_state == nm.MANAGER_STATE_SLEEPING:
                print "Disabled"
            else:
                print "Enabled"

            return 0

        new_state = non_option_args[0].lower()
        if new_state == "on" or new_state == "enable" or new_state == "yes" or new_state == "1":
            if current_state == nm.MANAGER_STATE_SLEEPING:
                nmtalk.message("Enabling networking")
                manager.sleep(False)
            else:
                nmtalk.message("Networking is already enabled")
        elif new_state == "off" or new_state == "disable" or new_state == "no" or new_state == 0:
            if current_state != nm.MANAGER_STATE_SLEEPING:
                nmtalk.message("Disabling networking")
                manager.sleep(True)
            else:
                nmtalk.message("Networking is already disabled")
        else:
            nmtalk.fatal("Invalid argument '%s'. Please use 'on' or 'off'" %
                         non_option_args[0])

        return 0
Пример #2
0
    def execute(self, options_dict, non_option_args):
        manager = self.Manager()
        current_state = manager.get_wireless_state()

        if len(non_option_args) < 1:
            if current_state:
                print "Enabled"
            else:
                print "Disabled"
            return 0

        new_state = non_option_args[0].lower()
        if new_state == "on" or new_state == "enable" or new_state == "yes" or new_state == "1":
            if not current_state:
                if not manager.get_wireless_hw_state():
                    nmtalk.message(
                        "Wireless hardware is disabled, can not enable wireless"
                    )
                    return 1
                nmtalk.message("Enabling wireless")
                manager.set_wireless_state(True)
            else:
                nmtalk.message("Wireless is already enabled")
        elif new_state == "off" or new_state == "disable" or new_state == "no" or new_state == 0:
            if current_state:
                nmtalk.message("Disabling wireless")
                manager.set_wireless_state(False)
            else:
                nmtalk.message("Wireless is already disabled")
        else:
            nmtalk.fatal("Invalid argument '%s'. Please use 'on' or 'off'" %
                         non_option_args[0])

        return 0
Пример #3
0
    def execute(self, options_dict, non_option_args):
        manager = self.Manager()
        current_state = manager.get_wireless_state()

        if len(non_option_args) < 1:
            if current_state:
                print "Enabled"
            else:
                print "Disabled"
            return 0

        new_state = non_option_args[0].lower()
        if new_state == "on" or new_state == "enable" or new_state == "yes" or new_state == "1":
            if not current_state:
                if not manager.get_wireless_hw_state():
                    nmtalk.message("Wireless hardware is disabled, can not enable wireless")
                    return 1
                nmtalk.message("Enabling wireless")
                manager.set_wireless_state(True)
            else:
                nmtalk.message("Wireless is already enabled")
        elif new_state == "off" or new_state == "disable" or new_state == "no" or new_state == 0:
            if current_state:
                nmtalk.message("Disabling wireless")
                manager.set_wireless_state(False)
            else:
                nmtalk.message("Wireless is already disabled")
        else:
            nmtalk.fatal("Invalid argument '%s'. Please use 'on' or 'off'" % non_option_args[0])

        return 0
Пример #4
0
    def execute(self, options_dict, non_option_args):
        manager = self.Manager()
        current_state = manager.get_state()

        if len(non_option_args) < 1:
            if current_state == nm.MANAGER_STATE_SLEEPING:
                print "Disabled"
            else:
                print "Enabled"

            return 0

        new_state = non_option_args[0].lower()
        if new_state == "on" or new_state == "enable" or new_state == "yes" or new_state == "1":
            if current_state == nm.MANAGER_STATE_SLEEPING:
                nmtalk.message("Enabling networking")
                manager.sleep(False)
            else:
                nmtalk.message("Networking is already enabled")
        elif new_state == "off" or new_state == "disable" or new_state == "no" or new_state == 0:
            if current_state != nm.MANAGER_STATE_SLEEPING:
                nmtalk.message("Disabling networking")
                manager.sleep(True)
            else:
                nmtalk.message("Networking is already disabled")
        else:
            nmtalk.fatal("Invalid argument '%s'. Please use 'on' or 'off'" % non_option_args[0])

        return 0
Пример #5
0
    def execute(self, options_dict, non_option_args):
        if len(non_option_args) != 1:
            self.usage()

        manager = self.Manager()

        device_iface = non_option_args.pop(0)
        device = manager.get_device_by_iface(device_iface)
        if not device:
            nmtalk.fatal("Invalid device %s" % device_iface)

        device.deactivate()

        return 0
Пример #6
0
    def execute(self, options_dict, non_option_args):
        if len(non_option_args) != 1:
            self.usage()

        manager = self.Manager()

        device_iface = non_option_args.pop(0)
        device = manager.get_device_by_iface(device_iface)
        if not device:
            nmtalk.fatal("Invalid device %s" % device_iface)

        device.deactivate()

        return 0
Пример #7
0
    def execute(self, options_dict, non_option_args):
        if len(non_option_args) != 1:
            self.usage()

        # Find the VPN connection
        manager = nmsettings.ConnectionManager()
        connection_name = non_option_args.pop(0)

        if options_dict.has_key("system"):
            connection = manager.get_connection_by_name(
                nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS, connection_name,
                "vpn")
        elif options_dict.has_key("user"):
            connection = manager.get_connection_by_name(
                nmsettings.DBUS_SERVICE_USER_SETTINGS, connection_name, "vpn")
        else:
            connection = manager.get_connection_by_name(
                nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS, connection_name,
                "vpn")
            if not connection:
                connection = manager.get_connection_by_name(
                    nmsettings.DBUS_SERVICE_USER_SETTINGS, connection_name,
                    "vpn")

        if not connection:
            nmtalk.error("VPN connection '%s' not found." % connection_name)
            return 1

        manager = nm.NetworkManager()

        # Find the first active device
        device = None
        for d in manager.get_devices():
            if d.get_state() == nmdevice.DEVICE_STATE_ACTIVATED:
                device = d
                break

        if not device:
            nmtalk.fatal("Can not activate VPN, no active device found")

        vpn_manager = nmvpn.VpnManager()
        vpn_connection = vpn_manager.connect(connection, device)

        if options_dict.has_key("dont-wait"):
            return 0

        loop = gobject.MainLoop()
        self.exit_status = 0

        def monitor(state, reason):
            msg = "'%s': %s" % (connection_name,
                                nmvpn.vpn_connection_state_to_str(state))
            if reason != nmvpn.VPN_CONNECTION_STATE_REASON_NONE:
                msg += " (%s)" % nmvpn.vpn_connection_state_reason_to_str(
                    reason)

            nmtalk.message(msg)

            if state == nmvpn.VPN_CONNECTION_STATE_ACTIVATED:
                loop.quit()

            elif state == nmvpn.VPN_CONNECTION_STATE_FAILED or state == nmvpn.VPN_CONNECTION_STATE_DISCONNECTED:
                loop.quit()
                self.exit_status = 1

        vpn_connection.proxy.connect_to_signal(
            "StateChanged",
            monitor,
            dbus_interface=nmvpn.DBUS_INTERFACE_VPN_CONNECTION)

        loop.run()

        return self.exit_status
Пример #8
0
    def execute(self, options_dict, non_option_args):
        if len(non_option_args) < 2:
            self.usage()

        manager = self.Manager()

        # Device
        device_iface = non_option_args.pop(0)
        device = manager.get_device_by_iface(device_iface)
        if not device:
            nmtalk.fatal("Invalid device %s" % device_iface)

        # Connection
        c_manager = nmsettings.ConnectionManager()
        connection_name = non_option_args.pop(0)
        if options_dict.has_key("system"):
            connection = c_manager.get_connection_by_name(nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS,
                                                          connection_name)
        elif options_dict.has_key("user"):
            connection = c_manager.get_connection_by_name(nmsettings.DBUS_SERVICE_USER_SETTINGS,
                                                          connection_name)
        else:
            connection = c_manager.get_connection_by_name(nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS,
                                                          connection_name)
            if not connection:
                connection = c_manager.get_connection_by_name(nmsettings.DBUS_SERVICE_USER_SETTINGS,
                                                              connection_name)

        if not connection:
            nmtalk.fatal("Invalid connection '%s'" % connection_name)

        # Specific object
        if len(non_option_args) > 0:
            specific_object = device.get_specific_object(non_option_args)
        else:
            specific_object = None

        manager.activate_device(device, connection, specific_object)

        if options_dict.has_key("dont-wait"):
            return 0

        loop = gobject.MainLoop()
        self.exit_status = 0

        def monitor(state):
            nmtalk.message("'%s': %s" % (device_iface, nmdevice.device_state_to_str(state)))
            if state == nmdevice.DEVICE_STATE_ACTIVATED:
                loop.quit()

            elif state == nmdevice.DEVICE_STATE_FAILED or state == nmdevice.DEVICE_STATE_DISCONNECTED or \
                    state == nmdevice.DEVICE_STATE_CANCELLED:
                loop.quit()
                self.exit_status = 1

        device.proxy.connect_to_signal("StateChanged", monitor,
                                       dbus_interface=nmdevice.DBUS_INTERFACE_DEVICE)


        loop.run()

        return self.exit_status
Пример #9
0
    def execute(self, options_dict, non_option_args):
        if len(non_option_args) != 1:
            self.usage()

        # Find the VPN connection
        manager = nmsettings.ConnectionManager()
        connection_name = non_option_args.pop(0)

        if options_dict.has_key("system"):
            connection = manager.get_connection_by_name(nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS,
                                                        connection_name, "vpn")
        elif options_dict.has_key("user"):
            connection = manager.get_connection_by_name(nmsettings.DBUS_SERVICE_USER_SETTINGS,
                                                        connection_name, "vpn")
        else:
            connection = manager.get_connection_by_name(nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS,
                                                        connection_name, "vpn")
            if not connection:
                connection = manager.get_connection_by_name(nmsettings.DBUS_SERVICE_USER_SETTINGS,
                                                            connection_name, "vpn")

        if not connection:
            nmtalk.error("VPN connection '%s' not found." % connection_name)
            return 1

        manager = nm.NetworkManager()

        # Find the first active device
        device = None
        for d in manager.get_devices():
            if d.get_state() == nmdevice.DEVICE_STATE_ACTIVATED:
                device = d
                break

        if not device:
            nmtalk.fatal("Can not activate VPN, no active device found")

        vpn_manager = nmvpn.VpnManager()
        vpn_connection = vpn_manager.connect(connection, device)

        if options_dict.has_key("dont-wait"):
            return 0

        loop = gobject.MainLoop()
        self.exit_status = 0

        def monitor(state, reason):
            msg = "'%s': %s" % (connection_name, nmvpn.vpn_connection_state_to_str(state))
            if reason != nmvpn.VPN_CONNECTION_STATE_REASON_NONE:
                msg += " (%s)" % nmvpn.vpn_connection_state_reason_to_str(reason)

            nmtalk.message(msg)

            if state == nmvpn.VPN_CONNECTION_STATE_ACTIVATED:
                loop.quit()

            elif state == nmvpn.VPN_CONNECTION_STATE_FAILED or state == nmvpn.VPN_CONNECTION_STATE_DISCONNECTED:
                loop.quit()
                self.exit_status = 1

        vpn_connection.proxy.connect_to_signal("StateChanged", monitor,
                                                dbus_interface=nmvpn.DBUS_INTERFACE_VPN_CONNECTION)


        loop.run()

        return self.exit_status
Пример #10
0
    def execute(self, options_dict, non_option_args):
        if len(non_option_args) < 2:
            self.usage()

        manager = self.Manager()

        # Device
        device_iface = non_option_args.pop(0)
        device = manager.get_device_by_iface(device_iface)
        if not device:
            nmtalk.fatal("Invalid device %s" % device_iface)

        # Connection
        c_manager = nmsettings.ConnectionManager()
        connection_name = non_option_args.pop(0)
        if options_dict.has_key("system"):
            connection = c_manager.get_connection_by_name(
                nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS, connection_name)
        elif options_dict.has_key("user"):
            connection = c_manager.get_connection_by_name(
                nmsettings.DBUS_SERVICE_USER_SETTINGS, connection_name)
        else:
            connection = c_manager.get_connection_by_name(
                nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS, connection_name)
            if not connection:
                connection = c_manager.get_connection_by_name(
                    nmsettings.DBUS_SERVICE_USER_SETTINGS, connection_name)

        if not connection:
            nmtalk.fatal("Invalid connection '%s'" % connection_name)

        # Specific object
        if len(non_option_args) > 0:
            specific_object = device.get_specific_object(non_option_args)
        else:
            specific_object = None

        manager.activate_device(device, connection, specific_object)

        if options_dict.has_key("dont-wait"):
            return 0

        loop = gobject.MainLoop()
        self.exit_status = 0

        def monitor(state):
            nmtalk.message("'%s': %s" %
                           (device_iface, nmdevice.device_state_to_str(state)))
            if state == nmdevice.DEVICE_STATE_ACTIVATED:
                loop.quit()

            elif state == nmdevice.DEVICE_STATE_FAILED or state == nmdevice.DEVICE_STATE_DISCONNECTED or \
                    state == nmdevice.DEVICE_STATE_CANCELLED:
                loop.quit()
                self.exit_status = 1

        device.proxy.connect_to_signal(
            "StateChanged",
            monitor,
            dbus_interface=nmdevice.DBUS_INTERFACE_DEVICE)

        loop.run()

        return self.exit_status