Beispiel #1
0
    def create_tar_file(self, archive_full_path, compression="gz"):
        """Creates a tarball and writes it out to the file specified in fd

        @Note: we don't have to worry about ReadError, since we don't allow
            appending.  We only write to a tarball on create.

        @param fd: The file that the tarball will be written to
        @param compression: The type of compression that should be used

        @raise glideinwms_tarfile.CompressionError: This exception can be raised is an
            invalid compression type has been passed in
        """
        tar_mode = "w:%s" % compression
        tf = glideinwms_tarfile.open(archive_full_path, mode=tar_mode)
        self.create_tar(tf)
        tf.close()
Beispiel #2
0
    def create_tar_blob(self, compression="gz"):
        """Creates a tarball and writes it out to memory

        @Note: we don't have to worry about ReadError, since we don't allow
            appending.  We only write to a tarball on create.

        @param fd: The file that the tarball will be written to
        @param compression: The type of compression that should be used

        @raise glideinwms_tarfile.CompressionError: This exception can be raised is an
            invalid compression type has been passed in
        """
        from cStringIO import StringIO
        tar_mode = "w:%s" % compression
        file_out = StringIO()
        tf = glideinwms_tarfile.open(fileobj=file_out, mode=tar_mode)
        self.create_tar(tf)
        tf.close()
        return file_out.getvalue()
Beispiel #3
0
def extract_user_data(config):
    delimiter = "####"
    # need to add max lifetime
    # need to add alternate formats
    # need to be more robust
    try:
        # The user data has the following format:
        #     base64data####extra args
        # OR
        #     ini file

        # Split the user data
        userdata = open(config.userdata_file, 'r').read()
        if userdata.find(delimiter) > 0:
            userdata = userdata.split(delimiter)
            extra_args = userdata[1]
            extra_args = extra_args.replace("\\", "")

            # handle the tarball
            tardata = base64.b64decode(userdata[0])
            temp = tempfile.TemporaryFile()
            temp.write(tardata)
            temp.seek(0)
            tar = glideinwms_tarfile.open(fileobj=temp, mode="r:gz")
            for tarinfo in tar:
                tar.extract(tarinfo, config.home_dir)

            # now that the tarball is extracted, we expect to have an x509 proxy
            # and an ini file waiting for us to use
            cp = ConfigParser.ConfigParser()
            cp.read(config.ini_file)

            config.pilot_args = cp.get("glidein_startup", "args")
            config.factory_url = cp.get("glidein_startup", "webbase")
            proxy_file_name = cp.get("glidein_startup", "proxy_file_name")
            config.proxy_file = "%s/%s" % (config.home_dir, proxy_file_name)

            # now add the extra args to the main arg list
            config.pilot_args += " %s" % extra_args

            # check to see if the "don't shutdown" flag has been set
            config.disable_shutdown = False
            if cp.has_option("vm_properties", "disable_shutdown"):
                config.disable_shutdown = smart_bool(cp.get("vm_properties", "disable_shutdown"))
            if cp.has_option("vm_properties", "home_dir"):
                config.home_dir = cp.get("vm_properties", "home_dir")
            if cp.has_option("vm_properties", "max_lifetime"):
                config.max_lifetime = cp.get("vm_properties", "max_lifetime")
        else:
            # the only thing expected here is a simple ini file containing:
            #
            # [VM_Properties]
            # disable_shutdown = False

            fd = open(config.ini_file, 'w')
            fd.write(userdata)
            fd.close()

            cp = ConfigParser.ConfigParser()
            cp.read(config.ini_file)

            if cp.has_option("vm_properties", "disable_shutdown"):
                config.disable_shutdown = smart_bool(cp.get("vm_properties", "disable_shutdown"))
                config.debug = True
            else:
                raise UserDataError("Invalid ini file in user data.\nUser data contents:\n%s" % userdata)

    except Exception, ex:
        raise PilotError("Error extracting User Data: %s\n" % str(ex))
    def extract_user_data(self):
        """
        The user data has the following format:
        base64data####extra args
        OR
        ini file
        """
        delimiter = "####"

        try:
            # Split the user data
            userdata = open(self.config.userdata_file, 'r').read()

            if userdata.find(delimiter) > 0:
                userdata = userdata.split(delimiter)
                extra_args = userdata[1]
                extra_args = extra_args.replace("\\", "")

                # handle the tarball
                tardata = base64.b64decode(userdata[0])
                temp = tempfile.TemporaryFile()
                temp.write(tardata)
                temp.seek(0)
                tar = glideinwms_tarfile.open(fileobj=temp, mode="r:gz")
                for tarinfo in tar:
                    tar.extract(tarinfo, self.config.home_dir)
                    vm_utils.chmod(0400, tarinfo.name)

                # now that the tarball is extracted, we expect to have an x509 proxy
                # and an ini file waiting for us to use
                ini = ini_handler.Ini(self.config.ini_file)

                self.config.pilot_args = ini.get("glidein_startup", "args")
                self.config.factory_url = ini.get("glidein_startup", "webbase")
                proxy_file_name = ini.get("glidein_startup", "proxy_file_name")
                self.config.proxy_file = "%s/%s" % (self.config.home_dir, proxy_file_name)

                # now add the extra args to the main arg list
                self.config.pilot_args += " %s" % extra_args

                # check to see if the "don't shutdown" flag has been set
                self.config.disable_shutdown = False
                if ini.has_option("vm_properties", "disable_shutdown"):
                    self.config.disable_shutdown = smart_bool(ini.get("vm_properties", "disable_shutdown"))
                if ini.has_option("vm_properties", "home_dir"):
                    self.config.home_dir = ini.get("vm_properties", "home_dir")
                if ini.has_option("vm_properties", "max_lifetime"):
                    self.config.max_lifetime = ini.get("vm_properties", "max_lifetime")
            else:
                # the only thing expected here is a simple ini file containing:
                #
                # [vm_properties]
                # disable_shutdown = False

                fd = open(self.config.ini_file, 'w')
                fd.write(userdata)
                fd.close()

                ini = ini_handler.Ini(self.config.ini_file)

                if ini.has_option("vm_properties", "disable_shutdown"):
                    self.config.disable_shutdown = smart_bool(ini.get("vm_properties", "disable_shutdown"))
                    self.config.debug = True
                else:
                    raise UserDataError("Invalid ini file in user data.\nUser data contents:\n%s" % userdata)

        except Exception, ex:
            raise PilotError("Error extracting User Data: %s\n" % str(ex))