Skip to content

Commit 3340796

Browse files
committed
Allow data candidates to be run directly
1 parent a299948 commit 3340796

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

os_capacity/data/candidates.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ def get_max_per_host(placement_client, resources, required_traits):
6565
return count_per_rp
6666

6767

68-
def print_exporter_data(app):
69-
flavors = list(app.compute_client.flavors())
70-
capacity_per_flavor = get_capacity_per_flavor(app.placement_client, flavors)
68+
69+
def print_details(compute_client, placement_client):
70+
flavors = list(compute_client.flavors())
71+
capacity_per_flavor = get_capacity_per_flavor(placement_client, flavors)
7172

7273
# total capacity per flavor
7374
flavor_names = sorted([f.name for f in flavors])
@@ -77,7 +78,7 @@ def print_exporter_data(app):
7778
print(f'openstack_total_capacity_per_flavor{{flavor="{flavor_name}"}} {total}')
7879

7980
# capacity per host
80-
raw_rps = list(app.placement_client.resource_providers())
81+
raw_rps = list(placement_client.resource_providers())
8182
resource_providers = {rp.name: rp.id for rp in raw_rps}
8283
hostnames = sorted(resource_providers.keys())
8384
for hostname in hostnames:
@@ -90,3 +91,12 @@ def print_exporter_data(app):
9091
print(
9192
f'openstack_capacity_by_hostname{{hypervisor="{hostname}",flavor="{flavor_name}"}} {our_count}'
9293
)
94+
95+
96+
def print_exporter_data(app):
97+
print_details(app.compute_client, app.placement_client)
98+
99+
100+
if __name__ == '__main__':
101+
conn = openstack.connect()
102+
print_details(conn.compute, conn.placement)

os_capacity/shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self):
4242
def initialize_app(self, argv):
4343
self.LOG.debug('initialize_app')
4444

45-
conn = openstack.openstack.connect()
45+
conn = openstack.connect()
4646
self.connection = conn
4747
self.compute_client = conn.compute
4848
self.placement_client = conn.placement

0 commit comments

Comments
 (0)