def to_xml(self):
        smf_svc_config = SMFConfig('system/config-user')
        smf_svc_config_default = SMFInstance('default')
        smf_svc_config.insert_children(smf_svc_config_default)
        smf_svc_config_default.insert_children(self.root)
        smf_svc_config_default.insert_children(self.user)

        return [smf_svc_config.get_xml_tree()]
Example #2
0
def _disable_ns(data_objects):
    ''' disable all name services
    Arg: data_objects - list of service objects to affect
    Effect: append all name services, disabling them explicitly
    Note: this is not presently used, since disabling name-service-switch
        results in disabling the GNOME desktop as a result of a dependency
        chain.
    '''
    for svcn in [
            # switch and cache
            "network/name-service/switch",
            "network/name-service/cache",
            # DNS
            "network/dns/client",
            # LDAP
            "network/ldap/client",
            # NIS client and server
            "network/nis/domain",
            "network/nis/client",
            "network/nis/server",
            "network/nis/passwd",
            "network/nis/update",
            "network/nis/xfr",
            # supporting services for NIS
            "network/rpc/keyserv"]:
        svc = SMFConfig(svcn)
        data_objects.append(svc)
        # configure default instance, disabled
        svc.insert_children([SMFInstance('default', enabled=False)])
Example #3
0
    def to_xml(self):
        data_objects = []

        net_physical = SMFConfig("network/physical")
        data_objects.append(net_physical)

        net_default = SMFInstance("default", enabled=True)
        net_physical.insert_children(net_default)

        netcfg_prop = SMFPropertyGroup("netcfg")
        net_default.insert_children(netcfg_prop)

        if self.type == NetworkInfo.AUTOMATIC:
            netcfg_prop.setprop(name="active_ncp",
                                ptype="astring",
                                value="Automatic")
        elif self.type == NetworkInfo.MANUAL:
            netcfg_prop.setprop(name="active_ncp",
                                ptype="astring",
                                value="DefaultFixed")

            net_install = SMFConfig('network/install')
            data_objects.append(net_install)

            net_install_default = SMFInstance("default", enabled=True)
            net_install.insert_children([net_install_default])

            ipv4 = SMFPropertyGroup('install_ipv4_interface')
            ipv6 = SMFPropertyGroup('install_ipv6_interface')
            net_install_default.insert_children([ipv4, ipv6])

            static_address = IPAddress(self.ip_address, netmask=self.netmask)

            nic_name = self.get_nic_name(self.nic_iface)

            # IPv4 configuration
            ipv4.add_props(static_address=static_address,
                           name='%s/v4' % nic_name,
                           address_type='static')

            #
            # IPv4 default route is optional. If it was not configured
            # on Network screen, do not populate related smf property.
            #
            if self.gateway:
                ipv4.add_props(default_route=self.gateway)

            # IPv6 configuration
            ipv6.add_props(name='%s/v6' % nic_name,
                           address_type='addrconf',
                           stateless='yes',
                           stateful='yes')

        return [do.get_xml_tree() for do in data_objects]
    def to_xml(self):
        data_objects = []

        net_physical = SMFConfig("network/physical")
        data_objects.append(net_physical)

        net_default = SMFInstance("default", enabled=True)
        net_physical.insert_children(net_default)

        netcfg_prop = SMFPropertyGroup("netcfg")
        net_default.insert_children(netcfg_prop)

        if self.type == NetworkInfo.AUTOMATIC:
            netcfg_prop.setprop(name="active_ncp", ptype="astring",
                                value="Automatic")
        elif self.type == NetworkInfo.MANUAL:
            netcfg_prop.setprop(name="active_ncp", ptype="astring",
                                value="DefaultFixed")

            net_install = SMFConfig('network/install')
            data_objects.append(net_install)

            net_install_default = SMFInstance("default", enabled=True)
            net_install.insert_children([net_install_default])

            ipv4 = SMFPropertyGroup('install_ipv4_interface')
            ipv6 = SMFPropertyGroup('install_ipv6_interface')
            net_install_default.insert_children([ipv4, ipv6])

            static_address = IPAddress(self.ip_address, netmask=self.netmask)

            nic_name = self.get_nic_name(self.nic_iface)

            # IPv4 configuration
            ipv4.add_props(static_address=static_address,
                           name='%s/v4' % nic_name,
                           address_type='static')

            #
            # IPv4 default route is optional. If it was not configured
            # on Network screen, do not populate related smf property.
            #
            if self.gateway:
                ipv4.add_props(default_route=self.gateway)

            # IPv6 configuration
            ipv6.add_props(name='%s/v6' % nic_name,
                           address_type='addrconf',
                           stateless='yes',
                           stateful='yes')
            
        return [do.get_xml_tree() for do in data_objects]
