Skip to content

Instantly share code, notes, and snippets.

@dstanek
Created March 3, 2017 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstanek/a8a343a3ab5ad4ad0862e3e1be332173 to your computer and use it in GitHub Desktop.
Save dstanek/a8a343a3ab5ad4ad0862e3e1be332173 to your computer and use it in GitHub Desktop.
Table structures:
limit_types:
id uuid
service string
name string
default int
project_limits:
id uuid
limit_type_id uuid
value integer
project uuid
Example data:
limit_types:
3134fdb, compute, vCPU, 10
18d864ff79e445fc789cebb19
project_limits
2234c2f, 3134fdb, 9, A
2645049, 3134fdb, 4, C
Example hierarchy:
A -> B
-> C
-> D
Example API:
>>> # project not explicitly defined gets the service default
>>> keystone.get_limits('compute', 'X')
{
'limits': {
'vCPU': 10,
},
}
>>> # root project get its limits
>>> keystone.get_limits('compute', 'A')
{
'limits': {
'vCPU': 9,
},
}
>>> # child gets a mini tree
>>> keystone.get_limits('compute', 'B')
{
'limits': {
'vCPU': None,
},
'parent': {
'name': 'A',
'limits': {
'vCPU': 9
},
},
}
>>> # grandchild gets a bigger tree
>>> keystone.get_limits('compute', 'C')
{
'limits': {
'vCPU': 4,
},
'parent':
'name': 'B',
'limits': {
'vCPU': None,
},
'parent': {
'name': 'A',
'limits': {
'vCPU': 9,
},
},
},
}
Notes:
1. There are lots of possiblities to flatten the nested structure
2. We can add a `'siblings': []` at the same level as parent if we end up needing it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment