/** * * * load server info for editing. Returns server info * * request object is like this; * <code> * $request['id'] = $id; //server ID * </code> * * @param sfWebRequest $request A request object * * @return string json string representation of array('success'=>true,'total'=>$total, 'data'=>$server_data) * */ public function executeJsonLoad(sfWebRequest $request) { $count = 0; $id = $request->getParameter('id'); if ($etva_server = EtvaServerPeer::retrieveByPK($id)) { $count = 1; } else { $msg_i18n = $this->getContext()->getI18N()->__(EtvaServerPeer::_ERR_NOTFOUND_ID_, array('%id%' => $id)); $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n, 'info' => $msg_i18n); // if is browser request return text renderer $error = $this->setJsonError($error); return $this->renderText($error); } $etva_node = $etva_server->getEtvaNode(); $server_array = $etva_server->toArray(BasePeer::TYPE_FIELDNAME); if ($etva_node) { $server_array['node_id'] = $etva_node->getId(); $server_array['node_hypervisor'] = $etva_node->getHypervisor(); $server_array['node_ncpus'] = $etva_node->getCputotal(); $server_array['node_state'] = $etva_node->getState(); $server_array['can_create_vms'] = $etva_node->canCreateVms(); $server_array['node_freememory'] = $etva_node->getMemfree(); $server_array['node_maxmemory'] = $etva_node->getMaxMem(); $server_array['unassigned'] = false; } else { $server_array['unassigned'] = true; } $server_array['vm_is_running'] = $etva_server->isRunning() ? true : false; $all_shared = $etva_server->isAllSharedLogicalvolumes(); $server_array['all_shared_disks'] = $all_shared; $has_snapshots = $etva_server->hasSnapshots(); $server_array['has_snapshots_disks'] = $has_snapshots; $server_array['has_snapshots_support'] = $etva_server->hasSnapshotsSupport() ? true : false; $server_array['has_devices'] = $etva_server->hasDevices(); /* * Disk stuff */ $srv_disks = EtvaServerLogicalQuery::create()->useEtvaServerQuery()->filterById($id)->endUse()->find(); $server_array['server_has_disks'] = $srv_disks->isEmpty() ? False : True; /* * Network interfaces stuff */ $srv_ifs = EtvaNetworkQuery::create()->filterByServerId($id)->find(); $server_array['server_has_netifs'] = $srv_ifs->isEmpty() ? False : True; if ($features = $etva_server->getFeatures()) { $features_arr = (array) json_decode($features); foreach ($features_arr as $f => $v) { $fk = "feature_" . $f; $server_array[$fk] = $v; } } /* * keymap stuff */ $vnc_keymap = EtvaSettingPeer::retrieveByPk('vnc_keymap'); $keymap_val = $vnc_keymap->getValue(); $keymap_data = array('vnc_keymap' => $etva_server->getVnckeymap(), 'vnc_keymap_default' => $etva_server->getVncKeymapDefault(), 'keymap_default' => $keymap_val); $return = array('success' => true, 'total' => $count, 'data' => array_merge($server_array, $keymap_data)); $result = json_encode($return); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($result); }
public function hasEtvaServerLogicals() { $count = EtvaServerLogicalQuery::create()->filterByServerId($this->getId())->count(); return $count ? true : false; }