예제 #1
0
 def wait_for_ovfenv(self, max_retry=1800, sleep_time=1):
     """
     Wait for cloud-init to copy ovf-env.xml file from provision ISO
     """
     ovf_file_path = os.path.join(conf.get_lib_dir(), OVF_FILE_NAME)
     for retry in range(0, max_retry):
         if os.path.isfile(ovf_file_path):
             try:
                 ovf_env = OvfEnv(fileutil.read_file(ovf_file_path))
                 self.handle_provision_guest_agent(ovf_env.provision_guest_agent)
                 return
             except ProtocolError as pe:
                 raise ProvisionError("OVF xml could not be parsed "
                                      "[{0}]: {1}".format(ovf_file_path,
                                                          ustr(pe)))
         else:
             if retry < max_retry - 1:
                 logger.info(
                     "Waiting for cloud-init to copy ovf-env.xml to {0} "
                     "[{1} retries remaining, "
                     "sleeping {2}s]".format(ovf_file_path,
                                             max_retry - retry,
                                             sleep_time))
                 if not self.validate_cloud_init():
                     logger.warn("cloud-init does not appear to be running")
                 time.sleep(sleep_time)
     raise ProvisionError("Giving up, ovf-env.xml was not copied to {0} "
                          "after {1}s".format(ovf_file_path,
                                              max_retry * sleep_time))
예제 #2
0
    def copy_ovf_env(self):
        """
        Copy ovf env file from dvd to hard disk.
        Remove password before save it to the disk
        """
        dvd_mount_point = conf.get_dvd_mount_point()
        ovf_file_path_on_dvd = os.path.join(dvd_mount_point, OVF_FILE_NAME)
        ovf_file_path = os.path.join(conf.get_lib_dir(), OVF_FILE_NAME)

        try:
            self.osutil.mount_dvd()
        except OSUtilError as e:
            raise ProtocolError("[CopyOvfEnv] Error mounting dvd: "
                                "{0}".format(ustr(e)))

        try:
            ovfxml = fileutil.read_file(ovf_file_path_on_dvd, remove_bom=True)
            ovfenv = OvfEnv(ovfxml)
        except (IOError, OSError) as e:
            raise ProtocolError("[CopyOvfEnv] Error reading file "
                                "{0}: {1}".format(ovf_file_path_on_dvd,
                                                  ustr(e)))

        try:
            ovfxml = re.sub(PASSWORD_PATTERN, PASSWORD_REPLACEMENT, ovfxml)
            fileutil.write_file(ovf_file_path, ovfxml)
        except (IOError, OSError) as e:
            raise ProtocolError("[CopyOvfEnv] Error writing file "
                                "{0}: {1}".format(ovf_file_path, ustr(e)))

        self._cleanup_ovf_dvd()

        return ovfenv
예제 #3
0
    def copy_ovf_env(self):
        """
        Copy ovf env file from dvd to hard disk.
        Remove password before save it to the disk
        """
        dvd_mount_point = conf.get_dvd_mount_point()
        ovf_file_path_on_dvd = os.path.join(dvd_mount_point, OVF_FILE_NAME)
        tag_file_path_on_dvd = os.path.join(dvd_mount_point, TAG_FILE_NAME)
        try:
            self.osutil.mount_dvd()
            ovfxml = fileutil.read_file(ovf_file_path_on_dvd, remove_bom=True)
            ovfenv = OvfEnv(ovfxml)
            ovfxml = re.sub("<UserPassword>.*?<", "<UserPassword>*<", ovfxml)
            ovf_file_path = os.path.join(conf.get_lib_dir(), OVF_FILE_NAME)
            fileutil.write_file(ovf_file_path, ovfxml)

            if os.path.isfile(tag_file_path_on_dvd):
                logger.info("Found {0} in provisioning ISO", TAG_FILE_NAME)
                tag_file_path = os.path.join(conf.get_lib_dir(), TAG_FILE_NAME)
                shutil.copyfile(tag_file_path_on_dvd, tag_file_path)

        except (OSUtilError, IOError) as e:
            raise ProtocolError(ustr(e))

        try:
            self.osutil.umount_dvd()
            self.osutil.eject_dvd()
        except OSUtilError as e:
            logger.warn(ustr(e))

        return ovfenv
예제 #4
0
 def get_ovf_env(self):
     """
     Load saved ovf-env.xml
     """
     ovf_file_path = os.path.join(conf.get_lib_dir(), OVF_FILE_NAME)
     if os.path.isfile(ovf_file_path):
         xml_text = fileutil.read_file(ovf_file_path)
         return OvfEnv(xml_text)
     else:
         raise ProtocolError("ovf-env.xml is missing.")
예제 #5
0
 def get_ovf_env(self):
     """
     Load saved ovf-env.xml
     """
     ovf_file_path = os.path.join(conf.get_lib_dir(), OVF_FILE_NAME)
     if os.path.isfile(ovf_file_path): # pylint: disable=R1705
         xml_text = fileutil.read_file(ovf_file_path)
         return OvfEnv(xml_text)
     else:
         raise ProtocolError(
             "ovf-env.xml is missing from {0}".format(ovf_file_path))
예제 #6
0
파일: util.py 프로젝트: zr000/WALinuxAgent
    def copy_ovf_env(self):
        """
        Copy ovf env file from dvd to hard disk.
        Remove password before save it to the disk
        """
        dvd_mount_point = conf.get_dvd_mount_point()
        ovf_file_path_on_dvd = os.path.join(dvd_mount_point, OVF_FILE_NAME)
        tag_file_path_on_dvd = os.path.join(dvd_mount_point, TAG_FILE_NAME)
        ovf_file_path = os.path.join(conf.get_lib_dir(), OVF_FILE_NAME)
        tag_file_path = os.path.join(conf.get_lib_dir(), TAG_FILE_NAME)

        try:
            self.osutil.mount_dvd()
        except OSUtilError as e:
            raise ProtocolError("[CopyOvfEnv] Error mounting dvd: "
                                "{0}".format(ustr(e)))

        try:
            ovfxml = fileutil.read_file(ovf_file_path_on_dvd, remove_bom=True)
            ovfenv = OvfEnv(ovfxml)
        except IOError as e:
            raise ProtocolError("[CopyOvfEnv] Error reading file "
                                "{0}: {1}".format(ovf_file_path_on_dvd,
                                                  ustr(e)))

        try:
            ovfxml = re.sub(PASSWORD_PATTERN,
                            PASSWORD_REPLACEMENT,
                            ovfxml)
            fileutil.write_file(ovf_file_path, ovfxml)
        except IOError as e:
            raise ProtocolError("[CopyOvfEnv] Error writing file "
                                "{0}: {1}".format(ovf_file_path,
                                                  ustr(e)))

        try:
            if os.path.isfile(tag_file_path_on_dvd):
                logger.info("Found {0} in provisioning ISO", TAG_FILE_NAME)
                shutil.copyfile(tag_file_path_on_dvd, tag_file_path)
        except IOError as e:
            raise ProtocolError("[CopyOvfEnv] Error copying file "
                                "{0} to {1}: {2}".format(tag_file_path,
                                                         tag_file_path,
                                                         ustr(e)))

        try:
            self.osutil.umount_dvd()
            self.osutil.eject_dvd()
        except OSUtilError as e:
            logger.warn(ustr(e))

        return ovfenv