示例#1
0
def _existsUserGroup(log, user, group):
    try:
        osetuputil.getUid(user)
    except (KeyError, IndexError):
        log.warn(_("User {user} does not exist.".format(user=user)))
        return False

    try:
        osetuputil.getGid(group)
    except (KeyError, IndexError):
        log.warn(_("Group {group} does not exist.".format(group=group)))
        return False

    return True
示例#2
0
    def _misc(self):
        uid = osetuputil.getUid(
            self.environment[osetupcons.SystemEnv.USER_ENGINE])
        gid = osetuputil.getGid(
            self.environment[osetupcons.SystemEnv.GROUP_ENGINE])
        if os.path.exists(osetupcons.FileLocations.OVIRT_ENGINE_TMPDIR):
            # clean the directory only if it contains at least one file
            # not owned by engine
            rm_tmp_dir = False
            for root, dirs, files in os.walk(
                    top=osetupcons.FileLocations.OVIRT_ENGINE_TMPDIR,
                    followlinks=False,
            ):
                for name in dirs + files:
                    if os.stat(os.path.join(root, name)).st_uid != uid:
                        rm_tmp_dir = True
                        break
                if rm_tmp_dir:
                    break
            if rm_tmp_dir:
                self.logger.debug('Cleaning {tmpdir}'.format(
                    tmpdir=osetupcons.FileLocations.OVIRT_ENGINE_TMPDIR, ))
                shutil.rmtree(osetupcons.FileLocations.OVIRT_ENGINE_TMPDIR)

        for root, dirs, files in os.walk(
                top=osetupcons.FileLocations.OVIRT_ENGINE_DEPLOYMENTS_DIR,
                followlinks=False,
        ):
            os.chown(root, uid, gid)
            for name in dirs + files:
                os.chown(os.path.join(root, name), uid, gid)
示例#3
0
 def _copyiso(self):
     self.logger.debug('Copying Iso Files')
     targetPath = os.path.join(
         self.environment[
             oenginecons.ConfigEnv.ISO_DOMAIN_NFS_MOUNT_POINT
         ],
         self.environment[
             oenginecons.ConfigEnv.ISO_DOMAIN_SD_UUID
         ],
         'images',
         oenginecons.Const.ISO_DOMAIN_IMAGE_UID
     )
     self.logger.debug('target path' + targetPath)
     # FIXME don't hardcode paths
     for filename in glob.glob('/home/liveuser/oVirtLiveFiles/iso/*.iso'):
         self.logger.debug(filename)
         shutil.move(filename, targetPath)
         os.chown(
             os.path.join(targetPath, os.path.basename(filename)),
             osetuputil.getUid(
                 oengcommcon.Defaults.DEFAULT_SYSTEM_USER_VDSM
             ),
             osetuputil.getGid(
                 oengcommcon.Defaults.DEFAULT_SYSTEM_GROUP_KVM
             )
         )
示例#4
0
    def _misc(self):
        """
        Load files (iso, vfd) from existing rpms to the NFS ISO domain
        TODO: use engine-iso-uploader when it will support local destinations
        """
        uninstall_files = []
        self.environment[
            osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS].createGroup(
                group='iso_images',
                description='Uploaded ISO images',
                optional=True).addFiles(
                    group='iso_images',
                    fileList=uninstall_files,
                )

        targetDir = self.environment[
            oenginecons.ConfigEnv.ISO_DOMAIN_STORAGE_DIR]

        # Iterate the list and copy all the files.
        for filename in self.environment[
                osetupcons.ConfigEnv.ISO_PATHS_TO_UPLOAD]:
            if os.path.exists(filename):
                try:
                    targetFile = os.path.join(targetDir,
                                              os.path.basename(filename))
                    if os.path.exists(targetFile):
                        shutil.move(
                            targetFile, '%s.%s' %
                            (targetFile,
                             datetime.datetime.now().strftime('%Y%m%d%H%M%S')))
                    shutil.copyfile(filename, targetFile)
                    uninstall_files.append(targetFile)
                    os.chmod(targetFile, 0o644)
                    os.chown(
                        targetFile,
                        osetuputil.getUid(self.environment[
                            oengcommcons.SystemEnv.USER_VDSM]),
                        osetuputil.getGid(self.environment[
                            oengcommcons.SystemEnv.GROUP_KVM]))
                except (OSError, shutil.Error) as e:
                    self.logger.warning(
                        _("Cannot copy '{filename}' to iso domain "
                          "'{directory}', error: {error}").format(
                              filename=filename,
                              directory=targetDir,
                              error=e,
                          ))
