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


Python user.User类代码示例

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


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

示例1: download

def download(caller_id, description, name, path, disk_controller, network_device, platform, video_device):
    """
    Downloads image depending on the \c data parameter.
    @cmview_user

    @parameter{path,string} HTTP or FTP path to image to download
    @parameter{name,string}
    @parameter{description,string}

    @parameter{type,image_types} type of image, automatically set, type is in the URL requested

    @response{None}

    @raises{image_not_found,CMException}
    @raises{image_create,CMException}
    """
    user = User.get(caller_id)

    if not any([path.startswith("http://"), path.startswith("https://"), path.startswith("ftp://")]):
        path = "http://" + path.strip()

    # size value is taken
    try:
        connection = urllib.urlopen(path)
        size = int(connection.info()["Content-Length"])
    except IOError:
        log.exception(caller_id, "Cannot find image")
        raise CMException("image_not_found")
    except KeyError:
        log.exception(caller_id, "Cannot calculate size")
        raise CMException("image_calculate_size")

    user = User.get(caller_id)
    user.check_storage(size / (1024 * 1024))

    image = SystemImage.create(
        name=name,
        description=description,
        user=user,
        platform=platform,
        disk_controller=disk_controller,
        network_device=network_device,
        video_device=video_device,
    )

    try:
        image.save()
    except Exception, e:
        log.error(caller_id, "Unable to save image to DB: %s" % str(e))
        raise CMException("image_create")
开发者ID:pojoba02,项目名称:cc1,代码行数:50,代码来源:system_image.py

示例2: multiple_change_quota

def multiple_change_quota(caller_id, user_ids, memory=None, cpu=None, storage=None, public_ip=None, points=None):
    """
    Method changes quota of multiple users.
    @cmview_admin_cm

    @dictkey{users,list(int)} ids of the users to change quota
    @dictkey{cpu,int} cpu to set
    @dictkey{storage,int} storage to set
    @dictkey{public_ip,int} number of public_ips to set
    @dictkey{points,int} points to set

    @response{None}
    """

    for user_id in user_ids:
        user = User.get(user_id)
        user.memory = memory or user.memory
        user.cpu = cpu or user.cpu
        user.storage = storage or user.storage
        user.public_ip = public_ip or user.public_ip
        user.points = points or user.points
        try:
            user.save()
        except:
            raise CMException('user_change_quota')
开发者ID:cloudcache,项目名称:cc1,代码行数:25,代码来源:user.py

示例3: change_quota

def change_quota(caller_id, user_id, memory, cpu, storage, public_ip, points):
    """
    Function changes quota for user @prm{user_id}.
    @cmview_admin_cm

    @parameter{user_id}
    @parameter{memory}
    @parameter{cpu,int}
    @parameter{storage,int}
    @parameter{public_ip,int}
    @parameter{points,int}
    """

    user = User.get(user_id)

    user.memory = memory
    user.cpu = cpu
    user.storage = storage
    user.public_ip = public_ip
    user.points = points

    try:
        user.save()
    except:
        raise CMException('user_change_quota')
开发者ID:cloudcache,项目名称:cc1,代码行数:25,代码来源:user.py

示例4: add

def add(caller_id, user_id):
    """
    Function adds new user to DB and creates its home directory.
    @cmview_user

    @note This method is decorated by user_log decorator, not by admin_cm_log.
    This is caused by the fact that CLMAdmin doesn't need to be CMAdmin and
    despite not having rights to call CMAdmin functions he needs to call it on
    CMAdmin priviledges.

    @parameter{user_id}

    @response{None}
    """

    User.create(user_id)
开发者ID:cloudcache,项目名称:cc1,代码行数:16,代码来源:user.py

示例5: create

def create(caller_id, name, description, filesystem, size, disk_controller):
    """
    Method creates new Image. It's only used by disk_volume type (only url view with create)
    @cmview_user

    @parameter{name,string}
    @parameter{description,string}
    @parameter{filesystem,int} id of the filesystem. Supported filesystems are listed in settings
    @parameter{size,int} size of the Image to create [MB]
    @parameter{disk_controller}

    @response{dict} Image's dictionary
    """
    if size < 1:
        raise CMException('image_invalid_size')

    user = User.get(caller_id)
    user.check_storage(size)
    image = StorageImage.create(user=user, disk_controller=disk_controller, description=description, name=name,
                                size=size)

    try:
        image.save()
    except Exception, e:
        log.error(caller_id, "Unable to save image to DB: %s" % str(e))
        raise CMException('image_create')
开发者ID:cloudcache,项目名称:cc1,代码行数:26,代码来源:storage_image.py

