Ejemplo n.º 1
0
class CheckResult(object):
    """Result of an input check."""

    def __init__(self):
        self._success = False
        self._error_message = ""
        self.error_message_changed = Signal()

    @property
    def success(self):
        return self._success

    @success.setter
    def success(self, value):
        self._success = value

    @property
    def error_message(self):
        """Optional error message describing why the input is not valid.

        :returns: why the input is bad (provided it is bad) or None
        :rtype: str or None
        """
        return self._error_message

    @error_message.setter
    def error_message(self, new_error_message):
        self._error_message = new_error_message
        self.error_message_changed.emit(new_error_message)
Ejemplo n.º 2
0
    def __init__(self, storage, payload):
        """Create a new Hub instance.

           The arguments this base class accepts defines the API that Hubs
           have to work with.  A Hub does not get free reign over everything
           in the anaconda class, as that would be a big mess.  Instead, a
           Hub may count on the following:

           data         -- An instance of a pykickstart Handler object.  The
                           Hub uses this to populate its UI with defaults
                           and to pass results back after it has run. The data
                           property must be implemented by classes inheriting
                           from Hub.
           storage      -- An instance of storage.Storage.  This is useful for
                           determining what storage devices are present and how
                           they are configured.
           payload      -- An instance of a payload.Payload subclass.  This
                           is useful for displaying and selecting packages to
                           install, and in carrying out the actual installation.
        """
        self._storage = storage
        self.payload = payload

        self.paths = {}
        self._spokes = {}

        # entry and exit signals
        # - get the hub instance as a single argument
        self.entered = Signal()
        self.exited = Signal()

        # connect the default callbacks
        self.entered.connect(self.entry_logger)
        self.exited.connect(self.exit_logger)
Ejemplo n.º 3
0
    class Test3Implementation(object):

        def __init__(self):
            self.module_properties_changed = Signal()
            self.a_changed = Signal()
            self.b_changed = Signal()

            self._a = 1
            self._b = 2

        @property
        def a(self):
            return self._a

        def set_a(self, a):
            self._a = a
            self.a_changed.emit()

        @property
        def b(self):
            return self._b

        @b.setter
        def b(self, b):
            self._b = b
            self.b_changed.emit()

        def do_external_changes(self, a, b):
            self.set_a(a)
            self.b = b

        def do_secret_changes(self, a, b):
            self._a = a
            self._b = b
Ejemplo n.º 4
0
    def __init__(self):
        super().__init__()

        self._firewall_module = FirewallModule()

        self.hostname_changed = Signal()
        self._hostname = "localhost.localdomain"

        self.current_hostname_changed = Signal()
        self._hostname_service_proxy = None

        if conf.system.provides_system_bus:
            self._hostname_service_proxy = HOSTNAME.get_proxy()
            self._hostname_service_proxy.PropertiesChanged.connect(self._hostname_service_properties_changed)

        self.connected_changed = Signal()
        self.nm_client = None
        # TODO fallback solution - use Gio/GNetworkMonitor ?
        if SystemBus.check_connection():
            nm_client = NM.Client.new(None)
            if nm_client.get_nm_running():
                self.nm_client = nm_client
                self.nm_client.connect("notify::%s" % NM.CLIENT_STATE, self._nm_state_changed)
                initial_state = self.nm_client.get_state()
                self.set_connected(self._nm_state_connected(initial_state))
            else:
                log.debug("NetworkManager is not running.")
Ejemplo n.º 5
0
        def __init__(self):
            self.module_properties_changed = Signal()
            self.a_changed = Signal()
            self.b_changed = Signal()

            self._a = 1
            self._b = 2
Ejemplo n.º 6
0
    def __init__(self):
        """Initialize the module."""
        super().__init__()

        self.bootloader_mode_changed = Signal()
        self._bootloader_mode = BootloaderMode.ENABLED

        self.bootloader_type_changed = Signal()
        self._bootloader_type = BootloaderType.DEFAULT

        self.preferred_location_changed = Signal()
        self._preferred_location = BOOTLOADER_LOCATION_DEFAULT

        self.drive_changed = Signal()
        self._drive = ""

        self.drive_order_changed = Signal()
        self._drive_order = []

        self.keep_mbr_changed = Signal()
        self._keep_mbr = False

        self.keep_boot_order_changed = Signal()
        self._keep_boot_order = False

        self.extra_arguments_changed = Signal()
        self._extra_arguments = []

        self.timeout_changed = Signal()
        self._timeout = BOOTLOADER_TIMEOUT_UNSET

        self.password_is_set_changed = Signal()
        self._password = ""
        self._password_is_encrypted = False
Ejemplo n.º 7
0
class InputField(object):
    """An input field containing data to be checked.

    The input field can have an initial value that can be
    monitored for change via signals.
    """

    def __init__(self, initial_content):
        self._initial_content = initial_content
        self._content = initial_content
        self.changed = Signal()
        self._initial_change_signal_fired = False
        self.changed_from_initial_state = Signal()

    @property
    def content(self):
        return self._content

    @content.setter
    def content(self, new_content):
        old_content = self._content
        self._content = new_content
        # check if the input changed from the initial state
        if old_content != new_content:
            self.changed.emit()
            # also fire the changed-from-initial-state signal if required
            if not self._initial_change_signal_fired and new_content != self._initial_content:
                self.changed_from_initial_state.emit()
                self._initial_change_signal_fired = True
Ejemplo n.º 8
0
    def __init__(self):
        """Initialize the module."""
        super().__init__()

        self.enabled_changed = Signal()
        self._enabled = False

        self.mount_points_changed = Signal()
        self._mount_points = list()
Ejemplo n.º 9
0
 def __init__(self):
     super().__init__()
     self._password_score = 0
     self.password_score_changed = Signal()
     self._status_text = ""
     self.status_text_changed = Signal()
     self._password_quality = 0
     self.password_quality_changed = Signal()
     self._length_ok = False
     self.length_ok_changed = Signal()
Ejemplo n.º 10
0
    def __init__(self):
        super().__init__()
        self._url_source_name = ""
        self._generate_source_name()

        self._repo_configuration = RepoConfigurationData()
        self.repo_configuration_changed = Signal()

        self._repo_configuration.name = self._url_source_name

        self._install_repo_enabled = False
        self.install_repo_enabled_changed = Signal()
Ejemplo n.º 11
0
 def __init__(self):
     super().__init__()
     self._directory = ""
     self.directory_changed = Signal()
     self._device = ""
     self.device_changed = Signal()
     self._install_tree_path = ""
     self._device_mount = MountPointGenerator.generate_mount_point(
         self.type.value.lower() + "-device")
     self._iso_mount = MountPointGenerator.generate_mount_point(
         self.type.value.lower() + "-iso")
     self._iso_name = ""
Ejemplo n.º 12
0
    def __init__(self):
        super().__init__()
        self.timezone_changed = Signal()
        self._timezone = "America/New_York"

        self.is_utc_changed = Signal()
        self._is_utc = False

        self.ntp_enabled_changed = Signal()
        self._ntp_enabled = True

        self.ntp_servers_changed = Signal()
        self._ntp_servers = []
Ejemplo n.º 13
0
    def __init__(self):
        super().__init__()

        # system purpose

        self._valid_roles = []
        self._valid_slas = []
        self._valid_usage_types = []

        self._system_purpose_data = SystemPurposeData()
        self.system_purpose_data_changed = Signal()

        self._load_valid_system_purpose_values()
