Example #1
0
    def test_sanitize_partition_name_for_api(self):
        allc = ''.join(map(chr, range(256)))
        self.assertEqual('foo', util.sanitize_partition_name_for_api('foo'))
        self.assertEqual('_______________________________',
                         util.sanitize_partition_name_for_api(allc))
        self.assertEqual('_ !_#_%_____+,-./0123456789:;_=',
                         util.sanitize_partition_name_for_api(allc[31:]))
        self.assertEqual('__@ABCDEFGHIJKLMNOPQRSTUVWXYZ__',
                         util.sanitize_partition_name_for_api(allc[62:]))
        self.assertEqual('_^__abcdefghijklmnopqrstuvwxyz{',
                         util.sanitize_partition_name_for_api(allc[93:]))
        self.assertEqual('_}_____________________________',
                         util.sanitize_partition_name_for_api(allc[124:]))
        for start in (155, 186, 217):
            self.assertEqual(
                '_______________________________',
                util.sanitize_partition_name_for_api(allc[start:]))
        self.assertEqual('________',
                         util.sanitize_partition_name_for_api(allc[248:]))
        self.assertEqual(
            'I _ _________',
            util.sanitize_partition_name_for_api(
                u'I \u611B \u01A4\u0177\u03C1\uFF4F\u05E9\u5DF3'
                u'\u5C3A\uFF56\uFF4D'))

        self.assertRaises(ValueError,
                          util.sanitize_partition_name_for_api,
                          allc,
                          trunc_ok=False)
        self.assertRaises(ValueError, util.sanitize_partition_name_for_api, '')
        self.assertRaises(ValueError, util.sanitize_partition_name_for_api,
                          None)
Example #2
0
    def test_sanitize_partition_name_for_api(self):
        allc = ''.join(map(chr, range(256)))
        self.assertEqual('foo', util.sanitize_partition_name_for_api('foo'))
        self.assertEqual('_______________________________',
                         util.sanitize_partition_name_for_api(allc))
        self.assertEqual('_ !_#_%_____+,-./0123456789:;_=',
                         util.sanitize_partition_name_for_api(allc[31:]))
        self.assertEqual('__@ABCDEFGHIJKLMNOPQRSTUVWXYZ__',
                         util.sanitize_partition_name_for_api(allc[62:]))
        self.assertEqual('_^__abcdefghijklmnopqrstuvwxyz{',
                         util.sanitize_partition_name_for_api(allc[93:]))
        self.assertEqual('_}_____________________________',
                         util.sanitize_partition_name_for_api(allc[124:]))
        for start in (155, 186, 217):
            self.assertEqual(
                '_______________________________',
                util.sanitize_partition_name_for_api(allc[start:]))
        self.assertEqual('________',
                         util.sanitize_partition_name_for_api(allc[248:]))
        self.assertEqual('I _ _________',
                         util.sanitize_partition_name_for_api(
                             u'I \u611B \u01A4\u0177\u03C1\uFF4F\u05E9\u5DF3'
                             u'\u5C3A\uFF56\uFF4D'))

        self.assertRaises(ValueError, util.sanitize_partition_name_for_api,
                          allc, trunc_ok=False)
        self.assertRaises(ValueError, util.sanitize_partition_name_for_api, '')
        self.assertRaises(ValueError, util.sanitize_partition_name_for_api,
                          None)
Example #3
0
    def _format_flavor(self, inst):
        """Returns the pypowervm format of the flavor.

        :param inst: The Nova VM instance.
        :return: A dict that can be used by the LPAR builder.
        """
        # The attrs are what is sent to pypowervm to convert the lpar.
        attrs = {
            lpar_bldr.NAME: pvm_u.sanitize_partition_name_for_api(inst.name),
            # The uuid is only actually set on a create of an LPAR
            lpar_bldr.UUID: get_pvm_uuid(inst),
            lpar_bldr.MEM: inst.flavor.memory_mb,
            lpar_bldr.VCPU: inst.flavor.vcpus,
            # Set the srr capability to True by default
            lpar_bldr.SRR_CAPABLE: True}

        # Loop through the extra specs and process powervm keys
        for key in inst.flavor.extra_specs.keys():
            # If it is not a valid key, then can skip.
            if not self._is_pvm_valid_key(key):
                continue

            # Look for the mapping to the lpar builder
            bldr_key = self._ATTRS_MAP.get(key)

            # Check for no direct mapping, if the value is none, need to
            # derive the complex type
            if bldr_key is None:
                self._build_complex_type(key, attrs, inst.flavor)
            else:
                # We found a direct mapping
                attrs[bldr_key] = inst.flavor.extra_specs[key]

        return attrs
Example #4
0
def update(adapter, host_wrapper, instance, entry=None, name=None):
    """Update an LPAR based on the host based on the instance

    :param adapter: The adapter for the pypowervm API
    :param host_wrapper: The host wrapper
    :param instance: The nova instance.
    :param entry: The instance pvm entry, if available, otherwise it will
        be fetched.
    :param name: VM name to use for the update.  Used on resize when we want
        to rename it but not use the instance name.
    :returns: The updated LPAR wrapper.
    """

    if not entry:
        entry = get_instance_wrapper(adapter, instance)

    lpar_b = VMBuilder(host_wrapper, adapter, cur_lpar_w=entry).lpar_builder(
        instance)
    lpar_b.rebuild(entry)

    # Set the new name if the instance name is not desired.
    if name:
        entry.name = pvm_util.sanitize_partition_name_for_api(name)
    # Write out the new specs, return the updated version
    return entry.update()
Example #5
0
def update(adapter, host_wrapper, instance, flavor, entry=None, name=None):
    """Update an LPAR based on the host based on the instance

    :param adapter: The adapter for the pypowervm API
    :param host_wrapper: The host wrapper
    :param instance: The nova instance.
    :param flavor: The nova flavor.
    :param entry: The instance pvm entry, if available, otherwise it will
        be fetched.
    :param name: VM name to use for the update.  Used on resize when we want
        to rename it but not use the instance name.
    :returns: The updated LPAR wrapper.
    """

    if not entry:
        entry = get_instance_wrapper(adapter, instance)

    lpar_b = VMBuilder(host_wrapper, adapter).lpar_builder(instance, flavor)
    lpar_b.rebuild(entry)

    # Set the new name if the instance name is not desired.
    if name:
        entry.name = pvm_util.sanitize_partition_name_for_api(name)
    # Write out the new specs, return the updated version
    return entry.update()
Example #6
0
    def _format_flavor(self, instance):
        """Returns the pypowervm format of the flavor.

        :param instance: the VM instance
        :return: a dict that can be used by the LPAR builder
        """
        # The attrs are what is sent to pypowervm to convert the lpar.
        attrs = {}

        attrs[lpar_bldr.NAME] = pvm_util.sanitize_partition_name_for_api(
            instance.name)
        # The uuid is only actually set on a create of an LPAR
        attrs[lpar_bldr.UUID] = pvm_uuid.convert_uuid_to_pvm(instance.uuid)
        attrs[lpar_bldr.MEM] = instance.flavor.memory_mb
        attrs[lpar_bldr.VCPU] = instance.flavor.vcpus
        # Set the srr capability to True by default
        attrs[lpar_bldr.SRR_CAPABLE] = True

        # Loop through the extra specs and process powervm keys
        for key in instance.flavor.extra_specs.keys():
            # If it is not a valid key, then can skip.
            if not self._is_pvm_valid_key(key):
                continue

            # Look for the mapping to the lpar builder
            bldr_key = self._ATTRS_MAP.get(key)

            # Check for no direct mapping, if the value is none, need to
            # derive the complex type
            if bldr_key is None:
                self._build_complex_type(key, attrs, instance.flavor)
            elif bldr_key == lpar_bldr.ENABLE_LPAR_METRIC:
                lpar_metric = self._flavor_bool(
                    instance.flavor.extra_specs[key], key)
                attrs[bldr_key] = lpar_metric
            elif bldr_key == lpar_bldr.PPT_RATIO:
                if (instance.task_state == task_states.REBUILD_SPAWNING
                        and not self.host_w.get_capability(
                            'physical_page_table_ratio_capable')):
                    # We still want to be able to rebuild from hosts that
                    # support setting the PPT ratio to hosts that don't support
                    # setting the PPT ratio.
                    LOG.info(
                        "Ignoring PPT ratio on rebuild to PPT ratio "
                        "unsupported host.",
                        instance=instance)
                else:
                    attrs[bldr_key] = instance.flavor.extra_specs[key]
            else:
                # We found a direct mapping
                attrs[bldr_key] = instance.flavor.extra_specs[key]

        return attrs
Example #7
0
    def lpar_builder(self, inst):
        """Returns the pypowervm LPARBuilder for a given Nova flavor.

        :param inst: the VM instance
        """
        attrs = {
            lpar_bldr.NAME: pvm_u.sanitize_partition_name_for_api(inst.name),
            lpar_bldr.UUID: get_pvm_uuid(inst),
            lpar_bldr.MEM: inst.flavor.memory_mb,
            lpar_bldr.VCPU: inst.flavor.vcpus
        }
        # TODO(efried): Loop through the extra specs and process powervm keys
        # TODO(thorst, efried) Add in IBMi attributes
        return lpar_bldr.LPARBuilder(self.adapter, attrs, self.stdz)
Example #8
0
def rename(adapter, instance, name, entry=None):
    """Rename a VM.

    :param adapter: The adapter for the pypowervm API
    :param instance: The nova instance.
    :param name: The new name.
    :param entry: The instance pvm entry, if available, otherwise it will
        be fetched.
    :returns: The updated LPAR wrapper.
    """
    if not entry:
        entry = get_instance_wrapper(adapter, instance)

    hyp_name = pvm_util.sanitize_partition_name_for_api(name)

    @pvm_trans.entry_transaction
    def _rename(entry):
        entry.name = hyp_name
        return entry.update()

    return _rename(entry)
Example #9
0
def rename(adapter, instance, name, entry=None):
    """Rename a VM.

    :param adapter: The adapter for the pypowervm API
    :param instance: The nova instance.
    :param name: The new name.
    :param entry: The instance pvm entry, if available, otherwise it will
        be fetched.
    :returns: The updated LPAR wrapper.
    """
    if not entry:
        entry = get_instance_wrapper(adapter, instance)

    hyp_name = pvm_util.sanitize_partition_name_for_api(name)

    @pvm_trans.entry_transaction
    def _rename(entry):
        entry.name = hyp_name
        return entry.update()

    return _rename(entry)