示例#1
0
    def __init__(self,
                 logid="AI",
                 logfile=system_temp_path("ai_sd_log"),
                 debuglevel=AI_DBGLVL_WARN):
        self.log_file = logfile
        self.logid = logid
        self.dbg_lvl_current = debuglevel
        self.fh_log = None

        # list of prefixes displayed for particular logging levels
        self.log_prefix = {
            AILog.AI_DBGLVL_EMERG: "!",
            AILog.AI_DBGLVL_ERR: "E",
            AILog.AI_DBGLVL_WARN: "W",
            AILog.AI_DBGLVL_INFO: "I"
        }

        # default logging level
        self.dbg_lvl_default = AILog.AI_DBGLVL_INFO

        # if provided, open log file in append mode
        if self.log_file is not None:
            try:
                self.fh_log = open(self.log_file, "a+")
            except IOError:
                self.fh_log = None
def parse_cli(cli_opts_args):
    """ Description:
            Main function - parses command line arguments and
                            carries out service discovery

            Parameters:
                cli_opts_args - command line arguments

            Returns:
                0 - service discovery succeeded
                2 - service discovery failed
    """
    if len(cli_opts_args) == 0:
        usage()

    opts_args = cli_opts_args[1:]

    try:
        opts = getopt.getopt(opts_args, "t:s:n:o:d:h")[0]
    except getopt.GetoptError:
        AISD_LOG.post(AILog.AI_DBGLVL_ERR,
                      "Invalid options or arguments provided")
        usage()

    service_name = ""
    service_lookup_timeout = 5

    service_file = system_temp_path("service_list")

    for option, argument in opts:
        if option == "-s":
            AIService.type = argument
        if option == "-n":
            service_name = argument
        elif option == "-o":
            service_file = argument
        elif option == "-t":
            service_lookup_timeout = int(argument)
        elif option == "-d":
            AISD_LOG.set_debug_level(int(argument))
        elif option == "-h":
            usage()

    AISD_LOG.post(AILog.AI_DBGLVL_INFO,
                  "Service file: %s", service_file)

    service_list = []

    #
    # if service name was specified, add it to the list
    # of services to be looked up
    #
    if service_name:
        service_list.append(AIService(service_name,
                            service_lookup_timeout))

    # add default service
    service_list.append(AIService('_default', service_lookup_timeout))

    # Go through the list of services and try to look up them
    for i in range(len(service_list)):
        svc_instance = "%s.%s.%s" % (service_list[i].name,
                                     AIService.type, service_list[i].domain)

        AISD_LOG.post(AILog.AI_DBGLVL_INFO,
                      "Service to look up: %s", svc_instance)

        # look up the service
        ret = service_list[i].lookup()
        if ret == 0:
            svc_found_index = i
            break

    if ret == -1:
        AISD_LOG.post(AILog.AI_DBGLVL_ERR,
                      "No valid AI service found")
        return 2

    #
    # parse information captured from dns-sd in order
    # to obtain source of service (address and port)
    # extract value from 'aiwebserver' name-value pair
    #
    svc_address = service_list[svc_found_index].get_txt_rec()
    svc_name = service_list[svc_found_index].name
    svc_address = svc_address.strip().split('aiwebserver=', 1)[1]
    svc_address = svc_address.split(',')[0]
    (svc_address, svc_port) = svc_address.split(':')

    AISD_LOG.post(AILog.AI_DBGLVL_INFO,
                  "%s can be reached at: %s:%s", svc_instance,
                  svc_address, svc_port)

    # write the information to the given location
    AISD_LOG.post(AILog.AI_DBGLVL_INFO,
                  "Storing service list into %s", service_file)

    try:
        fh_svc_list = open(service_file, 'w')
    except IOError:
        AISD_LOG.post(AILog.AI_DBGLVL_ERR,
                    "Could not open %s for saving service list", service_file)
        return 2

    fh_svc_list.write("%s:%s:%s\n" % (svc_address, svc_port, svc_name))
    fh_svc_list.close()

    return 0
示例#3
0
    def __init__(self, name, script=None, manifest=None):
        '''
        Checkpoint constructor.

        Args:
          name: Name of the checkpoint.

          script: Name of script to run.  Must be provided if the Data Object
                  Cache (DOC) does not provide it.  Used when the DOC does not
                  provide the script name.

          manifest: Name of the manifest to create.  Used when the DOC
                  does not provide the manifest name.  If not provided here nor
                  by the DOC, take a default name.
        '''

        super(DerivedManifestModule, self).__init__(name)

        # Check DOC for script name before checking input arg.
        doc = InstallEngine.get_instance().data_object_cache
        self.dmd = doc.volatile.get_first_child(name=DERIVED_MANIFEST_DATA)
        if self.dmd is None:
            self.dmd = DerivedManifestData(DERIVED_MANIFEST_DATA, script)
            doc.volatile.insert_children(self.dmd)

        # Use script name passed in if script name not available in the DOC.
        if script is None:
            if self.dmd.script is None:
                errmsg = (MSG_HEADER + "Scriptfile must be specified or " +
                          "stored in data object cache.")
                self.logger.critical(errmsg)
                raise DMMScriptInvalidError(errmsg)
        else:
            self.dmd.script = script

        # Read the location of the manifest.
        # Check DOC first.
        # If not there, see if it was specified as an input argument.
        # Take a default name if it has not been provided in either place.

        self.mpd = doc.volatile.get_first_child(name=MANIFEST_PARSER_DATA)
        if self.mpd is None:
            self.mpd = ManifestParserData(MANIFEST_PARSER_DATA)
            doc.volatile.insert_children(self.mpd)

        # If DOC doesn't have a manifest, get name from input arg if provided.
        if self.mpd.manifest is None:
            self.mpd.manifest = manifest

        # If still nothing, take a default.
        if self.mpd.manifest is None:
            self.mpd.manifest = DEFAULT_AIM_MANIFEST

        # Get aiuser account information for accessing the manifest.
        try:
            self.aiuser = pwd.getpwnam(AIUSER_ACCOUNT_NAME)
        except KeyError:
            errmsg = MSG_HEADER + "Account \"%s\" information not found" % (
                AIUSER_ACCOUNT_NAME)
            self.logger.critical(errmsg)
            raise DMMAccountError(errmsg)

        msg = (MSG_HEADER +
               "Creating/modifying manifest at \"%s\"" % self.mpd.manifest)
        self.logger.info(msg)

        # Copy the script into the same dir where the derived manifest will be.
        derived_dir = os.path.dirname(self.mpd.manifest)
        if not os.path.samefile(
                derived_dir, os.path.join(".", os.path.dirname(
                    self.dmd.script))):
            script_name = os.path.basename(self.dmd.script)
            shutil.copyfile(self.dmd.script,
                            os.path.join(derived_dir, script_name))

        # Set up name of logfile aimanifest command can use.
        # This log will be collected after the script completes.
        tempfile.tempdir = system_temp_path()
        self.aim_logfile = tempfile.mktemp()
示例#4
0
from solaris_install.engine import InstallEngine
from solaris_install.engine.checkpoint import AbstractCheckpoint
from solaris_install.manifest import ManifestError, validate_manifest
from solaris_install.manifest.parser import ManifestParserData, \
    MANIFEST_PARSER_DATA
from solaris_install.target.libdiskmgt import const, diskmgt

# Non-privileged account under which scripts are run / manifests are built.
AIUSER_ACCOUNT_NAME = "aiuser"

BYTES_PER_MB = 1048576

MSG_HEADER = "Derived Manifest Module: "

# Other configurables
DEFAULT_AIM_MANIFEST = system_temp_path("manifest.xml")
SYSTEM_CONF = "/etc/netboot/system.conf"

# Commands

DEVPROP = "/usr/sbin/devprop"
ISAINFO = "/usr/bin/isainfo"
PRTCONF = "/usr/sbin/prtconf"
SU = "/usr/bin/su"
TEST = "/usr/bin/test"
UNAME = "/usr/sbin/uname"

DERIVED_MANIFEST_DATA = "derived_manifest_data"