Ejemplo n.º 14
0
    def __init__(self, message_bus, service_name):
        """Creates an DBus service observer.

        :param message_bus: a message bus
        :param service_name: a DBus name of a service
        """
        self._message_bus = message_bus
        self._service_name = service_name
        self._is_service_available = False

        self._service_available = Signal()
        self._service_unavailable = Signal()

        self._watched_id = None
Ejemplo n.º 15
0
    def __init__(self, message_bus, service_name):
        """Creates an DBus service observer.

        :param message_bus: a message bus
        :param service_name: a DBus name of a service
        """
        self._message_bus = message_bus
        self._service_name = service_name
        self._is_service_available = False

        self._service_available = Signal()
        self._service_unavailable = Signal()

        self._watched_id = None
Ejemplo n.º 16
0
    def __init__(self):
        super().__init__()
        self.language_changed = Signal()
        self._language = ""

        self.language_support_changed = Signal()
        self._language_support = []

        self.language_seen_changed = Signal()
        self._language_seen = False

        self.keyboard_changed = Signal()
        self._keyboard = ""

        self.vc_keymap_changed = Signal()
        self._vc_keymap = ""

        self.x_layouts_changed = Signal()
        self._x_layouts = []

        self.switch_options_changed = Signal()
        self._switch_options = []

        self.keyboard_seen_changed = Signal()
        self._keyboard_seen = False
Ejemplo n.º 17
0
    def __init__(self):
        super().__init__()

        self._firewall_module = FirewallModule()

        self.hostname_changed = Signal()
        self._hostname = ""

        self.current_hostname_changed = Signal()
        self._hostname_service_proxy = self._get_hostname_proxy()

        self.connected_changed = Signal()
        self.nm_client = None
        # TODO fallback solution - use Gio/GNetworkMonitor ?
        if SystemBus.check_connection():
            nm_client = NM.Client.new(None)
            if nm_client.get_nm_running():
                self.nm_client = nm_client
                self.nm_client.connect("notify::%s" % NM.CLIENT_STATE,
                                       self._nm_state_changed)
                initial_state = self.nm_client.get_state()
                self.set_connected(self._nm_state_connected(initial_state))
            else:
                log.debug("NetworkManager is not running.")

        self._original_network_data = []
        self._device_configurations = None
        self._use_device_configurations = False
        self.configurations_changed = Signal()

        self._default_device_specification = DEFAULT_DEVICE_SPECIFICATION
        self._bootif = None
        self._ifname_option_values = []
        self._disable_ipv6 = False
        self._apply_boot_options(kernel_arguments)
Ejemplo n.º 18
0
    def __init__(self):
        super().__init__()

        self.selinux_changed = Signal()
        self._selinux = SELinuxMode.DEFAULT

        self.authselect_changed = Signal()
        self._authselect_args = []

        self.authconfig_changed = Signal()
        self._authconfig_args = []

        self.realm_changed = Signal()
        self._realm = self.create_realm()
Ejemplo n.º 19
0
    def __init__(self):
        super().__init__()
        self.rootpw_seen_changed = Signal()
        self._rootpw_seen = False

        self.root_password_is_set_changed = Signal()
        self._root_password_is_set = False
        self._root_password = ""
        self._root_password_is_crypted = False

        self.root_account_locked_changed = Signal()
        self._root_account_locked = False

        self.users_changed = Signal()
        self._users = {}
Ejemplo n.º 20
0
    def __init__(self, message_bus, service_name, monitoring=GLibMonitoring):
        """Creates an DBus service observer.

        :param message_bus: a message bus
        :param service_name: a DBus name of a service
        """
        self._message_bus = message_bus
        self._service_name = service_name
        self._is_service_available = False

        self._service_available = Signal()
        self._service_unavailable = Signal()

        self._monitoring = monitoring
        self._subscriptions = []
Ejemplo n.º 21
0
class ModuleManager(object):
    """A class for managing kickstart modules."""
    def __init__(self):
        self._module_observers = []
        self.module_observers_changed = Signal()

    @property
    def module_observers(self):
        """Return the modules observers."""
        return self._module_observers

    def set_module_observers(self, observers):
        """Set the module observers."""
        self._module_observers = observers
        self.module_observers_changed.emit(self._module_observers)

    def start_modules_with_task(self):
        """Start modules with the task."""
        task = StartModulesTask(DBus, conf.anaconda.kickstart_modules,
                                conf.anaconda.addons_enabled)
        task.succeeded_signal.connect(
            lambda: self.set_module_observers(task.get_result()))
        return task

    def set_modules_locale(self, locale):
        """Set locale of all modules.

        :param str locale: locale to set
        """
        log.info("Setting locale of all modules to %s.", locale)
        for observer in self.module_observers:
            if not observer.is_service_available:
                log.warning("%s is not available when setting locale",
                            observer)
                continue
            observer.proxy.SetLocale(locale)

    def stop_modules(self):
        """Tell all running modules to quit."""
        log.debug("Stop modules.")
        for observer in self.module_observers:
            if not observer.is_service_available:
                continue

            # Call synchronously, because we need to wait for the
            # modules to quit before the boss can quit itself.
            observer.proxy.Quit()
            log.debug("%s has quit.", observer)
Ejemplo n.º 22
0
 def __init__(self):
     self._lock = RLock()
     self._modules = set()
     self._all_modules_added = False
     self.init_done = Signal()
     self._init_done_triggered = False
     self._added_module_count = 0
Ejemplo n.º 23
0
    def __init__(self):
        super().__init__()
        self.enabled_services_changed = Signal()
        self._enabled_services = list()

        self.disabled_services_changed = Signal()
        self._disabled_services = list()

        self.default_target_changed = Signal()
        self._default_target = ""

        self.default_desktop_changed = Signal()
        self._default_desktop = ""

        self.setup_on_boot_changed = Signal()
        self._setup_on_boot = SetupOnBootAction.DEFAULT
Ejemplo n.º 24
0
    def __init__(self):
        super().__init__()
        self._progress_changed_signal = Signal()

        self.__progress_lock = Lock()
        self.__progress_step = 0
        self.__progress_msg = ""
Ejemplo n.º 25
0
    def __init__(self):
        super().__init__()

        # system purpose

        self._valid_roles = []
        self._valid_slas = []
        self._valid_usage_types = []

        self._system_purpose_data = SystemPurposeData()
        self.system_purpose_data_changed = Signal()

        self._load_valid_system_purpose_values()

        self._is_system_purpose_applied = False
        self.is_system_purpose_applied_changed = Signal()

        # subscription request

        self._subscription_request = SubscriptionRequest()
        self.subscription_request_changed = Signal()

        # Insights

        # What are the defaults for Red Hat Insights ?
        # - during a kickstart installation, the user
        #   needs to opt-in by using the rhsm command
        #   with the --connect-to-insights option
        # - during a GUI interactive installation the
        #  "connect to Insights" checkbox is checked by default,
        #  making Insights opt-out
        # - in both cases the system also needs to be subscribed,
        #   or else the system can't be connected to Insights
        self._connect_to_insights = False
        self.connect_to_insights_changed = Signal()

        # subscription status
        self.subscription_attached_changed = Signal()
        self._subscription_attached = False

        # RHSM service startup and access
        self._rhsm_startup_task = StartRHSMTask()
        self._rhsm_observer = RHSMObserver(
            self._rhsm_startup_task.is_service_available)

        # RHSM config default values cache
        self._rhsm_config_defaults = None
