def _create_lpar_instance(self, instance, network_info, host_stats=None): inst_name = instance['name'] # CPU/Memory min and max can be configurable. Lets assume # some default values for now. # Memory mem = instance['memory_mb'] if host_stats and mem > host_stats['host_memory_free']: LOG.error(_('Not enough free memory in the host')) raise exception.PowerVMInsufficientFreeMemory( instance_name=instance['name']) mem_min = min(mem, constants.POWERVM_MIN_MEM) mem_max = mem + constants.POWERVM_MAX_MEM # CPU cpus = instance['vcpus'] if host_stats: avail_cpus = host_stats['vcpus'] - host_stats['vcpus_used'] if cpus > avail_cpus: LOG.error(_('Insufficient available CPU on PowerVM')) raise exception.PowerVMInsufficientCPU( instance_name=instance['name']) cpus_min = min(cpus, constants.POWERVM_MIN_CPUS) cpus_max = cpus + constants.POWERVM_MAX_CPUS cpus_units_min = decimal.Decimal(cpus_min) / decimal.Decimal(10) cpus_units = decimal.Decimal(cpus) / decimal.Decimal(10) # Network # To ensure the MAC address on the guest matches the # generated value, pull the first 10 characters off the # MAC address for the mac_base_value parameter and then # get the integer value of the final 2 characters as the # slot_id parameter mac = network_info[0]['address'] mac_base_value = (mac[:-2]).replace(':', '') eth_id = self._operator.get_virtual_eth_adapter_id() slot_id = int(mac[-2:], 16) virtual_eth_adapters = ('%(slot_id)s/0/%(eth_id)s//0/0' % locals()) # LPAR configuration data # max_virtual_slots is hardcoded to 64 since we generate a MAC # address that must be placed in slots 32 - 64 lpar_inst = LPAR.LPAR(name=inst_name, lpar_env='aixlinux', min_mem=mem_min, desired_mem=mem, max_mem=mem_max, proc_mode='shared', sharing_mode='uncap', min_procs=cpus_min, desired_procs=cpus, max_procs=cpus_max, min_proc_units=cpus_units_min, desired_proc_units=cpus_units, max_proc_units=cpus_max, virtual_eth_mac_base_value=mac_base_value, max_virtual_slots=64, virtual_eth_adapters=virtual_eth_adapters) return lpar_inst
def fake_lpar(instance_name): return lpar.LPAR(name=instance_name, lpar_id=1, desired_mem=1024, max_mem=2048, max_procs=2, uptime=939395, state='Running')
def _create_lpar_instance(instance): host_stats = self.get_host_stats(refresh=True) inst_name = instance['name'] # CPU/Memory min and max can be configurable. Lets assume # some default values for now. # Memory mem = instance['memory_mb'] if mem > host_stats['host_memory_free']: LOG.error(_('Not enough free memory in the host')) raise exception.PowerVMInsufficientFreeMemory( instance_name=instance['name']) mem_min = min(mem, constants.POWERVM_MIN_MEM) mem_max = mem + constants.POWERVM_MAX_MEM # CPU cpus = instance['vcpus'] avail_cpus = host_stats['vcpus'] - host_stats['vcpus_used'] if cpus > avail_cpus: LOG.error(_('Insufficient available CPU on PowerVM')) raise exception.PowerVMInsufficientCPU( instance_name=instance['name']) cpus_min = min(cpus, constants.POWERVM_MIN_CPUS) cpus_max = cpus + constants.POWERVM_MAX_CPUS cpus_units_min = decimal.Decimal(cpus_min) / decimal.Decimal(10) cpus_units = decimal.Decimal(cpus) / decimal.Decimal(10) try: # Network eth_id = self._operator.get_virtual_eth_adapter_id() # LPAR configuration data lpar_inst = LPAR.LPAR(name=inst_name, lpar_env='aixlinux', min_mem=mem_min, desired_mem=mem, max_mem=mem_max, proc_mode='shared', sharing_mode='uncap', min_procs=cpus_min, desired_procs=cpus, max_procs=cpus_max, min_proc_units=cpus_units_min, desired_proc_units=cpus_units, max_proc_units=cpus_max, virtual_eth_adapters='4/0/%s//0/0' % eth_id) LOG.debug(_("Creating LPAR instance '%s'") % instance['name']) self._operator.create_lpar(lpar_inst) except nova_exception.ProcessExecutionError: LOG.exception( _("LPAR instance '%s' creation failed") % instance['name']) raise exception.PowerVMLPARCreationFailed()
def _create_lpar_instance(instance): host_stats = self.get_host_stats(refresh=True) inst_name = instance['name'] # CPU/Memory min and max can be configurable. Lets assume # some default values for now. # Memory mem = instance['memory_mb'] if mem > host_stats['host_memory_free']: LOG.error(_('Not enough free memory in the host')) raise exception.PowerVMInsufficientFreeMemory( instance_name=instance['name']) mem_min = min(mem, constants.POWERVM_MIN_MEM) mem_max = mem + constants.POWERVM_MAX_MEM # CPU cpus = instance['vcpus'] avail_cpus = host_stats['vcpus'] - host_stats['vcpus_used'] if cpus > avail_cpus: LOG.error(_('Insufficient available CPU on PowerVM')) raise exception.PowerVMInsufficientCPU( instance_name=instance['name']) cpus_min = min(cpus, constants.POWERVM_MIN_CPUS) cpus_max = cpus + constants.POWERVM_MAX_CPUS cpus_units_min = decimal.Decimal(cpus_min) / decimal.Decimal(10) cpus_units = decimal.Decimal(cpus) / decimal.Decimal(10) try: # Network # To ensure the MAC address on the guest matches the # generated value, pull the first 10 characters off the # MAC address for the mac_base_value parameter and then # get the integer value of the final 2 characters as the # slot_id parameter mac = network_info[0]['address'] mac_base_value = (mac[:-2]).replace(':', '') eth_id = self._operator.get_virtual_eth_adapter_id() slot_id = int(mac[-2:], 16) virtual_eth_adapters = ('%(slot_id)s/0/%(eth_id)s//0/0' % locals()) # LPAR configuration data # max_virtual_slots is hardcoded to 64 since we generate a MAC # address that must be placed in slots 32 - 64 lpar_inst = LPAR.LPAR( name=inst_name, lpar_env='aixlinux', min_mem=mem_min, desired_mem=mem, max_mem=mem_max, proc_mode='shared', sharing_mode='uncap', min_procs=cpus_min, desired_procs=cpus, max_procs=cpus_max, min_proc_units=cpus_units_min, desired_proc_units=cpus_units, max_proc_units=cpus_max, virtual_eth_mac_base_value=mac_base_value, max_virtual_slots=64, virtual_eth_adapters=virtual_eth_adapters) LOG.debug(_("Creating LPAR instance '%s'") % instance['name']) self._operator.create_lpar(lpar_inst) #TODO(mjfork) capture the error and handle the error when the MAC # prefix already exists on the system (1 in 2^28) except nova_exception.ProcessExecutionError: LOG.exception(_("LPAR instance '%s' creation failed") % instance['name']) raise exception.PowerVMLPARCreationFailed()
def fake_lpar(instance_name, state=constants.POWERVM_RUNNING): return lpar.LPAR(name=instance_name, lpar_id=1, desired_mem=1024, max_mem=2048, max_procs=2, uptime=939395, state=state)