Example #5
0
    def to_xml(self):
        '''Write SupportInfo object data to XML.

        Write out "None" values as empty strings.
        '''

        # Create no profile data if neither OCM nor ASR services are
        # configured on the system creating the profiles.
        if self.netcfg == SupportInfo.NOSVC:
            LOGGER().debug("SupportInfo.to_xml: NOT creating profile data.")
            return []

        LOGGER().debug("SupportInfo.to_xml: Creating profile data.")

        data_objects = []

        # Set up network configuration variables.  This blocks any entered
        # proxy variables from being put in the profile, if the last thing the
        # user selected was hub, etc.
        phost = puser = ocm_ppassword = asr_ppassword = None
        ocm_hub = asr_hub = None
        if self.netcfg == SupportInfo.PROXY:
            phost = "%s%s%s" % (self.proxy_hostname.strip(), ":",
                                self.proxy_port.strip())
            puser = self.proxy_user
            ocm_ppassword = self.ocm_proxy_password
            asr_ppassword = self.asr_proxy_password
        elif self.netcfg == SupportInfo.HUB:
            ocm_hub = self.ocm_hub
            asr_hub = self.asr_hub

        if self.ocm_available:
            LOGGER().debug("SupportInfo.to_xml: Creating OCM profile data.")
            smf_ocm_svc_config = SMFConfig('system/ocm')
            data_objects.append(smf_ocm_svc_config)
            smf_ocm_svc_config_instance = SMFInstance('default')
            smf_ocm_svc_pg = SMFPropertyGroup('reg')
            smf_ocm_svc_config.insert_children([smf_ocm_svc_config_instance])
            smf_ocm_svc_config_instance.insert_children([smf_ocm_svc_pg])

            # Don't use SMFPropertyGroup add_props() as it doesn't handle
            # dashes in the property names.
            smf_ocm_svc_pg_props = [
                SMFProperty("user", propval=CONV_EMPTY(self.mos_email)),
                SMFProperty("password",
                            propval=CONV_EMPTY(self.ocm_mos_password)),
                SMFProperty("key", propval=CONV_EMPTY(self.ocm_index)),
                SMFProperty("cipher", propval=CONV_EMPTY(self.ocm_ciphertext)),

                SMFProperty("proxy_host", propval=CONV_EMPTY(phost)),
                SMFProperty("proxy_user", propval=CONV_EMPTY(puser)),
                SMFProperty("proxy_password",
                            propval=CONV_EMPTY(ocm_ppassword)),
                SMFProperty("config_hub", propval=CONV_EMPTY(ocm_hub))]
            smf_ocm_svc_pg.insert_children(smf_ocm_svc_pg_props)

        if self.asr_available:
            LOGGER().debug("SupportInfo.to_xml: Creating ASR profile data.")
            smf_asr_svc_config = SMFConfig('system/fm/asr-notify')
            data_objects.append(smf_asr_svc_config)
            smf_asr_svc_config_instance = SMFInstance('default')
            smf_asr_svc_pg = SMFPropertyGroup('autoreg')
            smf_asr_svc_config.insert_children([smf_asr_svc_config_instance])
            smf_asr_svc_config_instance.insert_children([smf_asr_svc_pg])

            smf_asr_svc_pg_props = [
                SMFProperty("user", propval=CONV_EMPTY(self.mos_email)),
                SMFProperty("password",
                            propval=CONV_EMPTY(self.asr_mos_password)),
                SMFProperty("index", propval=CONV_EMPTY(self.asr_index)),
                SMFProperty("private-key",
                            propval=CONV_EMPTY(self.asr_private_key)),
                SMFProperty("public-key",
                            propval=CONV_EMPTY(self.asr_public_key)),
                SMFProperty("client-id",
                            propval=CONV_EMPTY(self.asr_client_id)),
                SMFProperty("timestamp",
                            propval=CONV_EMPTY(self.asr_timestamp)),

                SMFProperty("proxy-host", propval=CONV_EMPTY(phost)),
                SMFProperty("proxy-user", propval=CONV_EMPTY(puser)),
                SMFProperty("proxy-password",
                            propval=CONV_EMPTY(asr_ppassword)),
                SMFProperty("hub-endpoint", propval=CONV_EMPTY(asr_hub))]
            smf_asr_svc_pg.insert_children(smf_asr_svc_pg_props)

        return [do.get_xml_tree() for do in data_objects]