Ejemplo n.º 26
0
    def __init__(self):
        super().__init__()

        self.selinux_changed = Signal()
        self._selinux = SELinuxMode.DEFAULT

        self.authselect_changed = Signal()
        self._authselect_args = []

        self.authconfig_changed = Signal()
        self._authconfig_args = []

        self.fingerprint_auth_enabled_changed = Signal()
        self._fingerprint_auth_enabled = False

        self.realm_changed = Signal()
        self._realm = RealmData()
Ejemplo n.º 27
0
    def __init__(self):
        super().__init__()
        self.timezone_changed = Signal()
        self._timezone = "America/New_York"

        self._geoloc_task = None
        self.geolocation_result_changed = Signal()
        self._geoloc_result = GeolocationData()

        self.is_utc_changed = Signal()
        self._is_utc = False

        self.ntp_enabled_changed = Signal()
        self._ntp_enabled = True

        self.time_sources_changed = Signal()
        self._time_sources = []
Ejemplo n.º 28
0
 def __init__(self):
     super().__init__()
     self._password_score = 0
     self.password_score_changed = Signal()
     self._status_text = ""
     self.status_text_changed = Signal()
     self._password_quality = 0
     self.password_quality_changed = Signal()
     self._length_ok = False
     self.length_ok_changed = Signal()
Ejemplo n.º 29
0
class NFSSourceModule(MountingSourceBase):
    """The NFS source module."""
    def __init__(self):
        super().__init__()
        self._url = ""
        self.url_changed = Signal()

    @property
    def type(self):
        """Get type of this source."""
        return SourceType.NFS

    def for_publication(self):
        """Return a DBus representation."""
        return NFSSourceInterface(self)

    @property
    def url(self):
        """URL for mounting.

        Combines server address, path, and options.

        :rtype: str
        """
        return self._url

    def set_url(self, url):
        """Set all NFS values with a valid URL.

        Fires all signals.

        :param url: URL
        :type url: str
        """
        self._url = url
        self.url_changed.emit()
        log.debug("NFS URL is set to %s", self._url)

    def set_up_with_tasks(self):
        """Set up the installation source for installation.

        :return: list of tasks required for the source setup
        :rtype: [Task]
        """
        return [SetUpNFSSourceTask(self.mount_point, self._url)]
Ejemplo n.º 30
0
    def __init__(self):
        super().__init__()
        self._storage = None

        self.selected_disks_changed = Signal()
        self._selected_disks = []

        self.exclusive_disks_changed = Signal()
        self._exclusive_disks = []

        self.ignored_disks_changed = Signal()
        self._ignored_disks = []

        self.protected_devices_changed = Signal()
        self._protected_devices = []

        self.disk_images_changed = Signal()
        self._disk_images = {}
Ejemplo n.º 31
0
    def __init__(self):
        super().__init__()
        self._storage = None

        self.selected_disks_changed = Signal()
        self._selected_disks = []

        self.exclusive_disks_changed = Signal()
        self._exclusive_disks = []

        self.ignored_disks_changed = Signal()
        self._ignored_disks = []

        self.protected_devices_changed = Signal()
        self._protected_devices = []

        self.disk_images_changed = Signal()
        self._disk_images = {}
Ejemplo n.º 32
0
class UIModule(KickstartBaseModule):
    """The user interface module."""
    def __init__(self):
        super().__init__()
        self._password_policies = self.get_default_password_policies()
        self.password_policies_changed = Signal()

    def publish(self):
        """Publish the module."""
        DBus.publish_object(USER_INTERFACE.object_path, UIInterface(self))

    @property
    def password_policies(self):
        """The password policies."""
        return self._password_policies

    def set_password_policies(self, policies):
        """Set the password policies.

        Default policy names:

            root  The policy for the root password.
            user  The policy for the user password.
            luks  The policy for the LUKS passphrase.

        :param policies: a dictionary of policy names and policy data
        """
        self._password_policies = policies
        self.password_policies_changed.emit()
        log.debug("Password policies are set to '%s'.", policies)

    def get_default_password_policies(self):
        """Get the default password policies.

        :return: a dictionary of policy names and policy data
        """
        return {
            PASSWORD_POLICY_ROOT:
            PasswordPolicy.from_defaults(PASSWORD_POLICY_ROOT),
            PASSWORD_POLICY_USER:
            PasswordPolicy.from_defaults(PASSWORD_POLICY_USER),
            PASSWORD_POLICY_LUKS:
            PasswordPolicy.from_defaults(PASSWORD_POLICY_LUKS),
        }
Ejemplo n.º 33
0
    def __init__(self, initial_password_content,
                 initial_password_confirmation_content, policy_name):
        self._password = InputField(initial_password_content)
        self._password_confirmation = InputField(
            initial_password_confirmation_content)
        self._checks = []
        self._success = False
        self._error_message = ""
        self._failed_checks = []
        self._policy_name = policy_name
        self._username = None
        self._fullname = ""
        self._secret_type = constants.SecretType.PASSWORD
        # connect to the password field signals
        self.password.changed.connect(self.run_checks)
        self.password_confirmation.changed.connect(self.run_checks)

        # signals
        self.checks_done = Signal()
Ejemplo n.º 34
0
    def _publish_object(self, xml="<node />"):
        """Publish an mocked object."""
        self.object = Mock(__dbus_xml__=dedent(xml))

        # Raise AttributeError for default methods.
        del self.object.Get
        del self.object.Set
        del self.object.GetAll

        # Create object signals.
        self.object.Signal1 = Signal()
        self.object.Signal2 = Signal()

        # Create default object signals.
        self.object.PropertiesChanged = Signal()

        self.handler = ServerObjectHandler(self.message_bus, self.object_path,
                                           self.object)
        self.handler.connect_object()
Ejemplo n.º 35
0
    def __init__(self):
        super().__init__()
        self._url = ""
        self.url_changed = Signal()

        self._proxy = ""
        self.proxy_changed = Signal()

        self._checksum = ""
        self.checksum_changed = Signal()

        self._verifyssl = True
        self.verifyssl_changed = Signal()

        self._kernel_version_list = []
        self.kernel_version_list_changed = Signal()

        self._image_path = conf.target.system_root + "/disk.img"

        self._requests_session = None
Ejemplo n.º 36
0
    def __init__(self):
        super().__init__()
        self._url = ""
        self.url_changed = Signal()

        self._proxy = ""
        self.proxy_changed = Signal()

        self._checksum = ""
        self.checksum_changed = Signal()

        self._verifyssl = True
        self.verifyssl_changed = Signal()
Ejemplo n.º 37
0
    def __init__(self):
        super().__init__()
        self.timezone_changed = Signal()
        self._timezone = "America/New_York"

        self.is_utc_changed = Signal()
        self._is_utc = False

        self.ntp_enabled_changed = Signal()
        self._ntp_enabled = True

        self.time_sources_changed = Signal()
        self._time_sources = []
Ejemplo n.º 38
0
    def __init__(self):
        super().__init__()
        self._progress = (0, "")

        self.__cancel_lock = Lock()
        self.__cancel = False

        self._started_signal = Signal()
        self._stopped_signal = Signal()
        self._progress_changed_signal = Signal()
        self._error_raised_signal = Signal()

        self._thread_name = "{}-{}".format(THREAD_DBUS_TASK, self.name)
Ejemplo n.º 39
0
    def __init__(self):
        self._dasds = []

        self._can_format_unformatted = True
        self._can_format_ldl = True

        self._report = Signal()
        self._report.connect(log.debug)
        self._last_message = ""

        self._dasd_module = STORAGE.get_proxy(DASD)
