/** * * load network devices from system-config-network-cmd data to a SystemNetwork object * */ public function loadSystemNetworks($devices) { $dns_tmp = array(); $matches_to_found = array(); $this->networks = array(); $i = 0; foreach ($devices as $type => $device) { $aux_network = new SystemNetwork(); $aux_network->fromArray(array('if' => $device)); $this->networks[$device] = $aux_network; $matches_to_found[$i] = array('type' => $type, 'if' => $device, 'match' => "/([\\w\\.]+\\.(\\w+))\\.Device={$device}/"); $i++; } $path = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . "utils"; if (!($p = popen('echo /usr/sbin/system-config-network-cmd -e 2>&1 | sudo /usr/bin/php -f ' . $path . '/sudoexec.php', 'r'))) { throw new Exception('could not execute system-config-network-cmd'); return false; } $aux = array(); $re_if = ''; $re_dev = ''; $if = ''; $profile = ''; while (!feof($p)) { $r = fgets($p); //get profile for dns $match = "/(ProfileList\\.[\\w\\.]+)\\.Active=true/"; if (preg_match($match, $r, $regs)) { $profile = $regs[1]; foreach ($aux as $st) { $match = "/{$profile}\\.DNS\\.(\\w+.DNS)=(.+)/"; if (preg_match($match, $st, $regs)) { $dns_tmp[$regs[1]] = $regs[2]; } } } elseif ($profile && preg_match("/{$profile}\\.DNS\\.(\\w+.DNS)=(.+)/", $r, $regs)) { $dns_tmp[$regs[1]] = $regs[2]; } //end dns stuff foreach ($matches_to_found as $match_data) { $match = $match_data['match']; $match_if = $match_data['if']; if (preg_match($match, $r, $regs)) { $re_if = $regs[1]; $re_dev = $match_if; $if = $regs[2]; $aux[] = $r; foreach ($aux as $st) { $match = "/{$re_if}\\.(\\w+)=(.+)/"; if (preg_match($match, $st, $regs)) { $this->networks[$match_if]->set($regs[1], $regs[2]); } } } elseif ($re_if && $re_dev == $match_if && preg_match("/{$re_if}\\.(\\w+)=(.+)/", $r, $regs)) { $this->networks[$match_if]->set($regs[1], $regs[2]); } else { $aux[] = $r; } } //end foreach devices } //end while read data fclose($p); //udpate networks dns foreach ($this->networks as $network) { $network->fromArray($dns_tmp, false); } }
public function send_change_ip($network) { $sys_network = new SystemNetwork(); if (!$sys_network->fromArray($network)) { $intf = $network['if']; $msg_i18n = sfContext::getInstance()->getI18N()->__(SystemNetwork::_ERR_NOTFOUND_INTF_, array('%name%' => $intf, '%info%' => '')); //notify event log $node_log = Etva::getLogMessage(array('name' => $intf, 'info' => ''), SystemNetwork::_ERR_NOTFOUND_INTF_); $message = Etva::getLogMessage(array('name' => sfConfig::get('config_acronym'), 'info' => $node_log), EtvaNodePeer::_ERR_CHANGEIP_); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n); return $error; } $criteria = new Criteria(); $criteria->add(EtvaNodePeer::ID, $this->etva_node->getId(), Criteria::NOT_EQUAL); $cluster_nodes = $this->etva_node->getNodesCluster($criteria); foreach ($cluster_nodes as $node) { $node_name = $node->getName(); $node_ip = $node->getIp(); if ($sys_network->get(SystemNetwork::IP) == $node_ip) { $msg_i18n = sfContext::getInstance()->getI18N()->__(SystemNetwork::_ERR_IP_INUSE_, array('%ip%' => $node_ip, '%name%' => $node_name)); $msg = Etva::getLogMessage(array('ip' => $node_ip, 'name' => $node_name), SystemNetwork::_ERR_IP_INUSE_); $message = Etva::getLogMessage(array('name' => sfConfig::get('config_acronym'), 'info' => $msg), EtvaNodePeer::_ERR_CHANGEIP_); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); $error = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_i18n); return $error; } } $method = self::CHANGE_IP; $params = $sys_network->_VA(); /* * update MA if any... * */ $etva_servers = $this->etva_node->getEtvaServers(); foreach ($etva_servers as $etva_server) { $server_ma = $etva_server->getAgentTmpl(); $server_state = $etva_server->getState(); if ($server_state && $server_ma) { $etva_server->setSoapTimeout(5); $response = $etva_server->soapSend($method, $params); $result = $this->processChangeIpResponse($response, $method); } } $this->etva_node->setSoapTimeout(5); $response = $this->etva_node->soapSend($method, $params); $result = $this->processChangeIpResponse($response, $method); return $result; }
private function localUpdate($net) { $sys = new SystemNetwork(); if (!$sys->fromArray($net)) { return false; } $updated_network = SystemNetworkUtil::updateLocalNetwork($sys); if (!$updated_network) { return false; } return true; }