示例#5
0
 def _closeupEngineAccess(self):
     # Doing this at closeup and not misc, because if using
     # remote_engine style manual_files, we prompt the user,
     # which might take a long time (until the user notices
     # and handles), and we'd rather not block the transaction
     # waiting. Downside is that if we fail during closeup
     # but before this event, it will not run, also on next
     # attempt.
     with open(
         odwhcons.FileLocations.
         OVIRT_ENGINE_ENGINE_SERVICE_CONFIG_DWH_DATABASE_EXAMPLE
     ) as f:
         self._remote_engine.copy_to_engine(
             file_name=(
                 odwhcons.FileLocations.
                 OVIRT_ENGINE_ENGINE_SERVICE_CONFIG_DWH_DATABASE
             ),
             content=f.read(),
             uid=osetuputil.getUid(
                 self.environment[osetupcons.SystemEnv.USER_ENGINE]
             ),
             gid=osetuputil.getGid(
                 self.environment[osetupcons.SystemEnv.GROUP_ENGINE]
             ),
             mode=0o600,
         )
     self._configured_now = True
     self.dialog.note(
         text=_(
             'Please restart the engine by running the following '
             'on {fqdn} :\n'
             '# service {service} restart\n'
             'This is required for the dashboard to work.'
         ).format(
             fqdn=self.environment[
                 oenginecons.ConfigEnv.ENGINE_FQDN
             ],
             service=oenginecons.Const.ENGINE_SERVICE_NAME,
         )
     )
示例#6
0
 def _misc(self):
     rc, privkey, stderr = self.execute(
         (
             oenginecons.FileLocations.OVIRT_ENGINE_PKI_PKCS12_EXTRACT,
             '--name=engine',
             '--passin=%s' %
             self.environment[oenginecons.PKIEnv.STORE_PASS],
             '--key=-',
         ),
         logStreams=False,
     )
     self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
         filetransaction.FileTransaction(
             name=oenginecons.FileLocations.OVIRT_ENGINE_PKI_ENGINE_SSH_KEY,
             content=privkey,
             mode=0o600,
             owner=self.environment[osetupcons.SystemEnv.USER_ENGINE],
             enforcePermissions=True,
             modifiedList=self.environment[
                 otopicons.CoreEnv.MODIFIED_FILES],
         ))
     if os.path.exists(
             oenginecons.FileLocations.OVIRT_ENGINE_PKI_ENGINE_SSH_KEY):
         # Previous versions created it as root:root 0600.
         # We now want to use it also from the engine (for ansible).
         # The filetransaction above will not change ownership
         # if content is not changed. So do this here. We do not
         # do this in a transaction, should be ok.
         os.chown(
             oenginecons.FileLocations.OVIRT_ENGINE_PKI_ENGINE_SSH_KEY,
             osetuputil.getUid(
                 self.environment[osetupcons.SystemEnv.USER_ENGINE], ),
             osetuputil.getGid(
                 self.environment[osetupcons.SystemEnv.GROUP_ENGINE], ),
         )
     self.environment[
         oenginecons.PKIEnv.ENGINE_SSH_PUBLIC_KEY] = self._getSSHPublicKey(
             self._getEnginePublicKey())
