function connect($uri = 'null') { $this->conn = libvirt_connect($uri, false); if ($this->conn == false) { return $this->_set_last_error(); } }
public function authenticate() { $resource = libvirt_connect("qemu+tcp://{$this->hostname}/system", $this->readonly, [VIR_CRED_AUTHNAME => $this->username, VIR_CRED_PASSPHRASE => $this->password]); if (!is_resource($resource)) { throw new \Exception("Falha na authenticação: " . libvirt_get_last_error()); } return $resource; }
private function connect() { if (!($this->connection = @libvirt_connect($this->connectionSettings['url'], true))) { $this->LinfoError->add('libvirt extension', 'Error connecting'); $this->res = false; return false; } return true; }
/** * connect to a virt host * * bit more info on a second line * * @param string $host_name name of virt host * @param string $host_domain domain of virt host * @param string $host_username username used to connect to virt host * @param string $host_password password of username account * * @return resource|bool libvirt host connection resource or FALSE if connection attempt fails * */ function ace_kvm_connect($host_name, $host_domain, $host_username, $host_password) { // $host_fqdn = $host_name . '.' . $host_domain; $host_cred = array($host_username, $host_password); // $host_uri = 'qemu+ssh://root@'.$host_fqdn.'/system'; $host_uri = 'qemu+ssh://root@' . $host_name . '/system'; $connect = libvirt_connect($host_uri, FALSE, $host_cred); ace_kvm_log_last_error(); return $connect; }
$redis = new Redis(); $redis->connect('127.0.0.1', 6379); if ($redis->ping()) { $num = $redis->get("cluster:num-nodes"); $res = null; for ($i = 0; $i < $num; $i++) { $ip = $redis->get("cluster:node" . $i); echo "<div id=\"widget\" style=\"float:left;font-size:100%;width:30%;margin-left:2.2%;\">"; echo "<div id=\"strip\">"; echo "NODE :" . $ip; echo "<button type=\"button\" class=\"primary\">-</button>"; echo "</div>"; echo "<div id=\"widget-main\">"; echo "<table style=\"font:serif;font-size:100%;text-align:left;\">"; $uri = "qemu+tcp://" . $ip . "/system"; $con = libvirt_connect($uri, false); if (!$con) { echo libvirt_get_last_error(); } $info = libvirt_connect_get_information($con); echo "<tr><th>Hostname</th><td>: " . $info['hostname'] . "</td></tr>"; echo "<tr><th>Hypervisor</th><td>: " . $info['hypervisor_string'] . "</td></tr>"; echo "<tr><th>Max VCPU(s) per VM</th><td>: " . $info['hypervisor_maxvcpus'] . "</td></tr>"; $info1 = libvirt_node_get_info($con); echo "<tr><th>CPU(s)</th><td>: " . $info1['cpus'] . "</td></tr>"; echo "<tr><th>CPU frequency</th><td>: " . $info1['mhz'] . "</td></tr>"; echo "<tr><th>Architecture</th><td>: " . $info1['model'] . "</td></tr>"; echo "<tr><th>Memory</th><td>: " . $info1['memory'] . "</td></tr>"; echo "<tr><th>Total Number of VM(s)</th><td>: " . $info['num_total_domains'] . "</td></tr>"; echo "<tr><th>Running VM(s)</th><td>: " . $info['num_active_domains'] . "</td></tr>"; echo "<tr><th>Stopped VM(s)</th><td>: " . $info['num_inactive_domains'] . "</td></tr>";
public function store() { $vm = Vm::create(Input::get()); $xml = <<<XML <domain type='kvm'> <name>{$vm->id}</name> <memory unit='MiB'>{$vm->memory}</memory> <currentMemory unit='MiB'>{$vm->memory}</currentMemory> <vcpu placement='static'>{$vm->cpu}</vcpu> <resource> <partition>/machine</partition> </resource> <os> <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type> <boot dev='hd'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> <source file='/var/lib/libvirt/images/{$vm->id}.qcow2'/> <target dev='hda' bus='ide'/> <alias name='ide0-0-0'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> <controller type='usb' index='0'> <alias name='usb0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='ide' index='0'> <alias name='ide0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <controller type='virtio-serial' index='0'> <alias name='virtio-serial0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </controller> <interface type='bridge'> <source bridge='br0'/> </interface> <serial type='pty'> <source path='/dev/pts/2'/> <target port='0'/> <alias name='serial0'/> </serial> <console type='pty' tty='/dev/pts/2'> <source path='/dev/pts/2'/> <target type='serial' port='0'/> <alias name='serial0'/> </console> <channel type='spicevmc'> <target type='virtio' name='com.redhat.spice.0'/> <alias name='channel0'/> <address type='virtio-serial' controller='0' bus='0' port='1'/> </channel> <input type='mouse' bus='ps2'/> <graphics type='spice' port='{$vm->port}' autoport='no' listen='0.0.0.0'> <listen type='address' address='0.0.0.0'/> </graphics> <video> <model type='qxl' ram='65536' vram='65536' heads='1'/> <alias name='video0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </video> <memballoon model='virtio'> <alias name='balloon0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> </memballoon> </devices> <seclabel type='dynamic' model='selinux' relabel='yes'> <label>system_u:system_r:svirt_t:s0:c786,c813</label> <imagelabel>system_u:object_r:svirt_image_t:s0:c786,c813</imagelabel> </seclabel> </domain> XML; $conn = libvirt_connect('qemu+tcp://192.168.1.143/system', false); libvirt_domain_create_xml($conn, $xml); }
function connect($uri = 'null', $login = false, $password = false) { if ($login !== false && $password !== false) { $this->conn=libvirt_connect($uri, false, array(VIR_CRED_AUTHNAME => $login, VIR_CRED_PASSPHRASE => $password)); } else { $this->conn=libvirt_connect($uri, false); } if ($this->conn==false) return $this->_set_last_error(); return true; }