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


Python User.get方法代码示例

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


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

示例1: download

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
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,代码行数:52,代码来源:system_image.py

示例2: multiple_change_quota

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
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,代码行数:27,代码来源:user.py

示例3: change_quota

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
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,代码行数:27,代码来源:user.py

示例4: points_history

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
def points_history(caller_id):
    """
    @cmview_user

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

示例5: download

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
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,代码行数:34,代码来源:storage_image.py

示例6: create

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
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,代码行数:28,代码来源:storage_image.py

示例7: request

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
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,代码行数:35,代码来源:network.py

示例8: create

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
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,代码行数:29,代码来源:storage_image.py

示例9: download

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
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,代码行数:37,代码来源:system_image.py

示例10: create

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
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,代码行数:36,代码来源:vm.py

示例11: list_user_networks

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
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,代码行数:27,代码来源:network.py

示例12: download

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
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,代码行数:37,代码来源:iso_image.py

示例13: request

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
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,代码行数:32,代码来源:public_ip.py

示例14: check_quota

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
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,代码行数:11,代码来源:user.py

示例15: get_list

# 需要导入模块: from cm.models.user import User [as 别名]
# 或者: from cm.models.user.User import get [as 别名]
def get_list(caller_id):
    """
    @cmview_user
    @response{list(dict)} PublicIP.dict property for each caller's PublicIP
    """
    user = User.get(caller_id)

    ips = PublicIP.objects.filter(user=user).all()
    return [ip.dict for ip in ips]
开发者ID:cc1-cloud,项目名称:cc1,代码行数:11,代码来源:public_ip.py


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