示例#7
0
    def _misc(self):
        uid = osetuputil.getUid(
            self.environment[osetupcons.SystemEnv.USER_ENGINE]
        )
        gid = osetuputil.getGid(
            self.environment[osetupcons.SystemEnv.GROUP_ENGINE]
        )
        if os.path.exists(osetupcons.FileLocations.OVIRT_ENGINE_TMPDIR):
            # clean the directory only if it contains at least one file
            # not owned by engine
            rm_tmp_dir = False
            for root, dirs, files in os.walk(
                top=osetupcons.FileLocations.OVIRT_ENGINE_TMPDIR,
                followlinks=False,
            ):
                for name in dirs + files:
                    if os.stat(os.path.join(root, name)).st_uid != uid:
                        rm_tmp_dir = True
                        break
                if rm_tmp_dir:
                    break
            if rm_tmp_dir:
                self.logger.debug(
                    'Cleaning {tmpdir}'.format(
                        tmpdir=osetupcons.FileLocations.OVIRT_ENGINE_TMPDIR,
                    )
                )
                shutil.rmtree(osetupcons.FileLocations.OVIRT_ENGINE_TMPDIR)

        for root, dirs, files in os.walk(
            top=osetupcons.FileLocations.OVIRT_ENGINE_DEPLOYMENTS_DIR,
            followlinks=False,
        ):
            os.chown(root, uid, gid)
            for name in dirs + files:
                os.chown(os.path.join(root, name), uid, gid)
示例#8
0
    def _artifacts(self):

        #
        # Remove embedded psql resources
        #
        for f in glob.glob(
            os.path.join(
                oreportscons.FileLocations.OVIRT_ENGINE_REPORTS_JASPER_WAR,
                'WEB-INF',
                'lib',
                'postgresql-*.jar',
            )
        ):
            os.unlink(f)

        #
        # Files contain password
        #
        for f in (
            'WEB-INF/js-jboss7-ds.xml',
            'META-INF/context.xml',
        ):
            f = os.path.join(
                oreportscons.FileLocations.OVIRT_ENGINE_REPORTS_JASPER_WAR,
                f
            )
            os.chown(
                f,
                osetuputil.getUid(
                    self.environment[osetupcons.SystemEnv.USER_ENGINE]
                ),
                osetuputil.getGid(
                    self.environment[osetupcons.SystemEnv.GROUP_ENGINE],
                ),
            )
            os.chmod(f, 0o600)
