def _createIptablesConfig(self):
     return ohostedutil.processTemplate(
         ohostedcons.FileLocations.HOSTED_ENGINE_IPTABLES_TEMPLATE,
         subst={
             '@CUSTOM_RULES@':
             self._parseFirewalld(
                 format=('-A INPUT -p {protocol} -m state --state NEW '
                         '-m {protocol} --dport {port} -j ACCEPT\n'))
         })
    def _misc(self):
        self.logger.info(_("Updating hosted-engine configuration"))
        subst = {
            "@FQDN@": self.environment[ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN],
            "@VM_DISK_ID@": self.environment[ohostedcons.StorageEnv.IMG_UUID],
            "@VM_DISK_VOL_ID@": self.environment[ohostedcons.StorageEnv.VOL_UUID],
            "@SHARED_STORAGE@": self.environment[ohostedcons.StorageEnv.STORAGE_DOMAIN_CONNECTION],
            "@CONSOLE_TYPE@": self.environment[ohostedcons.VMEnv.CONSOLE_TYPE],
            "@VM_UUID@": self.environment[ohostedcons.VMEnv.VM_UUID],
            "@CONF_FILE@": ohostedcons.FileLocations.ENGINE_VM_CONF,
            "@HOST_ID@": self.environment[ohostedcons.StorageEnv.HOST_ID],
            "@DOMAIN_TYPE@": self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE],
            "@MNT_OPTIONS@": self.environment[ohostedcons.StorageEnv.MNT_OPTIONS] or "",
            "@SP_UUID@": self.environment[ohostedcons.StorageEnv.SP_UUID],
            "@SD_UUID@": self.environment[ohostedcons.StorageEnv.SD_UUID],
            "@CONNECTION_UUID@": self.environment[ohostedcons.StorageEnv.CONNECTION_UUID],
            "@CA_CERT@": ohostedcons.FileLocations.LIBVIRT_SPICE_CA_CERT,
            "@CA_SUBJECT@": self.environment[ohostedcons.VDSMEnv.SPICE_SUBJECT],
            "@VDSM_USE_SSL@": str(self.environment[ohostedcons.VDSMEnv.USE_SSL]).lower(),
            "@GATEWAY@": self.environment[ohostedcons.NetworkEnv.GATEWAY],
            "@BRIDGE@": self.environment[ohostedcons.NetworkEnv.BRIDGE_NAME],
            "@METADATA_VOLUME_UUID@": self.environment[ohostedcons.StorageEnv.METADATA_VOLUME_UUID],
            "@METADATA_IMAGE_UUID@": self.environment[ohostedcons.StorageEnv.METADATA_IMAGE_UUID],
            "@LOCKSPACE_VOLUME_UUID@": self.environment[ohostedcons.StorageEnv.LOCKSPACE_VOLUME_UUID],
            "@LOCKSPACE_IMAGE_UUID@": self.environment[ohostedcons.StorageEnv.LOCKSPACE_IMAGE_UUID],
            "@CONF_VOLUME_UUID@": self.environment[ohostedcons.StorageEnv.CONF_VOL_UUID],
            "@CONF_IMAGE_UUID@": self.environment[ohostedcons.StorageEnv.CONF_IMG_UUID],
            "@IQN@": "",
            "@PORTAL@": "",
            "@USER@": "",
            "@PASSWORD@": "",
            "@PORT@": "",
        }
        if self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE] in (ohostedcons.DomainTypes.ISCSI,):
            # Defaults are ok for NFS and GlusterFS, need to change only
            # for iSCSI
            subst["@SHARED_STORAGE@"] = self.environment[ohostedcons.StorageEnv.ISCSI_IP_ADDR]
            subst["@IQN@"] = self.environment[ohostedcons.StorageEnv.ISCSI_TARGET]
            subst["@PORTAL@"] = self.environment[ohostedcons.StorageEnv.ISCSI_PORTAL]
            subst["@USER@"] = self.environment[ohostedcons.StorageEnv.ISCSI_USER]
            subst["@PASSWORD@"] = self.environment[ohostedcons.StorageEnv.ISCSI_PASSWORD]
            subst["@PORT@"] = self.environment[ohostedcons.StorageEnv.ISCSI_PORT]

        content = ohostedutil.processTemplate(
            template=ohostedcons.FileLocations.OVIRT_HOSTED_ENGINE_TEMPLATE, subst=subst
        )
        self.environment[ohostedcons.StorageEnv.HECONF_CONTENT] = content
        with transaction.Transaction() as localtransaction:
            localtransaction.append(
                filetransaction.FileTransaction(
                    name=(ohostedcons.FileLocations.OVIRT_HOSTED_ENGINE_SETUP_CONF),
                    content=content,
                    modifiedList=self.environment[otopicons.CoreEnv.MODIFIED_FILES],
                )
            )
 def _createIptablesConfig(self):
     return ohostedutil.processTemplate(
         ohostedcons.FileLocations.HOSTED_ENGINE_IPTABLES_TEMPLATE,
         subst={
             '@CUSTOM_RULES@': self._parseFirewalld(
                 format=(
                     '-A INPUT -p {protocol} -m state --state NEW '
                     '-m {protocol} --dport {port} -j ACCEPT\n'
                 )
             )
         }
     )
    def _process_templates(self):
        for service in self.environment[
            ohostedcons.NetworkEnv.FIREWALLD_SERVICES
        ]:
            content = ohostedutil.processTemplate(
                template=os.path.join(
                    ohostedcons.FileLocations.
                    HOSTED_ENGINE_FIREWALLD_TEMPLATES_DIR,
                    service['directory'],
                    '%s.xml.in' % service['name'],
                ),
                subst=self.environment[ohostedcons.NetworkEnv.FIREWALLD_SUBST],
            )

            self.environment[
                otopicons.NetEnv.FIREWALLD_SERVICE_PREFIX +
                service['name']
            ] = content

            target = os.path.join(
                ohostedcons.FileLocations.HOSTED_ENGINE_FIREWALLD_EXAMPLE_DIR,
                '%s.xml' % service['name']
            )

            self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
                filetransaction.FileTransaction(
                    name=target,
                    content=content,
                    modifiedList=self.environment[
                        otopicons.CoreEnv.MODIFIED_FILES
                    ],
                )
            )

        self.environment[
            otopicons.NetEnv.IPTABLES_RULES
        ] = self._createIptablesConfig()

        self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
            filetransaction.FileTransaction(
                name=ohostedcons.FileLocations.HOSTED_ENGINE_IPTABLES_EXAMPLE,
                content=self.environment[otopicons.NetEnv.IPTABLES_RULES],
                modifiedList=self.environment[
                    otopicons.CoreEnv.MODIFIED_FILES
                ],
            )
        )
 def _closeup(self):
     self.environment[
         ohostedcons.VMEnv.SUBST]['@BOOT_DISK@'] = ',bootOrder:1'
     self.environment[ohostedcons.VMEnv.SUBST]['@BOOT_PXE@'] = ''
     self.environment[ohostedcons.VMEnv.SUBST]['@BOOT_CDROM@'] = ''
     # Eject the cd-rom if present
     self.environment[ohostedcons.VMEnv.SUBST]['@CDROM@'] = ''
     content = ohostedutil.processTemplate(
         template=ohostedcons.FileLocations.ENGINE_VM_TEMPLATE,
         subst=self.environment[ohostedcons.VMEnv.SUBST],
     )
     with transaction.Transaction() as localtransaction:
         localtransaction.append(
             filetransaction.FileTransaction(
                 name=ohostedcons.FileLocations.ENGINE_VM_CONF,
                 content=content,
                 modifiedList=self.environment[
                     otopicons.CoreEnv.MODIFIED_FILES],
             ), )
 def _closeup(self):
     self.environment[ohostedcons.VMEnv.SUBST][
         '@BOOT_DISK@'
     ] = ',bootOrder:1'
     self.environment[ohostedcons.VMEnv.SUBST]['@BOOT_PXE@'] = ''
     self.environment[ohostedcons.VMEnv.SUBST]['@BOOT_CDROM@'] = ''
     content = ohostedutil.processTemplate(
         template=ohostedcons.FileLocations.ENGINE_VM_TEMPLATE,
         subst=self.environment[ohostedcons.VMEnv.SUBST],
     )
     with transaction.Transaction() as localtransaction:
         localtransaction.append(
             filetransaction.FileTransaction(
                 name=ohostedcons.FileLocations.ENGINE_VM_CONF,
                 content=content,
                 modifiedList=self.environment[
                     otopicons.CoreEnv.MODIFIED_FILES
                 ],
             ),
         )
 def _closeup(self):
     self.environment[ohostedcons.VMEnv.SUBST]["@BOOT_DISK@"] = ",bootOrder:1"
     self.environment[ohostedcons.VMEnv.SUBST]["@BOOT_PXE@"] = ""
     self.environment[ohostedcons.VMEnv.SUBST]["@BOOT_CDROM@"] = ""
     # Eject the cd-rom if present
     self.environment[ohostedcons.VMEnv.SUBST]["@CDROM@"] = ""
     content = ohostedutil.processTemplate(
         template=ohostedcons.FileLocations.ENGINE_VM_TEMPLATE, subst=self.environment[ohostedcons.VMEnv.SUBST]
     )
     self.environment[ohostedcons.StorageEnv.VM_CONF_CONTENT] = content
     with transaction.Transaction() as localtransaction:
         localtransaction.append(
             filetransaction.FileTransaction(
                 name=ohostedcons.FileLocations.ENGINE_VM_CONF,
                 content=content,
                 modifiedList=self.environment[otopicons.CoreEnv.MODIFIED_FILES],
                 mode=0o600,
                 owner=ohostedcons.Defaults.DEFAULT_SYSTEM_USER_VDSM,
                 group=ohostedcons.Defaults.DEFAULT_SYSTEM_GROUP_KVM,
                 enforcePermissions=True,
             )
         )
    def _process_templates(self):
        for service in self.environment[
                ohostedcons.NetworkEnv.FIREWALLD_SERVICES]:
            content = ohostedutil.processTemplate(
                template=os.path.join(
                    ohostedcons.FileLocations.
                    HOSTED_ENGINE_FIREWALLD_TEMPLATES_DIR,
                    service['directory'],
                    '%s.xml.in' % service['name'],
                ),
                subst=self.environment[ohostedcons.NetworkEnv.FIREWALLD_SUBST],
            )

            self.environment[otopicons.NetEnv.FIREWALLD_SERVICE_PREFIX +
                             service['name']] = content

            target = os.path.join(
                ohostedcons.FileLocations.HOSTED_ENGINE_FIREWALLD_EXAMPLE_DIR,
                '%s.xml' % service['name'])

            self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
                filetransaction.FileTransaction(
                    name=target,
                    content=content,
                    modifiedList=self.environment[
                        otopicons.CoreEnv.MODIFIED_FILES],
                ))

        self.environment[
            otopicons.NetEnv.IPTABLES_RULES] = self._createIptablesConfig()

        self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
            filetransaction.FileTransaction(
                name=ohostedcons.FileLocations.HOSTED_ENGINE_IPTABLES_EXAMPLE,
                content=self.environment[otopicons.NetEnv.IPTABLES_RULES],
                modifiedList=self.environment[
                    otopicons.CoreEnv.MODIFIED_FILES],
            ))
 def _closeup(self):
     self.environment[
         ohostedcons.VMEnv.SUBST]['@BOOT_DISK@'] = ',bootOrder:1'
     self.environment[ohostedcons.VMEnv.SUBST]['@BOOT_PXE@'] = ''
     self.environment[ohostedcons.VMEnv.SUBST]['@BOOT_CDROM@'] = ''
     # Eject the cd-rom if present
     self.environment[ohostedcons.VMEnv.SUBST]['@CDROM@'] = ''
     content = ohostedutil.processTemplate(
         template=ohostedcons.FileLocations.ENGINE_VM_TEMPLATE,
         subst=self.environment[ohostedcons.VMEnv.SUBST],
     )
     self.environment[ohostedcons.StorageEnv.VM_CONF_CONTENT] = content
     with transaction.Transaction() as localtransaction:
         localtransaction.append(
             filetransaction.FileTransaction(
                 name=ohostedcons.FileLocations.ENGINE_VM_CONF,
                 content=content,
                 modifiedList=self.environment[
                     otopicons.CoreEnv.MODIFIED_FILES],
                 mode=0o600,
                 owner=ohostedcons.Defaults.DEFAULT_SYSTEM_USER_VDSM,
                 group=ohostedcons.Defaults.DEFAULT_SYSTEM_GROUP_KVM,
                 enforcePermissions=True,
             ), )
    def _misc(self):
        self.logger.info(_('Updating hosted-engine configuration'))
        subst = {
            '@FQDN@':
            self.environment[ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN],
            '@VM_DISK_ID@':
            self.environment[ohostedcons.StorageEnv.IMG_UUID],
            '@VM_DISK_VOL_ID@':
            self.environment[ohostedcons.StorageEnv.VOL_UUID],
            '@SHARED_STORAGE@':
            self.environment[ohostedcons.StorageEnv.STORAGE_DOMAIN_CONNECTION],
            '@CONSOLE_TYPE@':
            self.environment[ohostedcons.VMEnv.CONSOLE_TYPE],
            '@VM_UUID@':
            self.environment[ohostedcons.VMEnv.VM_UUID],
            '@CONF_FILE@':
            ohostedcons.FileLocations.ENGINE_VM_CONF,
            '@HOST_ID@':
            self.environment[ohostedcons.StorageEnv.HOST_ID],
            '@DOMAIN_TYPE@':
            self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE],
            '@MNT_OPTIONS@':
            self.environment[ohostedcons.StorageEnv.MNT_OPTIONS] or '',
            '@SP_UUID@':
            self.environment[ohostedcons.StorageEnv.SP_UUID],
            '@SD_UUID@':
            self.environment[ohostedcons.StorageEnv.SD_UUID],
            '@CONNECTION_UUID@':
            self.environment[ohostedcons.StorageEnv.CONNECTION_UUID],
            '@CA_CERT@':
            ohostedcons.FileLocations.LIBVIRT_SPICE_CA_CERT,
            '@CA_SUBJECT@':
            self.environment[ohostedcons.VDSMEnv.SPICE_SUBJECT],
            '@VDSM_USE_SSL@':
            str(self.environment[ohostedcons.VDSMEnv.USE_SSL]).lower(),
            '@GATEWAY@':
            self.environment[ohostedcons.NetworkEnv.GATEWAY],
            '@BRIDGE@':
            self.environment[ohostedcons.NetworkEnv.BRIDGE_NAME],
            '@METADATA_VOLUME_UUID@':
            self.environment[ohostedcons.StorageEnv.METADATA_VOLUME_UUID],
            '@METADATA_IMAGE_UUID@':
            self.environment[ohostedcons.StorageEnv.METADATA_IMAGE_UUID],
            '@LOCKSPACE_VOLUME_UUID@':
            self.environment[ohostedcons.StorageEnv.LOCKSPACE_VOLUME_UUID],
            '@LOCKSPACE_IMAGE_UUID@':
            self.environment[ohostedcons.StorageEnv.LOCKSPACE_IMAGE_UUID],
            '@CONF_VOLUME_UUID@':
            self.environment[ohostedcons.StorageEnv.CONF_VOL_UUID],
            '@CONF_IMAGE_UUID@':
            self.environment[ohostedcons.StorageEnv.CONF_IMG_UUID],
            '@IQN@':
            '',
            '@PORTAL@':
            '',
            '@USER@':
            '',
            '@PASSWORD@':
            '',
            '@PORT@':
            '',
        }
        if self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE] in (
                ohostedcons.DomainTypes.ISCSI, ):
            # Defaults are ok for NFS and GlusterFS, need to change only
            # for iSCSI
            subst['@SHARED_STORAGE@'] = self.environment[
                ohostedcons.StorageEnv.ISCSI_IP_ADDR]
            subst['@IQN@'] = self.environment[
                ohostedcons.StorageEnv.ISCSI_TARGET]
            subst['@PORTAL@'] = self.environment[
                ohostedcons.StorageEnv.ISCSI_PORTAL]
            subst['@USER@'] = self.environment[
                ohostedcons.StorageEnv.ISCSI_USER]
            subst['@PASSWORD@'] = self.environment[
                ohostedcons.StorageEnv.ISCSI_PASSWORD]
            subst['@PORT@'] = self.environment[
                ohostedcons.StorageEnv.ISCSI_PORT]

        content = ohostedutil.processTemplate(
            template=ohostedcons.FileLocations.OVIRT_HOSTED_ENGINE_TEMPLATE,
            subst=subst)
        self.environment[ohostedcons.StorageEnv.HECONF_CONTENT] = content
        with transaction.Transaction() as localtransaction:
            localtransaction.append(
                filetransaction.FileTransaction(
                    name=(ohostedcons.FileLocations.
                          OVIRT_HOSTED_ENGINE_SETUP_CONF),
                    content=content,
                    modifiedList=self.environment[
                        otopicons.CoreEnv.MODIFIED_FILES],
                ), )
    def _misc(self):
        # TODO: what's an VM_DISK_ID and how can it change to another value?
        self.logger.info(_('Updating hosted-engine configuration'))
        subst = {
            '@FQDN@': self.environment[
                ohostedcons.NetworkEnv.OVIRT_HOSTED_ENGINE_FQDN
            ],
            '@VM_DISK_ID@': self.environment[
                ohostedcons.StorageEnv.IMG_UUID
            ],
            '@SHARED_STORAGE@': self.environment[
                ohostedcons.StorageEnv.STORAGE_DOMAIN_CONNECTION
            ],
            '@CONSOLE_TYPE@': self.environment[
                ohostedcons.VMEnv.CONSOLE_TYPE
            ],
            '@VM_UUID@': self.environment[
                ohostedcons.VMEnv.VM_UUID
            ],
            '@CONF_FILE@': ohostedcons.FileLocations.ENGINE_VM_CONF,
            '@HOST_ID@': self.environment[ohostedcons.StorageEnv.HOST_ID],
            '@DOMAIN_TYPE@': self.environment[
                ohostedcons.StorageEnv.DOMAIN_TYPE
            ],
            '@SP_UUID@': self.environment[ohostedcons.StorageEnv.SP_UUID],
            '@SD_UUID@': self.environment[ohostedcons.StorageEnv.SD_UUID],
            '@CONNECTION_UUID@': self.environment[
                ohostedcons.StorageEnv.CONNECTION_UUID
            ],
            '@CA_CERT@': ohostedcons.FileLocations.LIBVIRT_SPICE_CA_CERT,
            '@CA_SUBJECT@': self.environment[
                ohostedcons.VDSMEnv.SPICE_SUBJECT
            ],
            '@VDSM_USE_SSL@': str(
                self.environment[ohostedcons.VDSMEnv.USE_SSL]
            ).lower(),
            '@GATEWAY@': self.environment[ohostedcons.NetworkEnv.GATEWAY],
            '@BRIDGE@': self.environment[
                ohostedcons.NetworkEnv.BRIDGE_NAME
            ],
            '@METADATA_VOLUME_UUID@': self.environment[
                ohostedcons.StorageEnv.METADATA_VOLUME_UUID
            ],
            '@METADATA_IMAGE_UUID@': self.environment[
                ohostedcons.StorageEnv.METADATA_IMAGE_UUID
            ],
            '@LOCKSPACE_VOLUME_UUID@': self.environment[
                ohostedcons.StorageEnv.LOCKSPACE_VOLUME_UUID
            ],
            '@LOCKSPACE_IMAGE_UUID@': self.environment[
                ohostedcons.StorageEnv.LOCKSPACE_IMAGE_UUID
            ],
            '@IQN@': '',
            '@PORTAL@': '',
            '@USER@': '',
            '@PASSWORD@': '',
            '@PORT@': '',
        }
        if self.environment[ohostedcons.StorageEnv.DOMAIN_TYPE] in (
            ohostedcons.DomainTypes.ISCSI,
        ):
            # Defaults are ok for NFS and GlusterFS, need to change only
            # for iSCSI
            subst['@SHARED_STORAGE@'] = self.environment[
                ohostedcons.StorageEnv.ISCSI_IP_ADDR
            ]
            subst['@IQN@'] = self.environment[
                ohostedcons.StorageEnv.ISCSI_TARGET
            ]
            subst['@PORTAL@'] = self.environment[
                ohostedcons.StorageEnv.ISCSI_PORTAL
            ]
            subst['@USER@'] = self.environment[
                ohostedcons.StorageEnv.ISCSI_USER
            ]
            subst['@PASSWORD@'] = self.environment[
                ohostedcons.StorageEnv.ISCSI_PASSWORD
            ]
            subst['@PORT@'] = self.environment[
                ohostedcons.StorageEnv.ISCSI_PORT
            ]

        content = ohostedutil.processTemplate(
            template=ohostedcons.FileLocations.OVIRT_HOSTED_ENGINE_TEMPLATE,
            subst=subst
        )
        with transaction.Transaction() as localtransaction:
            localtransaction.append(
                filetransaction.FileTransaction(
                    name=(
                        ohostedcons.FileLocations.
                        OVIRT_HOSTED_ENGINE_SETUP_CONF
                    ),
                    content=content,
                    modifiedList=self.environment[
                        otopicons.CoreEnv.MODIFIED_FILES
                    ],
                ),
            )
    def _misc(self):
        self.logger.info(_('Configuring VM'))
        subst = {
            '@SP_UUID@': ohostedcons.Const.BLANK_UUID,
            '@SD_UUID@': self.environment[
                ohostedcons.StorageEnv.SD_UUID
            ],
            '@VOL_UUID@': self.environment[
                ohostedcons.StorageEnv.VOL_UUID
            ],
            '@IMG_UUID@': self.environment[
                ohostedcons.StorageEnv.IMG_UUID
            ],
            '@VM_UUID@': self.environment[
                ohostedcons.VMEnv.VM_UUID
            ],
            '@MEM_SIZE@': self.environment[
                ohostedcons.VMEnv.MEM_SIZE_MB
            ],
            '@MAC_ADDR@': self.environment[
                ohostedcons.VMEnv.MAC_ADDR
            ],
            '@NAME@': ohostedcons.Const.HOSTED_ENGINE_VM_NAME,
            '@CONSOLE_TYPE@': self.environment[
                ohostedcons.VMEnv.CONSOLE_TYPE
            ],
            '@VCPUS@': self.environment[
                ohostedcons.VMEnv.VCPUS
            ],
            '@CPU_TYPE@': self.environment[
                ohostedcons.VDSMEnv.VDSM_CPU
            ].replace('model_', ''),
            '@EMULATED_MACHINE@': self.environment[
                ohostedcons.VMEnv.EMULATED_MACHINE
            ],
            '@CDROM_UUID@': self.environment[
                ohostedcons.VMEnv.CDROM_UUID
            ],
            '@NIC_UUID@': self.environment[
                ohostedcons.VMEnv.NIC_UUID
            ],
            '@CONSOLE_UUID@': self.environment[
                ohostedcons.VMEnv.CONSOLE_UUID
            ],
            '@BRIDGE@': self.environment[
                ohostedcons.NetworkEnv.BRIDGE_NAME
            ],
        }

        if self.environment[ohostedcons.VMEnv.CONSOLE_TYPE] == 'vnc':
            subst['@VIDEO_DEVICE@'] = 'vga'
        else:
            subst['@VIDEO_DEVICE@'] = 'qxl'
        if self.environment[
            ohostedcons.VMEnv.BOOT
        ] in self.BOOT_DEVICE.keys():
            for key in self.BOOT_DEVICE.keys():
                if key != self.environment[ohostedcons.VMEnv.BOOT]:
                    subst[self.BOOT_DEVICE[key]] = ''
                else:
                    subst[self.BOOT_DEVICE[key]] = ',bootOrder:1'

        if self.environment[
            ohostedcons.VMEnv.CDROM
        ]:
            subst['@CDROM@'] = self.environment[
                ohostedcons.VMEnv.CDROM
            ]
        else:
            subst['@CDROM@'] = ''

        content = ohostedutil.processTemplate(
            template=ohostedcons.FileLocations.ENGINE_VM_TEMPLATE,
            subst=subst,
        )
        self.environment[ohostedcons.VMEnv.SUBST] = subst
        with transaction.Transaction() as localtransaction:
            localtransaction.append(
                filetransaction.FileTransaction(
                    name=ohostedcons.FileLocations.ENGINE_VM_CONF,
                    content=content,
                    modifiedList=self.environment[
                        otopicons.CoreEnv.MODIFIED_FILES
                    ],
                    mode=0o600,
                    owner=ohostedcons.Defaults.DEFAULT_SYSTEM_USER_VDSM,
                    group=ohostedcons.Defaults.DEFAULT_SYSTEM_GROUP_KVM,
                    enforcePermissions=True,
                ),
            )
