Пример #1
0
    def getBaseInstallParameters(self, device_uuid, data=None):
        """
        Return parameters used to bootstrap a device.

        =============== ====================
        Parameter       Description
        =============== ====================
        device_uuid     Unique device ID
        =============== ====================

        Please take a look at
        :meth:`libinst.interface.BaseInstallMethod.setBaseInstallParameters`
        for more information about the returned properties.

        ``Return:`` dict
        """
        res = {}
        if not data:
            data = load_system(device_uuid, None, False)

        for key, value in self.attributes.items():
            if key in data:
                res[value] = data[key]

        if 'installTemplateDN' in data:
            lh = LDAPHandler.get_instance()
            with lh.get_handle() as conn:
                lres = conn.search_s(data['installTemplateDN'][0],
                        ldap.SCOPE_BASE, "(objectClass=installTemplate)", ["cn"])

            res['template'] = lres[0][1]['cn'][0]

        return res
Пример #2
0
    def getConfigParameters(self, device_uuid, data=None):
        """
        Return the systems config parameters that are used
        to provision the config management system.

        =========== ===========================================
        Parameter   Description
        =========== ===========================================
        device_uuid Optional unique identifier of a device
        =========== ===========================================

        Please take a look at
        :meth:`libinst.methods.InstallMethod.setConfigParameters`
        for more information about the returned properties.

        ``Return:`` dict of properties
        """
        res = {}
        if not data:
            data = load_system(device_uuid, None, False)

        if 'configMethod' in data:
            res['method'] = data['configMethod'][0]

            if 'configItem' in data:
                res['item'] = data['configItem']

            if 'configVariable' in data:
                res['var'] = {}
                for var in data['configVariable']:
                    (name, value) = var.split("=", 1)
                    res['var'][name] = value

        return res
Пример #3
0
    def getBootString(self, device_uuid, mac=None):
        super(DebianPreseed, self).getBootString(device_uuid, mac)

        # Load device data
        data = load_system(device_uuid, mac)
        arch = data["installArchitecture"][0]

        return "label default\n    kernel debian-installer/%s/linux\n    append %%s\n" % arch
Пример #4
0
    def getBootParams(self, device_uuid, mac=None):
        super(DebianPreseed, self).getBootParams(device_uuid, mac)

        # Load device data
        data = load_system(device_uuid, mac)

        arch = data["installArchitecture"][0]
        keymap = data["installKeyboardLayout"][0] \
            if "installKeyboardLayout" in data else "us"
        locale = data["installSystemLocale"][0] \
            if "installSystemLocale" in data else "en_US.UTF-8"

        url = "%s://%s:%s/%s/%s" % (
            self.__http.scheme,
            self.__http.host,
            self.__http.port,
            self.path.lstrip("/"),
            data['macAddress'][0].replace(":", "-"))

        hostname = data['cn'][0]
        #TODO: take a look at RFC 1279 before doing anything else
        domain = "please-fixme.org"

        return [
            "vga=normal",
            "initrd=debian-installer/%s/initrd.gz" % arch,
            "netcfg/choose_interface=eth0",
            "locale=%s" % locale[:5],
            "debian-installer/country=%s" % locale[3:5],
            "debian-installer/language=%s" % locale[0:2],
            "debian-installer/keymap=%s" % keymap,
            "console-keymaps-at/keymap=%s" % keymap,
            "auto-install/enable=false",
            "preseed/url=%s" % url,
            "debian/priority=critical",
            "hostname=%s" % hostname,
            "domain=%s" % domain,
            "DEBCONF_DEBUG=5",
            ]
Пример #5
0
    def removeBaseInstallParameters(self, device_uuid, data=None):
        """
        Disable device base install capabilities.

        =========== ===========================================
        Parameter   Description
        =========== ===========================================
        device_uuid Unique identifier of a device
        =========== ===========================================
        """
        if not data:
            data = load_system(device_uuid)

        mods = [(ldap.MOD_DELETE, 'objectClass', 'installRecipe')]
        for attr in self.attributes.keys() + ["installTemplateDN"]:
            if attr in data:
                mods.append((ldap.MOD_DELETE, attr, None))

        # Do LDAP operations to remove the device
        lh = LDAPHandler.get_instance()
        with lh.get_handle() as conn:
            conn.modify_s(data['dn'], mods)
Пример #6
0
    def getBootConfiguration(self, device_uuid, mac=None):
        super(DebianPreseed, self).getBootConfiguration(device_uuid, mac)

        # Load device data
        data = load_system(device_uuid, mac)

        # Attribute conversion
        mapped_data = {
            'installer_locale': self.__attr_map("installSystemLocale", "en_US.UTF-8", data=data),
            'installer_keymap': self.__attr_map("installKeyboardLayout", "us", data=data),
            'console_keymap': self.__attr_map("installKeyboardLayout", "us", data=data),
            'console_layout_code': self.__console_layout_code(data=data),
            'time_utc': "true" if self.__attr_map("installTimeUTC", "TRUE", data=data) == "TRUE" else "false",
            'time_zone': self.__attr_map("installTimezone", "GMT", data=data),
            'ntp': self.__ntp(data=data),
            'root_login_enabled': "true" if self.__attr_map("installRootEnabled", "FALSE", data=data) == "TRUE" else "false",
            'root_password_md5': self.__attr_map("installRootPasswordHash", "$1$2wd8zNj7$eWsmsB/lVdY/m4T8wi65W1", data=data),
            'kernel_package': self.__kernel_package(data=data),
            'partition': self.__partition(data=data),
            }
        mapped_data.update(self.__load_release(data=data))

        return data['templateData'].format(**mapped_data)