Example #6
0
    def to_xml(self):
        data_objects = []

        #
        # fmri:
        #  svc:/system/timezone:default
        #
        # configures:
        #  timezone - timezone/localtime smf property
        #
        if self.tz_timezone is not None:
            smf_svc_timezone = SMFConfig('system/timezone')
            data_objects.append(smf_svc_timezone)

            smf_svc_timezone_default = SMFInstance('default')
            smf_svc_timezone.insert_children(smf_svc_timezone_default)
            smf_pg_timezone = SMFPropertyGroup('timezone')
            smf_svc_timezone_default.insert_children(smf_pg_timezone)

            smf_pg_timezone.add_props(localtime=self.tz_timezone)

        #
        # fmri:
        #  svc:/system/environment:init
        #
        # configures:
        #  locale - environment/LANG smf property
        #
        if self.locale is not None:
            smf_svc_env = SMFConfig('system/environment')
            data_objects.append(smf_svc_env)

            smf_svc_env_init = SMFInstance('init')
            smf_svc_env.insert_children(smf_svc_env_init)
            smf_pg_env = SMFPropertyGroup('environment')
            smf_svc_env_init.insert_children(smf_pg_env)

            smf_pg_env.add_props(LANG=self.locale)

        #
        # fmri:
        #  svc:/system/identity:node
        #
        # configures:
        #  system hostname - config/nodename smf property
        #

        smf_svc_system_identity = SMFConfig('system/identity')
        data_objects.append(smf_svc_system_identity)
        smf_instance_system_identity = SMFInstance('node')
        smf_svc_system_identity.insert_children([smf_instance_system_identity])

        smf_pg_config = SMFPropertyGroup('config')
        smf_instance_system_identity.insert_children([smf_pg_config])

        # force the property type to 'astring'
        smf_pg_config.setprop(name="nodename",
                              ptype="astring",
                              value=self.hostname)

        #
        # fmri:
        #  svc:/system/keymap/config:default
        #
        # configures:
        #  keyboard layout - keymap/layout smf property
        #

        smf_svc_keymap = SMFConfig('system/keymap')
        data_objects.append(smf_svc_keymap)
        smf_instance_keymap = SMFInstance('default')
        smf_svc_keymap.insert_children([smf_instance_keymap])

        smf_pg_keymap = SMFPropertyGroup('keymap', pg_type='system')
        smf_instance_keymap.insert_children([smf_pg_keymap])

        smf_pg_keymap.add_props(layout=self.keyboard)

        #
        # fmri:
        #  svc:/system/console-login:default
        #
        # configures:
        #  terminal type - ttymon/terminal_type smf property
        #

        smf_svc_console = SMFConfig('system/console-login')
        data_objects.append(smf_svc_console)
        smf_instance_console = SMFInstance('default')
        smf_svc_console.insert_children([smf_instance_console])

        smf_pg_ttymon = SMFPropertyGroup('ttymon')
        smf_instance_console.insert_children([smf_pg_ttymon])

        smf_pg_ttymon.add_props(terminal_type=self.terminal_type)

        return [do.get_xml_tree() for do in data_objects]