Ejemplo n.º 40
0
    def __init__(self):
        super().__init__()

        self._firewall_seen = False

        self.firewall_mode_changed = Signal()
        self._firewall_mode = FirewallMode.DEFAULT

        self.enabled_ports_changed = Signal()
        self._enabled_ports = []

        self.trusts_changed = Signal()
        self._trusts = []

        # services to allow
        self.enabled_services_changed = Signal()
        self._enabled_services = []

        # services to explicitly disallow
        self.disabled_services_changed = Signal()
        self._disabled_services = []
Ejemplo n.º 41
0
    def __init__(self):
        super().__init__()

        self.selinux_changed = Signal()
        self._selinux = SELinuxMode.DEFAULT

        self.authselect_changed = Signal()
        self._authselect_args = []

        self.authconfig_changed = Signal()
        self._authconfig_args = []

        self.realm_changed = Signal()
        self._realm = self.create_realm()
Ejemplo n.º 42
0
    def __init__(self):
        super().__init__()

        self.firewall_seen_changed = Signal()
        self._firewall_seen = False

        self.firewall_mode_changed = Signal()
        self._firewall_mode = FirewallMode.DEFAULT

        self.enabled_ports_changed = Signal()
        self._enabled_ports = []

        self.trusts_changed = Signal()
        self._trusts = []

        # services to allow
        self.enabled_services_changed = Signal()
        self._enabled_services = []

        # services to explicitly disallow
        self.disabled_services_changed = Signal()
        self._disabled_services = []

        self.use_system_defaults_changed = Signal()
        self._use_system_defaults = False
Ejemplo n.º 43
0
    def __init__(self, storage, payload, instclass):
        """Create a new Spoke instance.

           The arguments this base class accepts defines the API that spokes
           have to work with.  A Spoke does not get free reign over everything
           in the anaconda class, as that would be a big mess.  Instead, a
           Spoke may count on the following:

           data         -- An instance of a pykickstart Handler object.  The
                           Spoke uses this to populate its UI with defaults
                           and to pass results back after it has run. The data
                           property must be implemented by classes inherting
                           from Spoke.
           storage      -- An instance of storage.Storage.  This is useful for
                           determining what storage devices are present and how
                           they are configured.
           payload      -- An instance of a payload.Payload subclass.  This
                           is useful for displaying and selecting packages to
                           install, and in carrying out the actual installation.
           instclass    -- An instance of a BaseInstallClass subclass.  This
                           is useful for determining distribution-specific
                           installation information like default package
                           selections and default partitioning.
        """
        self._storage = storage
        self.payload = payload
        self.instclass = instclass
        self.applyOnSkip = False

        self.visitedSinceApplied = True

        # entry and exit signals
        # - get the hub instance as a single argument
        self.entered = Signal()
        self.exited = Signal()

        # connect default callbacks for the signals
        self.entered.connect(self.entry_logger)
        self.entered.connect(self._mark_screen_visited)
        self.exited.connect(self.exit_logger)
Ejemplo n.º 44
0
    def __init__(self):
        super().__init__()

        self.selinux_changed = Signal()
        self._selinux = SELINUX_DEFAULT

        self.authselect_changed = Signal()
        self._authselect_args = []

        self.authconfig_changed = Signal()
        self._authconfig_args = []

        self.realm_changed = Signal()
        self._realm = {REALM_NAME: "", REALM_DISCOVER: [], REALM_JOIN: []}
Ejemplo n.º 45
0
    def __init__(self):
        super().__init__()

        self._firewall_module = FirewallModule()

        self.hostname_changed = Signal()
        self._hostname = "localhost.localdomain"

        self.current_hostname_changed = Signal()
        self._hostname_service_proxy = None
        if SystemBus.check_connection():
            self._hostname_service_proxy = HOSTNAME.get_proxy()
            self._hostname_service_proxy.PropertiesChanged.connect(
                self._hostname_service_properties_changed)

        self.connected_changed = Signal()
        self.nm_client = None
        # TODO fallback solution - use Gio/GNetworkMonitor ?
        if SystemBus.check_connection():
            nm_client = NM.Client.new(None)
            if nm_client.get_nm_running():
                self.nm_client = nm_client
                self.nm_client.connect("notify::%s" % NM.CLIENT_STATE,
                                       self._nm_state_changed)
                initial_state = self.nm_client.get_state()
                self.set_connected(self._nm_state_connected(initial_state))
            else:
                log.debug("NetworkManager is not running.")
Ejemplo n.º 46
0
    def __init__(self):
        super().__init__()

        self._firewall_module = FirewallModule()

        self.hostname_changed = Signal()
        self._hostname = "localhost.localdomain"

        self.current_hostname_changed = Signal()
        self._hostname_service_proxy = None

        if conf.system.provides_system_bus:
            self._hostname_service_proxy = HOSTNAME.get_proxy()
            self._hostname_service_proxy.PropertiesChanged.connect(self._hostname_service_properties_changed)

        self.connected_changed = Signal()
        self.nm_client = None
        # TODO fallback solution - use Gio/GNetworkMonitor ?
        if SystemBus.check_connection():
            nm_client = NM.Client.new(None)
            if nm_client.get_nm_running():
                self.nm_client = nm_client
                self.nm_client.connect("notify::%s" % NM.CLIENT_STATE, self._nm_state_changed)
                initial_state = self.nm_client.get_state()
                self.set_connected(self._nm_state_connected(initial_state))
            else:
                log.debug("NetworkManager is not running.")

        self._original_network_data = []
        self._onboot_yes_ifaces = []
        self._device_configurations = None
        self._use_device_configurations = False
        self.configurations_changed = Signal()

        self._default_device_specification = DEFAULT_DEVICE_SPECIFICATION
        self._bootif = None
        self._ifname_option_values = []
        self._disable_ipv6 = False
        self._apply_boot_options(flags.cmdline)
Ejemplo n.º 47
0
    def __init__(self):
        super().__init__()
        self.rootpw_seen_changed = Signal()
        self._rootpw_seen = False

        self.root_password_is_set_changed = Signal()
        self._root_password_is_set = False
        self._root_password = ""
        self._root_password_is_crypted = False

        self.root_account_locked_changed = Signal()
        self._root_account_locked = False

        self.users_changed = Signal()
        self._users = {}
Ejemplo n.º 48
0
class ClosestMirrorSourceModule(RepoFilesSourceModule):
    """The source payload module for the closest mirror."""
    def __init__(self):
        """Create the module."""
        super().__init__()
        self._updates_enabled = True
        self.updates_enabled_changed = Signal()

    def for_publication(self):
        """Get the interface used to publish this source."""
        return ClosestMirrorSourceInterface(self)

    @property
    def type(self):
        """Get type of this source."""
        return SourceType.CLOSEST_MIRROR

    @property
    def description(self):
        """Get description of this source."""
        return _("Closest mirror")

    @property
    def updates_enabled(self):
        """Should repositories that provide updates be enabled?

        :return: True or False
        """
        return self._updates_enabled

    def set_updates_enabled(self, enabled):
        """Enable or disable repositories that provide updates.

        :param enabled: True to enable, False to disable
        """
        self._updates_enabled = enabled
        self.updates_enabled_changed.emit()
        log.debug("Updates enabled is set to '%s'.", enabled)
