Fix ranger resource status
Fix ranger code to ensure that the resource status (flavors, images, and customers) are showing correctly in their respective LIST APIs. Change-Id: I1647e32c6e0fd362716d10740f00715eb25ac75a
This commit is contained in:
parent
f4d5192e35
commit
6587e662ee
@ -77,14 +77,19 @@ class CustomerRecord:
|
||||
return None
|
||||
|
||||
def get_customers_status_by_uuids(self, uuid_str):
|
||||
results = self.session.connection().execute("SELECT resource_id, status from rds_resource_status_view"
|
||||
" WHERE resource_id in ({})".format(uuid_str))
|
||||
resource_status_dict = {}
|
||||
results = self.session.connection().execute("SELECT id, resource_id, region, status"
|
||||
" FROM rds_resource_status_view WHERE resource_id IN ({})".format(uuid_str))
|
||||
cust_region_dict = {}
|
||||
if results:
|
||||
resource_status_dict = dict((resource_id, status) for resource_id, status in results)
|
||||
|
||||
resource_status_dict = dict((id, (resource_id, region, status)) for id, resource_id, region, status in results)
|
||||
# using resource_status_dict, create cust_region_dict with resource_id as key and (region, status) as value
|
||||
for v in resource_status_dict.values():
|
||||
if v[0] in cust_region_dict:
|
||||
cust_region_dict[v[0]].append(v[1:])
|
||||
else:
|
||||
cust_region_dict[v[0]] = [v[1:]]
|
||||
results.close()
|
||||
return resource_status_dict
|
||||
return cust_region_dict
|
||||
|
||||
def delete_customer_by_uuid(self, uuid):
|
||||
try:
|
||||
|
@ -671,8 +671,27 @@ class CustomerLogic(object):
|
||||
for sql_customer in sql_customers:
|
||||
customer = CustomerSummary.from_db_model(sql_customer)
|
||||
if sql_customer.uuid:
|
||||
status = resource_status_dict.get(sql_customer.uuid)
|
||||
customer.status = not status and 'no regions' or status
|
||||
# rds_region_list contains tuples - each containing the region associated
|
||||
# with the customer along with the region status
|
||||
rds_region_list = resource_status_dict.get(sql_customer.uuid)
|
||||
|
||||
if rds_region_list and customer.regions:
|
||||
# set customer.status to 'error' if any of the regions has an 'Error' status'
|
||||
# else, if any region status shows 'Submitted' then set customer status to 'Pending'
|
||||
# otherwise customer status is 'Success'
|
||||
error_status = [item for item in rds_region_list if item[1] == 'Error']
|
||||
submitted_status = [item for item in rds_region_list if item[1] == 'Submitted']
|
||||
success_status = [item for item in rds_region_list if item[1] == 'Success']
|
||||
|
||||
if len(error_status) > 0:
|
||||
customer.status = 'Error'
|
||||
elif len(submitted_status) > 0:
|
||||
customer.status = 'Pending'
|
||||
elif len(success_status) > 0:
|
||||
customer.status = 'Success'
|
||||
else:
|
||||
customer.status = 'no regions'
|
||||
|
||||
response.customers.append(customer)
|
||||
return response
|
||||
|
||||
|
@ -150,14 +150,22 @@ class FlavorRecord:
|
||||
raise
|
||||
|
||||
def get_flavors_status_by_uuids(self, uuid_str):
|
||||
results = self.session.connection().execute("SELECT resource_id, status from rds_resource_status_view"
|
||||
" WHERE resource_id in ({})".format(uuid_str))
|
||||
resource_status_dict = {}
|
||||
results = self.session.connection().execute("SELECT id, resource_id, region, status"
|
||||
" FROM rds_resource_status_view WHERE resource_id IN ({})".format(uuid_str))
|
||||
|
||||
flvr_region_dict = {}
|
||||
|
||||
if results:
|
||||
resource_status_dict = dict((resource_id, status) for resource_id, status in results)
|
||||
resource_status_dict = dict((id, (resource_id, region, status)) for id, resource_id, region, status in results)
|
||||
# using resource_status_dict, create flvr_region_dict with resource_id as key and (region, status) as value
|
||||
for v in resource_status_dict.values():
|
||||
if v[0] in flvr_region_dict:
|
||||
flvr_region_dict[v[0]].append(v[1:])
|
||||
else:
|
||||
flvr_region_dict[v[0]] = [v[1:]]
|
||||
|
||||
results.close()
|
||||
return resource_status_dict
|
||||
return flvr_region_dict
|
||||
|
||||
def get_flavors_by_criteria(self, **criteria):
|
||||
try:
|
||||
|
@ -808,8 +808,34 @@ def get_flavor_list_by_params(visibility, region, tenant, series, vm_type,
|
||||
for sql_flavor in sql_flavors:
|
||||
flavor = Flavor.from_db_model(sql_flavor)
|
||||
if sql_flavor.id:
|
||||
status = resource_status_dict.get(sql_flavor.id)
|
||||
flavor.status = not status and 'no regions' or status
|
||||
# rds_region_list contains tuples - each containing the region associated
|
||||
# with the flavor along with the region status
|
||||
rds_region_list = resource_status_dict.get(sql_flavor.id)
|
||||
|
||||
# determine flavor overall status by checking its region statuses:
|
||||
if rds_region_list and flavor.regions:
|
||||
# set image.status to 'error' if any of the regions has an 'Error' status'
|
||||
# else, if any region status shows 'Submitted' then set image status to 'Pending'
|
||||
# otherwise image status = 'Success'
|
||||
error_status = [item for item in rds_region_list if item[1] == 'Error']
|
||||
submitted_status = [item for item in rds_region_list if item[1] == 'Submitted']
|
||||
success_status = [item for item in rds_region_list if item[1] == 'Success']
|
||||
|
||||
if len(error_status) > 0:
|
||||
flavor.status = 'Error'
|
||||
elif len(submitted_status) > 0:
|
||||
flavor.status = 'Pending'
|
||||
elif len(success_status) > 0:
|
||||
flavor.status = 'Success'
|
||||
|
||||
# use rds_region_list to format the regions' statuses in flavor record
|
||||
for rgn in flavor.regions:
|
||||
for rds_row_items in rds_region_list:
|
||||
if rgn.name == rds_row_items[0]:
|
||||
rgn.status = rds_row_items[1]
|
||||
else:
|
||||
flavor.status = 'no regions'
|
||||
|
||||
response.flavors.append(flavor)
|
||||
|
||||
except Exception as exp:
|
||||
|
@ -511,8 +511,27 @@ def get_image_list_by_params(visibility, region, Customer):
|
||||
for sql_image in sql_images:
|
||||
image = ImageSummary.from_db_model(sql_image)
|
||||
if sql_image.id:
|
||||
status = resource_status_dict.get(sql_image.id)
|
||||
image.status = not status and 'no regions' or status
|
||||
# rds_region_list contains tuples - each containing the regions associated with the image
|
||||
# along with the region status
|
||||
rds_region_list = resource_status_dict.get(sql_image.id)
|
||||
|
||||
if rds_region_list and image.regions:
|
||||
# set image.status to 'error' if any of the regions has an 'Error' status'
|
||||
# else, if any region status shows 'Submitted' then set image status to 'Pending'
|
||||
# otherwise image status is 'Success'
|
||||
error_status = [item for item in rds_region_list if item[1] == 'Error']
|
||||
submitted_status = [item for item in rds_region_list if item[1] == 'Submitted']
|
||||
success_status = [item for item in rds_region_list if item[1] == 'Success']
|
||||
|
||||
if len(error_status) > 0:
|
||||
image.status = 'Error'
|
||||
elif len(submitted_status) > 0:
|
||||
image.status = 'Pending'
|
||||
elif len(success_status) > 0:
|
||||
image.status = 'Success'
|
||||
else:
|
||||
image.status = 'no regions'
|
||||
|
||||
response.images.append(image)
|
||||
return response
|
||||
|
||||
|
@ -95,12 +95,17 @@ class ImageRecord(Record):
|
||||
raise
|
||||
|
||||
def get_images_status_by_uuids(self, uuid_str):
|
||||
results = self.session.connection().execute("SELECT resource_id, status from rds_resource_status_view"
|
||||
" WHERE resource_id in ({})".format(uuid_str))
|
||||
resource_status_dict = {}
|
||||
results = self.session.connection().execute("SELECT id, resource_id, region, status"
|
||||
" FROM rds_resource_status_view WHERE resource_id IN ({})".format(uuid_str))
|
||||
img_region_dict = {}
|
||||
if results:
|
||||
resource_status_dict = dict((resource_id, status) for resource_id, status in results)
|
||||
|
||||
resource_status_dict = dict((id, (resource_id, region, status)) for id, resource_id, region, status in results)
|
||||
# using resource_status_dict, create img_region_dict with resource_id as key and (region, status) as value
|
||||
for v in resource_status_dict.values():
|
||||
if v[0] in img_region_dict:
|
||||
img_region_dict[v[0]].append(v[1:])
|
||||
else:
|
||||
img_region_dict[v[0]] = [v[1:]]
|
||||
results.close()
|
||||
return resource_status_dict
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user