Example #7
0
 def to_xml(self):
     data_objects = []
     if not self.dns and self.nameservice is None:
         # if no name services, files only
         LOGGER().info('setting name service to files only')
     # configure svc:system/name-service/switch
     LOGGER().info('preparing profile with nsswitch')
     # set NS switch service objects according to user's selection
     data_objects.append(_set_nsswitch(self.dns, self.nameservice))
     # enable name service cache
     data_objects.append(_enable_service('system/name-service/cache'))
     LOGGER().debug('to_xml:name service type=%s', self.nameservice)
     LOGGER().info(self)
     if self.dns:
         LOGGER().info('preparing profile for DNS')
         dns = SMFConfig('network/dns/client')
         data_objects.append(dns)
         # configure 'config' property group
         dns_props = SMFPropertyGroup('config')
         dns.insert_children([dns_props])
         # configure DNS nameservers
         if self.dns_server:
             # filter empty values from list
             ilist = [val for val in self.dns_server if val]
             if ilist:
                 proptype = 'net_address'
                 nameserver = dns_props.setprop("property", "nameserver",
                                                proptype)
                 nameserver.add_value_list(propvals=ilist,
                                           proptype=proptype)
         if self.dns_search:
             # filter empty values from list
             ilist = [val for val in self.dns_search if val]
             if ilist:
                 search = dns_props.setprop("property", "search", "astring")
                 search.add_value_list(propvals=[" ".join(ilist)])
         # configure default service instance
         dns.insert_children(ENABLED_DEFAULT_SERVICE_LIST)
     else:
         # explicitly disable DNS client service
         dns = SMFConfig('network/dns/client')
         dns.insert_children([SMFInstance('default', enabled=False)])
         data_objects.append(dns)
     if self.nameservice == 'LDAP':
         LOGGER().info('preparing profile for LDAP')
         ldap = SMFConfig('network/ldap/client')
         data_objects.append(ldap)
         # configure 'config' property group
         ldap_config_props = SMFPropertyGroup('config')
         ldap.insert_children([ldap_config_props])
         # add properties to 'config' property group
         ldap_config_props.setprop("propval", "profile", "astring",
                                   self.ldap_profile)
         proptype = 'host'
         nameserver = ldap_config_props.setprop("property", "server_list",
                                                proptype)
         nameserver.add_value_list(propvals=[self.ldap_ip],
                                   proptype=proptype)
         ldap_config_props.setprop("propval", "search_base", "astring",
                                   self.ldap_search_base)
         # if user chose to provide proxy bind info
         if self.ldap_proxy_bind == self.LDAP_CHOICE_PROXY_BIND:
             # create and add properties to 'cred' property group
             ldap_cred_props = SMFPropertyGroup('cred')
             ldap.insert_children([ldap_cred_props])
             ldap_cred_props.setprop("propval", "bind_dn", "astring",
                                     self.ldap_pb_dn)
             ldap_cred_props.setprop("propval", "bind_passwd", "astring",
                                     self.ldap_pb_psw)
         # configure default service instance
         ldap.insert_children(ENABLED_DEFAULT_SERVICE_LIST)
     # For NIS, user can choose either automatic (broadcast) or manual
     # specification of NIS server.  If user selected automatic, skip
     # configuration of smf properties carrying list of NIS servers.
     # That will signal ypbind(1m) to operate in broadcast mode.
     # Note: NIS domain is set below for LDAP as well as NIS
     if self.nameservice == 'NIS' or \
             (self.nameservice == 'LDAP' and self.domain):
         LOGGER().info('preparing profile for NIS')
         # manual NIS server and/or domain for LDAP and NIS
         if self.domain or (self.nis_auto == self.NIS_CHOICE_MANUAL and
                            self.nameservice == 'NIS'):
             # enable network/nis/domain smf service
             nis = SMFConfig('network/nis/domain')
             data_objects.append(nis)
             # configure 'config' property group
             nis_props = SMFPropertyGroup('config')
             nis.insert_children([nis_props])
             # configure domain for NIS or LDAP
             if self.domain:
                 LOGGER().info('setting NIS domain: %s', self.domain)
                 nis_props.setprop("propval", "domainname", "hostname",
                                   self.domain)
             # NIS server specified.
             if self.nis_auto == self.NIS_CHOICE_MANUAL and \
                     self.nameservice == 'NIS':
                 proptype = 'host'
                 nis_ip = nis_props.setprop("property", "ypservers",
                                            proptype)
                 nis_ip.add_value_list(propvals=[self.nis_ip],
                                       proptype=proptype)
             # configure default service instance
             nis.insert_children(ENABLED_DEFAULT_SERVICE_LIST)
         # enable network/nis/client smf service
         if self.nameservice == 'NIS':
             nis_client = SMFConfig('network/nis/client')
             data_objects.append(nis_client)
             # Enable default service instance.
             nis_client.insert_children(ENABLED_DEFAULT_SERVICE_LIST)
     return [do.get_xml_tree() for do in data_objects]
