Ejemplo n.º 1
0
        public lockableVMSpec createChildVM(SQLiteConnection conn, hostDB db, VMHardwareSpec reqhw, VMSoftwareSpec reqsw, string newOwner)
        {
            if ((permittedAccessRead & bladeLockType.lockVMCreation) == bladeLockType.lockNone)
            {
                throw new Exception("lockVMCreation is needed when calling .createChildVM");
            }

            vmserverTotals totals        = db.getVMServerTotals(this);
            int            indexOnServer = totals.VMs + 1;
            string         newBladeName  = xdlClusterNaming.makeVMName(bladeIP, indexOnServer);

            // If we set the debugger port automatically, make sure we reset it to zero before we return.
            bool needToResetReqSWDebugPort = false;

            if (reqsw.debuggerPort == 0)
            {
                reqsw.debuggerPort        = xdlClusterNaming.makeVMKernelDebugPort(bladeIP, indexOnServer);
                needToResetReqSWDebugPort = true;
            }

            vmSpec newVM = new vmSpec(conn, newBladeName, reqsw, bladeLockType.lockAll, bladeLockType.lockAll);

            newVM.parentBladeIP = bladeIP;
            newVM.state         = bladeStatus.inUseByDirector;
            newVM.currentOwner  = "vmserver"; // We own the blade until we are done setting it up
            newVM.nextOwner     = newOwner;
            newVM.parentBladeID = bladeID.Value;
            newVM.memoryMB      = reqhw.memoryMB;
            newVM.cpuCount      = reqhw.cpuCount;
            newVM.indexOnServer = indexOnServer;

            newVM.VMIP    = xdlClusterNaming.makeVMIP(bladeIP, newVM);
            newVM.iscsiIP = xdlClusterNaming.makeiSCSIIP(bladeIP, newVM);
            newVM.eth0MAC = xdlClusterNaming.makeEth0MAC(bladeIP, newVM);
            newVM.eth1MAC = xdlClusterNaming.makeEth1MAC(bladeIP, newVM);

            // VMs always have this implicit snapshot.
            newVM.currentSnapshot = "vm";

            if (needToResetReqSWDebugPort)
            {
                reqsw.debuggerPort = 0;
            }

            lockableVMSpec toRet = new lockableVMSpec(newVM.VMIP, bladeLockType.lockAll, bladeLockType.lockAll);

            toRet.setSpec(newVM);
            return(toRet);
        }
Ejemplo n.º 2
0
        public bool canAccommodate(hostDB db, VMHardwareSpec req)
        {
            if ((permittedAccessRead & bladeLockType.lockVMCreation) == bladeLockType.lockNone)
            {
                throw  new Exception("lockVMCreation is needed when calling .canAccomodate");
            }

            vmserverTotals totals = db.getVMServerTotals(this);

            if (totals.VMs + 1 > _VMCapacity.maxVMs)
            {
                return(false);
            }
            if (totals.ram + req.memoryMB > _VMCapacity.maxVMMemoryMB)
            {
                return(false);
            }
            if (totals.cpus + req.cpuCount > _VMCapacity.maxCPUCount)
            {
                return(false);
            }

            return(true);
        }