예제 #1
0
파일: farm.py 프로젝트: cloudcache/cc1
def destroy(caller_id, farm_id):
    """
    Destroys caller's farms with ids listed in data.

    @decoratedby{src.cm.utils.decorators.user_log}
    @parameter{data,list} list of destroyed farm's \c id's

    @response @asreturned{src.cm.manager.farm.utils.destroy()}
    """

    return Farm.destroy([Farm.get(caller_id, farm_id)])
예제 #2
0
def destroy(caller_id, farm_id):
    """
    Destroys specified caller's farm.

    @cmview_user
    @param_post{farm_id,int} destroyed farm's id

    @response @asreturned{src.cm.manager.farm.utils.destroy()}
    """

    return Farm.destroy([Farm.get(caller_id, farm_id)])
예제 #3
0
파일: farm.py 프로젝트: cc1-cloud/cc1
def save_and_shutdown(caller_id, farm_id, name, description):
    """
    Saves and shutdowns specified Farm's head. Worker nodes are destroyed.

    @cmview_admin_cm
    @param_post{farm_id,int} id of the Farm to save
    @param_post{name,string} name which Farm's head should saved to
    @param_post{description,string} description for newly saved Farm
    """
    farm = Farm.admin_get(farm_id)
    return Farm.save_and_shutdown(farm, name, description)
예제 #4
0
파일: farm.py 프로젝트: cloudcache/cc1
def save_and_shutdown(caller_id, farm_id, name, description):
    """
    Saves and shutdowns VM described by \c data.
    @decoratedby{src.cm.utils.decorators.admin_cm_log}

    @parameter{farm_id,int} id of the requested farm
    @parameter{data,dict}
    \n fields @asrequired{manager.cm.farm.utils.save_and_shutdown()}
    """
    farm = Farm.admin_get(farm_id)
    return Farm.save_and_shutdown(farm, name, description)
예제 #5
0
def save_and_shutdown(caller_id, farm_id, name, description):
    """
    Saves and shutdowns specified Farm's head. Worker nodes are destroyed.

    @cmview_admin_cm
    @param_post{farm_id,int} id of the Farm to save
    @param_post{name,string} name which Farm's head should saved to
    @param_post{description,string} description for newly saved Farm
    """
    farm = Farm.admin_get(farm_id)
    return Farm.save_and_shutdown(farm, name, description)
예제 #6
0
파일: farm.py 프로젝트: cc1-cloud/cc1
def destroy(caller_id, farm_id):
    """
    Destroys specified caller's farm.

    @cmview_user
    @param_post{farm_id,int} destroyed farm's id

    @response @asreturned{src.cm.manager.farm.utils.destroy()}
    """

    return Farm.destroy([Farm.get(caller_id, farm_id)])
예제 #7
0
파일: farm.py 프로젝트: cloudcache/cc1
def destroy(caller_id, farm_ids):
    """
    @decoratedby{src.cm.utils.decorators.admin_cm_log}
    Admin method to destroy farms with ids listed in \c data.

    @parameter{data,list} list of destroyed farm's \c id's

    @response @asreturned{src.cm.manager.farm.utils.destroy()}
    """
    farms = []
    for farm_id in farm_ids:
        farms.append(Farm.admin_get(farm_id))
    return Farm.destroy(farms)
예제 #8
0
def destroy(caller_id, farm_ids):
    """
    Destroyes specified Farms. Neither Farm's head nor worker nodes are saved.
    Destroyed Farm cannot be recovered.

    @cmview_admin_cm
    @param_post{farm_ids,list(int)} ids of the Farms to destroy

    @response{list{HTTPResponse}} list of responses for each VM destruction
    """
    farms = []
    for farm_id in farm_ids:
        farms.append(Farm.admin_get(farm_id))
    return Farm.destroy(farms)
예제 #9
0
파일: farm.py 프로젝트: cc1-cloud/cc1
def destroy(caller_id, farm_ids):
    """
    Destroyes specified Farms. Neither Farm's head nor worker nodes are saved.
    Destroyed Farm cannot be recovered.

    @cmview_admin_cm
    @param_post{farm_ids,list(int)} ids of the Farms to destroy

    @response{list{HTTPResponse}} list of responses for each VM destruction
    """
    farms = []
    for farm_id in farm_ids:
        farms.append(Farm.admin_get(farm_id))
    return Farm.destroy(farms)
예제 #10
0
def save_and_shutdown(caller_id, farm_id, name, description):
    """
    Safely saves and shutdowns Farm's Head.

    @cmview_user
    @param_post{farm_id,int}
    @param_post{name,string}
    @param_post{description,string}

    @response{src.cm.manager.farm.utils.save_and_shutdown()}
    """
    farm = Farm.get(caller_id, farm_id)
    if farm.user.id == caller_id:
        return Farm.save_and_shutdown(farm, name, description)
    else:
        raise CMException("farm_save")