示例6: points_history

def points_history(caller_id):
    """
    @cmview_user

    @response caller's point history
    """
    return User.get(caller_id).points_history()
开发者ID:cloudcache,项目名称:cc1,代码行数:7,代码来源:user.py

示例7: download

def download(caller_id, description, name, path, disk_dev, disk_controller):
    """
    Downloads specified StorateImage from remote path.

    @cmview_admin_cm
    @param_post{description,string}
    @param_post{name,string} how to name newly downloaded storage image
    @param_post{path,string} HTTP or FTP path to download StorageImage.
    @param_post{disk_dev}
    @param_post{disk_controller}
    """

    # size value is taken
    try:
        connection = urllib.urlopen(path)
        size = int(connection.info()["Content-Length"])
    except IOError:
        log.exception('Cannot find image')
        raise CMException('image_not_found')
    except KeyError:
        log.exception(caller_id, 'Cannot calculate size')
        raise CMException('image_calculate_size')

    user = User.get(caller_id)

    image = StorageImage.create(name=name, description=description, user=user, disk_dev=disk_dev,  disk_controller=disk_controller)

    try:
        image.save()
    except Exception, e:
        log.error(caller_id, "Unable to save image to DB: %s" % str(e))
        raise CMException('image_create')
开发者ID:cc1-cloud,项目名称:cc1,代码行数:32,代码来源:storage_image.py

示例8: create

def create(caller_id, name, description, image_id, template_id, public_ip_id, iso_list, disk_list, vnc, groups, count=1, user_data=None,
           ssh_key=None, ssh_username=None):
    """
    Creates virtual machines.
    @cmview_user

    @parameter{name,string}
    @parameter{description,string}
    @parameter{image_id,int}
    @parameter{template_id,int}
    @parameter{ip_id,int}
    @parameter{iso_list,list(int)} ISOs' ids
    @parameter{vnc}
    @parameter{groups}
    @parameter{user_data} data accessible via ec2ctx
    @parameter{ssh_key}
    @parameter{ssh_username}

    @returns @asreturned{src.cm.views.utils.vm.create()}
    """
    user = User.get(caller_id)
    try:
        user.check_points()
    except:
        message.warn(caller_id, 'point_limit', {'used_points': user.used_points, 'point_limit': user.points})
    vms = VM.create(user, name=name, description=description, image_id=image_id,
                    template_id=template_id, public_ip_id=public_ip_id, iso_list=iso_list, disk_list=disk_list,
                    vnc=vnc, groups=groups, count=count, user_data=user_data, ssh_key=ssh_key, ssh_username=ssh_username)

    for vm in vms:
        thread = VMThread(vm, 'create')
        thread.start()

    return [vm.dict for vm in vms]
开发者ID:cloudcache,项目名称:cc1,代码行数:34,代码来源:vm.py

示例9: request

def request(caller_id):
    """
    Method requests single PublicIP address for caller. If caller's quota
    is exceeded, exception is raised. Otherwise caller obtains a new PublicIP
    address.

    @cmview_user
    @response{string} newly obtained PublicIP's address

    @raises{public_lease_not_found,CMException}
    @raises{public_lease_request,CMException}
    """
    user = User.get(caller_id)

    if len(user.public_ips.all()) >= user.public_ip:
        raise CMException('public_lease_limit')

    ips = PublicIP.objects.filter(user=None).all()
    if len(ips) == 0:
        raise CMException('public_lease_not_found')

    ip = ips[0]
    ip.user = user
    ip.request_time = datetime.now()
    ip.release_time = None
    try:
        ip.save()
    except Exception:
        raise CMException('public_lease_request')
    return ip.address
开发者ID:cc1-cloud,项目名称:cc1,代码行数:30,代码来源:public_ip.py

示例10: download

def download(caller_id, description, name, path, disk_controller, network_device, platform, video_device):
    """
    Downloads image depending on the \c data parameter.
    @cmview_admin_cm

    @parameter{description,string}
    @parameter{name,string}
    @parameter{path,string} HTTP or FTP path to image to download
    @parameter{type,image_types} type of image, automatically set, type is in the URL requested

    @response{None}
    """

    # size value is taken
    try:
        connection = urllib.urlopen(path)
        size = int(connection.info()["Content-Length"])
    except IOError:
        log.exception(caller_id, 'Cannot find image')
        raise CMException('image_not_found')
    except KeyError:
        log.exception(caller_id, 'Cannot calculate size')
        raise CMException('image_calculate_size')

    user = User.get(caller_id)

    image = SystemImage.create(name=name, description=description, user=user, platform=platform,
                               disk_controller=disk_controller, network_device=network_device,
                               video_device=video_device)

    try:
        image.save()
    except Exception, e:
        log.error(caller_id, "Unable to save image to DB: %s" % str(e))
        raise CMException('image_create')
