def startStopSlice(action,uuid):

    "Manages the actions executed over VMs at url manage resources."
    try: 
        vmsToStart = VM.objects.filter(sliceId = uuid)
    
        #if action_type == 'stop' : action_type = 'hardStop'
        globalRspec = XmlHelper.getSimpleActionSpecificQuery(action, "dummy")
    	globalRspec.query.provisioning.action.pop()
        for vm in vmsToStart:
            rspec = XmlHelper.getSimpleActionSpecificQuery(action, vm.serverID)
            Translator.PopulateNewAction(rspec.query.provisioning.action[0], vm)
            globalRspec.query.provisioning.action.append(copy.deepcopy(rspec.query.provisioning.action[0]))
    
        ServiceThread.startMethodInNewThread(ProvisioningDispatcher.processProvisioning,globalRspec.query.provisioning, None)
    
        for vm in vmsToStart:
            if action == 'start':
            	vm.state = 'starting...'
            elif action == 'stop':
                vm.state = 'stopping'
            vm.save()
    except Exception as e:
        print e
        raise e
Exemplo n.º 2
0
def startStopSlice(action, uuid):

    "Manages the actions executed over VMs at url manage resources."
    try:
        vmsToStart = VM.objects.filter(sliceId=uuid)

        #if action_type == 'stop' : action_type = 'hardStop'
        globalRspec = XmlHelper.getSimpleActionSpecificQuery(action, "dummy")
        globalRspec.query.provisioning.action.pop()
        for vm in vmsToStart:
            rspec = XmlHelper.getSimpleActionSpecificQuery(action, vm.serverID)
            Translator.PopulateNewAction(rspec.query.provisioning.action[0],
                                         vm)
            globalRspec.query.provisioning.action.append(
                copy.deepcopy(rspec.query.provisioning.action[0]))

        ServiceThread.startMethodInNewThread(
            ProvisioningDispatcher.processProvisioning,
            globalRspec.query.provisioning, None)

        for vm in vmsToStart:
            if action == 'start':
                vm.state = 'starting...'
            elif action == 'stop':
                vm.state = 'stopping'
            vm.save()
    except Exception as e:
        print e
        raise e
def manage_vm(request, slice_id, vm_id, action_type):
    "Manages the actions executed over VMs at url manage resources."
    if not (action_type.startswith("force")):
        vm = VM.objects.get(id = vm_id)
        rspec = XmlHelper.getSimpleActionSpecificQuery(action_type, vm.serverID)
        Translator.PopulateNewAction(rspec.query.provisioning.action[0], vm)
        ServiceThread.startMethodInNewThread(ProvisioningDispatcher.processProvisioning,rspec.query.provisioning, request.user)
        if action_type == 'start':
            vm.state = 'starting...'
        elif action_type == 'stop':
            vm.state = 'stopping...'
        elif action_type == 'reboot':
            vm.state = 'rebooting...'
        elif action_type == 'delete':
            vm.state = 'deleting...'
            # Delete the associated entry in the database
            Action.objects.all().filter(vm = vm).delete()
            # Keep actions table up-to-date after each deletion
            #Action.objects.all().exclude(vm__in = VM.objects.all()).delete()
        elif action_type == 'create':
            vm.state = 'creating...'
        vm.save()

    elif action_type == "force_update_vm":
        InformationDispatcher.force_update_vms(vm_id=vm_id)
    elif action_type == "force_update_server":
        InformationDispatcher.force_update_vms(client_id=vm_id)
    elif action_type == "force_update_all":
        for server in VTServer.objects.all():
             InformationDispatcher.force_update_vms(client_id=server.id) 
    #go to manage resources again
    response = HttpResponse("")
    return response
Exemplo n.º 4
0
def manage_vm(request, slice_id, vm_id, action_type):
    "Manages the actions executed over VMs at url manage resources."
    if not (action_type.startswith("force")):
        vm = VM.objects.get(id=vm_id)
        rspec = XmlHelper.getSimpleActionSpecificQuery(action_type,
                                                       vm.serverID)
        Translator.PopulateNewAction(rspec.query.provisioning.action[0], vm)
        ServiceThread.startMethodInNewThread(
            ProvisioningDispatcher.processProvisioning,
            rspec.query.provisioning, request.user)
        if action_type == 'start':
            vm.state = 'starting...'
        elif action_type == 'stop':
            vm.state = 'stopping...'
        elif action_type == 'reboot':
            vm.state = 'rebooting...'
        elif action_type == 'delete':
            vm.state = 'deleting...'
            # Delete the associated entry in the database
            Action.objects.all().filter(vm=vm).delete()
            # Keep actions table up-to-date after each deletion
            #Action.objects.all().exclude(vm__in = VM.objects.all()).delete()
        elif action_type == 'create':
            vm.state = 'creating...'
        vm.save()

    elif action_type == "force_update_vm":
        InformationDispatcher.force_update_vms(vm_id=vm_id)
    elif action_type == "force_update_server":
        InformationDispatcher.force_update_vms(client_id=vm_id)
    elif action_type == "force_update_all":
        for server in VTServer.objects.all():
            InformationDispatcher.force_update_vms(client_id=server.id)
    #go to manage resources again
    response = HttpResponse("")
    return response