コード例 #1
0
    def _create_config_entry(self, id_value, id_method="uuid", cfg_file=None):
        """Adds an entry in the config file for the provider using the
        requested identification method [uuid, name] with additional traits
        and inventories.
        """
        # if an existing config file was not passed, create a new one
        if not cfg_file:
            cfg_file = copy.deepcopy(self.BASE_CONFIG)
        provider = copy.deepcopy(self.EMPTY_PROVIDER)

        # create identification method
        provider['identification'] = {id_method: id_value}

        # create entries for additional traits and inventories using values
        # unique to this provider entry
        provider['inventories']['additional'].append({
            orc.normalize_name(id_value): {
                "total": 100,
                "reserved": 0,
                "min_unit": 1,
                "max_unit": 10,
                "step_size": 1,
                "allocation_ratio": 1
            }
        })
        provider['traits']['additional'].append(
            os_traits.normalize_name(id_value))

        # edit cfg_file in place, but return it in case this is the first call
        cfg_file['providers'].append(provider)
        return cfg_file
コード例 #2
0
def vnic_type_trait(vnic_type):
    """A Placement trait name to represent support for a vnic_type.

    :param physnet: The vnic_type.
    :returns: The trait name representing the vnic_type.
    """
    return os_traits.normalize_name(
        '%s%s' % (place_const.TRAIT_PREFIX_VNIC_TYPE, vnic_type))
コード例 #3
0
def physnet_trait(physnet):
    """A Placement trait name to represent being connected to a physnet.

    :param physnet: The physnet name.
    :returns: The trait name representing the physnet.
    """
    return os_traits.normalize_name(
        '%s%s' % (place_const.TRAIT_PREFIX_PHYSNET, physnet))
コード例 #4
0
 def test_normalize_name(self):
     values = [
         ("foo", "CUSTOM_FOO"),
         ("VCPU", "CUSTOM_VCPU"),
         ("CUSTOM_BOB", "CUSTOM_CUSTOM_BOB"),
         ("CUSTM_BOB", "CUSTOM_CUSTM_BOB"),
         (u"Fu\xdfball", u"CUSTOM_FU_BALL"),
         ("abc-123", "CUSTOM_ABC_123"),
         ("Hello, world!  This is a test ^_^",
          "CUSTOM_HELLO_WORLD_THIS_IS_A_TEST_"),
         ("  leading and trailing spaces  ",
          "CUSTOM__LEADING_AND_TRAILING_SPACES_"),
     ]
     for test_value, expected in values:
         result = ot.normalize_name(test_value)
         self.assertEqual(expected, result)