Example #8
0
'''
Class and functions supporting name services
'''

import logging

from solaris_install.data_object import DataObject
from solaris_install.logger import INSTALL_LOGGER_NAME
from solaris_install.sysconfig.profile import NAMESERVICE_LABEL, SMFConfig, \
        SMFInstance, SMFPropertyGroup


_LOGGER = None
# creates oft-used SMF instance list enabling default service
ENABLED_DEFAULT_SERVICE_LIST = [SMFInstance('default', enabled=True)]


def LOGGER():
    global _LOGGER
    if _LOGGER is None:
        _LOGGER = logging.getLogger(INSTALL_LOGGER_NAME + ".sysconfig")
    return _LOGGER


class NameServiceInfo(SMFConfig):
    '''Represents the Name service selected'''

    LABEL = NAMESERVICE_LABEL
    MAXDNSSERV = 3    # number of DNS server input fields
    NIS_CHOICE_AUTO = 0
    def to_xml(self):
        data_objects = []

        #
        # fmri:
        #  svc:/system/timezone:default
        #
        # configures:
        #  timezone - timezone/localtime smf property
        #
        if self.tz_timezone is not None:
            smf_svc_timezone = SMFConfig('system/timezone')
            data_objects.append(smf_svc_timezone)
        
            smf_svc_timezone_default = SMFInstance('default')
            smf_svc_timezone.insert_children(smf_svc_timezone_default)
            smf_pg_timezone = SMFPropertyGroup('timezone')
            smf_svc_timezone_default.insert_children(smf_pg_timezone)

            smf_pg_timezone.add_props(localtime=self.tz_timezone)

        #
        # fmri:
        #  svc:/system/environment:init
        #
        # configures:
        #  locale - environment/LANG smf property
        #
        if self.locale is not None:
            smf_svc_env = SMFConfig('system/environment')
            data_objects.append(smf_svc_env)
        
            smf_svc_env_init = SMFInstance('init')
            smf_svc_env.insert_children(smf_svc_env_init)
            smf_pg_env = SMFPropertyGroup('environment')
            smf_svc_env_init.insert_children(smf_pg_env)

            smf_pg_env.add_props(LANG=self.locale)

        #
        # fmri:
        #  svc:/system/identity:node
        #
        # configures:
        #  system hostname - config/nodename smf property
        #

        smf_svc_system_identity = SMFConfig('system/identity')
        data_objects.append(smf_svc_system_identity)
        smf_instance_system_identity = SMFInstance('node')
        smf_svc_system_identity.insert_children([smf_instance_system_identity])

        smf_pg_config = SMFPropertyGroup('config')
        smf_instance_system_identity.insert_children([smf_pg_config])

        smf_pg_config.add_props(nodename=self.hostname)

        #
        # fmri:
        #  svc:/system/keymap/config:default
        #
        # configures:
        #  keyboard layout - keymap/layout smf property
        #

        smf_svc_keymap = SMFConfig('system/keymap')
        data_objects.append(smf_svc_keymap)
        smf_instance_keymap = SMFInstance('default')
        smf_svc_keymap.insert_children([smf_instance_keymap])
        
        smf_pg_keymap = SMFPropertyGroup('keymap', pg_type='system')
        smf_instance_keymap.insert_children([smf_pg_keymap])
        
        smf_pg_keymap.add_props(layout=self.keyboard)
        
        #
        # fmri:
        #  svc:/system/console-login:default
        #
        # configures:
        #  terminal type - ttymon/terminal_type smf property
        #
        
        smf_svc_console = SMFConfig('system/console-login')
        data_objects.append(smf_svc_console)
        smf_instance_console = SMFInstance('default')
        smf_svc_console.insert_children([smf_instance_console])
        
        smf_pg_ttymon = SMFPropertyGroup('ttymon')
        smf_instance_console.insert_children([smf_pg_ttymon])
        
        smf_pg_ttymon.add_props(terminal_type=self.terminal_type)
        
        return [do.get_xml_tree() for do in data_objects]