public function setPhysicalvolumes($v) { if (!($etva_cluster = $this->getEtvaCluster())) { return; } $list = array($v); $criteria = new Criteria(); $criteria->add(EtvaPhysicalvolumePeer::CLUSTER_ID, $etva_cluster->getId()); $etva_volphys = $this->getEtvaVolumePhysicals(); $etva_phys_uuid = array(); if ($etva_volphys) { foreach ($etva_volphys as $etva_volphy) { $etva_phy = $etva_volphy->getEtvaPhysicalvolume(); $etva_phys_uuid[$etva_phy->getUuid()] = $etva_phy; } } foreach ($v as $pv => $device) { $device_array = (array) $device; $dev_uuid = $device_array['uuid']; if (in_array($dev_uuid, array_keys($etva_phys_uuid))) { $etva_physicalvol = $etva_phys_uuid[$dev_uuid]; } else { $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByUUID($dev_uuid, $criteria); } $etva_physicalvol->initData($device_array); if ($etva_physicalvol) { $this->physicalvolumes[] = $etva_physicalvol; } } return $this; }
public function initialize(EtvaNode $etva_node, $devs, $force_regist = false) { $etva_cluster = $etva_node->getEtvaCluster(); $volumegroup_names = array(); $errors = array(); /* * check shared vgs consistency (applies only for enterprise) */ $etva_data = Etva::getEtvaModelFile(); /*$etvamodel = $etva_data['model']; $consist = 1; if($etvamodel != 'standard') $consist = $this->check_shared_consistency($etva_node,$devs);*/ $check_res = $this->check_consistency($etva_node, $devs); if (!$check_res['success']) { $errors = $check_res['errors']; $inconsistent_message = Etva::getLogMessage(array('info' => ''), EtvaPhysicalvolumePeer::_ERR_INCONSISTENT_); $etva_node->setErrorMessage(self::PVINIT); $message = Etva::getLogMessage(array('info' => $inconsistent_message), EtvaPhysicalvolumePeer::_ERR_SOAPUPDATE_); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); //return array('success'=>false,'error'=>$errors); } /*if(!$consist){ $errors = $this->missing_pvs[$etva_node->getId()]; $inconsistent_message = Etva::getLogMessage(array('info'=>''), EtvaPhysicalvolumePeer::_ERR_INCONSISTENT_); $etva_node->setErrorMessage(self::PVINIT); $message = Etva::getLogMessage(array('info'=>$inconsistent_message), EtvaPhysicalvolumePeer::_ERR_SOAPUPDATE_); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(),'event.log',array('message' =>$message,'priority'=>EtvaEventLogger::ERR))); return array('success'=>false,'error'=>$errors); }*/ $physical_names = array(); foreach ($devs as $dev => $devInfo) { $dev_info = (array) $devInfo; $dev_type = $dev_info[EtvaPhysicalvolume::STORAGE_TYPE_MAP]; $dev_device = $dev_info[EtvaPhysicalvolume::DEVICE_MAP]; //error_log(sprintf("node name=%s id=%d device=%s uuid=%s type=%s",$etva_node->getName(),$etva_node->getId(),$dev_device,$dev_info[EtvaPhysicalvolume::UUID_MAP],$dev_type)); if ($dev_type == EtvaPhysicalvolume::STORAGE_TYPE_LOCAL_MAP) { $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByNodeTypeDevice($etva_node->getId(), $dev_type, $dev_device); } else { if (isset($dev_info[EtvaPhysicalvolume::UUID_MAP])) { $dev_uuid = $dev_info[EtvaPhysicalvolume::UUID_MAP]; $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByUUID($dev_uuid); } else { $dev_info[EtvaPhysicalvolume::UUID_MAP] = ''; // clean uuid $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByNodeTypeDevice($etva_node->getId(), $dev_type, $dev_device); } if (!$etva_physicalvol) { $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByNodeTypeDevice($etva_node->getId(), $dev_type, $dev_device); } if (!$etva_physicalvol) { $etva_physicalvol = EtvaPhysicalvolumePeer::retrieveByClusterTypeUUIDDevice($etva_node->getClusterId(), $dev_type, $dev_info[EtvaPhysicalvolume::UUID_MAP], $dev_device); } } if ($force_regist && !$etva_physicalvol) { // no pv in db... and force registration ... so create new one $etva_node_physicalvol = new EtvaNodePhysicalvolume(); $etva_physicalvol = new EtvaPhysicalvolume(); } else { if ($etva_physicalvol) { //if pv already in DB we need to make sure if already exists association with node. if not create new one $etva_node_physicalvol = EtvaNodePhysicalvolumePeer::retrieveByPK($etva_node->getId(), $etva_physicalvol->getId()); if (!$etva_node_physicalvol) { $etva_node_physicalvol = new EtvaNodePhysicalvolume(); } } } if ($etva_physicalvol) { $etva_physicalvol->initData($dev_info); $etva_physicalvol->setEtvaCluster($etva_cluster); $etva_node_physicalvol->setEtvaPhysicalvolume($etva_physicalvol); $etva_node_physicalvol->setEtvaNode($etva_node); $etva_node_physicalvol->setDevice($dev_device); $etva_node_physicalvol->save(); $physical_names[] = $etva_physicalvol->getName(); } // TODO treat ignoring cases } if (!empty($errors)) { // if have some errors, return it return array('success' => false, 'error' => $errors); } else { /* * check if is an appliance restore operation... */ $apli = new Appliance(); $action = $apli->getStage(Appliance::RESTORE_STAGE); if ($action) { $apli->setStage(Appliance::RESTORE_STAGE, Appliance::VA_UPDATE_PVS); } $etva_node->clearErrorMessage(self::PVINIT); $message = Etva::getLogMessage(array('info' => implode(', ', $physical_names)), EtvaPhysicalvolumePeer::_OK_SOAPUPDATE_); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message))); return array('success' => true, 'response' => $physical_names); } }