Esempio n. 1
0
    def __process_chassis_device(self):
        '''
        assign IDs of shared devices
        merge shared device to node.
        '''
        self.__process_chassis_data(self.__chassis.get("data"))
        self.__process_chassis_slots(self.__chassis.get("slots", []))

        # set sharemeory id for sub node.
        for node in self.__chassis.get("nodes"):
            set_option(node, "compute", "communicate", "shm_key", "share_mem_{}".format(self.__chassis_name))
            set_option(node, "bmc", "shm_key", "share_mem_{}".format(self.__chassis_name))
Esempio n. 2
0
 def init(self):
     self.workspace = ChassisWorkspace(self.__chassis)
     nodes = self.__chassis.get("nodes")
     if nodes is None:
         raise InfraSimError("There is no nodes under chassis")
     for node in nodes:
         node_name = node.get("name", "{}_node_{}".format(self.__chassis_name, nodes.index(node)))
         node["name"] = node_name
         node["type"] = self.__chassis["type"]
         set_option(node, "compute", "machine", "spid", nodes.index(node))
     self.workspace.init()
     self.__file_name = os.path.join(self.workspace.get_workspace_data(), "shm_data.bin")
     self.__daemon = CChassisDaemon(self.__chassis_name, self.__file_name)
Esempio n. 3
0
    def __process_chassis_device(self):
        '''
        assign IDs of shared devices
        merge shared device to node.
        '''
        self.__process_chassis_data(self.__chassis.get("data"))
        self.__process_chassis_slots(self.__chassis.get("slots", []))

        # set sharemeory id for sub node.
        for node in self.__chassis.get("nodes"):
            set_option(node, "compute", "communicate", "shm_key",
                       "share_mem_{}".format(self.__chassis_name))
            set_option(node, "bmc", "shm_key",
                       "share_mem_{}".format(self.__chassis_name))
Esempio n. 4
0
 def init(self):
     self.workspace = ChassisWorkspace(self.__chassis)
     nodes = self.__chassis.get("nodes")
     if nodes is None:
         raise InfraSimError("There is no nodes under chassis")
     for node in nodes:
         node_name = node.get(
             "name", "{}_node_{}".format(self.__chassis_name,
                                         nodes.index(node)))
         node["name"] = node_name
         node["type"] = self.__chassis["type"]
         set_option(node, "compute", "machine", "spid", nodes.index(node))
     self.workspace.init()
     self.__file_name = os.path.join(self.workspace.get_workspace_data(),
                                     "shm_data.bin")
     self.__daemon = CChassisDaemon(self.__chassis_name, self.__file_name)
Esempio n. 5
0
    def __render_chassis_info(self):
        """
        update smbios and emulation data.
        """
        data = self.__chassis.get("data", None)
        if not data:
            return

        for node in self.__chassis.get("nodes"):
            if 'pn' in data:
                set_option(node, "bmc", "chassis_pn", data['pn'])
            if 'sn' in data:
                set_option(node, "bmc", "chassis_sn", data['sn'])
                set_option(node, "compute", "smbios", "type3", "sn", data['sn'])
Esempio n. 6
0
    def __render_chassis_info(self):
        """
        update smbios and emulation data.
        """
        data = self.__chassis.get("data", None)
        if not data:
            return

        for node in self.__chassis.get("nodes"):
            if 'pn' in data:
                set_option(node, "bmc", "chassis_pn", data['pn'])
            if 'sn' in data:
                set_option(node, "bmc", "chassis_sn", data['sn'])
                set_option(node, "compute", "smbios", "type3", "sn",
                           data['sn'])
Esempio n. 7
0
    def init(self):
        if not helper.check_kvm_existence():
            self.__enable_kvm = False
        else:
            self.__enable_kvm = self.__compute.get('kvm_enabled', True)

        if self.get_workspace():
            # this file copy is performed in workspace.init()
            self.__smbios = os.path.join(self.get_workspace(), "data",
                                         "{}_smbios.bin".format(self.__vendor_type))
        else:
            default = os.path.join(config.infrasim_data, "{0}/{0}_smbios.bin".format(self.__vendor_type))
            if isinstance(self.__compute.get("smbios"), dict):
                self.__smbios = self.__compute["smbios"].get("file", default)
            else:
                self.__smbios = self.__compute.get("smbios", default)

        if os.path.exists(self.__smbios):
            if 'serial_number' in self.__compute:
                self.__serial_number = self.__compute['serial_number']
                set_option(self.__compute, "smbios", "type1", "sn", self.__serial_number)
            if 'uuid' in self.__compute:
                set_option(self.__compute, "smbios", "type1", "uuid", self.__compute["uuid"])

            bios = SMBios(self.__smbios)
            # safe check for compatible with previous version.
            if isinstance(self.__compute.get("smbios"), dict):
                bios.ModifyData(self.__compute["smbios"])
            bios.save(self.__smbios)

        self.__bios = self.__compute.get('bios')
        if 'boot' in self.__compute:
            self.__boot_order = self.__compute['boot'].get('boot_order', "ncd")
            if 'menu' in self.__compute['boot']:
                self.__boot_menu = "on" if self.__compute['boot']['menu'] in [True, 'on'] else "off"
            self.__boot_splash_name = self.__compute['boot'].get('splash', None)
            self.__boot_splash_time = self.__compute['boot'].get('splash-time', None)
            self.checking_time = self.__compute['boot'].get('checking_time', 1)
        else:
            self.__boot_order = "ncd"

        self.__numactl_info = self.__compute.get("numa_control")
        if self.__numactl_info and os.path.exists("/usr/bin/numactl"):
            self.__numactl_mode = self.__numactl_info.get("mode", "auto")
            if self.__class__.numactl is None:
                self.__class__.numactl = NumaCtl()

            self.logger.info('[compute] infrasim has '
                             'enabled numa control')
        else:
            self.logger.info('[compute] infrasim can\'t '
                             'find numactl in this environment')

        self.__display = self.__compute.get('vnc_display', 1)
        self.__kernel = self.__compute.get('kernel')
        self.__initrd = self.__compute.get('initrd')

        self.__cmdline = self.__compute.get("cmdline")

        self.__mem_path = self.__compute.get("mem_path")
        self.__machine = self.__compute.get("machine")

        self.__extra_option = self.__compute.get("extra_option")
        self.__extra_device = self.__compute.get("extra_device", "")
        self.__qemu_bin = self.__compute.get("qemu_bin", self.__qemu_bin)
        self.__force_shutdown = self.__compute.get("force_shutdown", True)

        self.__shm_key = self.__compute.get("communicate", {}).get("shm_key")

        if "uuid" in self.__compute:
            self.__uuid = self.__compute.get("uuid")

        machine_obj = CMachine(self.__machine)
        machine_obj.logger = self.logger
        self.__element_list.append(machine_obj)

        cpu_obj = CCPU(self.__compute['cpu'])
        cpu_obj.logger = self.logger
        self.__element_list.append(cpu_obj)
        self.__cpu_obj = cpu_obj

        memory_obj = CMemory(self.__compute['memory'])
        memory_obj.logger = self.logger
        self.__element_list.append(memory_obj)

        # If PCI device wants to sit on one specific PCI bus, the bus should be
        # created first prior to using the bus, here we always create the PCI
        # bus prior to other PCI devices' creation
        pci_topology_manager_obj = None
        if 'pci_bridge_topology' in self.__compute:
            pci_topology_manager_obj = CPCITopologyManager(self.__compute['pci_bridge_topology'])
            pci_topology_manager_obj.logger = self.logger
            self.__element_list.append(pci_topology_manager_obj)

        if 'pcie_topology' in self.__compute:
            pcie_topology_obj = CPCIETopology(self.__compute['pcie_topology'])
            pcie_topology_obj.logger = self.logger
            self.__element_list.append(pcie_topology_obj)
            if 'sec_bus' in str(self.__compute.get('pcie_topology')):
                fw_cfg_obj = CPCIEFwcfg()
                fw_cfg_obj.logger = self.logger
                fw_cfg_obj.set_workspace(self.get_workspace())
                pcie_topology_obj.set_fw_cfg_obj(fw_cfg_obj)
                self.__element_list.append(fw_cfg_obj)

        backend_network_obj = CBackendNetwork(self.__compute['networks'])
        backend_network_obj.logger = self.logger
        self.__element_list.append(backend_network_obj)

        for imc_element in self.__compute.get("imc", []):
            imc_obj = CPCIIMC(imc_element)
            self.__element_list.append(imc_obj)

        for pcu_element in self.__compute.get("pcu", []):
            pcu_obj = CPCIPCU(pcu_element)
            self.__element_list.append(pcu_obj)

        cdrom_info = self.__compute.get("cdrom")
        backend_storage_obj = CBackendStorage(self.__compute['storage_backend'],
                                              (cdrom_info is not None))
        backend_storage_obj.logger = self.logger
        backend_storage_obj.owner = self
        if pci_topology_manager_obj:
            backend_storage_obj.set_pci_topology_mgr(pci_topology_manager_obj)
        backend_storage_obj.owner = self
        self.__element_list.append(backend_storage_obj)

        for ntb in self.__compute.get("ntb", []):
            ntb_obj = CNTB(ntb)
            self.__element_list.append(ntb_obj)

        for dma_engine in self.__compute.get("dma_engine", []):
            dma_engine_obj = CDMAEngine(dma_engine)
            self.__element_list.append(dma_engine_obj)

        if has_option(self.__compute, "ipmi"):
            ipmi_obj = CIPMI(self.__compute['ipmi'])
        else:
            ipmi_info = {
                'interface': 'kcs',
                'chardev': {
                    'backend': 'socket',
                    'host': '127.0.0.1',
                }
            }
            ipmi_obj = CIPMI(ipmi_info)
        ipmi_obj.logger = self.logger
        ipmi_obj.set_bmc_conn_port(self.__port_qemu_ipmi)
        self.__element_list.append(ipmi_obj)

        if self.__enable_monitor:
            self.__monitor = CQemuMonitor({
                'mode': 'control',
                'chardev': {
                    'backend': 'socket',
                    'path': os.path.join(self.get_workspace(), '.monitor'),
                    'server': True,
                    'wait': False
                }
            })
            self.__monitor.set_workspace(self.get_workspace())
            self.__monitor.logger = self.logger
            self.__element_list.append(self.__monitor)

        if has_option(self.__compute, "cpu_binding"):
            self.__cpu_binding_obj = CCPUBinding(self.__compute["cpu_binding"])
            self.__cpu_binding_obj.monitor = self.__monitor
            self.__cpu_binding_obj.logger = self.logger
            self.__cpu_binding_obj.owner = self
            self.__cpu_binding_obj.vcpu_quantities = self.__compute["cpu"].get("quantities", 0)
            self.__element_list.append(self.__cpu_binding_obj)

        # create cdrom if exits
        if cdrom_info:
            cdrom_obj = IDECdrom(cdrom_info)
            cdrom_obj.logger = self.logger
            cdrom_obj.index = 0
            cdrom_obj.owner = cdrom_obj
            cdrom_obj.set_bus(0)
            cdrom_obj.set_scsi_id(0)
            self.__element_list.append(cdrom_obj)

        # create channel for guest agent
        has_guest_agent = self.__compute.get('guest-agent')
        if has_guest_agent or has_guest_agent == 'on':
            self.__element_list.append(GuestAgent(self.get_workspace()))

        # add debug option
        trace_info = self.__compute.get("trace")
        if trace_info:
            self.__element_list.append(QTrace(trace_info, self.get_workspace()))

        for ppi in self.__compute.get("pcie-passthrough", []):
            ppi_obj = CPCIEPassthrough(ppi)
            self.__element_list.append(ppi_obj)

        for element in self.__element_list:
            element.init()