Ejemplo n.º 49
0
class UserModule(KickstartBaseModule):
    """The user module."""

    def __init__(self):
        super().__init__()

        self.name_changed = Signal()
        self._name = ""

    # pylint: disable=arguments-differ
    def process_kickstart(self, data, user_data=None):
        """Process the kickstart data."""
        if not user_data:
            return

        self.set_name(user_data.name)

    def setup_kickstart(self, data):
        """Setup the kickstart data."""
        user_data = data.UserData()
        user_data.name = self.name

        data.user.userList.append(user_data)
        return data

    @property
    def name(self):
        """Name of the user."""
        return self._name

    def set_name(self, name):
        """Set a name of the user.

        :param name: a name
        """
        self._name = name
        self.name_changed.emit()
        log.debug("User name is set to '%s'.", name)
Ejemplo n.º 50
0
    def __init__(self):
        super().__init__()
        self.timezone_changed = Signal()
        self._timezone = "America/New_York"

        self.is_utc_changed = Signal()
        self._is_utc = False

        self.ntp_enabled_changed = Signal()
        self._ntp_enabled = True

        self.ntp_servers_changed = Signal()
        self._ntp_servers = []

        # FIXME: temporary workaround until PAYLOAD module is available
        self._ntp_excluded = False
Ejemplo n.º 51
0
class UserModule(KickstartBaseModule):
    """The user module."""
    def __init__(self):
        super().__init__()

        self.name_changed = Signal()
        self._name = ""

    # pylint: disable=arguments-differ
    def process_kickstart(self, data, user_data=None):
        """Process the kickstart data."""
        if not user_data:
            return

        self.set_name(user_data.name)

    def setup_kickstart(self, data):
        """Setup the kickstart data."""
        user_data = data.UserData()
        user_data.name = self.name

        data.user.userList.append(user_data)
        return data

    @property
    def name(self):
        """Name of the user."""
        return self._name

    def set_name(self, name):
        """Set a name of the user.

        :param name: a name
        """
        self._name = name
        self.name_changed.emit()
        log.debug("User name is set to '%s'.", name)
Ejemplo n.º 52
0
    def __init__(self, initial_password_content, initial_password_confirmation_content,
                 policy):
        self._password = InputField(initial_password_content)
        self._password_confirmation = InputField(initial_password_confirmation_content)
        self._checks = []
        self._success = False
        self._error_message = ""
        self._failed_checks = []
        self._successful_checks = []
        self._policy = policy
        self._username = None
        self._fullname = ""
        self._secret_type = constants.SecretType.PASSWORD
        # connect to the password field signals
        self.password.changed.connect(self.run_checks)
        self.password_confirmation.changed.connect(self.run_checks)

        # signals
        self.checks_done = Signal()
Ejemplo n.º 53
0
    def __init__(self):
        super().__init__()

        self.format_unrecognized_enabled_changed = Signal()
        self._format_unrecognized_enabled = False

        self.format_ldl_enabled_changed = Signal()
        self._format_ldl_enabled = False

        self.initialize_labels_enabled_changed = Signal()
        self._initialize_labels_enabled = False

        self.default_disk_label_changed = Signal()
        self._default_disk_label = ""

        self.initialization_mode_changed = Signal()
        self._initialization_mode = InitializationMode.DEFAULT

        self.devices_to_clear_changed = Signal()
        self._devices_to_clear = []

        self.drives_to_clear_changed = Signal()
        self._drives_to_clear = []
Ejemplo n.º 54
0
class LocalizationModule(KickstartModule):
    """The Localization module."""

    def __init__(self):
        super().__init__()
        self.language_changed = Signal()
        self._language = ""

        self.language_support_changed = Signal()
        self._language_support = []

        self.language_seen_changed = Signal()
        self._language_seen = False

        self.keyboard_changed = Signal()
        self._keyboard = ""

        self.vc_keymap_changed = Signal()
        self._vc_keymap = ""

        self.x_layouts_changed = Signal()
        self._x_layouts = []

        self.switch_options_changed = Signal()
        self._switch_options = []

        self.keyboard_seen_changed = Signal()
        self._keyboard_seen = False

    def publish(self):
        """Publish the module."""
        DBus.publish_object(LOCALIZATION.object_path, LocalizationInterface(self))
        DBus.register_service(LOCALIZATION.service_name)

    @property
    def kickstart_specification(self):
        """Return the kickstart specification."""
        return LocalizationKickstartSpecification

    def process_kickstart(self, data):
        """Process the kickstart data."""
        log.debug("Processing kickstart data...")

        # lang
        self.set_language(data.lang.lang)
        self.set_language_support(data.lang.addsupport)

        self.set_language_seen(data.lang.seen)

        # keyboard
        self.set_keyboard(data.keyboard._keyboard)
        self.set_vc_keymap(data.keyboard.vc_keymap)
        self.set_x_layouts(data.keyboard.x_layouts)
        self.set_switch_options(data.keyboard.switch_options)

        self.set_keyboard_seen(data.keyboard.seen)

    def generate_kickstart(self):
        """Return the kickstart string."""
        log.debug("Generating kickstart data...")
        data = self.get_kickstart_handler()

        # lang
        data.lang.lang = self.language
        data.lang.addsupport = self.language_support

        # keyboard
        data.keyboard._keyboard = self.keyboard
        data.keyboard.vc_keymap = self.vc_keymap
        data.keyboard.x_layouts = self.x_layouts
        data.keyboard.switch_options = self.switch_options

        return str(data)

    @property
    def language(self):
        """Return the language."""
        return self._language

    def set_language(self, language):
        """Set the language."""
        self._language = language
        self.language_changed.emit()
        log.debug("Language is set to %s.", language)

    @property
    def language_support(self):
        """Return suppored languages."""
        return self._language_support

    def set_language_support(self, language_support):
        """Set supported languages."""
        self._language_support = language_support
        self.language_support_changed.emit()
        log.debug("Language support is set to %s.", language_support)

    @property
    def language_seen(self):
        """Was language command seen in kickstart?"""
        return self._language_seen

    def set_language_seen(self, seen):
        """Set whether language command was seen in kickstart."""
        self._language_seen = seen
        self.language_seen_changed.emit()
        log.debug("Language seen set to %s.", seen)

    def install_language_with_task(self, sysroot):
        """Install language with an installation task.

        FIXME: This is just a temporary method.

        :param sysroot: a path to the root of the installed system
        :return: a DBus path of an installation task
        """
        task = LanguageInstallationTask(sysroot, self.language)
        path = self.publish_task(LOCALIZATION.namespace, task)
        return path

    @property
    def keyboard(self):
        """Return keyboard."""
        return self._keyboard

    def set_keyboard(self, keyboard):
        """Set the keyboard."""
        self._keyboard = keyboard
        self.keyboard_changed.emit()
        log.debug("Keyboard is set to %s.", keyboard)

    @property
    def vc_keymap(self):
        """Return virtual console keymap."""
        return self._vc_keymap

    def set_vc_keymap(self, vc_keymap):
        """Set virtual console keymap."""
        self._vc_keymap = vc_keymap
        self.vc_keymap_changed.emit()
        log.debug("Virtual console keymap is set to %s.", vc_keymap)

    @property
    def x_layouts(self):
        """Return X Keyboard Layouts."""
        return self._x_layouts

    def set_x_layouts(self, x_layouts):
        """Set X Keyboard Layouts."""
        self._x_layouts = x_layouts
        self.x_layouts_changed.emit()
        log.debug("X Layouts are set to %s.", x_layouts)

    @property
    def switch_options(self):
        """Return X layout switching options."""
        return self._switch_options

    def set_switch_options(self, switch_options):
        """Set X layout switching options."""
        self._switch_options = switch_options
        self.switch_options_changed.emit()
        log.debug("X layout switch options are set to %s.", switch_options)

    @property
    def keyboard_seen(self):
        """Was keyboard command seen in kickstart?"""
        return self._keyboard_seen

    def set_keyboard_seen(self, keyboard_seen):
        """Set whether keyboard command was seen in kickstart."""
        self._keyboard_seen = keyboard_seen
        self.keyboard_seen_changed.emit()
        log.debug("keyboard command considered seen in kicksatart: %s.", keyboard_seen)
Ejemplo n.º 55
0
    def __init__(self):
        super().__init__()

        self._core_group_enabled = True
        self.core_group_enabled_changed = Signal()
        self._default_environment = False

        self._environment = ""
        self.environment_changed = Signal()
        self._groups = []
        self.groups_changed = Signal()
        self._groups_flags = {}
        self._packages = []
        self.packages_changed = Signal()

        self._excluded_packages = []
        self.excluded_packages_changed = Signal()
        self._excluded_groups = []
        self.excluded_groups_changed = Signal()

        self._docs_excluded = False
        self.docs_excluded_changed = Signal()
        self._weakdeps_excluded = False
        self.weakdeps_excluded_changed = Signal()
        self._missing_ignored = False
        self.missing_ignored_changed = Signal()
        self._languages = LANGUAGES_DEFAULT
        self.languages_changed = Signal()
        self._multilib_policy = MultilibPolicy.BEST
        self.multilib_policy_changed = Signal()
        self._timeout = TIMEOUT_UNSET
        self.timeout_changed = Signal()
        self._retries = RETRIES_UNSET
        self.retries_changed = Signal()
Ejemplo n.º 56
0
class PackagesHandlerModule(KickstartBaseModule):
    """The DNF sub-module for packages section."""

    def __init__(self):
        super().__init__()

        self._core_group_enabled = True
        self.core_group_enabled_changed = Signal()
        self._default_environment = False

        self._environment = ""
        self.environment_changed = Signal()
        self._groups = []
        self.groups_changed = Signal()
        self._groups_flags = {}
        self._packages = []
        self.packages_changed = Signal()

        self._excluded_packages = []
        self.excluded_packages_changed = Signal()
        self._excluded_groups = []
        self.excluded_groups_changed = Signal()

        self._docs_excluded = False
        self.docs_excluded_changed = Signal()
        self._weakdeps_excluded = False
        self.weakdeps_excluded_changed = Signal()
        self._missing_ignored = False
        self.missing_ignored_changed = Signal()
        self._languages = LANGUAGES_DEFAULT
        self.languages_changed = Signal()
        self._multilib_policy = MultilibPolicy.BEST
        self.multilib_policy_changed = Signal()
        self._timeout = TIMEOUT_UNSET
        self.timeout_changed = Signal()
        self._retries = RETRIES_UNSET
        self.retries_changed = Signal()

    def publish(self):
        """Publish the module."""
        DBus.publish_object(DNF_PACKAGES.object_path, PackagesHandlerInterface(self))

    def process_kickstart(self, data):
        """Process the kickstart data."""
        packages = data.packages

        self.set_core_group_enabled(not packages.nocore)
        self.set_default_environment(packages.default)

        self.set_environment("" if packages.environment is None else packages.environment)
        self.set_groups(self._convert_from_kickstart_groups(packages.groupList))
        self.set_packages(packages.packageList)

        self.set_excluded_packages(packages.excludedList)
        groups = self._convert_from_excluded_kickstart_groups(packages.excludedGroupList)
        self.set_excluded_groups(groups)

        self.set_docs_excluded(packages.excludeDocs)
        self.set_weakdeps_excluded(packages.excludeWeakdeps)

        if packages.handleMissing == KS_MISSING_IGNORE:
            self.set_missing_ignored(True)
        else:
            self.set_missing_ignored(False)

        if packages.instLangs is None:
            self.set_languages(LANGUAGES_DEFAULT)
        elif packages.instLangs == "":
            self.set_languages(LANGUAGES_NONE)
        else:
            self.set_languages(packages.instLangs)

        if packages.multiLib:
            self.set_multilib_policy(MultilibPolicy.ALL)
        else:
            self.set_multilib_policy(MultilibPolicy.BEST)

        self.set_timeout(TIMEOUT_UNSET if packages.timeout is None else packages.timeout)
        self.set_retries(RETRIES_UNSET if packages.retries is None else packages.retries)

    def setup_kickstart(self, data):
        """Setup the kickstart data."""
        packages = data.packages

        packages.nocore = not self.core_group_enabled
        packages.default = self.default_environment

        packages.environment = None if self.environment == "" else self.environment
        packages.groupList = self._convert_to_kickstart_groups()
        packages.packageList = self.packages

        packages.excludedList = self.excluded_packages
        packages.excludedGroupList = self._convert_to_excluded_kickstart_groups()

        packages.excludeDocs = self.docs_excluded
        packages.excludeWeakdeps = self.weakdeps_excluded
        packages.handleMissing = KS_MISSING_IGNORE if self.missing_ignored else KS_MISSING_PROMPT

        if self.languages == LANGUAGES_DEFAULT:
            packages.instLangs = None
        elif self.languages == LANGUAGES_NONE:
            packages.instLangs = ""
        else:
            packages.instLangs = self.languages

        if self.multilib_policy == MultilibPolicy.ALL:
            packages.multiLib = True
        else:
            packages.multiLib = False

        packages.timeout = self.timeout if self.timeout >= 0 else None
        packages.retries = self.retries if self.retries >= 0 else None

        # The empty packages section won't be printed without seen set to True
        packages.seen = True

    def _convert_from_kickstart_groups(self, kickstart_groups):
        groups = []
        for group in kickstart_groups:
            groups.append(group.name)
            self._groups_flags[group.name] = group.include

        log.debug("Storing groups flags: %s", self._groups_flags)
        return groups

    def _convert_to_kickstart_groups(self):
        ks_groups = []
        for group_name in self.groups:
            ks_groups.append(
                Group(name=group_name,
                      include=self._groups_flags.get(group_name, GROUP_DEFAULT)))

        return ks_groups

    def _convert_from_excluded_kickstart_groups(self, kickstart_groups):
        """Get group name from the KS excluded groups"""
        return [group.name for group in kickstart_groups]

    def _convert_to_excluded_kickstart_groups(self):
        """Create KS excluded groups from an excluded_groups"""
        return [Group(name=group, include=GROUP_DEFAULT) for group in self.excluded_groups]

    @property
    def core_group_enabled(self):
        """Should the core group be installed?

        :rtype: Bool
        """
        return self._core_group_enabled

    def set_core_group_enabled(self, core_group_enabled):
        """Set if the core group should be installed.

        :param core_group_enabled: True if the core group should be installed
        :type core_group_enabled: Bool
        """
        self._core_group_enabled = core_group_enabled
        self.core_group_enabled_changed.emit()
        log.debug("Core group enabled is set to %s.", core_group_enabled)

    @property
    def default_environment(self):
        """Default environment should be marked for installation?

        :rtype: Bool
        """
        return self._default_environment

    def set_default_environment(self, default_environment):
        """Mark the default environment for installation.

        :param default_environment: True if the default package set should be installed
        :type default_environment: True
        """
        self._default_environment = default_environment
        log.debug("Default package set is set to %s.", default_environment)

    @property
    def environment(self):
        """Get chosen packages environment.

        :rtype: str
        """
        return self._environment

    def set_environment(self, environment):
        """Set packages environment.

        :param environment: environment id
        :type environment: str
        """
        self._environment = environment
        self.environment_changed.emit()
        log.debug("Environment is set to '%s'.", environment)

    @property
    def groups(self):
        """Get list of package groups marked for installation.

        :rtype: [str]
        """
        return self._groups

    def set_groups(self, groups):
        """Set package groups marked for installation.

        :param groups: list of package groups
        :type groups: [str]
        """
        self._groups = groups
        self.groups_changed.emit()
        log.debug("Groups is set to %s.", groups)

    @property
    def packages(self):
        """Get list of packages marked for installation.

        :rtype: [str]
        """
        return self._packages

    def set_packages(self, packages):
        """Set list of packages marked for installation.

        :param packages: list of packages
        :type packages: [str]
        """
        self._packages = packages
        self.packages_changed.emit()
        log.debug("Packages is set to %s.", packages)

    @property
    def excluded_groups(self):
        """Get list of excluded groups from the installation.

        :rtype: [str]
        """
        return self._excluded_groups

    def set_excluded_groups(self, excluded_groups):
        """Set list of excluded groups to the installation.

        :param excluded_groups: list of excluded group
        :type excluded_groups: [str]
        """
        self._excluded_groups = excluded_groups
        self.excluded_groups_changed.emit()
        log.debug("Excluded groups is set to %s.", excluded_groups)

    @property
    def excluded_packages(self):
        """Get list of excluded packages from the installation.

        :rtype: [str]
        """
        return self._excluded_packages

    def set_excluded_packages(self, excluded_packages):
        """Set list of excluded packages from the installation.

        :param excluded_packages: list of excluded packages
        :type excluded_packages: [str]
        """
        self._excluded_packages = excluded_packages
        self.excluded_packages_changed.emit()
        log.debug("Excluded packages is set to %s.", excluded_packages)

    @property
    def docs_excluded(self):
        """Should the documentation be excluded during the installation.

        :rtype: bool
        """
        return self._docs_excluded

    def set_docs_excluded(self, docs_excluded):
        """Set if the documentation should be installed with the packages.

        :param docs_excluded: True if packages documentation should be installed
        :type docs_excluded: bool
        """
        self._docs_excluded = docs_excluded
        self.docs_excluded_changed.emit()
        log.debug("Exclude docs is set to %s.", docs_excluded)

    @property
    def weakdeps_excluded(self):
        """Should the packages weak dependencies be excluded from the installation.

        :rtype: bool
        """
        return self._weakdeps_excluded

    def set_weakdeps_excluded(self, weakdeps_excluded):
        """Set if the weak dependencies should be excluded during the installation.

        :param weakdeps_excluded: True if the weak dependencies should be excluded
        :type weakdeps_excluded: bool
        """
        self._weakdeps_excluded = weakdeps_excluded
        self.weakdeps_excluded_changed.emit()
        log.debug("Exclude weakdeps is set to %s.", weakdeps_excluded)

    @property
    def missing_ignored(self):
        """Ignore packages that are missing from the repositories.

        :rtype: bool
        """
        return self._missing_ignored

    def set_missing_ignored(self, missing_ignored):
        """Set if the packages missing during the installation should be ignored.

        :param missing_ignored: True if missing packages should be ignored.
        :type missing_ignored: bool
        """
        self._missing_ignored = missing_ignored
        self.missing_ignored_changed.emit()
        log.debug("Ignore missing is set to %s.", missing_ignored)

    @property
    def languages(self):
        """Languages marked for installation.

        In case multiple languages are specified they are split by ',' in the string returned.

        There are special values for this property supported:
            none  - Use nil in the rpm macro.
            all   - Do not change the default settings.

        :rtype: str
        """
        return self._languages

    def set_languages(self, languages):
        """Languages marked for installation.

        Possible values are list of languages split by ',' or 'none' or 'all'.

        'none' - Use nil in the rpm macro.
        'all'  - Default behavior.

        :param languages: list of languages split by ',' or 'none' or 'all'
        :type languages: str
        """
        # raise exception if languages is None or ""
        if not languages:
            raise InvalidValueError("Languages value have to be 'none', "
                                    "'all' or list of languages")
        self._languages = languages
        self.languages_changed.emit()
        log.debug("Install languages is set to %s.", languages)

    @property
    def multilib_policy(self):
        """Get multilib policy set.

        :rtype: enum :class:`~.constants.MultilibPolicy`
        """
        return self._multilib_policy

    def set_multilib_policy(self, multilib_policy):
        """Set the multilib 'all' policy.

        :param multilib_policy: True if we want to set 'all' multilib policy.
        :type multilib_policy: enum :class:`~.constants.MultilibPolicy`
        """
        self._multilib_policy = multilib_policy
        self.multilib_policy_changed.emit()
        log.debug("Multilib policy is set to %s.", multilib_policy)

    @property
    def timeout(self):
        """Timeout how long to try before failing during the package installation.

        :rtype: int
        """
        return self._timeout

    def set_timeout(self, timeout):
        """Set timeout how long to try before failing during the package installation.

        :param timeout: number of seconds to wait
        :type timeout: int
        """
        self._timeout = timeout
        self.timeout_changed.emit()
        log.debug("Timeout is set to %s.", timeout)

    @property
    def retries(self):
        """How many times to try before failing during the package installation.

        :rtype: int
        """
        return self._retries

    def set_retries(self, retries):
        """Set how many times to try before failing during the package installation.

        :param retries: number of how many times to try
        :type retries: int
        """
        self._retries = retries
        self.retries_changed.emit()
        log.debug("Retries is set to %s.", retries)
