protected function call_backup($etva_node, $params = array(), $filepath = null) { if ($filepath) { $url = "http://" . $etva_node->getIp(); $port = $etva_node->getPort(); if ($port) { $url .= ":" . $port; } $url .= "/vm_backup"; $request_body = "uuid=" . $params['uuid']; if ($params['snapshot']) { $request_body .= "&snapshot=" . $params['snapshot']; } if ($params['location']) { if ($params['do_not_generate_tar'] && $params['do_not_generate_tar'] != 'false') { // do not generate tar $request_body .= "&do_not_generate_tar=1"; } $request_body .= "&location=" . $params['location']; } if ($params['shutdown']) { $request_body .= "&shutdown=1"; } $filename = $params['name'] . ".tar"; /* * get response stream data */ $ovf_curl = new ovfcURL($url); $ovf_curl->post($request_body); $ovf_curl->setFilename($filename); // set file to write output if ($filepath != 'STDOUT') { $ovf_curl->setOutputFile($filepath); } $ovf_curl->exec(); if ($ovf_curl->getStatus() == 500) { // Error; $err_m = "[ERROR] Server '" . $etva_server->getName() . "' can't download backup, we get STATUS 500: {$data}"; $this->report .= $err_m . "\r\n"; $this->log($err_m); array_push($this->errors, array('message' => $err_m)); return -111; } } else { $res_backup = $etva_node->soapSend("vm_backup", $params); if (!$res_backup['success']) { $err_m = '[ERROR] Backup of ' . $params['name'] . ' VM: ' . $res_backup['info']; $this->log($err_m . "\n"); $this->report .= $err_m . "\r\n"; array_push($this->errors, array('message' => $err_m, 'error' => $res_backup)); return -111; } } // backup with success $info_m = '[INFO] Backup ' . $params['name'] . ' VM successfully.'; $this->report .= $info_m . "\r\n"; $this->log($info_m . "\n"); return 0; }
/** * * exports virtual machine in ovf format * */ public function executeOvfDownload(sfWebRequest $request) { //$this->getUser()->shutdown(); //session_write_close(); if ($sid = $request->getParameter('uuid')) { $etva_server = EtvaServerPeer::retrieveByUuid($sid); } else { $sid = $request->getParameter('sid'); $etva_server = EtvaServerPeer::retrieveByPK($sid); } if (!$etva_server) { $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_ID_, array('%id%' => $sid)); return $this->renderText($msg_i18n); } $snapshot = $request->getParameter('snapshot'); if (!$snapshot && $etva_server->getVmState() != 'stop' && $etva_server->getVmState() != 'notrunning') { $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_ID_, array('%id%' => $sid)); return $this->renderText($msg_i18n); } $etva_node = $etva_server->getEtvaNode(); $url = "http://" . $etva_node->getIp(); $request_body = "uuid=" . $etva_server->getUuid(); if ($snapshot) { $request_body .= "&snapshot={$snapshot}"; } $filename = $etva_server->getName() . ".tar"; $port = $etva_node->getPort(); if ($port) { $url .= ":" . $port; } $url .= "/vm_ovf_export_may_fork"; /* * get response stream data */ $ovf_curl = new ovfcURL($url); $ovf_curl->post($request_body); $ovf_curl->setFilename($filename); $ovf_curl->exec(); if ($ovf_curl->getStatus() == 500) { return $this->renderText('Error 500'); } return sfView::NONE; }