当前位置: 首页>>代码示例>>Python>>正文


Python driver.prepare_driver函数代码示例

本文整理汇总了Python中service.driver.prepare_driver函数的典型用法代码示例。如果您正苦于以下问题:Python prepare_driver函数的具体用法?Python prepare_driver怎么用?Python prepare_driver使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了prepare_driver函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _update_machine

    def _update_machine(self, request, provider_uuid, identity_uuid, machine_id):
        # TODO: Determine who is allowed to edit machines besides
        # core_machine.owner
        user = request.user
        data = request.DATA
        esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
        if not esh_driver:
            return invalid_creds(provider_uuid, identity_uuid)
        esh_machine = esh_driver.get_machine(machine_id)
        core_machine = convert_esh_machine(esh_driver, esh_machine, provider_uuid, user)
        if not user.is_staff and user is not core_machine.application_version.application.created_by:
            logger.warn("%s is Non-staff/non-owner trying to update a machine" % (user.username))
            return failure_response(
                status.HTTP_401_UNAUTHORIZED, "Only Staff and the machine Owner " "are allowed to change machine info."
            )

        partial_update = True if request.method == "PATCH" else False
        serializer = ProviderMachineSerializer(
            core_machine, request_user=request.user, data=data, partial=partial_update
        )
        if serializer.is_valid():
            logger.info("metadata = %s" % data)
            update_machine_metadata(esh_driver, esh_machine, data)
            machine = serializer.save()
            if "created_by_identity" in request.DATA:
                identity = machine.created_by_identity
                update_application_owner(core_machine.application_version.application, identity)
            logger.info(serializer.data)
            return Response(serializer.data)
        return failure_response(status.HTTP_400_BAD_REQUEST, serializer.errors)
开发者ID:EmilyCressey,项目名称:atmosphere,代码行数:30,代码来源:machine.py

示例2: get_esh_instance

def get_esh_instance(request, provider_uuid, identity_uuid, instance_id):
    esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
    if not esh_driver:
        raise InvalidCredsError(
            "Provider_uuid && identity_uuid "
            "did not produce a valid combination")
    esh_instance = None
    try:
        esh_instance = esh_driver.get_instance(instance_id)
    except (socket_error, ConnectionFailure):
        return connection_failure(provider_uuid, identity_uuid)
    except InvalidCredsError:
        return invalid_creds(provider_uuid, identity_uuid)
    except Exception as exc:
        logger.exception("Encountered a generic exception. "
                         "Returning 409-CONFLICT")
        return failure_response(status.HTTP_409_CONFLICT,
                                str(exc.message))

    if not esh_instance:
        # End date everything
        try:
            core_inst = CoreInstance.objects.get(
                provider_alias=instance_id,
                source__provider__uuid=provider_uuid,
                created_by_identity__uuid=identity_uuid)
            core_inst.end_date_all()
        except CoreInstance.DoesNotExist:
            pass
    return esh_instance
开发者ID:catdewey,项目名称:atmosphere,代码行数:30,代码来源:instance.py

示例3: get

 def get(self, request, provider_uuid, identity_uuid, action=None):
     """
     """
     if not action:
         return failure_response(
             status.HTTP_400_BAD_REQUEST,
             'Action is not supported.'
         )
     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)
     esh_meta = esh_driver.meta()
     try:
         if 'test_links' in action:
             test_links = esh_meta.test_links()
             return Response(test_links, status=status.HTTP_200_OK)
     except LibcloudInvalidCredsError:
         logger.warn('Authentication Failed. Provider-id:%s Identity-id:%s'
                     % (provider_uuid, identity_uuid))
         return failure_response(
             status.HTTP_401_UNAUTHORIZED,
             'Identity/Provider Authentication Failed')
     except NotImplemented as ne:
         logger.exception(ne)
         return failure_response(
             status.HTTP_404_NOT_FOUND,
             'The requested resource %s is not available on this provider'
             % action)
开发者ID:Duke-GCB,项目名称:atmosphere,代码行数:35,代码来源:meta.py

示例4: get

 def get(self, request, provider_uuid, identity_uuid, volume_id):
     """
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
     if not esh_driver:
         return invalid_creds(provider_uuid, identity_uuid)
     try:
         esh_volume = esh_driver.get_volume(volume_id)
     except ConnectionFailure:
         return connection_failure(provider_uuid, identity_uuid)
     except InvalidCredsError:
         return invalid_creds(provider_uuid, identity_uuid)
     except Exception as exc:
         logger.exception("Encountered a generic exception. "
                          "Returning 409-CONFLICT")
         return failure_response(status.HTTP_409_CONFLICT,
                                 str(exc.message))
     if not esh_volume:
         try:
             source = InstanceSource.objects.get(
                 identifier=volume_id,
                 provider__uuid=provider_uuid)
             source.end_date = datetime.now()
             source.save()
         except (InstanceSource.DoesNotExist, CoreVolume.DoesNotExist):
             pass
         return volume_not_found(volume_id)
     core_volume = convert_esh_volume(esh_volume, provider_uuid,
                                      identity_uuid, user)
     serialized_data = VolumeSerializer(core_volume,
                                        context={'request': request}).data
     response = Response(serialized_data)
     return response
开发者ID:transformersprimeabcxyz,项目名称:atmosphere-science,代码行数:34,代码来源:volume.py

示例5: provider_filtered_machines

def provider_filtered_machines(request, provider_uuid,
                               identity_uuid, request_user=None):
    """
    Return all filtered machines. Uses the most common,
    default filtering method.
    """
    identity = Identity.objects.filter(uuid=identity_uuid)
    if not identity:
        raise ObjectDoesNotExist()

    try:
        esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
    except Exception:
        # TODO: Observe the change of 'Fail loudly' here
        # and clean up the noise, rather than hide it.
        logger.exception(
            "Driver could not be prepared - Provider: %s , Identity: %s"
            % (provider_uuid, identity_uuid))
        esh_driver = None

    if not esh_driver:
        raise LibcloudInvalidCredsError()

    logger.debug(esh_driver)

    return list_filtered_machines(esh_driver, provider_uuid, request_user)
开发者ID:xuhang57,项目名称:atmosphere,代码行数:26,代码来源:machine.py

示例6: get

    def get(self, request, provider_uuid, identity_uuid):
        """
        """
        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)
        try:
            esh_snapshots = esh_driver._connection.ex_list_snapshots()
        except LibcloudBadResponseError:
            return malformed_response(provider_uuid, identity_uuid)
        except LibcloudInvalidCredsError:
            return invalid_creds(provider_uuid, identity_uuid)
        snapshot_data = []
        for ss in esh_snapshots:
            snapshot_data.append({
                'id': ss.id,
                'name': ss.extra['name'],
                'size': ss.size,
                'description': ss.extra['description'],
                'created': ss.extra['created'],
                'status': ss.extra['status'],
                'volume_id': ss.extra['volume_id'], })

        response = Response(snapshot_data)
        return response
开发者ID:xuhang57,项目名称:atmosphere,代码行数:32,代码来源:volume.py

示例7: get

 def get(self, request, provider_uuid, identity_uuid):
     """
     Using provider and identity, getlist of machines
     TODO: Cache this request
     """
     # TODO: Decide how we should pass this in (I.E. GET query string?)
     active = False
     user = request.user
     esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
     if not esh_driver:
         return invalid_creds(provider_uuid, identity_uuid)
     try:
         esh_size_list = esh_driver.list_sizes()
     except MalformedResponseError:
         return malformed_response(provider_uuid, identity_uuid)
     except InvalidCredsError:
         return invalid_creds(provider_uuid, identity_uuid)
     except (socket_error, ConnectionFailure):
         return connection_failure(provider_uuid, identity_uuid)
     all_size_list = [convert_esh_size(size, provider_uuid)
                      for size in esh_size_list]
     if active:
         all_size_list = [s for s in all_size_list if s.active()]
     serialized_data = ProviderSizeSerializer(all_size_list, many=True).data
     response = Response(serialized_data)
     return response
开发者ID:EthanChen-Field,项目名称:atmosphere,代码行数:26,代码来源:size.py

示例8: get

 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
开发者ID:EmilyCressey,项目名称:atmosphere,代码行数:30,代码来源:instance.py

示例9: delete

 def delete(self, request, provider_uuid, identity_uuid, volume_id):
     """
     Destroys the volume and updates the DB
     """
     user = request.user
     # Ensure volume exists
     esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
     if not esh_driver:
         return invalid_creds(provider_uuid, identity_uuid)
     try:
         esh_volume = esh_driver.get_volume(volume_id)
     except ConnectionFailure:
         return connection_failure(provider_uuid, identity_uuid)
     except InvalidCredsError:
         return invalid_creds(provider_uuid, identity_uuid)
     except Exception as exc:
         logger.exception("Encountered a generic exception. "
                          "Returning 409-CONFLICT")
         return failure_response(status.HTTP_409_CONFLICT,
                                 str(exc.message))
     if not esh_volume:
         return volume_not_found(volume_id)
     core_volume = convert_esh_volume(esh_volume, provider_uuid,
                                      identity_uuid, user)
     # Delete the object, update the DB
     esh_driver.destroy_volume(esh_volume)
     core_volume.end_date = now()
     core_volume.save()
     # Return the object
     serialized_data = VolumeSerializer(core_volume,
                                        context={'request': request}).data
     response = Response(serialized_data)
     return response
开发者ID:transformersprimeabcxyz,项目名称:atmosphere-science,代码行数:33,代码来源:volume.py

示例10: get

    def get(self, request, provider_uuid, identity_uuid, machine_id):
        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)
        # TODO: Need to determine that identity_uuid is ALLOWED to
        # see machine_id.
        # if not covered by calling as the users driver..
        esh_machine = esh_driver.get_machine(machine_id)
        core_machine = convert_esh_machine(esh_driver, esh_machine,
                                           provider_uuid, user)
        if not core_machine:
            return failure_response(
                status.HTTP_400_BAD_REQUEST,
                "Could not retrieve machine with ID = %s" % machine_id)
        if not core_machine.application_version.application.icon:
            return None
        app_icon = core_machine.application_version.application.icon
        image_name, image_ext = os.path.splitext(app_icon.name)
        return Response(app_icon.file)
开发者ID:xuhang57,项目名称:atmosphere,代码行数:28,代码来源:machine.py

示例11: get

    def get(self, request, provider_uuid, identity_uuid, instance_id):
        """
        Authentication Required, get instance details.
        """
        user = request.user
        # NOTE: This 'Scheme' should be used across
        #       the ENTIRE API v1 (Machines, Volumes, Sizes)
        # NOTE: Especially the part below, where you end date
        #       all the things that are 'inactive'
        try:
            provider = Provider.objects.get(uuid=provider_uuid)
            if not provider.is_current():
                raise ProviderNotActive(provider)
        except Provider.DoesNotExist:
            return invalid_creds(provider_uuid, identity_uuid)
        except ProviderNotActive as pna:
            return inactive_provider(pna)

        # Cleared provider testing -- ready for driver prep.
        try:
            esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
            if not esh_driver:
                return invalid_creds(provider_uuid, identity_uuid)
            logger.info("InstanceQuery Looking for %s" % instance_id)
            esh_instance = esh_driver.get_instance(instance_id)
            logger.info("InstanceQuery Found instance %s" % esh_instance)
        except (socket_error, ConnectionFailure):
            logger.exception("Connection failure prevented InstanceQuery")
            return connection_failure(provider_uuid, identity_uuid)
        except LibcloudInvalidCredsError:
            logger.exception("Invalid credentialsprevented InstanceQuery")
            return invalid_creds(provider_uuid, identity_uuid)
        except Exception as exc:
            logger.exception("Encountered a generic exception. "
                             "Returning 409-CONFLICT")
            return failure_response(status.HTTP_409_CONFLICT,
                                    str(exc.message))

        # NOTE: Especially THIS part below, where you end date all the
        #       things that are 'inactive'
        if not esh_instance:
            try:
                core_inst = CoreInstance.objects.get(
                    provider_alias=instance_id,
                    source__provider__uuid=provider_uuid,
                    created_by_identity__uuid=identity_uuid)
                core_inst.end_date_all()
            except CoreInstance.DoesNotExist:
                pass
            return instance_not_found(instance_id)

        core_instance = convert_esh_instance(esh_driver, esh_instance,
                                             provider_uuid, identity_uuid,
                                             user)
        serialized_data = InstanceSerializer(
            core_instance,
            context={"request": request}).data
        response = Response(serialized_data)
        response['Cache-Control'] = 'no-cache'
        return response
开发者ID:xuhang57,项目名称:atmosphere,代码行数:60,代码来源:instance.py

示例12: create_volume_or_fail

def create_volume_or_fail(name, size, user, provider, identity,
                          image_id=None, snapshot_id=None):
    snapshot = None
    image = None
    # FIXME: fix prepare_driver to take a user directly
    request = Request(user)
    driver = prepare_driver(request, provider.uuid, identity.uuid,
                            raise_exception=True)

    if snapshot_id:
        snapshot = driver._connection.ex_get_snapshot(image_id)

    if image_id:
        image = driver.get_machine(image_id)
        restrict_size_by_image(size, image)

    #: Guard against both snapshot and image being present
    assert snapshot is None or image is None, (
        "A volume can only be constructed from a `snapshot` "
        "or an `image` not both.")

    #: Create the volume or raise an exception
    _, volume = create_volume(driver, identity.uuid, name, size,
                              snapshot=snapshot, image=image,
                              raise_exception=True)
    return volume
开发者ID:EthanChen-Field,项目名称:atmosphere,代码行数:26,代码来源:volume.py

示例13: destroy_volume_or_fail

def destroy_volume_or_fail(volume, user, cascade=False):
    """
    Destroy the volume specified

    :param cascade: Cascades through and destroy volume snapshots
                    (defaults is False)
    :type cascade: ``bool``
    """
    provider = volume.instance_source.provider
    identity = volume.instance_source.created_by_identity
    # FIXME: fix prepare_driver to take a user directly
    request = Request(user)
    driver = prepare_driver(request, provider.uuid, identity.uuid,
                            raise_exception=True)

    # retrieve volume or fail with not found
    esh_volume = driver.get_volume(volume.identifier)

    if esh_volume is None:
        raise exceptions.NotFound(
            "The `%s` could not be found."
            % volume.identifier)

    # if cascade True and snapshots exist delete all snapshots
    if cascade:
        snapshots = esh_volume.list_snapshots()
        for snapshot in snapshots:
            driver.destroy_snapshot(snapshot)

    # destroy the volume successfully or raise an exception
    if not driver.destroy_volume(esh_volume):
        raise Exception("Encountered an error destroying the volume.")
开发者ID:EthanChen-Field,项目名称:atmosphere,代码行数:32,代码来源:volume.py

示例14: get_core_instance

def get_core_instance(request, provider_uuid, identity_uuid, instance_id):
    user = request.user
    esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
    esh_instance = get_esh_instance(request, provider_uuid, identity_uuid, instance_id)
    core_instance = convert_esh_instance(esh_driver, esh_instance,
                                         provider_uuid, identity_uuid, user)
    return core_instance
开发者ID:MMontgomeryII,项目名称:atmosphere,代码行数:7,代码来源:instance.py

示例15: get

    def get(self, request, provider_uuid, identity_uuid):
        """
        Retrieves list of volumes and updates the DB
        """
        user = request.user
        esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
        if not esh_driver:
            return invalid_creds(provider_uuid, identity_uuid)
        volume_list_method = esh_driver.list_volumes

        if AccountProvider.objects.filter(identity__uuid=identity_uuid):
            # Instance list method changes when using the OPENSTACK provider
            volume_list_method = esh_driver.list_all_volumes
        try:
            esh_volume_list = volume_list_method()
        except MalformedResponseError:
            return malformed_response(provider_id, identity_id)
        except InvalidCredsError:
            return invalid_creds(provider_id, identity_id)

        core_volume_list = [convert_esh_volume(volume, provider_uuid,
                                               identity_uuid, user)
                            for volume in esh_volume_list]
        serializer = VolumeSerializer(core_volume_list,
                                      context={'request': request}, many=True)
        response = Response(serializer.data)
        return response
开发者ID:JScottWagner,项目名称:atmosphere,代码行数:27,代码来源:volume.py


注:本文中的service.driver.prepare_driver函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。