示例#9
0
    def _prepare_new_domain(self, path):
        uninstall_files = []
        self.environment[
            osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS
        ].createGroup(
            group='iso_domain',
            description='ISO domain layout',
            optional=True
        ).addFiles(
            group='iso_domain',
            fileList=uninstall_files,
        )
        if os.path.exists(path):
            self.logger.debug(
                'Enforcing ownership and access bits on {path}'.format(
                    path=path,
                )
            )
            os.chown(
                path,
                osetuputil.getUid(
                    self.environment[osetupcons.SystemEnv.USER_VDSM]
                ),
                osetuputil.getGid(
                    self.environment[osetupcons.SystemEnv.GROUP_KVM]
                )
            )
            os.chmod(path, 0o755)

        self.logger.debug('Generating a new uuid for ISO domain')
        sdUUID = str(uuid.uuid4())
        description = self.environment[
            osetupcons.ConfigEnv.ISO_DOMAIN_NAME
        ]
        self.logger.debug(
            'Creating ISO domain for {path}. uuid: {uuid}'.format(
                path=path,
                uuid=sdUUID
            )
        )
        #Create images directory tree
        basePath = os.path.join(path, sdUUID)
        self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
            filetransaction.FileTransaction(
                name=os.path.join(
                    basePath,
                    'images',
                    osetupcons.Const.ISO_DOMAIN_IMAGE_UID,
                    '.keep',
                ),
                content=[],
                mode=0o644,
                dmode=0o755,
                owner=self.environment[osetupcons.SystemEnv.USER_VDSM],
                group=self.environment[osetupcons.SystemEnv.GROUP_KVM],
                downer=self.environment[
                    osetupcons.SystemEnv.USER_VDSM
                ],
                dgroup=self.environment[osetupcons.SystemEnv.GROUP_KVM],
                modifiedList=uninstall_files,
            )
        )
        #Create dom_md directory tree
        domMdDir = os.path.join(basePath, 'dom_md')
        for name in ('ids', 'inbox', 'outbox'):
            filename = os.path.join(domMdDir, name)
            self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
                filetransaction.FileTransaction(
                    name=filename,
                    content=[],
                    mode=0o660,
                    dmode=0o755,
                    owner=self.environment[osetupcons.SystemEnv.USER_VDSM],
                    group=self.environment[osetupcons.SystemEnv.GROUP_KVM],
                    downer=self.environment[
                        osetupcons.SystemEnv.USER_VDSM
                    ],
                    dgroup=self.environment[osetupcons.SystemEnv.GROUP_KVM],
                    modifiedList=uninstall_files,
                )
            )
        self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
            filetransaction.FileTransaction(
                name=os.path.join(domMdDir, 'leases'),
                content=b'\x00' * 512,
                binary=True,
                mode=0o660,
                dmode=0o755,
                owner=self.environment[osetupcons.SystemEnv.USER_VDSM],
                group=self.environment[osetupcons.SystemEnv.GROUP_KVM],
                downer=self.environment[
                    osetupcons.SystemEnv.USER_VDSM
                ],
                dgroup=self.environment[osetupcons.SystemEnv.GROUP_KVM],
                modifiedList=uninstall_files,
            )
        )
        metadata = os.path.join(domMdDir, 'metadata')
        self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
            filetransaction.FileTransaction(
                name=metadata,
                mode=0o644,
                dmode=0o755,
                owner=self.environment[osetupcons.SystemEnv.USER_VDSM],
                group=self.environment[osetupcons.SystemEnv.GROUP_KVM],
                downer=self.environment[osetupcons.SystemEnv.USER_VDSM],
                dgroup=self.environment[osetupcons.SystemEnv.GROUP_KVM],
                content=self._generate_md_content(sdUUID, description),
                modifiedList=uninstall_files,
            )
        )

        return sdUUID
