<%
    static_compute_info = attributes['static_compute_info']
    shares = attributes['shares']
    all_endpoints = {url: endpoint for vo, share in shares.items() for url, endpoint in share['endpoints']['endpoints'].items()}
    # Collect template and images from all shares using nest dict comprehension
    # http://stackoverflow.com/questions/20446526/nested-dictionary-comprehension-in-python
    templates = {template_id: template for vo, share in shares.items() for template_id, template in share['templates'].items()}
    images = {image_id: image for vo, share in shares.items() for image_id, image in share['images'].items()}
%>\
dn: GLUE2ServiceID=${static_compute_info['compute_service_name']}_cloud.compute,GLUE2GroupID=cloud,${static_compute_info['suffix']}
objectClass: GLUE2Entity
objectClass: GLUE2Service
objectClass: GLUE2ComputingService
GLUE2ServiceAdminDomainForeignKey: ${static_compute_info['site_name']}
GLUE2ServiceID: ${static_compute_info['compute_service_name']}_cloud.compute
GLUE2ServiceQualityLevel: ${static_compute_info['compute_service_production_level']}
GLUE2ServiceType: IaaS
GLUE2ServiceCapability: ${static_compute_info['compute_capabilities']}

dn: GLUE2ManagerID=${static_compute_info['compute_service_name']}_cloud.compute_manager,GLUE2ServiceID=${static_compute_info['compute_service_name']}_cloud.compute,GLUE2GroupID=cloud,${static_compute_info['suffix']}
objectClass: GLUE2Entity
objectClass: GLUE2Manager
objectClass: GLUE2ComputingManager
GLUE2ManagerID: ${static_compute_info['compute_service_name']}_cloud.compute_manager
GLUE2ManagerProductName: ${static_compute_info['compute_hypervisor']}
GLUE2ManagerServiceForeignKey: ${static_compute_info['compute_service_name']}_cloud.compute
GLUE2ComputingManagerComputingServiceForeignKey: ${static_compute_info['compute_service_name']}_cloud.compute
GLUE2EntityName: Cloud Manager for ${static_compute_info['compute_service_name']}
GLUE2ManagerProductVersion: ${static_compute_info['compute_hypervisor_version']}
GLUE2ComputingManagerTotalLogicalCPUs: ${static_compute_info['compute_total_cores']}
GLUE2ComputingManagerWorkingAreaTotal: ${static_compute_info['compute_total_ram']}

% for url, endpoint in all_endpoints.items():
<%
    compute_endpoint_url = endpoint.get('compute_nova_endpoint_url', endpoint.get('compute_endpoint_url'))
    compute_api_version = endpoint.get('compute_nova_api_version', endpoint.get('compute_api_version'))
%>\
dn: GLUE2EndpointID=${compute_endpoint_url}_${endpoint['compute_api_type']}_${compute_api_version}_${endpoint['compute_api_authn_method']},GLUE2ServiceID=${endpoint['compute_service_name']}_cloud.compute,GLUE2GroupID=cloud,${endpoint['suffix']}
objectClass: GLUE2Entity
objectClass: GLUE2Endpoint
objectClass: GLUE2ComputingEndpoint
GLUE2EndpointHealthState: ok
GLUE2EndpointID: ${compute_endpoint_url}_${endpoint['compute_api_type']}_${compute_api_version}_${endpoint['compute_api_authn_method']}
GLUE2EndpointInterfaceName: ${endpoint['compute_api_type']}
GLUE2EndpointQualityLevel: ${endpoint['compute_production_level']}
GLUE2EndpointServiceForeignKey: ${endpoint['compute_service_name']}_cloud.compute
GLUE2EndpointServingState: ${endpoint['compute_production_level']}
GLUE2EndpointURL: ${compute_endpoint_url}
GLUE2ComputingEndpointComputingServiceForeignKey: ${endpoint['compute_service_name']}_cloud.compute
GLUE2EndpointCapability: ${endpoint['compute_capabilities']}
GLUE2EndpointImplementationName: ${endpoint['compute_middleware']}
GLUE2EndpointImplementationVersion: ${endpoint['compute_middleware_version']}
GLUE2EndpointImplementor: ${endpoint['compute_middleware_developer']}
GLUE2EndpointInterfaceVersion: ${compute_api_version}
#GLUE2EndpointSemantics:
#GLUE2EndpointSupportedProfile:
GLUE2EntityOtherInfo: Authn=${endpoint['compute_api_authn_method']}
GLUE2EndpointTechnology: ${endpoint['compute_api_endpoint_technology']}

% endfor
% for template_id, template in templates.items():
<%
    if template['template_disk'] is None:
        template['template_disk'] = 0
%>\
dn: GLUE2ResourceID=${template['template_id']}_${template['compute_service_name']},GLUE2ServiceID=${template['compute_service_name']}_cloud.compute,GLUE2GroupID=cloud,${template['suffix']}
objectClass: GLUE2Entity
objectClass: GLUE2Resource
objectClass: GLUE2ExecutionEnvironment
GLUE2ExecutionEnvironmentConnectivityIn: TRUE
GLUE2ExecutionEnvironmentConnectivityOut: TRUE
GLUE2ExecutionEnvironmentVirtualMachine: TRUE
GLUE2ExecutionEnvironmentMainMemorySize: ${template['template_memory']}
GLUE2ExecutionEnvironmentPlatform: ${template['template_platform']}
GLUE2ExecutionEnvironmentOSFamily: linux
GLUE2ResourceManagerForeignKey: ${endpoint['compute_service_name']}_cloud.compute_manager
GLUE2EntityName: ${template['template_id']}
GLUE2ExecutionEnvironmentComputingManagerForeignKey: ${endpoint['compute_service_name']}_cloud.compute_manager
GLUE2ExecutionEnvironmentCPUModel: virtual model
GLUE2ExecutionEnvironmentCPUMultiplicity: multicpu-multicore
GLUE2ExecutionEnvironmentCPUVendor: virtual vendor
GLUE2ExecutionEnvironmentLogicalCPUs: ${template['template_cpu']}
GLUE2ExecutionEnvironmentPhysicalCPUs: ${template['template_cpu']}
GLUE2EntityOtherInfo: disk=${template['template_disk']}

% endfor
% for image_id, image in images.items():
<%
    if image['image_description'] is None:
        image['image_description'] = ('%(image_name)s version '
            '%(image_version)s on '
            '%(image_os_family)s %(image_os_name)s '
            '%(image_os_version)s '
            '%(image_platform)s' % image)
%>\
dn: GLUE2ApplicationEnvironmentID=${image['image_id']}_${endpoint['compute_service_name']},GLUE2ServiceID=${endpoint['compute_service_name']}_cloud.compute,GLUE2GroupID=cloud,${endpoint['suffix']}
objectClass: GLUE2Entity
objectClass: GLUE2ApplicationEnvironment
GLUE2ApplicationEnvironmentID: ${image['image_id']}_${endpoint['compute_service_name']}
GLUE2ApplicationEnvironmentAppName: ${image['image_name']}
GLUE2ApplicationEnvironmentAppVersion: ${image['image_version']}
GLUE2ApplicationEnvironmentRepository: ${image['image_marketplace_id']}
GLUE2ApplicationEnvironmentDescription: ${image['image_description']}
GLUE2EntityName: ${image['image_id']}
GLUE2ApplicationEnvironmentComputingManagerForeignKey: ${endpoint['compute_service_name']}_cloud.compute_manager

% endfor
