Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion os_capacity/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class FlavorList(Lister):

def take_action(self, parsed_args):
flavors = utils.get_flavors(self.app)
return (('UUID', 'Name', 'VCPUs', 'RAM MB', 'DISK GB'), flavors)
return (('UUID', 'Name', 'VCPUs', 'RAM MB', 'DISK GB', 'Extra Specs'),
flavors)


class ListResourcesAll(Lister):
Expand Down
16 changes: 11 additions & 5 deletions os_capacity/data/flavors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@


Flavor = collections.namedtuple(
"Flavor", ("id", "name", "vcpus", "ram_mb", "disk_gb"))
"Flavor", ("id", "name", "vcpus", "ram_mb", "disk_gb", "extra_specs"))


def get_all(compute_client):
response = compute_client.get("/flavors/detail").json()
def get_all(compute_client, include_extra_specs=True):
response = compute_client.get('/flavors/detail').json()
raw_flavors = response['flavors']
# TODO(johngarbutt) disk should probably include ephemeral
return [Flavor(f['id'], f['name'], f['vcpus'], f['ram'], f['disk'])
if include_extra_specs:
for flavor in raw_flavors:
url = '/flavors/%s/os-extra_specs' % flavor['id']
response = compute_client.get(url).json()
flavor['extra_specs'] = response['extra_specs']
return [Flavor(f['id'], f['name'], f['vcpus'], f['ram'],
(f['disk'] + f['OS-FLV-EXT-DATA:ephemeral']),
f.get('extra_specs'))
for f in raw_flavors]
19 changes: 14 additions & 5 deletions os_capacity/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

def get_flavors(app):
app.LOG.debug("Getting flavors")
raw_flavors = flavors.get_all(app.compute_client)
return [(f.id, f.name, f.vcpus, f.ram_mb, f.disk_gb) for f in raw_flavors]
return flavors.get_all(app.compute_client, include_extra_specs=True)


def get_providers_with_resources_and_servers(app):
Expand Down Expand Up @@ -54,7 +53,13 @@ def group_providers_by_type_with_capacity(app):
all_flavors = flavors.get_all(app.compute_client)
grouped_flavors = collections.defaultdict(list)
for flavor in all_flavors:
key = (flavor.vcpus, flavor.ram_mb, flavor.disk_gb)
custom_rc = None
for extra_spec in flavor.extra_specs:
if extra_spec.startswith('resources:CUSTOM'):
custom_rc = extra_spec.replace('resources:', '')
break # Assuming a good Ironic setup here

key = (flavor.vcpus, flavor.ram_mb, flavor.disk_gb, custom_rc)
grouped_flavors[key] += [flavor.name]

all_resource_providers = resource_provider.get_all(app.placement_client)
Expand All @@ -69,14 +74,17 @@ def group_providers_by_type_with_capacity(app):
vcpus = 0
ram_mb = 0
disk_gb = 0
custom_rc = None
for inventory in inventories:
if "VCPU" in inventory.resource_class:
vcpus += inventory.total
if "MEMORY" in inventory.resource_class:
ram_mb += inventory.total
if "DISK" in inventory.resource_class:
disk_gb += inventory.total
key = (vcpus, ram_mb, disk_gb)
if inventory.resource_class.startswith('CUSTOM_'):
custom_rc = inventory.resource_class # Ironic specific
key = (vcpus, ram_mb, disk_gb, custom_rc)

inventory_counts[key] += 1

Expand All @@ -86,8 +94,9 @@ def group_providers_by_type_with_capacity(app):
allocation_counts[key] += 1

for key, inventory_count in inventory_counts.items():
resources = "VCPU:%s,MEMORY_MB:%s,DISK_GB:%s" % key
resources = "VCPU:%s,MEMORY_MB:%s,DISK_GB:%s,%s" % key
matching_flavors = grouped_flavors[key]
matching_flavors.sort()
matching_flavors = ", ".join(matching_flavors)
total = inventory_count
used = allocation_counts[key]
Expand Down