示例#10
0
    def _prepare_new_domain(self, path):
        uninstall_files = []
        self.environment[
            osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS].createGroup(
                group='iso_domain',
                description='ISO domain layout',
                optional=True).addFiles(
                    group='iso_domain',
                    fileList=uninstall_files,
                )
        if os.path.exists(path):
            self.logger.debug(
                'Enforcing ownership and access bits on {path}'.format(
                    path=path, ))
            os.chown(
                path,
                osetuputil.getUid(
                    self.environment[oengcommcons.SystemEnv.USER_VDSM]),
                osetuputil.getGid(
                    self.environment[oengcommcons.SystemEnv.GROUP_KVM]))
            os.chmod(path, 0o755)

        self.logger.debug('Generating a new uuid for ISO domain')
        sdUUID = str(uuid.uuid4())
        description = self.environment[oenginecons.ConfigEnv.ISO_DOMAIN_NAME]
        self.logger.debug(
            'Creating ISO domain for {path}. uuid: {uuid}'.format(path=path,
                                                                  uuid=sdUUID))
        # Create images directory tree
        basePath = os.path.join(path, sdUUID)
        self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
            filetransaction.FileTransaction(
                name=os.path.join(
                    basePath,
                    'images',
                    oenginecons.Const.ISO_DOMAIN_IMAGE_UID,
                    '.keep',
                ),
                content=[],
                mode=0o644,
                dmode=0o755,
                owner=self.environment[oengcommcons.SystemEnv.USER_VDSM],
                group=self.environment[oengcommcons.SystemEnv.GROUP_KVM],
                downer=self.environment[oengcommcons.SystemEnv.USER_VDSM],
                dgroup=self.environment[oengcommcons.SystemEnv.GROUP_KVM],
                modifiedList=uninstall_files,
            ))
        # Create dom_md directory tree
        domMdDir = os.path.join(basePath, 'dom_md')
        for name in ('ids', 'inbox', 'outbox'):
            filename = os.path.join(domMdDir, name)
            self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
                filetransaction.FileTransaction(
                    name=filename,
                    content=[],
                    mode=0o660,
                    dmode=0o755,
                    owner=self.environment[oengcommcons.SystemEnv.USER_VDSM],
                    group=self.environment[oengcommcons.SystemEnv.GROUP_KVM],
                    downer=self.environment[oengcommcons.SystemEnv.USER_VDSM],
                    dgroup=self.environment[oengcommcons.SystemEnv.GROUP_KVM],
                    modifiedList=uninstall_files,
                ))
        self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
            filetransaction.FileTransaction(
                name=os.path.join(domMdDir, 'leases'),
                content=b'\x00' * 512,
                binary=True,
                mode=0o660,
                dmode=0o755,
                owner=self.environment[oengcommcons.SystemEnv.USER_VDSM],
                group=self.environment[oengcommcons.SystemEnv.GROUP_KVM],
                downer=self.environment[oengcommcons.SystemEnv.USER_VDSM],
                dgroup=self.environment[oengcommcons.SystemEnv.GROUP_KVM],
                modifiedList=uninstall_files,
            ))
        metadata = os.path.join(domMdDir, 'metadata')
        self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
            filetransaction.FileTransaction(
                name=metadata,
                mode=0o644,
                dmode=0o755,
                owner=self.environment[oengcommcons.SystemEnv.USER_VDSM],
                group=self.environment[oengcommcons.SystemEnv.GROUP_KVM],
                downer=self.environment[oengcommcons.SystemEnv.USER_VDSM],
                dgroup=self.environment[oengcommcons.SystemEnv.GROUP_KVM],
                content=self._generate_md_content(sdUUID, description),
                modifiedList=uninstall_files,
            ))

        return sdUUID
示例#11
0
    def _misc(self):
        """
        Load files (iso, vfd) from existing rpms to the NFS ISO domain
        TODO: use engine-iso-uploader when it will support local destinations
        """
        uninstall_files = []
        self.environment[
            osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS
        ].createGroup(
            group='iso_images',
            description='Uploaded ISO images',
            optional=True
        ).addFiles(
            group='iso_images',
            fileList=uninstall_files,
        )

        targetDir = self.environment[
            oenginecons.ConfigEnv.ISO_DOMAIN_STORAGE_DIR
        ]

        # Iterate the list and copy all the files.
        for filename in self.environment[
            osetupcons.ConfigEnv.ISO_PATHS_TO_UPLOAD
        ]:
            if os.path.exists(filename):
                try:
                    targetFile = os.path.join(
                        targetDir,
                        os.path.basename(filename)
                    )
                    if os.path.exists(targetFile):
                        shutil.move(
                            targetFile,
                            '%s.%s' % (
                                targetFile,
                                datetime.datetime.now().strftime(
                                    '%Y%m%d%H%M%S'
                                )
                            )
                        )
                    shutil.copyfile(filename, targetFile)
                    uninstall_files.append(targetFile)
                    os.chmod(targetFile, 0o644)
                    os.chown(
                        targetFile,
                        osetuputil.getUid(
                            self.environment[oengcommcons.SystemEnv.USER_VDSM]
                        ),
                        osetuputil.getGid(
                            self.environment[oengcommcons.SystemEnv.GROUP_KVM]
                        )
                    )
                except (OSError, shutil.Error) as e:
                    self.logger.warning(
                        _(
                            "Cannot copy '{filename}' to iso domain "
                            "'{directory}', error: {error}"
                        ).format(
                            filename=filename,
                            directory=targetDir,
                            error=e,
                        )
                    )