Exemplo n.º 1
0
    def save_and_shutdown(farm, name, description):
        """
        """
        from cm.models.vm import VM

        if farm.state == farm_states['failed']:
            raise CMException('farm_wrong_state')

        head_vm = farm.head
        try:
            VM.save_and_shutdown(head_vm.user_id, head_vm, name, description)
        except Exception:
            CMException('farm_save')

        node_vms = []
        if farm.state == farm_states['init_head']:
            for vm in farm.vms.all():
                if vm.is_head():
                    continue
                vm.release_resources()
                vm.state = vm_states['closed']
        else:
            for vm in farm.vms.all():
                if not vm.is_head():
                    node_vms.append(vm)
            VM.destroy(node_vms)

        try:
            farm.state = farm_states['closed']
            farm.save()
        except:
            CMException('farm_save')
Exemplo n.º 2
0
Arquivo: farm.py Projeto: pojoba02/cc1
    def save_and_shutdown(farm, name, description):
        """
        """
        from cm.models.vm import VM

        if farm.state == farm_states["failed"]:
            raise CMException("farm_wrong_state")

        head_vm = farm.head
        try:
            VM.save_and_shutdown(head_vm.user_id, head_vm, name, description)
        except Exception:
            CMException("farm_save")

        node_vms = []
        if farm.state == farm_states["init_head"]:
            for vm in farm.vms.all():
                if vm.is_head():
                    continue
                vm.release_resources()
                vm.state = vm_states["closed"]
        else:
            for vm in farm.vms.all():
                if not vm.is_head():
                    node_vms.append(vm)
            VM.destroy(node_vms)

        try:
            farm.state = farm_states["closed"]
            farm.save()
        except:
            CMException("farm_save")
Exemplo n.º 3
0
    def destroy(farms):
        """
        Destroyes farms' VMs (Head and Worker Nodes of each farm) without saving them.

        @parameter{farms,list} list of farms to destroy

        @response{list(dict)} list of statuses returned by destroyed VMs

        @raises{farm_wrong_state,CMException}
        @raises{farm_destroy,CMException}
        """
        from cm.models.vm import VM

        vm_resp = []
        for farm in farms:
            # those are states in which farm can not be destroyed
            if farm.state in (farm_states['init'], farm_states['closing'], farm_states['closed']):
                raise CMException('farm_wrong_state')

        for farm in farms:
            # stop all threads
            if farm.state == farm_states['init_head']:
                for vm in farm.vms.all():
                    if vm.is_head():
                        continue
                    vm.release_resources()
                    vm.state = vm_states['closed']
                    vm.stop_time = datetime.now()
                    vm.save()
                    log.debug(vm.user.id, "vm state %s" % vm.state)
                r = VM.destroy([farm.head])
            else:
                for vm in farm.vms.all():
                    if vm.state == vm_states['init']:
                        raise CMException('farm_wrong_state')
                log.debug(farm.user_id, "killing wn: %s" % farm.vms)
                r = VM.destroy(farm.vms.all())

            if True in [x['status'] != 'ok' for x in r]:
                farm.state = farm_states['failed']
                try:
                    farm.save()
                except Exception:
                    raise CMException('farm_destroy')
            vm_resp.append(r)

            farm.state = farm_states['closed']

            try:
                farm.save()
            except Exception:
                raise CMException('farm_destroy')

            log.debug(farm.user_id, "session commited")
            for vm in farm.vms.all():
                log.debug(vm.user.id, "vm state %s" % vm.state)

        return vm_resp
Exemplo n.º 4
0
Arquivo: farm.py Projeto: pojoba02/cc1
    def destroy(farms):
        """
        Destroyes farms' VMs (Head and Worker Nodes of each farm) without saving them.

        @parameter{farms,list} list of farms to destroy

        @response{list(dict)} list of statuses returned by destroyed VMs

        @raises{farm_wrong_state,CMException}
        @raises{farm_destroy,CMException}
        """
        from cm.models.vm import VM

        vm_resp = []
        for farm in farms:
            # those are states in which farm can not be destroyed
            if farm.state in (farm_states["init"], farm_states["closing"], farm_states["closed"]):
                raise CMException("farm_wrong_state")

        for farm in farms:
            # stop all threads
            if farm.state == farm_states["init_head"]:
                for vm in farm.vms.all():
                    if vm.is_head():
                        continue
                    vm.release_resources()
                    vm.state = vm_states["closed"]
                    vm.stop_time = datetime.now()
                    vm.save()
                    log.debug(vm.user.id, "vm state %s" % vm.state)
                r = VM.destroy([farm.head])
            else:
                for vm in farm.vms.all():
                    if vm.state == vm_states["init"]:
                        raise CMException("farm_wrong_state")
                log.debug(farm.user_id, "killing wn: %s" % farm.vms)
                r = VM.destroy(farm.vms.all())

            if True in [x["status"] != "ok" for x in r]:
                farm.state = farm_states["failed"]
                try:
                    farm.save()
                except Exception:
                    raise CMException("farm_destroy")
            vm_resp.append(r)

            farm.state = farm_states["closed"]

            try:
                farm.save()
            except Exception:
                raise CMException("farm_destroy")

            log.debug(farm.user_id, "session commited")
            for vm in farm.vms.all():
                log.debug(vm.user.id, "vm state %s" % vm.state)

        return vm_resp