Ejemplo n.º 57
0
 def __init__(self):
     super().__init__()
     self.kickstarted_changed = Signal()
     self._kickstarted = False
Ejemplo n.º 58
0
class KickstartModule(MainModule, KickstartBaseModule):
    """Implementation of a main kickstart module.

    The main kickstart module is able to parse and generate the given
    kickstart string based on its kickstart specification.
    """

    def __init__(self):
        super().__init__()
        self.kickstarted_changed = Signal()
        self._kickstarted = False

    @property
    def kickstart_specification(self):
        """Return a kickstart specification.

        Every kickstart module that is interested in processing
        kickstart files, should provide its own specification.

        :return: a subclass of KickstartSpecification
        """
        return NoKickstartSpecification

    @property
    def kickstart_command_names(self):
        """Return a list of kickstart command names."""
        return list(self.kickstart_specification.commands.keys())

    @property
    def kickstart_section_names(self):
        """Return a list of kickstart section names."""
        return list(self.kickstart_specification.sections.keys())

    @property
    def kickstart_addon_names(self):
        """Return a list of kickstart addon names."""
        # TODO: We need to add support for addons.
        return list()

    @property
    def kickstarted(self):
        """Was this module set up by the kickstart?"""
        return self._kickstarted

    @kickstarted.setter
    def kickstarted(self, value):
        self._kickstarted = value
        self.kickstarted_changed.emit()
        log.debug("Kickstarted is set to %s.", value)

    def get_kickstart_handler(self):
        """Return a kickstart handler.

        :return: a kickstart handler
        """
        return KickstartSpecificationHandler(self.kickstart_specification)

    def get_kickstart_parser(self, handler):
        """Return a kickstart parser.

        :param handler: a kickstart handler
        :return: a kickstart parser
        """
        return KickstartSpecificationParser(handler, self.kickstart_specification)

    def read_kickstart(self, s):
        """Read the given kickstart string.

        The kickstart string should contain only commands and
        sections that are defined by the kickstart specification.

        :param s: a kickstart string
        :raises: instances of KickstartError
        """
        log.debug("Reading kickstart...")
        handler = self.get_kickstart_handler()
        parser = self.get_kickstart_parser(handler)

        parser.readKickstartFromString(s)
        self.process_kickstart(handler)
        self.kickstarted = True

    def generate_kickstart(self):
        """Return a kickstart representation of this module.

        The kickstart string should contain only commands and
        sections that are defined by the kickstart specification.

        :return: a kickstart string
        """
        handler = self.get_kickstart_handler()
        self.setup_kickstart(handler)
        return str(handler)

    def generate_temporary_kickstart(self):
        """Return a temporary kickstart representation of this module.

        Don't include kickstart commands temporarily unsupported in UI.

        :return: a kickstart string
        """
        return self.generate_kickstart()

    def install_with_tasks(self, sysroot):
        """Return installation tasks of this module.

        :param sysroot: a path to the root of the installed system
        :return: a list of DBus paths of the installation tasks
        """
        return []
Ejemplo n.º 59
0
class NetworkModule(KickstartModule):
    """The Network module."""

    def __init__(self):
        super().__init__()

        self._firewall_module = FirewallModule()

        self.hostname_changed = Signal()
        self._hostname = "localhost.localdomain"

        self.current_hostname_changed = Signal()
        self._hostname_service_proxy = None

        if conf.system.provides_system_bus:
            self._hostname_service_proxy = HOSTNAME.get_proxy()
            self._hostname_service_proxy.PropertiesChanged.connect(self._hostname_service_properties_changed)

        self.connected_changed = Signal()
        self.nm_client = None
        # TODO fallback solution - use Gio/GNetworkMonitor ?
        if SystemBus.check_connection():
            nm_client = NM.Client.new(None)
            if nm_client.get_nm_running():
                self.nm_client = nm_client
                self.nm_client.connect("notify::%s" % NM.CLIENT_STATE, self._nm_state_changed)
                initial_state = self.nm_client.get_state()
                self.set_connected(self._nm_state_connected(initial_state))
            else:
                log.debug("NetworkManager is not running.")

    def publish(self):
        """Publish the module."""
        self._firewall_module.publish()

        DBus.publish_object(NETWORK.object_path, NetworkInterface(self))
        DBus.register_service(NETWORK.service_name)

    @property
    def kickstart_specification(self):
        """Return the kickstart specification."""
        return NetworkKickstartSpecification

    def process_kickstart(self, data):
        """Process the kickstart data."""
        if data.network.hostname:
            self.set_hostname(data.network.hostname)
        self._firewall_module.process_kickstart(data)

    def generate_kickstart(self):
        """Return the kickstart string."""
        data = self.get_kickstart_handler()
        data.network.network = []
        # hostname
        hostname_data = data.NetworkData(hostname=self.hostname, bootProto="")
        data.network.network.append(hostname_data)
        # firewall
        self._firewall_module.setup_kickstart(data)
        return str(data)

    @property
    def hostname(self):
        """Return the hostname."""
        return self._hostname

    def set_hostname(self, hostname):
        """Set the hostname."""
        self._hostname = hostname
        self.hostname_changed.emit()
        log.debug("Hostname is set to %s", hostname)

    def _hostname_service_properties_changed(self, interface, changed, invalid):
        if interface == HOSTNAME.interface_name and "Hostname" in changed:
            hostname = changed["Hostname"]
            self.current_hostname_changed.emit(hostname)
            log.debug("Current hostname changed to %s", hostname)

    def get_current_hostname(self):
        """Return current hostname of the system."""
        if self._hostname_service_proxy:
            return self._hostname_service_proxy.Hostname

        log.debug("Current hostname cannot be get.")
        return ""

    def set_current_hostname(self, hostname):
        """Set current system hostname."""
        if not self._hostname_service_proxy:
            log.debug("Current hostname cannot be set.")
            return

        self._hostname_service_proxy.SetHostname(hostname, False)
        log.debug("Current hostname is set to %s", hostname)

    @property
    def nm_available(self):
        return self.nm_client is not None

    @property
    def connected(self):
        """Is the system connected to the network?"""
        if self.nm_available:
            return self._connected
        else:
            log.debug("Connectivity state can't be determined, assuming connected.")
            return True

    def set_connected(self, connected):
        """Set network connectivity status."""
        self._connected = connected
        self.connected_changed.emit()
        self.module_properties_changed.emit()
        log.debug("Connected to network: %s", connected)

    def is_connecting(self):
        """Is NM in connecting state?"""
        if self.nm_available:
            return self.nm_client.get_state() == NM.State.CONNECTING
        else:
            log.debug("Connectivity state can't be determined, assuming not connecting.")
            return False

    @staticmethod
    def _nm_state_connected(state):
        return state in (NM.State.CONNECTED_LOCAL, NM.State.CONNECTED_SITE, NM.State.CONNECTED_GLOBAL)

    def _nm_state_changed(self, *args):
        state = self.nm_client.get_state()
        log.debug("NeworkManager state changed to %s", state)
        self.set_connected(self._nm_state_connected(state))
Ejemplo n.º 60
0
class Controller(object):
    """A singleton that track initialization of Anaconda modules."""
    def __init__(self):
        self._lock = RLock()
        self._modules = set()
        self._all_modules_added = False
        self.init_done = Signal()
        self._init_done_triggered = False
        self._added_module_count = 0

    @synchronized
    def module_init_start(self, module):
        """Tell the controller that a module has started initialization.

        :param module: a module which has started initialization
        """
        if self._all_modules_added:
            log.warning("Late module_init_start() from: %s", self)
        elif module in self._modules:
            log.warning("Module already marked as initializing: %s", module)
        else:
            self._added_module_count += 1
            self._modules.add(module)

    def all_modules_added(self):
        """Tell the controller that all expected modules have started initialization.

        Tell the controller that all expected modules have been registered
        for initialization tracking (or have already been initialized)
        and no more are expected to be added.

        This is needed so that we don't prematurely trigger the init_done signal
        when all known modules finish initialization while other modules have not
        yet been added.
        """
        init_done = False
        with self._lock:
            log.info("Initialization of all modules (%d) has been started.", self._added_module_count)
            self._all_modules_added = True

            # if all modules finished initialization before this was added then
            # trigger the init_done signal at once
            if not self._modules and not self._init_done_triggered:
                self._init_done_triggered = True
                init_done = True

        # we should emit the signal out of the main lock as it doesn't make sense
        # to hold the controller-state lock once we decide to the trigger init_done signal
        # (and any callbacks registered on it)
        if init_done:
            self._trigger_init_done()

    def module_init_done(self, module):
        """Tell the controller that a module has finished initialization.

        And if no more modules are being initialized trigger the init_done signal.

        :param module: a module that has finished initialization
        """
        init_done = False
        with self._lock:
            # prevent the init_done signal from
            # being triggered more than once
            if self._init_done_triggered:
                log.warning("Late module_init_done from module %s.", module)
            else:
                if module in self._modules:
                    log.info("Module initialized: %s", module)
                    self._modules.discard(module)
                else:
                    log.warning("Unknown module reported as initialized: %s", module)
                # don't trigger the signal if all modules have not yet been added
                if self._all_modules_added and not self._modules:
                    init_done = True
                    self._init_done_triggered = True

        # we should emit the signal out of the main lock as it doesn't make sense
        # to hold the controller-state lock once we decide to the trigger init_done signal
        # (and any callbacks registered on it)
        if init_done:
            self._trigger_init_done()

    def _trigger_init_done(self):
        log.info("All modules have been initialized.")
        self.init_done.emit()