示例#1
0
文件: vm.py 项目: cloudcache/cc1
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]
示例#2
0
文件: farm.py 项目: cloudcache/cc1
def create(caller_id, name, description, image_id, head_template_id, worker_template_id, public_ip_id, iso_list, disk_list, vnc, groups, count):
    """
    Method creates new Farm for caller:

    -#. Creates VMs described by \c machine dict.
    -#. Creates farm named by \c machine[name] consisting of those VMs.
    -#. Creates thread for this farm.

    @decoratedby{src.cm.utils.decorators.user_log}
    @parameter{machine,dict}
    \n fields:
    @dictkey{name,string} farm's name
    @dictkey{count,int} number of Worker Nodes
    @dictkey{template_id,int} Worker Node's template
    @dictkey{head_template_id,int} Head's template
    @dictkey{image_id,int} image for WNs and Head
    @dictkey{groups,list} optional
    @dictkey{node_id} optional on which node farm is to be created
    @dictkey{description,string} description of the farm

    @response{None}

    @raises{farm_create,CMException}
    """
    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})

    farm = Farm.create(user=user, name=name, description=description)

    vms = VM.create(user, name=name, description=description, image_id=image_id, template_id=worker_template_id,
                    head_template_id=head_template_id, public_ip_id=public_ip_id, iso_list=iso_list, disk_list=disk_list,
                    vnc=vnc, groups=groups, farm=farm, count=count)

    farm.save()
    for vm in vms:
        vm.farm = farm
        if not vm.is_head():
            # disable autosave
            vm.save_vm = 0
        vm.save()

    try:
        farm.save()
    except Exception:
        log.exception(caller_id, 'farm_create')
        raise CMException('farm_create')

    VMThread(vms[0], 'create').start()
    return [vm.dict for vm in vms]
示例#3
0
文件: farm.py 项目: cc1-cloud/cc1
def create(caller_id, name, description, image_id, head_template_id, worker_template_id, public_ip_id, iso_list, disk_list, vnc, groups, count):
    """
    Method creates new caller's Farm.

    @cmview_user
    @param_post{name,string} Farm's name
    @param_post{description,string}
    @param_post{image_id,int} image for WNs and Head
    @param_post{head_template_id,int} Head's template
    @param_post{worker_template_id,int} Worker Node's template
    @param_post{public_ip_id,int} Worker Node's template
    @param_post{iso_list,list}
    @param_post{disk_list,list}
    @param_post{vnc,list}
    @param_post{groups,list}
    @param_post{count,int} number of Worker Nodes

    @raises{farm_create,CMException}
    """
    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})

    farm = Farm.create(user=user, name=name, description=description)

    vms = VM.create(user, name=name, description=description, image_id=image_id, template_id=worker_template_id,
                    head_template_id=head_template_id, public_ip_id=public_ip_id, iso_list=iso_list, disk_list=disk_list,
                    vnc=vnc, groups=groups, farm=farm, count=count)

    farm.save()
    for vm in vms:
        vm.farm = farm
        if not vm.is_head():
            # disable autosave
            vm.save_vm = 0
        vm.save()

    try:
        farm.save()
    except Exception:
        log.exception(caller_id, 'farm_create')
        raise CMException('farm_create')

    VMThread(vms[0], 'create').start()
    return [vm.dict for vm in vms]
示例#4
0
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
    @param_post{name,string}
    @param_post{description,string}
    @param_post{image_id,int}
    @param_post{template_id,int}
    @param_post{public_ip_id,int}
    @param_post{iso_list,list(int)} ISOs' ids
    @param_post{disk_list,list(int)}
    @param_post{vnc}
    @param_post{count}
    @param_post{groups}
    @param_post{user_data} data accessible via ec2ctx
    @param_post{ssh_key}
    @param_post{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]
示例#5
0
def create(caller_id, name, description, image_id, head_template_id,
           worker_template_id, public_ip_id, iso_list, disk_list, vnc, groups,
           count):
    """
    Method creates new caller's Farm.

    @cmview_user
    @param_post{name,string} Farm's name
    @param_post{description,string}
    @param_post{image_id,int} image for WNs and Head
    @param_post{head_template_id,int} Head's template
    @param_post{worker_template_id,int} Worker Node's template
    @param_post{public_ip_id,int} Worker Node's template
    @param_post{iso_list,list}
    @param_post{disk_list,list}
    @param_post{vnc,list}
    @param_post{groups,list}
    @param_post{count,int} number of Worker Nodes

    @raises{farm_create,CMException}
    """
    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
        })

    farm = Farm.create(user=user, name=name, description=description)

    vms = VM.create(user,
                    name=name,
                    description=description,
                    image_id=image_id,
                    template_id=worker_template_id,
                    head_template_id=head_template_id,
                    public_ip_id=public_ip_id,
                    iso_list=iso_list,
                    disk_list=disk_list,
                    vnc=vnc,
                    groups=groups,
                    farm=farm,
                    count=count)

    farm.save()
    for vm in vms:
        vm.farm = farm
        if not vm.is_head():
            # disable autosave
            vm.save_vm = 0
        vm.save()

    try:
        farm.save()
    except Exception:
        log.exception(caller_id, 'farm_create')
        raise CMException('farm_create')

    VMThread(vms[0], 'create').start()
    return [vm.dict for vm in vms]