Exemplo n.º 5
0
Arquivo: vm.py Projeto: cc1-cloud/cc1
def destroy(caller_id, vm_ids):
    """
    This function only destroys VM. All the cleanup (removing disk, saving,
    rescuing resources, ...) is done by hook through
    \c contextualization.update_vm method (yeah, intuitive).

    Simple sequence diagram:

    @code
            CLM        CM         CTX           Node (HOOK)
             .
            Destroy -->destroy
             |          |       (LV.destroy)
             |          |------------------------->HookScript
             .          .                          |
             .          .          ctx.update_vm<--|
             .          .           |              |
             .          .           |------------->cp
             .          .           |------------->rm
             .          .          update_resources
    @endcode

    @cmview_user
    @param_post{vm_ids,list} list of virtual machines' ids

    @response{list(dict)} VM.destroy() retval
    """
    vms = []
    for vm_id in vm_ids:
        vms.append(VM.get(caller_id, vm_id))
    return VM.destroy(vms)
Exemplo n.º 6
0
def destroy(caller_id, vm_ids):
    """
    This function only destroys VM. All the cleanup (removing disk, saving,
    rescuing resources, ...) is done by hook through
    \c contextualization.update_vm method (yeah, intuitive).

    Simple sequence diagram:

    @code
            CLM        CM         CTX           Node (HOOK)
             .
            Destroy -->destroy
             |          |       (LV.destroy)
             |          |------------------------->HookScript
             .          .                          |
             .          .          ctx.update_vm<--|
             .          .           |              |
             .          .           |------------->cp
             .          .           |------------->rm
             .          .          update_resources
    @endcode

    @cmview_user
    @param_post{vm_ids,list} list of virtual machines' ids

    @response{list(dict)} VM.destroy() retval
    """
    vms = []
    for vm_id in vm_ids:
        vms.append(VM.get(caller_id, vm_id))
    return VM.destroy(vms)
Exemplo n.º 7
0
    def save_and_shutdown(farm, name, description):
        """
        """
        from cm.models.vm import VM

        if farm.state == farm_states['failed']:
            raise CMException('farm_wrong_state')

        head_vm = farm.head
        try:
            head_vm.name = name
            head_vm.description = description
            head_vm.save_vm = 2
            head_vm.save()
            head_vm.save_image()
            head_vm.release_resources()
            head_vm.remove()
            head_vm.state = vm_states['closed']
            head_vm.save()
        except Exception:
            CMException('farm_save')

        node_vms = []
        if farm.state == farm_states['init_head']:
            for vm in farm.vms.all():
                if vm.is_head():
                    continue
                vm.release_resources()
                vm.state = vm_states['closed']
        else:
            for vm in farm.vms.all():
                node_vms.append(vm)
            VM.destroy(node_vms)

        try:
            farm.state = farm_states['closed']
            farm.save()
        except:
            CMException('farm_save')
Exemplo n.º 8
0
def destroy(caller_id, vm_id_list):
    """
    Destroyes specified VMs. Destroyed VM can in no way be recovered.

    @cmview_admin_cm
    @param_post{vm_id_list,list} ids to destroy

    @response{src.cm.views.utils.image.destroy()}
    """

    vms = []
    for vm_id in vm_id_list:
        vms.append(VM.admin_get(vm_id))
    return VM.destroy(vms)
Exemplo n.º 9
0
Arquivo: vm.py Projeto: cc1-cloud/cc1
def destroy(caller_id, vm_id_list):
    """
    Destroyes specified VMs. Destroyed VM can in no way be recovered.

    @cmview_admin_cm
    @param_post{vm_id_list,list} ids to destroy

    @response{src.cm.views.utils.image.destroy()}
    """

    vms = []
    for vm_id in vm_id_list:
        vms.append(VM.admin_get(vm_id))
    return VM.destroy(vms)
Exemplo n.º 10
0
Arquivo: vm.py Projeto: cloudcache/cc1
def destroy(caller_id, vm_id_list):
    """
    Method destroyes VMs with ids listed in \c vm_ids.
    @cmview_admin_cm

    @parameter{vm_ids,list} list of vm id's

    @response{src.cm.views.utils.image.destroy()}
    """

    vms = []
    for vm_id in vm_id_list:
        vms.append(VM.admin_get(vm_id))
    return VM.destroy(vms)