Beispiel #13
0
    def _misc(self):
        self.logger.info(_('Configuring VM'))
        subst = {
            '@SP_UUID@': ohostedcons.Const.BLANK_UUID,
            '@SD_UUID@': self.environment[
                ohostedcons.StorageEnv.SD_UUID
            ],
            '@VOL_UUID@': self.environment[
                ohostedcons.StorageEnv.VOL_UUID
            ],
            '@IMG_UUID@': self.environment[
                ohostedcons.StorageEnv.IMG_UUID
            ],
            '@VM_UUID@': self.environment[
                ohostedcons.VMEnv.VM_UUID
            ],
            '@MEM_SIZE@': self.environment[
                ohostedcons.VMEnv.MEM_SIZE_MB
            ],
            '@MAC_ADDR@': self.environment[
                ohostedcons.VMEnv.MAC_ADDR
            ],
            '@NAME@': ohostedcons.Const.HOSTED_ENGINE_VM_NAME,
            '@CONSOLE_TYPE@': self.environment[
                ohostedcons.VMEnv.CONSOLE_TYPE
            ],
            '@VCPUS@': self.environment[
                ohostedcons.VMEnv.VCPUS
            ],
            '@CPU_TYPE@': self.environment[
                ohostedcons.VDSMEnv.VDSM_CPU
            ].replace('model_', ''),
            '@EMULATED_MACHINE@': self.environment[
                ohostedcons.VMEnv.EMULATED_MACHINE
            ],
            '@CDROM_UUID@': self.environment[
                ohostedcons.VMEnv.CDROM_UUID
            ],
            '@NIC_UUID@': self.environment[
                ohostedcons.VMEnv.NIC_UUID
            ],
            '@CONSOLE_UUID@': self.environment[
                ohostedcons.VMEnv.CONSOLE_UUID
            ],
            '@BRIDGE@': self.environment[
                ohostedcons.NetworkEnv.BRIDGE_NAME
            ],
        }
        if self.environment[
            ohostedcons.VMEnv.BOOT
        ] in self.BOOT_DEVICE.keys():
            for key in self.BOOT_DEVICE.keys():
                if key != self.environment[ohostedcons.VMEnv.BOOT]:
                    subst[self.BOOT_DEVICE[key]] = ''
                else:
                    subst[self.BOOT_DEVICE[key]] = ',bootOrder:1'

        if self.environment[
            ohostedcons.VMEnv.CDROM
        ]:
            subst['@CDROM@'] = self.environment[
                ohostedcons.VMEnv.CDROM
            ]
        else:
            subst['@CDROM@'] = ''

        content = ohostedutil.processTemplate(
            template=ohostedcons.FileLocations.ENGINE_VM_TEMPLATE,
            subst=subst,
        )
        self.environment[ohostedcons.VMEnv.SUBST] = subst
        with transaction.Transaction() as localtransaction:
            localtransaction.append(
                filetransaction.FileTransaction(
                    name=ohostedcons.FileLocations.ENGINE_VM_CONF,
                    content=content,
                    modifiedList=self.environment[
                        otopicons.CoreEnv.MODIFIED_FILES
                    ],
                ),
            )