Esempio n. 8
0
    def init(self):
        if not helper.check_kvm_existence():
            self.__enable_kvm = False
        else:
            self.__enable_kvm = self.__compute.get('kvm_enabled', True)

        if self.get_workspace():
            # this file copy is performed in workspace.init()
            self.__smbios = os.path.join(
                self.get_workspace(), "data",
                "{}_smbios.bin".format(self.__vendor_type))
        else:
            default = os.path.join(
                config.infrasim_data,
                "{0}/{0}_smbios.bin".format(self.__vendor_type))
            if isinstance(self.__compute.get("smbios"), dict):
                self.__smbios = self.__compute["smbios"].get("file", default)
            else:
                self.__smbios = self.__compute.get("smbios", default)

        if os.path.exists(self.__smbios):
            if 'serial_number' in self.__compute:
                self.__serial_number = self.__compute['serial_number']
                set_option(self.__compute, "smbios", "type1", "sn",
                           self.__serial_number)
            if 'uuid' in self.__compute:
                set_option(self.__compute, "smbios", "type1", "uuid",
                           self.__compute["uuid"])

            bios = SMBios(self.__smbios)
            # safe check for compatible with previous version.
            if isinstance(self.__compute.get("smbios"), dict):
                bios.ModifyData(self.__compute["smbios"])
            bios.save(self.__smbios)

        self.__bios = self.__compute.get('bios')
        if 'boot' in self.__compute:
            self.__boot_order = self.__compute['boot'].get('boot_order', "ncd")
            if 'menu' in self.__compute['boot']:
                self.__boot_menu = "on" if self.__compute['boot']['menu'] in [
                    True, 'on'
                ] else "off"
            self.__boot_splash_name = self.__compute['boot'].get(
                'splash', None)
            self.__boot_splash_time = self.__compute['boot'].get(
                'splash-time', None)
            self.checking_time = self.__compute['boot'].get('checking_time', 1)
        else:
            self.__boot_order = "ncd"

        self.__numactl_info = self.__compute.get("numa_control")
        if self.__numactl_info and os.path.exists("/usr/bin/numactl"):
            self.__numactl_mode = self.__numactl_info.get("mode", "auto")
            if self.__class__.numactl is None:
                self.__class__.numactl = NumaCtl()

            self.logger.info('[compute] infrasim has ' 'enabled numa control')
        else:
            self.logger.info('[compute] infrasim can\'t '
                             'find numactl in this environment')

        self.__display = self.__compute.get('vnc_display', 1)
        self.__kernel = self.__compute.get('kernel')
        self.__initrd = self.__compute.get('initrd')

        self.__cmdline = self.__compute.get("cmdline")

        self.__mem_path = self.__compute.get("mem_path")
        self.__machine = self.__compute.get("machine")

        self.__extra_option = self.__compute.get("extra_option")
        self.__extra_device = self.__compute.get("extra_device", "")
        self.__qemu_bin = self.__compute.get("qemu_bin", self.__qemu_bin)
        self.__force_shutdown = self.__compute.get("force_shutdown", True)

        self.__shm_key = self.__compute.get("communicate", {}).get("shm_key")

        if "uuid" in self.__compute:
            self.__uuid = self.__compute.get("uuid")

        machine_obj = CMachine(self.__machine)
        machine_obj.logger = self.logger
        self.__element_list.append(machine_obj)

        cpu_obj = CCPU(self.__compute['cpu'])
        cpu_obj.logger = self.logger
        self.__element_list.append(cpu_obj)
        self.__cpu_obj = cpu_obj

        memory_obj = CMemory(self.__compute['memory'])
        memory_obj.logger = self.logger
        self.__element_list.append(memory_obj)

        # If PCI device wants to sit on one specific PCI bus, the bus should be
        # created first prior to using the bus, here we always create the PCI
        # bus prior to other PCI devices' creation
        pci_topology_manager_obj = None
        if 'pci_bridge_topology' in self.__compute:
            pci_topology_manager_obj = CPCITopologyManager(
                self.__compute['pci_bridge_topology'])
            pci_topology_manager_obj.logger = self.logger
            self.__element_list.append(pci_topology_manager_obj)

        if 'pcie_topology' in self.__compute:
            pcie_topology_obj = CPCIETopology(self.__compute['pcie_topology'])
            pcie_topology_obj.logger = self.logger
            self.__element_list.append(pcie_topology_obj)
            if 'sec_bus' in str(self.__compute.get('pcie_topology')):
                fw_cfg_obj = CPCIEFwcfg()
                fw_cfg_obj.logger = self.logger
                fw_cfg_obj.set_workspace(self.get_workspace())
                pcie_topology_obj.set_fw_cfg_obj(fw_cfg_obj)
                self.__element_list.append(fw_cfg_obj)

        backend_network_obj = CBackendNetwork(self.__compute['networks'])
        backend_network_obj.logger = self.logger
        self.__element_list.append(backend_network_obj)

        for imc_element in self.__compute.get("imc", []):
            imc_obj = CPCIIMC(imc_element)
            self.__element_list.append(imc_obj)

        for pcu_element in self.__compute.get("pcu", []):
            pcu_obj = CPCIPCU(pcu_element)
            self.__element_list.append(pcu_obj)

        cdrom_info = self.__compute.get("cdrom")
        backend_storage_obj = CBackendStorage(
            self.__compute['storage_backend'], (cdrom_info is not None))
        backend_storage_obj.logger = self.logger
        backend_storage_obj.owner = self
        if pci_topology_manager_obj:
            backend_storage_obj.set_pci_topology_mgr(pci_topology_manager_obj)
        backend_storage_obj.owner = self
        self.__element_list.append(backend_storage_obj)

        for ntb in self.__compute.get("ntb", []):
            ntb_obj = CNTB(ntb)
            self.__element_list.append(ntb_obj)

        for dma_engine in self.__compute.get("dma_engine", []):
            dma_engine_obj = CDMAEngine(dma_engine)
            self.__element_list.append(dma_engine_obj)

        if has_option(self.__compute, "ipmi"):
            ipmi_obj = CIPMI(self.__compute['ipmi'])
        else:
            ipmi_info = {
                'interface': 'kcs',
                'chardev': {
                    'backend': 'socket',
                    'host': '127.0.0.1',
                }
            }
            ipmi_obj = CIPMI(ipmi_info)
        ipmi_obj.logger = self.logger
        ipmi_obj.set_bmc_conn_port(self.__port_qemu_ipmi)
        self.__element_list.append(ipmi_obj)

        if self.__enable_monitor:
            self.__monitor = CQemuMonitor({
                'mode': 'control',
                'chardev': {
                    'backend': 'socket',
                    'path': os.path.join(self.get_workspace(), '.monitor'),
                    'server': True,
                    'wait': False
                }
            })
            self.__monitor.set_workspace(self.get_workspace())
            self.__monitor.logger = self.logger
            self.__element_list.append(self.__monitor)

        if has_option(self.__compute, "cpu_binding"):
            self.__cpu_binding_obj = CCPUBinding(self.__compute["cpu_binding"])
            self.__cpu_binding_obj.monitor = self.__monitor
            self.__cpu_binding_obj.logger = self.logger
            self.__cpu_binding_obj.owner = self
            self.__cpu_binding_obj.vcpu_quantities = self.__compute["cpu"].get(
                "quantities", 0)
            self.__element_list.append(self.__cpu_binding_obj)

        # create cdrom if exits
        if cdrom_info:
            cdrom_obj = IDECdrom(cdrom_info)
            cdrom_obj.logger = self.logger
            cdrom_obj.index = 0
            cdrom_obj.owner = cdrom_obj
            cdrom_obj.set_bus(0)
            cdrom_obj.set_scsi_id(0)
            self.__element_list.append(cdrom_obj)

        # create channel for guest agent
        has_guest_agent = self.__compute.get('guest-agent')
        if has_guest_agent or has_guest_agent == 'on':
            self.__element_list.append(GuestAgent(self.get_workspace()))

        # add debug option
        trace_info = self.__compute.get("trace")
        if trace_info:
            self.__element_list.append(QTrace(trace_info,
                                              self.get_workspace()))

        for ppi in self.__compute.get("pcie-passthrough", []):
            ppi_obj = CPCIEPassthrough(ppi)
            self.__element_list.append(ppi_obj)

        for element in self.__element_list:
            element.init()