def test_get_service_type(self): test_datum = { '?': { consts.DASHBOARD_ATTRS_KEY: { 'name': 'foo_name' } } } self.assertEqual('foo_name', tables.get_service_type(test_datum))
def get_context_data(self, request): """Return application details. :param request: :return: """ def find_stack(name, **kwargs): stacks, has_more, has_prev = heat_api.stacks_list(request, sort_dir='asc', **kwargs) for stack in stacks: if name in stack.stack_name: stack_data = {'id': stack.id, 'name': stack.stack_name} return stack_data if has_more: return find_stack(name, marker=stacks[-1].id) return {} def get_instance_and_stack(instance_data, request): instance_name = instance_data['name'] nova_openstackid = instance_data['openstackId'] stack_name = '' instance_result_data = {} stack_result_data = {} instances, more = nova_api.server_list(request) for instance in instances: if nova_openstackid in instance.id: instance_result_data = { 'name': instance.name, 'id': instance.id } stack_name = instance.name.split('-' + instance_name)[0] break # Add link to stack details page if stack_name: stack_result_data = find_stack(stack_name) return instance_result_data, stack_result_data service_data = self.tab_group.kwargs['service'] status_name = '' for id, name in consts.STATUS_DISPLAY_CHOICES: if id == service_data['?']['status']: status_name = name detail_info = collections.OrderedDict([ ('Name', getattr(service_data, 'name', '')), ('ID', service_data['?']['id']), ('Type', tables.get_service_type(service_data) or 'Unknown'), ('Status', status_name), ]) if hasattr(service_data, 'domain'): if not service_data.domain: detail_info['Domain'] = 'Not in domain' else: detail_info['Domain'] = service_data.domain if hasattr(service_data, 'repository'): detail_info['Application repository'] = service_data.repository if hasattr(service_data, 'uri'): detail_info['Load Balancer URI'] = service_data.uri if hasattr(service_data, 'floatingip'): detail_info['Floating IP'] = service_data.floatingip # TODO(efedorova): Need to determine Instance subclass # after it would be possible if hasattr(service_data, 'instance') and service_data['instance'] is not None: instance, stack = get_instance_and_stack(service_data['instance'], request) if instance: detail_info['Instance'] = instance if stack: detail_info['Stack'] = stack if hasattr(service_data, 'instances') and service_data['instances'] is not None: instances_for_template = [] stacks_for_template = [] for instance in service_data['instances']: instance, stack = get_instance_and_stack(instance, request) instances_for_template.append(instance) if stack: stacks_for_template.append(stack) if instances_for_template: detail_info['Instances'] = instances_for_template if stacks_for_template: detail_info['Stacks'] = stacks_for_template return {'service': detail_info}
def get_context_data(self, request): """Return application details. :param request: :return: """ def find_stack(name): stacks, has_more, has_prev = heat_api.stacks_list(request) for stack in stacks: if name in stack.stack_name: stack_data = {'id': stack.id, 'name': stack.stack_name} return stack_data if has_more: find_stack() return {} def get_instance_and_stack(instance_data, request): instance_name = instance_data['name'] stack_name = '' instance_result_data = {} stack_result_data = {} instances, more = nova_api.server_list(request) for instance in instances: if instance_name in instance.name: instance_result_data = {'name': instance.name, 'id': instance.id} stack_name = instance.name.split('-' + instance_name)[0] break # Add link to stack details page if stack_name: stack_result_data = find_stack(stack_name) return instance_result_data, stack_result_data service_data = self.tab_group.kwargs['service'] status_name = '' for id, name in consts.STATUS_DISPLAY_CHOICES: if id == service_data['?']['status']: status_name = name detail_info = OrderedDict([ ('Name', getattr(service_data, 'name', '')), ('ID', service_data['?']['id']), ('Type', tables.get_service_type(service_data) or 'Unknown'), ('Status', status_name), ]) if hasattr(service_data, 'domain'): if not service_data.domain: detail_info['Domain'] = 'Not in domain' else: detail_info['Domain'] = service_data.domain if hasattr(service_data, 'repository'): detail_info['Application repository'] = service_data.repository if hasattr(service_data, 'uri'): detail_info['Load Balancer URI'] = service_data.uri if hasattr(service_data, 'floatingip'): detail_info['Floating IP'] = service_data.floatingip # TODO(efedorova): Need to determine Instance subclass # after it would be possible if hasattr(service_data, 'instance') and service_data['instance'] is not None: instance, stack = get_instance_and_stack( service_data['instance'], request) if instance: detail_info['Instance'] = instance if stack: detail_info['Stack'] = stack if hasattr(service_data, 'instances') and service_data['instance'] is not None: instances_for_template = [] stacks_for_template = [] for instance in service_data['instances']: instance, stack = get_instance_and_stack(instance, request) instances_for_template.append(instance) if stack: stacks_for_template.append(stack) if instances_for_template: detail_info['Instances'] = instances_for_template if stacks_for_template: detail_info['Stacks'] = stacks_for_template return {'service': detail_info}