# Derived Manifest Module error classes
示例#5
0
    def __init__(self, name, script=None, manifest=None):
        '''
        Checkpoint constructor.

        Args:
          name: Name of the checkpoint.

          script: Name of script to run.  Must be provided if the Data Object
                  Cache (DOC) does not provide it.  Used when the DOC does not
                  provide the script name.

          manifest: Name of the manifest to create.  Used when the DOC
                  does not provide the manifest name.  If not provided here nor
                  by the DOC, take a default name.
        '''

        super(DerivedManifestModule, self).__init__(name)

        # Check DOC for script name before checking input arg.
        doc = InstallEngine.get_instance().data_object_cache
        self.dmd = doc.volatile.get_first_child(name=DERIVED_MANIFEST_DATA)
        if self.dmd is None:
            self.dmd = DerivedManifestData(DERIVED_MANIFEST_DATA, script)
            doc.volatile.insert_children(self.dmd)

        # Use script name passed in if script name not available in the DOC.
        if script is None:
            if  self.dmd.script is None:
                errmsg = (MSG_HEADER + "Scriptfile must be specified or " +
                    "stored in data object cache.")
                self.logger.critical(errmsg)
                raise DMMScriptInvalidError(errmsg)
        else:
            self.dmd.script = script

        # Read the location of the manifest.
        # Check DOC first.
        # If not there, see if it was specified as an input argument.
        # Take a default name if it has not been provided in either place.

        self.mpd = doc.volatile.get_first_child(name=MANIFEST_PARSER_DATA)
        if self.mpd is None:
            self.mpd = ManifestParserData(MANIFEST_PARSER_DATA)
            doc.volatile.insert_children(self.mpd)

        # If DOC doesn't have a manifest, get name from input arg if provided.
        if self.mpd.manifest is None:
            self.mpd.manifest = manifest

        # If still nothing, take a default.
        if self.mpd.manifest is None:
            self.mpd.manifest = DEFAULT_AIM_MANIFEST

        # Get aiuser account information for accessing the manifest.
        try:
            self.aiuser = pwd.getpwnam(AIUSER_ACCOUNT_NAME)
        except KeyError:
            errmsg = MSG_HEADER + "Account \"%s\" information not found" % (
                                   AIUSER_ACCOUNT_NAME)
            self.logger.critical(errmsg)
            raise DMMAccountError(errmsg)

        msg = (MSG_HEADER + "Creating/modifying manifest at \"%s\"" %
            self.mpd.manifest)
        self.logger.info(msg)

        # Copy the script into the same dir where the derived manifest will be.
        derived_dir = os.path.dirname(self.mpd.manifest)
        if not os.path.samefile(derived_dir,
                                os.path.join(".",
                                            os.path.dirname(self.dmd.script))):
            script_name = os.path.basename(self.dmd.script)
            shutil.copyfile(self.dmd.script,
                            os.path.join(derived_dir, script_name))

        # Set up name of logfile aimanifest command can use.
        # This log will be collected after the script completes.
        tempfile.tempdir = system_temp_path()
        self.aim_logfile = tempfile.mktemp()
示例#6
0
from solaris_install.engine import InstallEngine
from solaris_install.engine.checkpoint import AbstractCheckpoint
from solaris_install.manifest import ManifestError, validate_manifest
from solaris_install.manifest.parser import ManifestParserData, \
    MANIFEST_PARSER_DATA
from solaris_install.target.libdiskmgt import const, diskmgt

# Non-privileged account under which scripts are run / manifests are built.
AIUSER_ACCOUNT_NAME = "aiuser"

BYTES_PER_MB = 1048576

MSG_HEADER = "Derived Manifest Module: "

# Other configurables
DEFAULT_AIM_MANIFEST = system_temp_path("manifest.xml")
SYSTEM_CONF = "/etc/netboot/system.conf"

# Commands

DEVPROP = "/sbin/devprop"
ISAINFO = "/usr/bin/isainfo"
SU = "/usr/bin/su"
TEST = "/usr/bin/test"
UNAME = "/usr/sbin/uname"

DERIVED_MANIFEST_DATA = "derived_manifest_data"

# Derived Manifest Module error classes