Beispiel #14
0
    def _misc(self):
        self.logger.info(_('Configuring VM'))
        subst = {
            '@SP_UUID@':
            ohostedcons.Const.BLANK_UUID,
            '@SD_UUID@':
            self.environment[ohostedcons.StorageEnv.SD_UUID],
            '@VOL_UUID@':
            self.environment[ohostedcons.StorageEnv.VOL_UUID],
            '@IMG_UUID@':
            self.environment[ohostedcons.StorageEnv.IMG_UUID],
            '@VM_UUID@':
            self.environment[ohostedcons.VMEnv.VM_UUID],
            '@MEM_SIZE@':
            self.environment[ohostedcons.VMEnv.MEM_SIZE_MB],
            '@MAC_ADDR@':
            self.environment[ohostedcons.VMEnv.MAC_ADDR],
            '@NAME@':
            ohostedcons.Const.HOSTED_ENGINE_VM_NAME,
            '@CONSOLE_TYPE@':
            self.environment[ohostedcons.VMEnv.CONSOLE_TYPE],
            '@VCPUS@':
            self.environment[ohostedcons.VMEnv.VCPUS],
            '@MAXVCPUS@':
            self.environment[ohostedcons.VMEnv.MAXVCPUS],
            '@CPU_TYPE@':
            self.environment[ohostedcons.VDSMEnv.VDSM_CPU].replace(
                'model_', ''),
            '@EMULATED_MACHINE@':
            self.environment[ohostedcons.VMEnv.EMULATED_MACHINE],
            '@CDROM_UUID@':
            self.environment[ohostedcons.VMEnv.CDROM_UUID],
            '@NIC_UUID@':
            self.environment[ohostedcons.VMEnv.NIC_UUID],
            '@CONSOLE_UUID@':
            self.environment[ohostedcons.VMEnv.CONSOLE_UUID],
            '@BRIDGE@':
            self.environment[ohostedcons.NetworkEnv.BRIDGE_NAME],
        }

        if self.environment[ohostedcons.VMEnv.CONSOLE_TYPE] == 'vnc':
            subst['@VIDEO_DEVICE@'] = 'vga'
            subst['@GRAPHICS_DEVICE@'] = 'vnc'
        else:
            subst['@VIDEO_DEVICE@'] = 'qxl'
            subst['@GRAPHICS_DEVICE@'] = 'spice'

        if self.environment[ohostedcons.VMEnv.CDROM]:
            subst['@CDROM@'] = self.environment[ohostedcons.VMEnv.CDROM]
        else:
            subst['@CDROM@'] = ''

        content = ohostedutil.processTemplate(
            template=ohostedcons.FileLocations.ENGINE_VM_TEMPLATE,
            subst=subst,
        )
        self.environment[ohostedcons.VMEnv.SUBST] = subst
        with transaction.Transaction() as localtransaction:
            localtransaction.append(
                filetransaction.FileTransaction(
                    name=ohostedcons.FileLocations.ENGINE_VM_CONF,
                    content=content,
                    modifiedList=self.environment[
                        otopicons.CoreEnv.MODIFIED_FILES],
                    mode=0o600,
                    owner=ohostedcons.Defaults.DEFAULT_SYSTEM_USER_VDSM,
                    group=ohostedcons.Defaults.DEFAULT_SYSTEM_GROUP_KVM,
                    downer=ohostedcons.Defaults.DEFAULT_SYSTEM_USER_VDSM,
                    dgroup=ohostedcons.Defaults.DEFAULT_SYSTEM_GROUP_KVM,
                    enforcePermissions=True,
                ), )