Commit 8f286999 authored by Simon Leinen's avatar Simon Leinen

Handle case where server disappears under us

parent 923ab756
......@@ -28,12 +28,13 @@
import os
import re
import sys
import warnings
from keystoneclient.v2_0 import client
from keystoneclient.auth.identity import v2
from keystoneclient import session
from novaclient.client import Client
from novaclient.exceptions import BadRequest
import sys
from novaclient.exceptions import BadRequest, NotFound
class UsageAnalyzer:
......@@ -149,13 +150,13 @@ class UsageAnalyzer:
return 'other'
def cost_center_name_from_tenant(self, tenant, fine_grained=None):
cc_name = None
if fine_grained is None:
fine_grained = self.fine_grained
m = self.cc_re.match(tenant.description)
if m:
cc_name = m.group(1)
else:
cc_name = None
if tenant.description is not None:
m = self.cc_re.match(tenant.description)
if m:
cc_name = m.group(1)
return self.cc_name_from_tenant_1(tenant, cc_name, fine_grained=fine_grained)
def get_cost_centers(self, fine_grained=None):
......@@ -205,9 +206,12 @@ class UsageAnalyzer:
ne = nes[r]
servers = ne.servers.list(search_opts = {'all_tenants': 1})
for server in servers:
s = ne.servers.get(server.id)
f = self.get_flavor(s.flavor['id'], r)
self.note_usage(s.tenant_id, r, s.status, ram=f.ram, vcpus=f.vcpus, disk=f.disk)
try:
s = ne.servers.get(server.id)
f = self.get_flavor(s.flavor['id'], r)
self.note_usage(s.tenant_id, r, s.status, ram=f.ram, vcpus=f.vcpus, disk=f.disk)
except NotFound as c:
warn("Instance {:s} disappeared".format(server.id))
def collect_flavors(self):
self.flavors = dict()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment