Beispiel #1
0
 def get(self, request, provider_uuid, identity_uuid):
     """
     Returns a list of all instances
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
     if not esh_driver:
         return invalid_creds(provider_uuid, identity_uuid)
     identity = Identity.objects.get(uuid=identity_uuid)
     try:
         esh_instance_list = get_cached_instances(identity=identity)
     except MalformedResponseError:
         return malformed_response(provider_uuid, identity_uuid)
     except (socket_error, ConnectionFailure):
         return connection_failure(provider_uuid, identity_uuid)
     except InvalidCredsError:
         return invalid_creds(provider_uuid, identity_uuid)
     core_instance_list = [convert_esh_instance(esh_driver,
                                                inst,
                                                provider_uuid,
                                                identity_uuid,
                                                user)
                           for inst in esh_instance_list]
     # TODO: Core/Auth checks for shared instances
     serialized_data = InstanceSerializer(core_instance_list,
                                          context={"request": request},
                                          many=True).data
     response = Response(serialized_data)
     response['Cache-Control'] = 'no-cache'
     return response
Beispiel #2
0
def _get_instance_owner_map(provider, users=None):
    """
    All keys == All identities
    Values = List of identities / username
    NOTE: This is KEYSTONE && NOVA specific. the 'instance owner' here is the
          username // ex_tenant_name
    """
    from service.driver import get_account_driver

    admin_driver = get_cached_driver(provider=provider)
    accounts = get_account_driver(provider=provider, raise_exception=True)
    all_identities = _select_identities(provider, users)
    acct_providers = AccountProvider.objects.filter(provider=provider)
    if acct_providers:
        account_identity = acct_providers[0].identity
        provider = None
    else:
        account_identity = None

    all_instances = get_cached_instances(provider=provider,
                                         identity=account_identity,
                                         force=True)
    #all_tenants = admin_driver._connection._keystone_list_tenants()
    all_tenants = accounts.list_projects()
    # Convert instance.owner from tenant-id to tenant-name all at once
    all_instances = _convert_tenant_id_to_names(all_instances, all_tenants)
    # Make a mapping of owner-to-instance
    instance_map = _make_instance_owner_map(all_instances, users=users)
    logger.info("Instance owner map created")
    identity_map = _include_all_idents(all_identities, instance_map)
    logger.info("Identity map created")
    return identity_map
def _get_instance_owner_map(provider, users=None):
    """
    All keys == All identities
    Values = List of identities / username
    NOTE: This is KEYSTONE && NOVA specific. the 'instance owner' here is the
          username // ex_tenant_name
    """
    from service.driver import get_account_driver

    accounts = get_account_driver(provider=provider, raise_exception=True)
    all_identities = _select_identities(provider, users)
    acct_providers = AccountProvider.objects.filter(provider=provider)
    if acct_providers:
        account_identity = acct_providers[0].identity
        provider = None
    else:
        account_identity = None

    all_instances = get_cached_instances(
        provider=provider, identity=account_identity, force=True
    )
    #all_tenants = admin_driver._connection._keystone_list_tenants()
    all_tenants = accounts.list_projects()
    # Convert instance.owner from tenant-id to tenant-name all at once
    all_instances = _convert_tenant_id_to_names(all_instances, all_tenants)
    # Make a mapping of owner-to-instance
    instance_map = _make_instance_owner_map(all_instances, users=users)
    logger.info("Instance owner map created")
    identity_map = _include_all_idents(all_identities, instance_map)
    logger.info("Identity map created")
    return identity_map
Beispiel #4
0
 def get(self, request, provider_uuid, identity_uuid):
     """
     Returns a list of all instances
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
     if not esh_driver:
         return invalid_creds(provider_uuid, identity_uuid)
     identity = Identity.objects.get(uuid=identity_uuid)
     try:
         esh_instance_list = get_cached_instances(identity=identity)
     except MalformedResponseError:
         return malformed_response(provider_uuid, identity_uuid)
     except (socket_error, ConnectionFailure):
         return connection_failure(provider_uuid, identity_uuid)
     except InvalidCredsError:
         return invalid_creds(provider_uuid, identity_uuid)
     core_instance_list = [convert_esh_instance(esh_driver,
                                                inst,
                                                provider_uuid,
                                                identity_uuid,
                                                user)
                           for inst in esh_instance_list]
     # TODO: Core/Auth checks for shared instances
     serialized_data = InstanceSerializer(core_instance_list,
                                          context={"request": request},
                                          many=True).data
     response = Response(serialized_data)
     response['Cache-Control'] = 'no-cache'
     return response
def get_instance_owner_map(provider, users=None):
    """
    All keys == All identities
    """
    admin_driver = get_cached_driver(provider=provider)
    all_identities = _select_identities(provider, users)
    all_instances = get_cached_instances(provider=provider)
    all_tenants = admin_driver._connection._keystone_list_tenants()
    #Convert instance.owner from tenant-id to tenant-name all at once
    all_instances = _convert_tenant_id_to_names(all_instances, all_tenants)
    #Make a mapping of owner-to-instance
    instance_map = _make_instance_owner_map(all_instances, users=users)
    logger.info("Instance owner map created")
    identity_map = _include_all_idents(all_identities, instance_map)
    logger.info("Identity map created")
    return identity_map
Beispiel #6
0
def get_instance_owner_map(provider, users=None):
    """
    All keys == All identities
    """
    admin_driver = get_cached_driver(provider=provider)
    all_identities = _select_identities(provider, users)
    all_instances = get_cached_instances(provider=provider)
    all_tenants = admin_driver._connection._keystone_list_tenants()
    #Convert instance.owner from tenant-id to tenant-name all at once
    all_instances = _convert_tenant_id_to_names(all_instances, all_tenants)
    #Make a mapping of owner-to-instance
    instance_map = _make_instance_owner_map(all_instances, users=users)
    logger.info("Instance owner map created")
    identity_map = _include_all_idents(all_identities, instance_map)
    logger.info("Identity map created")
    return identity_map
Beispiel #7
0
def _get_instance_owner_map(provider, users=None):
    """
    All keys == All identities
    Values = List of identities / username
    NOTE: This is KEYSTONE && NOVA specific. the 'instance owner' here is the
          username // ex_tenant_name
    """
    admin_driver = get_cached_driver(provider=provider)
    all_identities = _select_identities(provider, users)
    all_instances = get_cached_instances(provider=provider)
    all_tenants = admin_driver._connection._keystone_list_tenants()
    # Convert instance.owner from tenant-id to tenant-name all at once
    all_instances = _convert_tenant_id_to_names(all_instances, all_tenants)
    # Make a mapping of owner-to-instance
    instance_map = _make_instance_owner_map(all_instances, users=users)
    logger.info("Instance owner map created")
    identity_map = _include_all_idents(all_identities, instance_map)
    logger.info("Identity map created")
    return identity_map
Beispiel #8
0
def _get_instance_owner_map(provider, users=None):
    """
    All keys == All identities
    Values = List of identities / username
    NOTE: This is KEYSTONE && NOVA specific. the 'instance owner' here is the
          username // ex_tenant_name
    """
    admin_driver = get_cached_driver(provider=provider)
    all_identities = _select_identities(provider, users)
    all_instances = get_cached_instances(provider=provider)
    all_tenants = admin_driver._connection._keystone_list_tenants()
    # Convert instance.owner from tenant-id to tenant-name all at once
    all_instances = _convert_tenant_id_to_names(all_instances, all_tenants)
    # Make a mapping of owner-to-instance
    instance_map = _make_instance_owner_map(all_instances, users=users)
    logger.info("Instance owner map created")
    identity_map = _include_all_idents(all_identities, instance_map)
    logger.info("Identity map created")
    return identity_map
Beispiel #9
0
 def get(self, request, provider_uuid, identity_uuid):
     """
     Returns a list of all instances
     """
     user = request.user
     try:
         esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
     except ProviderNotActive as pna:
         return inactive_provider(pna)
     except Exception as e:
         return failure_response(
             status.HTTP_409_CONFLICT,
             e.message)
     if not esh_driver:
         return invalid_creds(provider_uuid, identity_uuid)
     identity = Identity.objects.get(uuid=identity_uuid)
     # Probably redundant
     if not user.can_use_identity(identity.id):
         return invalid_creds(provider_uuid, identity_uuid)
     try:
         esh_instance_list = get_cached_instances(identity=identity)
     except MalformedResponseError:
         return malformed_response(provider_uuid, identity_uuid)
     except (socket_error, ConnectionFailure):
         return connection_failure(provider_uuid, identity_uuid)
     except InvalidCredsError:
         return invalid_creds(provider_uuid, identity_uuid)
     core_instance_list = [convert_esh_instance(esh_driver,
                                                inst,
                                                provider_uuid,
                                                identity_uuid,
                                                user)
                           for inst in esh_instance_list]
     # TODO: Core/Auth checks for shared instances
     serialized_data = InstanceSerializer(core_instance_list,
                                          context={"request": request},
                                          many=True).data
     response = Response(serialized_data)
     response['Cache-Control'] = 'no-cache'
     return response
Beispiel #10
0
 def get(self, request, provider_uuid, identity_uuid):
     """
     Returns a list of all instances
     """
     user = request.user
     try:
         esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
     except ProviderNotActive as pna:
         return inactive_provider(pna)
     except Exception as e:
         return failure_response(status.HTTP_409_CONFLICT, e.message)
     if not esh_driver:
         return invalid_creds(provider_uuid, identity_uuid)
     identity = Identity.objects.get(uuid=identity_uuid)
     # Probably redundant
     if not user.can_use_identity(identity.id):
         return invalid_creds(provider_uuid, identity_uuid)
     try:
         esh_instance_list = get_cached_instances(identity=identity)
     except LibcloudBadResponseError:
         return malformed_response(provider_uuid, identity_uuid)
     except (socket_error, ConnectionFailure):
         return connection_failure(provider_uuid, identity_uuid)
     except LibcloudInvalidCredsError:
         return invalid_creds(provider_uuid, identity_uuid)
     core_instance_list = [
         convert_esh_instance(esh_driver, inst, provider_uuid,
                              identity_uuid, user)
         for inst in esh_instance_list
     ]
     # TODO: Core/Auth checks for shared instances
     serialized_data = InstanceSerializer(core_instance_list,
                                          context={
                                              "request": request
                                          },
                                          many=True).data
     response = Response(serialized_data)
     response['Cache-Control'] = 'no-cache'
     return response
Beispiel #11
0
 def get(self, request, provider_id, identity_id):
     """
     Returns a list of all instances
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     identity = Identity.objects.get(id=identity_id)
     esh_instance_list = get_cached_instances(identity=identity)
     core_instance_list = [convert_esh_instance(esh_driver,
                                                inst,
                                                provider_id,
                                                identity_id,
                                                user)
                           for inst in esh_instance_list]
     #TODO: Core/Auth checks for shared instances
     serialized_data = InstanceSerializer(core_instance_list,
                                          context={"request":request},
                                          many=True).data
     response = Response(serialized_data)
     response['Cache-Control'] = 'no-cache'
     return response
Beispiel #12
0
 def get(self, request, provider_id, identity_id):
     """
     Returns a list of all instances
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     identity = Identity.objects.get(id=identity_id)
     esh_instance_list = get_cached_instances(identity=identity)
     core_instance_list = [
         convert_esh_instance(esh_driver, inst, provider_id, identity_id,
                              user) for inst in esh_instance_list
     ]
     #TODO: Core/Auth checks for shared instances
     serialized_data = InstanceSerializer(core_instance_list,
                                          context={
                                              "request": request
                                          },
                                          many=True).data
     response = Response(serialized_data)
     response['Cache-Control'] = 'no-cache'
     return response