Commit Graph

19 Commits

Author SHA1 Message Date
Stephen Finucane 865cf20732 Remove use of six
Only one user here which is no longer needed in a Python 3 only world.

Change-Id: Iac33e324d07d67368a5b544030cd5414d0586955
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2020-02-27 15:04:41 +00:00
Eric Fried fc685f9e3b Privatize and reorganize base package methods
On the theory that they aren't and shouldn't be used, the following
methods are removed from the public interface of the base os_traits
package:

- symbolize (deleted, unused internally)
- import_submodules (deleted, replaced with appropriate call to
  _walk_submodules)

This commit also reorganizes the module to put private methods first,
public methods last; and alphabetize within those groupings.

Sem-Ver: api-break
Change-Id: Idb5613bc016743ba689c6996d39399aae774daa9
2019-10-09 15:43:53 +00:00
Eric Fried 6a5e829b0d Add method to visualize the os-traits tree
Add a print_tree method in the base os_traits package. This recursively
walks the repository and prints a formatted tree of short names of all
the namespaces and their traits. You can try it like this:

  python -c 'import os_traits; os_traits.print_tree()'

Here's an abbreviated subset of the output:

   COMPUTE:
      DEVICE_TAGGING, TRUSTED_CERTS
      GRAPHICS:
         MODEL_CIRRUS, MODEL_GOP, MODEL_NONE, MODEL_QXL, MODEL_VGA, MODEL_VIRTIO, MODEL_VMVGA, MODEL_XEN
   HW:
      CPU:
         HYPERTHREADING
         AMD:
            SEV
         PPC64LE:
            POWER8, POWER9
      NUMA:
         ROOT
   MISC:
      SHARES_VIA_AGGREGATE
   STORAGE:
      DISK:
         HDD, SSD

Change-Id: I6309501f10544f468bb694361c845a393a9491cf
2019-10-08 12:35:06 -05:00
Eric Fried 65a8daf8ff normalize_name helper
Names of traits in placement are restricted to certain characters and
lengths.  Consumers (e.g. Nova virt driver implementations of
update_provider_tree) may wish to generate such names dynamically based
on inputs that don't necessarily know or follow those rules.  Such
consumers could use a convenient way to sanitize generated names such
that they conform to what placement expects.

This change set introduces a normalize_name method into the base
os_traits namespace.  It is functionally identical to
ResourceClass.normalize_name: it converts and squashes any sequences of
non-alphanumeric characters to an underscore, upcases, and prepends
CUSTOM_.

Change-Id: I0d83cb39abb417b337a3429d374e88942561d254
Related-Blueprint: update-provider-tree
2018-06-13 08:18:25 -05:00
Rodolfo Alonso Hernandez ce9bef1c5b Add a new parameter ``suffix`` to function ``get_traits``
Added a new optional parameter ``suffix`` to function ``get_traits``. This
new parameter allows filtering the list of traits returned by the ending
of the name.

Change-Id: Ifadb72a1b8b64971c0377eaef89522fe979c0c87
2017-07-20 16:31:51 +01:00
Rodolfo Alonso Hernandez 43ee0a5d68 Add filtering option in "check_traits"
Added "prefix" parameter to "check_traits" function. Now it's
possible to check a list of strings with a subset of defined
traits.

Change-Id: Ie2e7a5a7a264f887673bd3855efde44da1324701
2017-06-28 12:17:47 +01:00
Chris Dent 5baa0f6170 Adjust module level constants to uppercase
They are constants, after all.

In the process make sure that none of these constants are presented
as traits when get_traits is called.

Change-Id: I783e0a2e99823ff061303152def64db59f3c31de
2017-05-31 19:34:01 +00:00
Chris Dent 789ce955ea Correctly recurse os_traits packages
When walk_packages is called, unless a prefix is provided, it is
easy to escape the os_traits package and start walking other
packages. If there is a top-level 'tests' package somewhere in the
python path, this can then lead to importing all sorts of things,
some which rely on the environment having certain characteristics
and fail the import without that, some which will change the
environment.

Neither of these things are good. Nor do we want to be walking
packages all over the place. By providing a prefix we stay within
the os_traits package as desired.

Change-Id: Icde41191e39317ff5a031fff9ece0f05f1e0b4bc
Closes-Bug: #1694792
2017-05-31 19:04:05 +00:00
Jay Pipes 8503afd938 Remove 'CUSTOM_NAMESPACE'/'os_traits' from traits
The get_traits() function was erroneously including 'CUSTOM_NAMESPACE' and
'os_traits' in the list of returned traits because the matching expression in
the list comprehension wasn't filtering out these two module-level string
attributes.

Also removes the name.upper() in symbolize() because that's actually dangerous
-- it may make a symbol in os_traits that doesn't actually match the trait name
defined in the submodule. For instance, if someone creates an
os_traits/foo/bar.py module with::

TRAITS = [
    'baz',
]

the name.upper() would make a symbol os_traits.foo.bar.BAZ and
os_traits.FOO_BAR_baz

Change-Id: I8633cb29649ad0ca67f7669fd2b405b55e16258e
2017-05-04 19:47:04 -04:00
Jay Pipes 5a704fd08d remove redundant get_symbol_names() func
The os_traits.get_symbol_names() function implementation was identical to the
os_traits.get_traits() function. Remove it.

Change-Id: I8656d98e51258b641190cfca1da71348ca7b6752
2017-05-04 19:47:02 -04:00
EdLeafe 2eb278ce1b Automate the import of traits
The previous patch broke apart the single monolithic declaration of
traits into a branching directory structure. That was great, but it
added a lot of repetitive code to get the subpackages and submodules
into the proper namespace. This patch automates that for any file in the
tree that contains a 'TRAITS' property.

Change-Id: I904789cbec76d83a14e213ce6bb474c9967d588b
2017-04-25 17:51:26 +00:00
Jay Pipes 842a43b515 Add NIC namespace and features
Adds a set of traits representing features that hardware networking interface
controllers expose. A number of source documents were used to come up with
these traits:

https://review.openstack.org/#/c/341341/4/specs/newton/approved/standardize-network-capabilities.rst
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Performance_Tuning_Guide/network-nic-offloads.html
https://www.kernel.org/doc/Documentation/networking/scaling.txt
https://www.kernel.org/doc/Documentation/networking/multiqueue.txt

Change-Id: If8a9f08b8b45ebcac53ea9a406c210605b163516
2017-04-24 11:53:21 -04:00
Jay Pipes 23d81d4451 organize os_traits for the future
Sean Mooney had a good idea that for future-proofing the os-traits library and
ensuring that we don't have to deal with one giant const.py file, that we break
the library into various modules corresponding to the higher-level namespaces.

This patch adds some symbol-registration foo into a utils module and allows the
os_traits module and "leaf modules" to be called in the following way:

 import os_traits
 from os_traits.hw.cpu import x86

 assert os_traits.HW_CPU_X86_SSE42 == x86.SSE42
 assert x86.SSE42 == 'HW_CPU_X86_SSE42'

Change-Id: I0e8f50822ab67cb3be85ed3b935dd6cdb4436dbf
2017-04-05 16:01:33 +00:00
Jay Pipes 2855c25eb3 Add custom namespace
Adds the CUSTOM_ trait namespace prefix, matching the CUSTOM_ prefix
from the resource classes in the placement API. Also adds a simple
is_custom() method to the library for testing whether a trait is
custom or not.

Change-Id: I37cd61516eb68c9bf07778fe6ad42bb34c19d4da
2017-03-03 14:38:26 +00:00
Jay Pipes 9452af54b1 normalize constants to align with resource classes
Changes the lowercased constants to uppercase and replaces the : with a
_ character. This aligns with the naming convention for resource classes
in the placement API.

Change-Id: Ic8e87ff8db5b1893d2060af01bf48adda712a27c
2017-03-03 12:20:38 +00:00
Jay Pipes 6f4b514145 update pep8/hacking and address failures
update to necessary hacking from global requirements and fix up the
linting failures.

Change-Id: Ie6baa9e1b97ea3e1b61a418b00b64d1be391866a
2017-03-02 11:37:02 -05:00
Yingxin f04ae239f4 Add check_traits function
The added function check_traits accepts an iteration of string and group
them as standard traits set and other traits set.
2016-10-08 08:16:03 +00:00
Yingxin d56ac9facb Rename the rest capabilities to traits 2016-09-20 05:40:55 +00:00
Jay Pipes d5ab376e0a Rename capabilities to traits 2016-09-19 11:00:31 -04:00