def __crudVM(self, server_uuid, vm_id, action): try: VTDriver.PropagateActionToProvisioningDispatcher( vm_id, server_uuid, action) except Exception as e: raise e return 1
def action_vm(request, server_id, vm_id, action): if (not request.user.is_superuser): return simple.direct_to_template(request, template = 'not_admin.html', extra_context = {'user':request.user}, ) if(action == 'list'): return simple.direct_to_template( request, template="servers/server_vm_details.html", extra_context={"vm": VTDriver.getVMbyId(vm_id), "server_id":server_id} ) elif(action == 'check_status'): #XXX: Do this function if needed return simple.direct_to_template( request, template="servers/list_vm.html", extra_context={"vm": VM.objects.get(id = vm_id)} ) elif(action == 'force_update_server'): InformationDispatcher.forceListActiveVMs(serverID=server_id) elif(action == 'force_update_vm'): InformationDispatcher.forceListActiveVMs(vmID=vm_id) else: #XXX: serverUUID should be passed in a different way VTDriver.PropagateActionToProvisioningDispatcher(vm_id, VTServer.objects.get(id=server_id).uuid, action) #return HttpResponseRedirect(reverse('edit_server', args = [server_id])) return HttpResponse("")
def __crud_vm(self, urn, action): params = self.__urn_to_vm_params(urn) servers = VTServer.objects.all() vm_server_pairs = list() resources = list() for server in servers: vms = list() # Look for provisioned VMs vms_provisioned = server.getChildObject().getVMs(**params) # ... Also for reserved VMs vms_allocated = Reservation.objects.filter(server__id=server.id, **params) vms.extend(vms_provisioned) vms.extend(vms_allocated) for vm in vms: # The following is to be executed only for provisioned VMs if isinstance(vm, VirtualMachine): # Return "REFUSED" exception if sliver is in a transient state self.__validate_precondition_states(vm, action) # Return "BUSY" exception if sliver is in incorrect operational state if self.__translate_to_operational_state( vm) == self.GENI_UPDATING_USERS: raise Exception("BUSY sliver in state '%s'" % self.GENI_UPDATING_USERS) vm_params = {"server_uuid": server.uuid, "vm_id": vm.id} if vm_params not in vm_server_pairs: vm_server_pairs.append(vm_params) try: with self.__mutex_thread: VTDriver.PropagateActionToProvisioningDispatcher( vm.id, server.uuid, action) except Exception as e: try: if self.get_geni_best_effort_mode(): resource = self.__convert_to_resources_with_slivers( server, [vm])[0] resource.set_error_message(str(e)) #resources.extend(resource) resources.append(resource) continue else: raise e except Exception as e: raise e # The resources are fetched for any (allocated/provisioned) VM resource = self.__convert_to_resources_with_slivers( server, [vm]) resources.extend(resource) return resources