开发者ID:cloudcache,项目名称:cc1,代码行数:35,代码来源:system_image.py

示例11: list_user_networks

def list_user_networks(caller_id, user_id=None):
    """
    @cmview_admin_cm
    @param_post{user_id,int} (optional) if specified, only networks belonging
    to specigied User are fetched.
    @param_post{only_unused,bool} (optional) if @val{True}, only unused
    networks are returned

    @response{list(dict)} UserNetwork.dict property for each requested
    UserNetwork
    """
    try:
        user_networks = []
        if user_id:
            user = User.get(user_id)
            user_networks = UserNetwork.objects.filter(user=user)
        else:
            user_networks = UserNetwork.objects.all()
    except:
        raise CMException('network_not_found')

    response = []
    for network in user_networks:
        response.append(network.dict)
    return response
开发者ID:cc1-cloud,项目名称:cc1,代码行数:25,代码来源:network.py

示例12: download

def download(caller_id, name, description, path, disk_controller):
    """
    Downloads specified IsoImage and saves it with specified name and description.

    @cmview_user
    @param_post{name,string}
    @param_post{description,string}
    @param_post{path,string} HTTP or FTP path to IsoImage to download
    @param_post{disk_controller}
    """
    user = User.get(caller_id)

    if not any([path.startswith('http://'), path.startswith('https://'), path.startswith('ftp://')]):
        path = 'http://' + path.strip()

    # size value is taken
    try:
        connection = urllib.urlopen(path)
        size = int(connection.info()["Content-Length"])
    except IOError:
        log.exception('Cannot find image')
        raise CMException('image_not_found')
    except KeyError:
        log.exception(caller_id, 'Cannot calculate size')
        raise CMException('image_calculate_size')

    user.check_storage(size / (1024 * 1024))

    image = IsoImage.create(user=user, description=description, name=name, disk_controller=disk_controller, disk_dev=1)

    try:
        image.save()
    except Exception, e:
        log.error(caller_id, "Unable to save image to DB: %s" % str(e))
        raise CMException('image_create')
开发者ID:cc1-cloud,项目名称:cc1,代码行数:35,代码来源:iso_image.py

示例13: request

def request(caller_id, mask, name):
    """
    Tries to allocate network with specified mask for caller.

    @cmview_user
    @param_post{mask}
    @param_post{name}

    @response{dict} UserNetwork.dict property of the newly created UserNetwork
    """
    new_net = None
    user = User.get(caller_id)
    for available_network in AvailableNetwork.objects.all():
        log.debug(user.id, "Trying to allocate in %s" % str(available_network.to_ipnetwork()))
        if available_network.state == available_network_states['ok']:
            try:
                net = available_network.get_unused_ipnetwork(mask)

                new_net = UserNetwork()
                new_net.address = str(net.network)
                new_net.mask = mask
                new_net.name = name
                new_net.available_network = available_network
                new_net.user = user
                new_net.save()

                new_net.allocate()

                return new_net.dict
            except:
                continue
    if new_net == None:
        raise CMException('available_network_not_found')
开发者ID:cc1-cloud,项目名称:cc1,代码行数:33,代码来源:network.py

示例14: create

def create(caller_id, name, description, filesystem, size, disk_controller):
    """
    Creates new StorageImage.

    @cmview_user
    @param_post{name,string}
    @param_post{description,string}
    @param_post{filesystem,int} id of the filesystem. Supported filesystems are
    common.hardware.disk_filesystems
    @param_post{size,int} size of the SystemImage to create [MB]
    @param_post{disk_controller}

    @response{dict} StorageImage.dict property of newly created StorageImage
    """
    if size < 1:
        raise CMException('image_invalid_size')

    user = User.get(caller_id)
    user.check_storage(size)
    image = StorageImage.create(user=user, disk_controller=disk_controller, description=description, name=name,
                                size=size)

    try:
        image.save()
    except Exception, e:
        log.error(caller_id, "Unable to save image to DB: %s" % str(e))
        raise CMException('image_create')
开发者ID:cc1-cloud,项目名称:cc1,代码行数:27,代码来源:storage_image.py

示例15: check_quota

def check_quota(caller_id):
    """
    Check quota for caller user.

    @cmview_user

    @response{dict} extended caller's data
    """
    return User.get(caller_id).long_dict
开发者ID:cloudcache,项目名称:cc1,代码行数:9,代码来源:user.py


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