Пример #7
0
    def removeConfigParameters(self, device_uuid, data=None):
        """
        Disable device configuration managmenet.

        =========== ===========================================
        Parameter   Description
        =========== ===========================================
        device_uuid Unique identifier of a device
        =========== ===========================================

        ``Return:`` True on success
        """
        if not data:
            data = load_system(device_uuid)

        mods = [(ldap.MOD_DELETE, 'objectClass', 'configRecipe')]
        for attr in ["configMethod", "configItem", "configVariable"]:
            mods.append((ldap.MOD_DELETE, attr, None))

        # Do LDAP operations to remove the device
        lh = LDAPHandler.get_instance()
        with lh.get_handle() as conn:
            conn.modify_s(data['dn'], mods)
Пример #8
0
    def setBaseInstallParameters(self, device_uuid, data, current_data=None):
        """
        Set the system base install parameters that are used
        to fill up the template.

        =============== ==============================
        Parameter       Description
        =============== ==============================
        device_uuid     Unique device ID
        data            Hash describing the parameters
        =============== ==============================

        The return parameters are encoded as a dictionary with these keys:

        =============== ======================================================
        Key             Description
        =============== ======================================================
        utc             Flag to specify if system uses UTC
        timezone        String to specify time zone
        ntp-servers     List of time server names/IPs
        kernel          The boot kernel package name
        root-hash       Hashed version of the root password
        root-user       Flag to decide if there's a root user
        disk-setup      String oriented at the RedHat kickstart device string
        template        String containing the system template
        system-locale   Locale definition for the system
        release         Release to install on the system
        keyboard-layout Keyboard layout to use
        =============== ======================================================

        ``Return:`` dict
        """
        # Load device
        if not current_data:
            current_data = load_system(device_uuid, None, False)

        is_new = not 'installRecipe' in current_data['objectClass']
        dn = current_data['dn']
        current_data = self.getBaseInstallParameters(device_uuid, current_data)

        mods = []

        # Add eventually missing objectclass
        if is_new:
            mods.append((ldap.MOD_ADD, 'objectClass', 'installRecipe'))

        # Transfer changed parameters
        for ldap_key, key in self.attributes.items():

            # New value?
            if key in data and not key in current_data:
                mods.append((ldap.MOD_ADD, ldap_key,
                    normalize_ldap(unicode2utf8(data[key]))))
                continue

            # Changed value?
            if key in data and key in current_data \
                    and data[key] != current_data[key]:

                mods.append((ldap.MOD_REPLACE, ldap_key,
                    normalize_ldap(unicode2utf8(data[key]))))
                continue

        # Removed values
        for key in current_data.keys():
            if key in self.rev_attributes and not key in data:
                mods.append((ldap.MOD_DELETE, self.rev_attributes[key], None))

        # Do LDAP operations to add the system
        res = None #@UnusedVariable
        lh = LDAPHandler.get_instance()
        with lh.get_handle() as conn:
            res = conn.search_s(",".join([self.env.config.get("libinst.template-rdn",
                "cn=templates,cn=libinst,cn=config"), lh.get_base()]),
                ldap.SCOPE_SUBTREE, "(&(objectClass=installTemplate)(cn=%s))" % data['template'], ["cn"])
            if len(res) != 1:
                raise ValueError("template '%s' not found" % data['template'])

            template_dn = res[0][0]
            if is_new:
                mods.append((ldap.MOD_ADD, 'installTemplateDN', [template_dn]))
            else:
                mods.append((ldap.MOD_REPLACE, 'installTemplateDN', [template_dn]))

            res = conn.modify_s(dn, mods)

        return res
Пример #9
0
    def setConfigParameters(self, device_uuid, data, current_data=None):
        """
        Set the system config parameters that are used
        provision the config management system.

        =========== ===========================================
        Parameter   Description
        =========== ===========================================
        device_uuid Unique device identifier
        data        Dictionary specifying the properties
        =========== ===========================================

        The data dictionary has the following property keys:
        always lists**):

        ====== ===================================
        Key    Description
        ====== ===================================
        item    List of assigned items
        method  Config management method to use
        var     Dict of variables and their values
        ====== ===================================

        ``Return:`` True no success
        """
        if not current_data:
            current_data = load_system(device_uuid, None, False)

        is_new = not 'configRecipe' in current_data['objectClass']
        dn = current_data['dn']
        current_data = self.getConfigParameters(device_uuid, current_data)

        mods = []

        # Add eventually missing objectclass
        if is_new:
            mods.append((ldap.MOD_ADD, 'objectClass', 'configRecipe'))

        # Map variables
        if 'var' in data:
            tmp = copy(data['var'])
            data['var'] = []
            if tmp:
                for key, value in tmp.items():
                    if "=" in key:
                        raise ValueError("variable key doesn't allow equal signs")
                    data['var'].append("%s=%s" % (key, value))

        # Transfer changed parameters
        for ldap_key, key in self.attributes.items():

            # New value?
            if key in data and not key in current_data:
                mods.append((ldap.MOD_ADD, ldap_key,
                    normalize_ldap(unicode2utf8(data[key]))))
                continue

            # Changed value?
            if key in data and key in current_data \
                    and data[key] != current_data[key]:

                mods.append((ldap.MOD_REPLACE, ldap_key,
                    normalize_ldap(unicode2utf8(data[key]))))
                continue

        # Removed values
        for key in current_data.keys():
            if key in self.rev_attributes and not key in data:
                mods.append((ldap.MOD_DELETE, self.rev_attributes[key], None))

        # Do LDAP operations to add the system
        lh = LDAPHandler.get_instance()
        with lh.get_handle() as conn:
            conn.modify_s(dn, mods)