예제 #11
0
파일: farm.py 프로젝트: cc1-cloud/cc1
def get_by_id(caller_id, farm_id):
    """
    @cmview_admin_cm
    @param_post{farm_id,int} id of the requested farm
    @response{dict} Farm.dict property of the requested Farm
    """
    return Farm.admin_get(farm_id).dict
예제 #12
0
def get_by_id(caller_id, farm_id):
    """
    @cmview_admin_cm
    @param_post{farm_id,int} id of the requested farm
    @response{dict} Farm.dict property of the requested Farm
    """
    return Farm.admin_get(farm_id).dict
예제 #13
0
파일: farm.py 프로젝트: cc1-cloud/cc1
def save_and_shutdown(caller_id, farm_id, name, description):
    """
    Safely saves and shutdowns Farm's Head.

    @cmview_user
    @param_post{farm_id,int}
    @param_post{name,string}
    @param_post{description,string}

    @response{src.cm.manager.farm.utils.save_and_shutdown()}
    """
    farm = Farm.get(caller_id, farm_id)
    if farm.user.id == caller_id:
        return Farm.save_and_shutdown(farm, name, description)
    else:
        raise CMException("farm_save")
예제 #14
0
파일: farm.py 프로젝트: cloudcache/cc1
def save_and_shutdown(caller_id, farm_id, name, description):
    """
    Saves and shutdowns safely farm's Head.
    It saves Head to image described in \c data.
    @decoratedby{src.cm.utils.decorators.user_log}

    @parameter{farm_id,int}
    @parameter{data,dict}
    \n fields @asrequired{src.cm.farm.utils.save_and_shutdown()}

    @response{src.cm.manager.farm.utils.save_and_shutdown()}
    """
    farm = Farm.get(caller_id, farm_id)
    if farm.user.id == caller_id:
        return Farm.save_and_shutdown(farm, name, description)
    else:
        raise CMException("farm_save")
예제 #15
0
def get_by_id(caller_id, farm_id):
    """
    Returns requested Farm.

    @cmview_user
    @param_post{farm_id,int} id of the requested Farm

    @response{dict} Farm.dict property of the requested Farm
    """
    return Farm.get(caller_id, farm_id).dict
예제 #16
0
파일: farm.py 프로젝트: cc1-cloud/cc1
def get_by_id(caller_id, farm_id):
    """
    Returns requested Farm.

    @cmview_user
    @param_post{farm_id,int} id of the requested Farm

    @response{dict} Farm.dict property of the requested Farm
    """
    return Farm.get(caller_id, farm_id).dict
예제 #17
0
파일: farm.py 프로젝트: cloudcache/cc1
def get_by_id(caller_id, farm_id):
    """
    Returns requested Farm.

    @decoratedby{src.cm.utils.decorators.user_log}
    @parameter{farm_id,int} id of the requested Farm

    @response{dict} requested Farm's data
    \n fields @asreturned{src.cm.database.entities.farm.Farm.get()}
    """
    return Farm.get(caller_id, farm_id).dict
예제 #18
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]
예제 #19
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]
예제 #20
0
파일: farm.py 프로젝트: cloudcache/cc1
def erase(caller_id, farm_ids):
    """
    Method erases (removes from database) details
    about VMs that haven't ran properly.
    @decoratedby{src.cm.utils.decorators.admin_cm_log}

    @parameter{farm_ids,list(int)} ids of the farms to erase
    """
    for fid in farm_ids:
        farm = Farm.admin_get(fid)
        for vm in farm.vms.all():
            VM.erase(vm)

            farm.state = farm_states['closed']
            try:
                farm.save()
            except Exception:
                log.exception('Cannot commit changes.')
예제 #21
0
파일: farm.py 프로젝트: cc1-cloud/cc1
def erase(caller_id, farm_ids):
    """
    Cleanes up after failed Farm. Only admin may erase Farm so that he
    previously may perform some analytics.

    @cmview_admin_cm
    @param_post{farm_ids,list(int)} ids of the Farms to erase
    """
    for fid in farm_ids:
        farm = Farm.admin_get(fid)
        for vm in farm.vms.all():
            VM.erase(vm)

            farm.state = farm_states['closed']
            try:
                farm.save()
            except Exception:
                log.exception('Cannot commit changes.')
예제 #22
0
def erase(caller_id, farm_ids):
    """
    Cleanes up after failed Farm. Only admin may erase Farm so that he
    previously may perform some analytics.

    @cmview_admin_cm
    @param_post{farm_ids,list(int)} ids of the Farms to erase
    """
    for fid in farm_ids:
        farm = Farm.admin_get(fid)
        for vm in farm.vms.all():
            VM.erase(vm)

            farm.state = farm_states['closed']
            try:
                farm.save()
            except Exception:
                log.exception('Cannot commit changes.')
예제 #23
0
파일: farm.py 프로젝트: cloudcache/cc1
def get_by_id(caller_id, farm_id):
    """
    @decoratedby{src.cm.utils.decorators.admin_cm_log}
    @parameter{farm_id,int} id of the requested farm
    """
    return Farm.admin_get(farm_id).dict
예제 #24
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]