protected function onChange($values) { $modifyhd = array('-q', 'modifyhd', $this->path); foreach ($values as $name => $value) { switch ($name) { case 'type': if ($this->get($name) != $value) { $modifyhd[] = '--type'; $modifyhd[] = $value; } break; case 'autoreset': $value = $value ? 'on' : 'off'; if ($this->get($name, 'off') != $value) { $modifyhd[] = '--autoreset'; $modifyhd[] = $value; } break; } } if (sizeof($modifyhd) > 3) { return voidExec(VIRTUALBOX_MGT_BIN, $modifyhd) == 0; } return FALSE; }
public function destroy() { if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'closemedium', 'floppy', $this->path, '--delete')) == 0) { $this->loaded = FALSE; return TRUE; } return FALSE; }
public static function createMachine($name, $ostype) { $path = BASE_PATH . '/machine/' . $name; if (file_exists($path)) { return FALSE; } $lines = simpleExec(VIRTUALBOX_MGT_BIN, array('-q', 'createvm', '--name', $name, '--ostype', $ostype, '--register', '--basefolder', BASE_PATH . '/machine/')); foreach ($lines as $line) { if (preg_match('/^UUID: ([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})$/', $line, $matches)) { $machine = self::getMachine($matches[1]); if ($machine->id == $matches[1]) { if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storagectl', $machine->id, '--name', 'FLOPPY', '--add', 'floppy', '--controller', 'I82078')) != 0) { $machine->destroy(); return FALSE; } if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storagectl', $machine->id, '--name', 'IDE', '--add', 'ide', '--controller', 'PIIX4')) != 0) { $machine->destroy(); return FALSE; } if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storagectl', $machine->id, '--name', 'SATA', '--add', 'sata', '--controller', 'IntelAHCI', '--portcount', '1')) != 0) { $machine->destroy(); return FALSE; } } return $machine; } } return FALSE; }
protected function onChange($values) { $changed = FALSE; $modifyvm = array('-q', 'modifyvm', $this->id); foreach ($values as $name => $value) { switch ($name) { // booleans case 'bioslogofadein': case 'bioslogofadeout': case 'acpi': case 'ioapic': case 'pae': case 'hpet': case 'rtcuseutc': case 'hwvirtex': // case 'hwvirtexexcl': // case 'hwvirtexexcl': case 'nestedpaging': case 'largepages': case 'pagefusion': case 'vtxvpid': case 'synthcpu': case 'accelerate2dvideo': case 'accelerate3d': case 'usb': case 'usbehci': case 'vrde': $value = $value ? 'on' : 'off'; if ($this->get($name, 'off') != $value) { $modifyvm[] = '--' . $name; $modifyvm[] = $value; } break; // integers // integers case 'memory': case 'vram': case 'cpus': case 'bioslogodisplaytime': case 'biossystemtimeoffset': if (intval($this->get($name, '0')) != intval($value)) { $modifyvm[] = '--' . $name; $modifyvm[] = intval($value); } break; // strings // strings case 'name': case 'ostype': case 'boot1': case 'boot2': case 'boot3': case 'boot4': case 'firmware': case 'biosbootmenu': case 'clipboard': case 'audio': case 'audiocontroller': case 'vrdeaddress': case 'vrdeport': case 'vrdeauthtype': if ($this->get($name) != $value) { $modifyvm[] = '--' . $name; $modifyvm[] = $value; } break; // fdd controllers // fdd controllers case 'fd0': case 'fd1': $port = 0; $device = 0; switch ($name) { case 'fd0': $port = 0; $device = 0; break; case 'fd1': $port = 0; $device = 1; break; } if (is_a($value, 'FDD')) { if ($value->exists()) { if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storageattach', $this->id, '--storagectl', 'FLOPPY', '--port', $port, '--device', $device, '--type', 'fdd', '--medium', $value->path)) == 0) { $changed = TRUE; } } else { if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storageattach', $this->id, '--storagectl', 'FLOPPY', '--port', $port, '--device', $device, '--type', 'fdd', '--medium', 'emptydrive')) == 0) { $changed = TRUE; } } } else { $current = $this->{$name}; if ($current) { if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storageattach', $this->id, '--storagectl', 'FLOPPY', '--port', $port, '--device', $device, '--medium', 'none')) == 0) { $changed = TRUE; } } } break; // ide controllers // ide controllers case 'ide0': case 'ide1': case 'ide2': case 'ide3': $port = 0; $device = 0; switch ($name) { case 'ide0': $port = 0; $device = 0; break; case 'ide1': $port = 0; $device = 1; break; case 'ide2': $port = 1; $device = 0; break; case 'ide3': $port = 1; $device = 1; break; } if (is_a($value, 'HDD')) { if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storageattach', $this->id, '--storagectl', 'IDE', '--port', $port, '--device', $device, '--type', 'hdd', '--medium', $value->path)) == 0) { $changed = TRUE; } } else { if (is_a($value, 'DVD')) { if ($value->exists()) { if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storageattach', $this->id, '--storagectl', 'IDE', '--port', $port, '--device', $device, '--type', 'dvddrive', '--medium', $value->path)) == 0) { $changed = TRUE; } } else { if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storageattach', $this->id, '--storagectl', 'IDE', '--port', $port, '--device', $device, '--type', 'dvddrive', '--medium', 'emptydrive')) == 0) { $changed = TRUE; } } } else { $current = $this->{$name}; if ($current) { if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storageattach', $this->id, '--storagectl', 'IDE', '--port', $port, '--device', $device, '--medium', 'none')) == 0) { $changed = TRUE; } } } } break; // sata controllers // sata controllers case 'sata0': case 'sata1': case 'sata2': case 'sata3': case 'sata4': case 'sata5': case 'sata6': case 'sata7': case 'sata8': case 'sata9': case 'sata10': case 'sata11': case 'sata12': case 'sata13': case 'sata14': case 'sata15': case 'sata16': case 'sata17': case 'sata18': case 'sata19': case 'sata20': case 'sata21': case 'sata22': case 'sata23': case 'sata24': case 'sata25': case 'sata26': case 'sata27': case 'sata28': case 'sata29': $i = substr($name, 4); if (is_a($value, 'HDD')) { if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storageattach', $this->id, '--storagectl', 'SATA', '--port', $i, '--device', '0', '--type', 'hdd', '--medium', $value->path)) == 0) { $changed = TRUE; } } else { if (is_a($value, 'DVD')) { if ($value->exists()) { if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storageattach', $this->id, '--storagectl', 'SATA', '--port', $i, '--device', '0', '--type', 'dvddrive', '--medium', $value->path)) == 0) { $changed = TRUE; } } else { if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storageattach', $this->id, '--storagectl', 'SATA', '--port', $i, '--device', '0', '--type', 'dvddrive', '--medium', 'emptydrive')) == 0) { $changed = TRUE; } } } else { $current = $this->{$name}; if ($current) { if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'storageattach', $this->id, '--storagectl', 'SATA', '--port', $i, '--device', '0', '--medium', 'none')) == 0) { $changed = TRUE; } } } } break; // network adapters // network adapters case 'nic0': case 'nic1': case 'nic2': case 'nic3': case 'nic4': case 'nic5': case 'nic6': case 'nic7': $i = substr($name, 3) + 1; if (!isset($value['type'])) { $value['type'] = 'none'; } if (!isset($value['driver'])) { $value['driver'] = 'Am79C973'; } if (!isset($value['mac'])) { $value['mac'] = 'auto'; } if (!isset($value['connected'])) { $value['connected'] = 'off'; } switch ($value['type']) { case 'nat': if (!isset($value['net'])) { $value['net'] = ''; } if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'modifyvm', $this->id, '--nic' . $i, $value['type'], '--nictype' . $i, $value['driver'], '--macaddress' . $i, $value['mac'], '--natnet' . $i, $value['net'], '--cableconnected' . $i, $value['connected'])) == 0) { $changed = TRUE; } break; case 'bridged': if (!isset($value['adapter'])) { $value['adapter'] = 'eth0'; } if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'modifyvm', $this->id, '--nic' . $i, $value['type'], '--nictype' . $i, $value['driver'], '--macaddress' . $i, $value['mac'], '--bridgeadapter' . $i, $value['adapter'], '--cableconnected' . $i, $value['connected'])) == 0) { $changed = TRUE; } break; case 'intnet': if (!isset($value['net'])) { $value['net'] = 'intnet'; } if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'modifyvm', $this->id, '--nic' . $i, $value['type'], '--nictype' . $i, $value['driver'], '--macaddress' . $i, $value['mac'], '--intnet' . $i, $value['net'], '--cableconnected' . $i, $value['connected'])) == 0) { $changed = TRUE; } break; case 'hostonly': if (!isset($value['adapter'])) { $value['adapter'] = 'vboxnet0'; } if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'modifyvm', $this->id, '--nic' . $i, $value['type'], '--nictype' . $i, $value['driver'], '--macaddress' . $i, $value['mac'], '--hostonlyadapter' . $i, $value['adapter'], '--cableconnected' . $i, $value['connected'])) == 0) { $changed = TRUE; } break; default: if (voidExec(VIRTUALBOX_MGT_BIN, array('-q', 'modifyvm', $this->id, '--nic' . $i, 'none')) == 0) { $changed = TRUE; } break; } break; } } if (sizeof($modifyvm) > 3) { if (voidExec(VIRTUALBOX_MGT_BIN, $modifyvm) == 0) { $changed = TRUE; } } return $changed; }