def _fetch_answer_file(self):
        self.logger.debug('_fetch_answer_file')

        source = heconflib.get_volume_path(
            self.environment[ohostedcons.StorageEnv.SP_UUID],
            self.environment[ohostedcons.StorageEnv.SD_UUID],
            self.environment[ohostedcons.StorageEnv.CONF_IMG_UUID],
            self.environment[ohostedcons.StorageEnv.CONF_VOL_UUID],
        )
        self.logger.debug('fetching from: ' + str(source))

        if not heconflib.validateConfImage(self.logger, source):
            msg = _('Unable to get the answer file from the shared storage')
            self.logger.error(msg)
            raise RuntimeError(msg)
        self._tmp_ans = heconflib.extractConfFile(
            self.logger,
            source,
            ohostedcons.FileLocations.HECONFD_ANSWERFILE,
        )
        self.logger.debug(
            'Answer file form the shared storage: {content}'.format(
                content=self._tmp_ans
            )
        )
        self.logger.info(_('Answer file successfully loaded'))
    def _fetch_answer_file(self):
        self.logger.debug('_fetch_answer_file')

        source = heconflib.get_volume_path(
            self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE],
            self.environment[ohostedcons.StorageEnv.SD_UUID],
            self.environment[ohostedcons.StorageEnv.CONF_IMG_UUID],
            self.environment[ohostedcons.StorageEnv.CONF_VOL_UUID],
        )
        self.logger.debug('fetching from: ' + str(source))

        if not heconflib.validateConfImage(self.logger, source):
            msg = _('Unable to get the answer file from the shared storage')
            self.logger.error(msg)
            raise RuntimeError(msg)
        self._tmp_ans = heconflib.extractConfFile(
            self.logger,
            source,
            ohostedcons.FileLocations.HECONFD_ANSWERFILE,
        )
        self.logger.debug(
            'Answer file form the shared storage: {content}'.format(
                content=self._tmp_ans
            )
        )
        self.logger.info(_('Answer file successfully loaded'))
 def getEngineVMOVF(self):
     self._log.debug('Extracting Engine VM OVF from the OVF_STORE')
     volumepath = OVFStore._ovf_store_path
     self._log.info('OVF_STORE volume path: %s ' % volumepath,
                    extra=log_filter.lf_args(LF_OVF_STORE_PATH,
                                             LF_OVF_LOG_DELAY))
     filename = self._HEVMID + '.ovf'
     ovf = heconflib.extractConfFile(self._log, volumepath, filename)
     self._log.debug('HEVM OVF: \n%s\n' % ovf)
     if ovf is None:
         self._log.error('Unable to extract HEVM OVF',
                         extra=log_filter.lf_args(LF_EXTRACTION_FAILED,
                                                  LF_OVF_LOG_DELAY))
     return ovf
 def getEngineVMOVF(self):
     self._log.info('Extracting Engine VM OVF from the OVF_STORE')
     volumepath = heconflib.get_volume_path(
         self._type,
         self._sdUUID,
         self._ovf_store_imgUUID,
         self._ovf_store_volUUID
     )
     self._log.info('OVF_STORE volume path: %s ' % volumepath)
     filename = self._HEVMID + '.ovf'
     ovf = heconflib.extractConfFile(self._log, volumepath, filename)
     self._log.debug('HEVM OVF: \n%s\n' % ovf)
     if ovf is None:
         self._log.error('Unable to extract HEVM OVF')
     return ovf
 def getEngineVMOVF(self):
     self._log.debug('Extracting Engine VM OVF from the OVF_STORE')
     volumepath = OVFStore._ovf_store_path
     self._log.info('OVF_STORE volume path: %s ' % volumepath,
                    extra=log_filter.lf_args(
                        LF_OVF_STORE_PATH,
                        LF_OVF_LOG_DELAY
                    ))
     filename = self._HEVMID + '.ovf'
     ovf = heconflib.extractConfFile(self._log, volumepath, filename)
     self._log.debug('HEVM OVF: \n%s\n' % ovf)
     if ovf is None:
         self._log.error('Unable to extract HEVM OVF',
                         extra=log_filter.lf_args(
                             LF_EXTRACTION_FAILED,
                             LF_OVF_LOG_DELAY
                         ))
     return ovf
    def _get_file_content_from_shared_storage(self):
        config_volume_path = self._get_config_volume_path()
        if not config_volume_path:
            return None

        archive_fname = os.path.basename(self.remote_path)
        if self._logger:
            self._logger.debug(
                "Reading '{archive_fname}' from '{source}'".format(
                    archive_fname=archive_fname,
                    source=config_volume_path,
                ))
        content = None
        if heconflib.validateConfImage(self._logger, config_volume_path):
            content = heconflib.extractConfFile(
                self._logger,
                config_volume_path,
                archive_fname,
            )
        return content
    def _get_file_content_from_shared_storage(self):
        config_volume_path = self._get_config_volume_path()
        if not config_volume_path:
            return None

        archive_fname = os.path.basename(self.remote_path)
        if self._logger:
            self._logger.debug(
                "Reading '{archive_fname}' from '{source}'".format(
                    archive_fname=archive_fname,
                    source=config_volume_path,
                )
            )
        content = None
        if heconflib.validateConfImage(self._logger, config_volume_path):
            content = heconflib.extractConfFile(
                self._logger,
                config_volume_path,
                archive_fname,
            )
        return content
    def refresh_local_conf_file(self, localcopy_filename, archive_fname):
        domain_type = self.get(ENGINE, DOMAIN_TYPE)
        sd_uuid = self.get(ENGINE, SD_UUID)
        conf_img_id = None
        conf_vol_id = None
        content = None
        try:
            conf_img_id = self.get(ENGINE, CONF_IMAGE_UUID)
            conf_vol_id = self.get(ENGINE, CONF_VOLUME_UUID)
        except (KeyError, ValueError):
            if self._logger:
                self._logger.debug("Configuration image doesn't exist")
            pass

        if not (conf_img_id and conf_vol_id):
            if self._logger:
                self._logger.debug(
                    "Failing back to conf file from a previous release"
                )
            return False

        if archive_fname == constants.HEConfFiles.HECONFD_VM_CONF:
            if self._logger:
                self._logger.info(
                    "Trying to get a fresher copy of vm configuration "
                    "from the OVF_STORE"
                )

            ovfs = ovf_store.OVFStore()
            conf = None
            scan = False

            try:
                scan = ovfs.scan()
            except (EnvironmentError, Exception) as err:
                self._logger.error(
                    "Failed scanning for OVF_STORE due to %s",
                    err
                )

            if scan:
                heovf = ovfs.getEngineVMOVF()
                if heovf is not None:
                    self._logger.info(
                        "Found an OVF for HE VM, "
                        "trying to convert"
                    )
                    conf = ovf2VmParams.confFromOvf(heovf)
            if conf is not None:
                self._logger.info('Got vm.conf from OVF_STORE')
                content = conf
            else:
                self._logger.error(
                    'Unable to get vm.conf from OVF_STORE, '
                    'falling back to initial vm.conf'
                )

        if not content:
            source = heconflib.get_volume_path(
                domain_type,
                sd_uuid,
                conf_img_id,
                conf_vol_id,
            )

            if self._logger:
                self._logger.debug(
                    "Reading '{archive_fname}' from '{source}'".format(
                        archive_fname=archive_fname,
                        source=source,

                    )
                )
            if heconflib.validateConfImage(self._logger, source):
                content = heconflib.extractConfFile(
                    self._logger,
                    source,
                    archive_fname,
                )

        if not content:
            if self._logger:
                self._logger.debug(
                    "unable to get a valid content"
                )
            return False
        if self._logger:
            self._logger.debug(
                "Writing to '{target}'".format(
                    target=localcopy_filename,
                )
            )
        with open(localcopy_filename, 'w') as target:
            target.write(content)
            if self._logger:
                self._logger.debug(
                    "local conf file was correctly written"
                )
            return True
        if self._logger:
            self._logger.error(
                "Unable to get conf file"
            )
            return False