def migrate(request): if request.method != "POST" or "secret" not in request.POST or "action" not in request.POST: return HttpResponseRedirect("%s" % (reverse("403"))) #endif secret = request.POST['secret'] action = request.POST['action'] permis = request.session.get("domains.domain.migrate", {}) if secret not in permis: return HttpResponseRedirect("%s" % (reverse("403"))) #endif domainData = permis[secret][1] domain = domainData['domain'] if not isAllowedTo(request, domain, "migrate_domain"): return HttpResponseRedirect("%s" % (reverse("403"))) #endif data = { "status": 200, "statusMessage": _("OK") } if action == "nodeList": # Ziskaj zoznam uzlov, na ktore mas pravo "add_domain" nodes = getNodes(request, "add_domain") # Filtruj iba uzle, ktore maju rovnaky hypervizor nodes = nodes.filter(driver=domain.node.driver).exclude(name=domain.node.name) # Vsetky otestuje na status availNodes = [] for node in nodes: try: virNode = virtualization.virNode(node) result = virNode.getInfo() except: continue finally: availNodes.append(node) #endtry #endfor data['nodes'] = [ { "label": node.name, "value": node.id } for node in availNodes ] elif action == "migrate": # Premigruje sa domena a v DB sa zmeni odkaz na node nodeId = int(request.POST['node']) node = get_object_or_404(Node, id=nodeId) try: virDomain = virtualization.virDomain(domain) virDomain.migrate(node) except virtualization.ErrorException, e: data['error'] = unicode(e) else: domain.node = node data['migrated'] = True data['id'] = domain.id
def testConnection(request): if request.method == "POST": form = NodeForm(request.POST) form.fields.pop("name", "") # We don't need check name if form.is_valid(): testNode = form.save(commit = False) data = { "status": 200, "statusMessage": "OK" } try: virNode = virtualization.virNode(testNode) result = virNode.getInfo() except virtualization.ErrorException, e: data['success'] = False data['error'] = unicode(e) else: data['success'] = True data['info'] = result #endtry else: data = { "status": 400, "statusMessage": "Data not valid!", "errors": [(k, v[0].__unicode__()) for k, v in form.errors.items()] } #endif return HttpResponse(simplejson.dumps(data))
def autoimport_list(request, secret): savedSecret, nodeId = request.session.pop("nodes.node.autoimport", (None, None)) node = get_object_or_404(Node, id=nodeId) if not savedSecret or not nodeId or secret != savedSecret: return HttpResponseRedirect("%s" % (reverse("403"))) #endif # test:///default - this doesn't have stable domains so report it as unimplemented if node.getURI() == "test:///default": data = { "status": 501, "statusMessage": _("Node `%(nodeUri)s` cannot autoimport domains." ) % { "nodeUri": node.getURI() } } return HttpResponse(simplejson.dumps(data)) #enddef nodeDomains = node.domain_set.all() data = { "status": 200, "statusMessage": "OK", "domains": {} } virNode = None try: virNode = virtualization.virNode(node) domainsUUIDs = virNode.listDomains(virtualization.LIST_DOMAINS_ACTIVE | virtualization.LIST_DOMAINS_INACTIVE) except virtualization.ErrorException, e: data['status'] = 503 data['statusMessage'] = _(unicode(e)) return HttpResponse(simplejson.dumps(data))
def checkStatus(request, nodeId): node = get_object_or_404(Node, id=nodeId) if not isAllowedTo(request, node, "view_node"): return HttpResponseRedirect("%s" % (reverse("403"))) #endif data = { "status": 200, "statusMessage": "OK", "node": {} } try: virNode = virtualization.virNode(node) result = virNode.getInfo() except virtualization.ErrorException, e: data['node']['status'] = False data['node']['error'] = unicode(e)
def add(request): if request.method != "POST" or "secret" not in request.POST or "action" not in request.POST: return HttpResponseRedirect("%s" % (reverse("403"))) #endif secret = request.POST['secret'] action = request.POST['action'] permis = request.session.get("domains.domain.add", {}) if secret not in permis: return HttpResponseRedirect("%s" % (reverse("403"))) #endif domainData = permis[secret][1] domain = domainData['domain'] node = domain.node if not nodeIsAllowedTo(request, node, "add_domain"): return HttpResponseRedirect("%s" % (reverse("403"))) #endif data = { "status": 200, "statusMessage": _("OK") } if action == "nodeCheck": try: virNode = virtualization.virNode(node) result = virNode.getInfo() except virtualization.ErrorException, e: data['nodeStatus'] = False data['error'] = unicode(e) else: data['nodeStatus'] = True data['info'] = result try: freeMemory = virNode.getFreeMemory() except virtualization.ErrorException, e: data['info']['freeMemory'] = -1 else:
domain.uuid = request.POST['uuid'] domain.description = request.POST['description'] elif action == "loadMemory": if domain.memory: data['memory'] = domain.memory / 1024 else: data['memory'] = domain.memory #endif data['vcpu'] = domain.vcpu elif action == "saveMemory": domain.memory = int(request.POST['memory']) * 1024 domain.vcpu = int(request.POST['vcpu']) elif action == "loadVolumes": pool = domainData['pool'] try: virNode = virtualization.virNode(node) poolInfo = virNode.getStoragePoolInfo(pool) result = virNode.listStorageVolumes(pool) volumes = [ { "value": volume, "label": "%s (%.2f GB)" % \ (volume, (float(virNode.getStorageVolumeInfo(pool, volume)['capacity']) / (1024 * 1024 * 1024))) } for volume in result ] except virtualization.ErrorException, e: data['error'] = unicode(e) else: data['poolInfo'] = poolInfo data['volumes'] = volumes #endtry if "volume" in domainData: