diff --git a/README.md b/README.md index 03a083d..5fed996 100644 --- a/README.md +++ b/README.md @@ -7,41 +7,50 @@ You have to use base PHP-CLI SHELL project that is here: https://github.com/clou # REQUIREMENTS #### PATCHMANAGER -* Import profiles which are in ressources/dcim +* Import profiles which are in addons/dcim/ressources * formats: ressources/dcim/formats * Reports: ressources/dcim/reports * Searches: ressources/dcim/searches -__*/!\ Version 1.1 add new profiles!*__ + +__*/!\ Do not rename custom profiles*__ +__*/!\ Version 2.0 add new profiles!*__ # INSTALLATION #### APT PHP +Ubuntu only, you can get last PHP version from this PPA: __*https://launchpad.net/~ondrej/+archive/ubuntu/php*__ * add-apt-repository ppa:ondrej/php -* apt-get update -* apt install php7.1-cli php7.1-mbstring php7.1-readline php7.1-soap -__Do not forget to install php7.1-soap__ +* apt update + +You have to install a PHP version >= 7.1: +* apt update +* apt install php7.2-cli php7.2-soap php7.2-mbstring php7.2-readline php7.2-curl +__Do not forget to install php7.2-soap__ #### REPOSITORIES * git clone https://github.com/cloudwatt/php-cli-shell_base -* git checkout tags/v1.1 +* git checkout tags/v2.0 * git clone https://github.com/cloudwatt/php-cli-shell_patchmanager -* git checkout tags/v1.1 +* git checkout tags/v2.0 * Merge these two repositories #### CONFIGURATION FILE -* mv configurations/config.json.example configurations/config.json -* vim configurations/config.json - * servers field contains all PatchManager server addresses which must be identified by custom key [DCIM_SERVER_KEY] +* mv configurations/dcim.json.example configurations/dcim.json +* vim configurations/dcim.json + * servers field contains all PatchManager server which must be identified by custom key [DCIM_SERVER_KEY] __server key must be unique and you will use it on next steps. You have an example in config file__ - * userAttrs field contains all custom attributes which must be created on your PatchManager - __If you have a serial number custom attribute, change [PM_ATTR_SN] with the name of this attribute__ + * userAttrs section contains all custom attributes which must be created in your PatchManager + __If you have a serial number custom attribute, change [PM_ATTR_SN] with the name of this attribute otherwise leave false__ + * preferences section contains all options about PatchManager + __CSV delimiter option must be identical between PHP-CLI configuration and PatchManager user preferences__ * Optionnal * You can create user configuration files to overwrite some configurations These files will be ignored for commits, so your user config files can not be overwrited by a futur release - * vim configurations/config.user.json - Change configuration like browserCmd + * mv configurations/dcim.user.json.example configurations/dcim.user.json + * vim configurations/dcim.user.json + Change configuration like browserCmd or DCIM preferences * All *.user.json files are ignored by .gitignore #### PHP LAUNCHER FILE @@ -50,7 +59,7 @@ __Do not forget to install php7.1-soap__ * Change [DCIM_SERVER_KEY] with the key of your PatchManager server in configuration file #### CREDENTIALS FILE -/!\ For security reason, use a read only account! +/!\ For security reason, you can use a read only account! __*Change informations which are between []*__ * vim credentialsFile * read -sr USER_PASSWORD_INPUT diff --git a/addons/dcim/api/abstract.php b/addons/dcim/api/abstract.php new file mode 100644 index 0000000..72e5922 --- /dev/null +++ b/addons/dcim/api/abstract.php @@ -0,0 +1,307 @@ +_DCIM_ = &$this->_ownerAdapter; // /!\ A executer avant _setObjectId + $this->_setObjectId($objectId); // @todo temp + } + + public static function objectIdIsValid($objectId) + { + return C\Tools::is('int&&>0', $objectId); + } + + public function hasObjectId() + { + return ($this->_objectId !== null); + } + + public function getObjectId() + { + return $this->_objectId; + } + + public function objectExists() + { + if($this->_objectExists !== null) { + return $this->_objectExists; + } + elseif($this->hasObjectId()) { + $this->_objectExists = ($this->_getObject() !== false); + return $this->_objectExists; + } + else { + return false; + } + } + + protected function _setObjectLabel($objectLabel) + { + if(!$this->objectExists() && C\Tools::is('string&&!empty', $objectLabel)) { + $this->_objectLabel = $objectLabel; + return true; + } + else { + return false; + } + } + + public function hasObjectLabel() + { + return ($this->getObjectLabel() !== false); + } + + public function getObjectLabel() + { + if($this->_objectLabel !== null) { // /!\ Ne pas appeler hasObjectLabel sinon boucle infinie + return $this->_objectLabel; + } + elseif($this->hasObjectId()) { // /!\ Ne pas appeler objectExists sinon boucle infinie + $objectDatas = $this->_getObject(); + $this->_objectLabel = ($objectDatas !== false) ? ($objectDatas[static::FIELD_NAME]) : (false); + return $this->_objectLabel; + } + else { + return false; + } + } + + /** + * Méthode courte comme getPath + */ + public function getLabel() + { + return $this->getObjectLabel(); + } + + public function getTemplateName() + { + if($this->objectExists()) { + $result = $this->_DCIM->resolvToTemplate(static::OBJECT_TYPE, $this->getObjectId()); + return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); + } + else { + return false; + } + } + + /** + * @param string $category + * @param null|string $attribute + * @return false|string + */ + public function getUserAttrField($category, $attribute = null) + { + if(!C\Tools::is('string&&!empty', $attribute)) { + $attribute = $category; + $category = 'default'; + $noCateg = true; + } + + $attrField = $this->_DCIM->getUserAttrName($category, $attribute); + return ($attrField === false && isset($noCateg)) ? ($attribute) : ($attrField); + } + + /** + * @param string $category + * @param null|string $attribute + * @return false|string + */ + public function getUserAttribute($category, $attribute = null) + { + if($this->objectExists()) + { + $attrField = $this->getUserAttrField($category, $attribute); + + if($attrField !== false) { + $result = $this->_DCIM->getUserAttrById(static::OBJECT_TYPE, $this->getObjectId(), $attrField); + return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); + } + } + + return false; + } + + public function __get($name) + { + switch($name) + { + case 'dcim': + case '_DCIM': { + return self::$_DCIM; + } + case 'id': { + return $this->getObjectId(); + } + case 'label': { + return $this->getObjectLabel(); + } + case 'templateName': { + return $this->getTemplateName(); + } + default: { + throw new Exception("This attribute '".$name."' does not exist", E_USER_ERROR); + } + } + } + + public function __call($method, $parameters = null) + { + if(substr($method, 0, 3) === 'get') + { + $name = substr($method, 3); + $name = mb_strtolower($name); + + switch($name) + { + case 'label': { + return $this->getObjectLabel(); + } + } + } + + throw new Exception("Method '".$method."' does not exist", E_USER_ERROR); + } + + /** + * @param string $section + * @param array $attributes + * @return false|string + */ + protected static function _getReportName($section, array $attributes) + { + if(array_key_exists($section, static::REPORT_NAMES)) + { + $reportNames = static::REPORT_NAMES[$section]; + $attributes = implode('&', $attributes); + + if(is_string($reportNames)) { + return $reportNames; + } + elseif(is_array($reportNames) && array_key_exists($attributes, $reportNames)) { + return $reportNames[$attributes]; + } + } + + return false; + } + + /** + * @param string $reportName + * @param null|array $args + * @param false|string $fieldNameFilter + * @throw Addon\Dcim\Exception + * @return array + */ + protected static function _getObjectsFromReport($reportName, array $args = null, $fieldNameFilter = false) + { + if($args !== null) + { + array_walk($args, function(&$item) + { + if(!C\Tools::is('human', $item)) { + $item = static::WILDCARD; + } + }); + } + + // @todo use _getReportName + $results = self::$_DCIM->getReportResults(static::REPORT_NAMES[$reportName], $args); + + if(C\Tools::is('array&&count>0', $results)) + { + if($fieldNameFilter !== false) { + $results = array_column($results, $fieldNameFilter); + } + + return $results; + } + else { + throw new Exception("Unable to retrieve objects from report '".$reportName."'", E_USER_ERROR); + } + } + + /** + * @param Addon\Dcim\Main|Addon\Dcim\Main[] $DCIM + * @return bool + */ + public static function setDcim($DCIM) + { + return self::setAdapter($DCIM); + } + + /** + * @param Addon\Dcim\Main|Addon\Dcim\Main[] $adapter + * @throw Core\Exception + * @return bool + */ + public static function setAdapter($adapter) + { + $status = parent::setAdapter($adapter); + + if($status) { + self::$_DCIM = &self::$_adapter; + self::$_aDCIM = &self::$_allAdapters; + } + + return $status; + } + + /** + * @return null|Addon\Dcim\Main|Addon\Dcim\Main[] + */ + public static function getDcim() + { + return self::getAdapter(); + } + + /** + * @param string $key + * @return bool + */ + public static function enableDcim($key) + { + return self::enableAdapter($key); + } + + /** + * @return null|Addon\Dcim\Main + */ + public static function getDcimEnabled() + { + return self::getAdapterEnabled(); + } + } \ No newline at end of file diff --git a/addons/dcim/api/abstract/location.php b/addons/dcim/api/abstract/location.php new file mode 100644 index 0000000..e0f88a4 --- /dev/null +++ b/addons/dcim/api/abstract/location.php @@ -0,0 +1,62 @@ +objectExists() && C\Tools::is('int&&>0', $locationId)) { + $this->_locationId = $locationId; + return true; + } + else { + return false; + } + } + + public function hasLocationId() + { + return ($this->getLocationId() !== false); + } + + abstract public function getLocationId(); + + public function getLocationApi() + { + if($this->_locationApi === null) + { + $locationId = $this->getLocationId(); + + if($locationId !== false) { + $this->_locationApi = new Api_Location($locationId); + } + else { + $this->_locationApi = false; + } + } + + return $this->_locationApi; + } + + /** + * @return void + */ + protected function _resetLocation() + { + $this->_locationId = null; + $this->_locationApi = null; + } + } \ No newline at end of file diff --git a/addons/dcim/api/cabinet.php b/addons/dcim/api/cabinet.php new file mode 100644 index 0000000..bd4d9bf --- /dev/null +++ b/addons/dcim/api/cabinet.php @@ -0,0 +1,333 @@ + 'CW - TOOLS-CLI - Cabinet0', + 'label' => 'CW - TOOLS-CLI - Cabinet1', + 'location' => 'CW - TOOLS-CLI - Cabinet2', + 'subLocation' => 'CW - TOOLS-CLI - Cabinet3', + ); + + const FIELD_ID = 'entity_id'; + const FIELD_NAME = 'name'; + const FIELD_DESC = 'description'; + + const SIDE_FRONT = 'front'; + const SIDE_REAR = 'rear'; + + /** + * Enable or disable cache feature + * /!\ Cache must be per type + * + * @var array + */ + protected static $_cache = array(); // DCIM server ID keys, boolean value + + /** + * All cabinets (cache) + * /!\ Cache must be per type + * + * @var array + */ + protected static $_objects = array(); // DCIM server ID keys, array value + + + public function cabinetIdIsValid($cabinetId) + { + return $this->objectIdIsValid($cabinetId); + } + + public function hasCabinetId() + { + return $this->hasObjectId(); + } + + public function getCabinetId() + { + return $this->getObjectId(); + } + + public function cabinetExists() + { + return $this->objectExists(); + } + + public function getCabinetLabel() + { + return $this->getObjectLabel(); + } + + protected function _getObject() + { + if($this->_objectExists === null || $this->objectExists()) + { + if($this->_objectDatas === null) + { + $args = array('cabinetid' => $this->getCabinetId()); + $results = $this->_DCIM->getReportResults(self::REPORT_NAMES['self'], $args); + + if(count($results) === 1) { + $this->_objectDatas = $results[0]; + } + else { + $this->_objectDatas = false; + } + } + + return $this->_objectDatas; + } + else { + return false; + } + } + + public function getLocationId() + { + if($this->cabinetExists()) + { + if($this->_locationId === null) + { + // Solution sans rapport + /*$equipmentIds = $this->getEquipmentIds(); + + if(C\Tools::is('array&&count>0', $equipmentIds)) + { + $equipmentId = current($equipmentIds); + + $Api_Equipment = new Api_Equipment($equipmentId); + $locationId = $Api_Equipment->getLocationId(); + $this->_locationId = ($locationId !== false) ? ($locationId) : (false); + } + else { + $this->_locationId = false; + }*/ + + $args = array('cabinetid' => $this->getCabinetId()); + $results = self::$_DCIM->getReportResults(self::REPORT_NAMES['self'], $args); + + if(count($results) === 1) { + $result = $results[0]; + $this->_locationId = $result['location_id']; + } + else { + $this->_locationId = false; + } + } + + return $this->_locationId; + } + else { + return false; + } + } + + public function getTemplateU() + { + $templateU = $this->_getField('template_u', 'string&&!empty'); + $templateU = substr($templateU, 0, -1); + + return (C\Tools::is('int&&>0', $templateU)) ? ((int) $templateU) : (false); + } + + public function getPath($includeLabel = false, $pathSeparator = false) + { + $locationApi = $this->getLocationApi(); + + if($locationApi !== false) + { + $path = $locationApi->getPath(true, $pathSeparator); + + if($path !== false && $includeLabel) + { + if($pathSeparator === false) { + $pathSeparator = self::SEPARATOR_PATH; + } + + $path .= $pathSeparator.$this->getCabinetLabel(); + } + + return $path; + } + else { + return false; + } + } + + /** + * @return array All equipment IDs or empty array + */ + public function getEquipmentIds() + { + if($this->cabinetExists()) { + return $this->_DCIM->getEquipmentIdsByCabinetId($this->getCabinetId()); + } + else { + return array(); + } + } + + public function getEquipmentId($equipmentLabel) + { + if($this->cabinetExists()) { + $result = $this->_DCIM->getEquipmentIdByCabinetIdEquipmentLabel($this->getCabinetId(), $equipmentLabel); + return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); + } + else { + return false; + } + } + + public function getEquipmentIdByU($positionU) + { + if(preg_match('#^u([0-9]{1,2})$#i', $positionU, $position)) { + $positionU = (int) $position[1]; + } + + if(C\Tools::is('int&&>0', $positionU)) + { + $equipments = Api_Equipment::searchEquipments('*', null, null, $this->getCabinetId(), null, false, true); + + foreach($equipments as $equipment) + { + if((int) $equipment['position_u'] === (int) $positionU) { + return $equipment[self::FIELD_ID]; + } + } + } + + return false; + } + + public function findEquipments($equipmentLabel, $equipmentDesc, $equipmentSN, $recursion = false, $firstLevel = true) + { + if($this->hasCabinetId()) { + $cabinetId = $this->getCabinetId(); + return Api_Equipment::searchEquipments($equipmentLabel, $equipmentDesc, $equipmentSN, $cabinetId, null, $recursion, $firstLevel); + } + else { + return false; + } + } + + /** + * @param bool $resetObjectId + * @return void + */ + protected function _hardReset($resetObjectId = false) + { + $this->_softReset($resetObjectId); + $this->_resetAttributes(); + $this->_resetLocation(); + } + + protected function _resetAttributes() + { + } + + public function __get($name) + { + switch($name) + { + case 'description': { + return $this->_getField(self::FIELD_DESC, 'string&&!empty'); + } + case 'locationApi': { + return $this->getLocationApi(); + } + default: { + return parent::__get($name); + } + } + } + + public function __call($method, $parameters = null) + { + if(substr($method, 0, 3) === 'get') + { + $name = substr($method, 3); + $name = mb_strtolower($name); + + switch($name) + { + case 'description': { + return $this->_getField(self::FIELD_DESC, 'string&&!empty'); + } + } + } + + return parent::__call($method, $parameters); + } + + /** + * Return all cabinets matches request + * + * @param $cabinetLabel string Cabinet label, wildcard * is allowed + * @param $locationId int location ID + * @param $recursion bool + * @return false|array + */ + public static function searchCabinets($cabinetLabel, $locationId = null, $recursion = false) + { + $args = array('label' => $cabinetLabel); + + array_walk($args, function(&$item) + { + if(!C\Tools::is('human', $item)) { + $item = self::WILDCARD; + } + }); + + if(C\Tools::is('int&&>0', $locationId)) { + $args['locationid'] = $locationId; + $reportName = ($recursion) ? ('subLocation') : ('location'); + } + else { + $reportName = 'label'; + } + + $results = self::$_DCIM->getReportResults(self::REPORT_NAMES[$reportName], $args); + + if($results !== false) + { + foreach($results as &$result) { + $fullPath = explode(self::SEPARATOR_PATH, $result['fullpath']); + $fullPath = array_reverse($fullPath); + $fullPath[] = $result['location_name']; + $result['path'] = implode(self::SEPARATOR_PATH, $fullPath); + $result['fullpath'] = $result['path']; + } + } + + return $results; + } + + /** + * @param Addon\Dcim\Main $DCIM + * @return bool + */ + protected static function _setObjects(C\Addon\Adapter $DCIM = null) + { + if($DCIM === null) { + $DCIM = self::$_DCIM; + } + + $id = $DCIM->getServerId(); + $result = self::searchCabinets(self::WILDCARD); + + if($result !== false) { + self::$_objects[$id] = $result; + return true; + } + else { + return false; + } + } + } \ No newline at end of file diff --git a/addons/dcim/api/cable.php b/addons/dcim/api/cable.php new file mode 100644 index 0000000..c5b5084 --- /dev/null +++ b/addons/dcim/api/cable.php @@ -0,0 +1,327 @@ + 'CW - TOOLS-CLI - Cable0', + 'label' => 'CW - TOOLS-CLI - Cable1', + 'equipment' => 'CW - TOOLS-CLI - Cable2', + ); + + const FIELD_ID = 'entity_id'; + const FIELD_NAME = 'label'; + const FIELD_DESC = 'description'; + + + public function cableIdIsValid($cableId) + { + return $this->objectIdIsValid($cableId); + } + + public function hasCableId() + { + return $this->hasObjectId(); + } + + public function getCableId() + { + return $this->getObjectId(); + } + + public function cableExists() + { + return $this->objectExists(); + } + + public function setCableLabel($cableLabel) + { + return $this->_setObjectLabel($cableLabel); + } + + public function hasCableLabel() + { + return $this->hasObjectLabel(); + } + + public function getCableLabel() + { + return $this->getObjectLabel(); + } + + protected function _getObject() + { + if($this->_objectExists === null || $this->objectExists()) + { + if($this->_objectDatas === null) + { + $args = array('cableid' => $this->getCableId()); + $results = $this->_DCIM->getReportResults(self::REPORT_NAMES['self'], $args); + + if(count($results) === 1) { + $this->_objectDatas = $results[0]; + } + else { + $this->_objectDatas = false; + } + } + + return $this->_objectDatas; + } + else { + return false; + } + } + + /** + * Do not call hasLocationId otherwise risk of infinite loop + */ + public function getLocationId() + { + if($this->cableExists()) + { + if($this->_locationId === null) + { + $args = array('cableid' => $this->getCableId()); + $results = $this->_DCIM->getReportResults(self::REPORT_NAMES['self'], $args); + + if(count($results) === 1) { + $this->_locationId = $result['location_id']; + } + else { + $this->_locationId = false; + } + } + + return $this->_locationId; + } + elseif($this->_locationId !== null) { + return $this->_locationId; + } + else { + return false; + } + } + + /** + * @return array All port IDs or empty array + */ + public function getPortIds() + { + // @todo a coder + return array(); + } + + /** + * @param $template string + * @param $label string + * @return false|int Cable ID or false if error has occured + */ + public function cabling($template, $label = null) + { + $this->_errorMessage = null; + + if(!$this->cableExists()) + { + if($this->hasLocationId()) + { + if($this->_DCIM->templateExists($template)) + { + if($label === null && $this->hasCableLabel()) { + $label = $this->getCableLabel(); + } + + try { + $cableId = $this->_DCIM->addCable($this->getLocationId(), $template, $label); + } + catch(E\Message $e) { + $this->_errorMessage = "Unable to create cable '".$template."' '".$label."' to location '".$this->locationApi->label."' in DCIM: ".$e->getMessage(); + $cableId = false; + } + + if($cableId !== false) { + $this->_hardReset(false); + $this->_setObjectId($cableId); + return $cableId; + } + } + else { + $this->_errorMessage = "DCIM template '".$template."' is missing"; + } + } + else { + $this->_errorMessage = "DCIM location is required"; + } + } + else { + $this->_errorMessage = "DCIM cable '".$this->label."' already exists"; + } + + return false; + } + + /** + * @param $portApi Addon\Dcim\Api_Equipment_Port + * @return false|true + */ + public function connect(Api_Equipment_Port $portApi) + { + $this->_errorMessage = null; + + if($this->cableExists()) + { + if($portApi->portExists()) + { + try { + $cableId = $this->_DCIM->connectCable($this->getCableId(), $portApi->id); + } + catch(E\Message $e) { + $this->_errorMessage = "Unable to connect cable '".$this->label."' to port '".$portApi->label."' in DCIM: ".$e->getMessage(); + $cableId = false; + } + + if($cableId !== false) { + return true; + } + } + else { + $this->_errorMessage = "DCIM port '".$portApi->label."' does not exist"; + } + } + else { + $this->_errorMessage = "DCIM cable does not exist"; + } + + return false; + } + + /** + * @param string $label + * @return bool + */ + public function renameLabel($label) + { + return $this->_updateInfos($label, $this->description); + } + + /** + * @param string $description + * @return bool + */ + public function setDescription($description) + { + return $this->_updateInfos($this->label, $description); + } + + /** + * @param string $label + * @param string $description + * @return bool + */ + public function updateInfos($label, $description) + { + return $this->_updateInfos($label, $description); + } + + /** + * @param string $label + * @param string $description + * @return bool + */ + protected function _updateInfos($label, $description) + { + if($this->cableExists()) + { + try { + $status = $this->_DCIM->updateCableInfos($this->getCableId(), $label, $description); + } + catch(E\Message $e) { + $this->_errorMessage = "Unable to update cable informations from DCIM: ".$e->getMessage(); + $status = false; + } + + $this->refresh(); + return $status; + } + else { + return false; + } + } + + /** + * @return bool + */ + public function remove() + { + $this->_errorMessage = null; + + if($this->cableExists()) + { + try { + $status = $this->_DCIM->removeCable($this->getCableId()); + } + catch(E\Message $e) { + $this->_errorMessage = "Unable to remove cable from DCIM: ".$e->getMessage(); + $status = false; + } + + $this->_hardReset(); + return $status; + } + else { + $this->_errorMessage = "DCIM cable does not exist"; + } + + return false; + } + + /** + * @param bool $resetObjectId + * @return void + */ + protected function _hardReset($resetObjectId = false) + { + $this->_softReset($resetObjectId); + $this->_resetAttributes(); + $this->_resetLocation(); + } + + protected function _resetAttributes() + { + } + + public function __get($name) + { + switch($name) + { + case 'description': { + return $this->_getField(self::FIELD_DESC, 'string&&!empty'); + } + default: { + return parent::__get($name); + } + } + } + + public function __call($method, $parameters = null) + { + if(substr($method, 0, 3) === 'get') + { + $name = substr($method, 3); + $name = mb_strtolower($name); + + switch($name) + { + case 'description': { + return $this->_getField(self::FIELD_DESC, 'string&&!empty'); + } + } + } + + return parent::__call($method, $parameters); + } + } \ No newline at end of file diff --git a/addons/dcim/api/equipment.php b/addons/dcim/api/equipment.php new file mode 100644 index 0000000..ff03ed1 --- /dev/null +++ b/addons/dcim/api/equipment.php @@ -0,0 +1,945 @@ + 'CW - TOOLS-CLI - Equipment0', + 'label' => array( + 'label' => 'CW - TOOLS-CLI - Equipment1-0', + 'description' => 'CW - TOOLS-CLI - Equipment1-1', + 'serialNumber' => 'CW - TOOLS-CLI - Equipment1-2', + 'label&description' => 'CW - TOOLS-CLI - Equipment1-3', + 'label&serialnumber' => 'CW - TOOLS-CLI - Equipment1-4', + 'description&serialnumber' => 'CW - TOOLS-CLI - Equipment1-5', + 'label&description&serialnumber' => 'CW - TOOLS-CLI - Equipment1-6', + ), + 'cabinet' => array( + 'label' => 'CW - TOOLS-CLI - Equipment4-0', + 'description' => 'CW - TOOLS-CLI - Equipment4-1', + 'serialNumber' => 'CW - TOOLS-CLI - Equipment4-2', + 'label&description' => 'CW - TOOLS-CLI - Equipment4-3', + 'label&serialnumber' => 'CW - TOOLS-CLI - Equipment4-4', + 'description&serialnumber' => 'CW - TOOLS-CLI - Equipment4-5', + 'label&description&serialnumber' => 'CW - TOOLS-CLI - Equipment4-6', + ), + 'location' => array( + 'label' => 'CW - TOOLS-CLI - Equipment2-0', + 'description' => 'CW - TOOLS-CLI - Equipment2-1', + 'serialNumber' => 'CW - TOOLS-CLI - Equipment2-2', + 'label&description' => 'CW - TOOLS-CLI - Equipment2-3', + 'label&serialnumber' => 'CW - TOOLS-CLI - Equipment2-4', + 'description&serialnumber' => 'CW - TOOLS-CLI - Equipment2-5', + 'label&description&serialnumber' => 'CW - TOOLS-CLI - Equipment2-6', + ), + 'subLocation' => array( + 'label' => 'CW - TOOLS-CLI - Equipment3-0', + 'description' => 'CW - TOOLS-CLI - Equipment3-1', + 'serialNumber' => 'CW - TOOLS-CLI - Equipment3-2', + 'label&description' => 'CW - TOOLS-CLI - Equipment3-3', + 'label&serialnumber' => 'CW - TOOLS-CLI - Equipment3-4', + 'description&serialnumber' => 'CW - TOOLS-CLI - Equipment3-5', + 'label&description&serialnumber' => 'CW - TOOLS-CLI - Equipment3-6', + ), + ); + + const FIELD_ID = 'entity_id'; + const FIELD_NAME = 'label'; + const FIELD_DESC = 'description'; + + /** + * Enable or disable cache feature + * /!\ Cache must be per type + * + * @var array + */ + protected static $_cache = array(); // DCIM server ID keys, boolean value + + /** + * All equipements (cache) + * /!\ Cache must be per type + * + * @var array + */ + protected static $_objects = array(); // DCIM server ID keys, array value + + /** + * @var int + */ + protected $_cabinetId = null; + + /** + * @var Addon\Dcim\Api_Cabinet + */ + protected $_cabinetApi = null; + + /** + * array(0 => $matches[2], 1 => $matches[1], 'side' => $matches[2], 'U' => $matches[1]) + * @var array + */ + protected $_position = null; + + /** + * @var string + */ + protected $_serialNumber = null; + + + public function equipmentIdIsValid($equipmentId) + { + return $this->objectIdIsValid($equipmentId); + } + + public function hasEquipmentId() + { + return $this->hasObjectId(); + } + + public function getEquipmentId() + { + return $this->getObjectId(); + } + + public function equipmentExists() + { + return $this->objectExists(); + } + + public function setEquipmentLabel($equipmentLabel) + { + return $this->_setObjectLabel($equipmentLabel); + } + + public function hasEquipmentLabel() + { + return $this->hasObjectLabel(); + } + + public function getEquipmentLabel() + { + return $this->getObjectLabel(); + } + + protected function _getObject() + { + if($this->_objectExists === null || $this->objectExists()) + { + if($this->_objectDatas === null) + { + $args = array('equipmentid' => $this->getEquipmentId()); + $results = $this->_DCIM->getReportResults(self::REPORT_NAMES['self'], $args); + + if(count($results) === 1) { + $this->_objectDatas = $results[0]; + } + else { + $this->_objectDatas = false; + } + } + + return $this->_objectDatas; + } + else { + return false; + } + } + + /** + * Do not call hasLocationId otherwise risk of infinite loop + */ + public function getLocationId() + { + if($this->equipmentExists()) + { + if($this->_locationId === null) { + $result = $this->_DCIM->getLocationIdByEquipmentId($this->getEquipmentId()); + $this->_locationId = ($this->_DCIM->isValidReturn($result)) ? ((int) $result) : (false); + } + + return $this->_locationId; + } + elseif($this->_locationId !== null) { + return $this->_locationId; + } + else { + return false; + } + } + + public function getCabinetId() + { + if($this->equipmentExists()) { + $result = $this->_DCIM->getCabinetIdByEquipmentId($this->getEquipmentId()); + return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); + } + else { + return false; + } + } + + public function getCabinetApi() + { + if($this->_cabinetApi === null) + { + $cabinetId = $this->getCabinetId(); + + if($cabinetId !== false) { + $this->_cabinetApi = new Api_Cabinet($cabinetId); + } + else { + $this->_cabinetApi = false; + } + } + + return $this->_cabinetApi; + } + + public function getPath($includeLabel = false, $pathSeparator = false) + { + $locationApi = $this->getLocationApi(); + $cabinetApi = $this->getCabinetApi(); + + /** + * Un equipement est obligatoirement dans une moins un emplacement + * Mais il n'est pas forcément dans une baie, donc ne pas tester $cabinetApi immédiatement + */ + if($locationApi !== false) + { + $path = $locationApi->getPath(true, $pathSeparator); + + if($path !== false) + { + if($cabinetApi !== false) + { + $cabinetLabel = $cabinetApi->getLabel(); + + if($cabinetLabel !== false) { + $path .= self::SEPARATOR_PATH.$cabinetLabel; + } + } + + if($includeLabel) + { + if($pathSeparator === false) { + $pathSeparator = self::SEPARATOR_PATH; + } + + $path .= $pathSeparator.$this->getEquipmentLabel(); + } + } + + return $path; + } + else { + return false; + } + } + + // array(0 => $matches[2], 1 => $matches[1], 'side' => $matches[2], 'U' => $matches[1]) + public function getPosition() + { + if($this->equipmentExists()) + { + if($this->_position === null) { + $this->_position = $this->_DCIM->getUByEquipmentId($this->getEquipmentId()); + } + + return $this->_position; + } + else { + return false; + } + } + + public function getPositionU() + { + return (($position = $this->getPosition()) !== false) ? ($position['U']) : (false); + } + + public function getPositionSide() + { + return (($position = $this->getPosition()) !== false) ? ($position['side']) : (false); + } + + public function getTemplateU() + { + $templateU = $this->_getField('template_u', 'string&&!empty'); + $templateU = substr($templateU, 0, -1); + + if(C\Tools::is('int&&>0', $templateU)) { + return (int) $templateU; + } + elseif(C\Tools::is('float&&>0', (float) $templateU)) { + return (int) ceil($templateU); + } + else { + return false; + } + } + + public function getSerialNumber() + { + if($this->equipmentExists()) + { + if($this->_serialNumber === null) { + $this->_serialNumber = $this->getUserAttribute('default', 'serialNumber'); + } + + return $this->_serialNumber; + } + else { + return false; + } + } + + /** + * Return the port ID of port label + * If no port ID is found or many port IDs are found, return false + * To get all port IDs of port label use getPortIds method + * + * @param $portLabel string Port label + * @return false|int Port ID or false if error has occured + */ + public function getPortId($portLabel) + { + if($this->equipmentExists()) { + return $this->_DCIM->getPortIdByParentEquipmentIdPortLabel($this->getEquipmentId(), $portLabel); + } + else { + return false; + } + } + + /** + * Retourne un tableau des ID des ports présents sur cet équipement + * ainsi que ceux présents sur les sous équipements (modules) + * + * @param $portLabel null|string Port label + * @return array All port IDs or empty array + */ + public function getPortIds($portLabel = null) + { + if($this->equipmentExists()) + { + if($portLabel === null) { + return $this->_DCIM->getPortIdsByEquipmentId($this->getEquipmentId()); + + } + else { + return $this->_DCIM->getPortIdsByParentEquipmentIdPortLabel($this->getEquipmentId(), $portLabel); + } + } + else { + return array(); + } + } + + /** + * Retourne un tableau des ID des ports connectés à cet équipement + * + * Les clés du tableau sont les IDs des ports connectés voisins à cet équipement + * Les valeurs du tableau sont les IDs des ports connectés présents sur cet équipement + * + * @return array All connected port IDs or empty array + */ + public function getConnectedPortIds() + { + $conPortIds = array(); + $portIds = $this->getPortIds(); + + foreach($portIds as $portId) + { + $result = $this->_DCIM->getConnectedPortIdByPortId($portId); + $nbPortId = ($this->_DCIM->isValidReturn($result)) ? ((int) $result) : (false); + + if($nbPortId !== false) { + $conPortIds[$nbPortId] = $portId; + } + } + + return $conPortIds; + } + + public function getSlotId($slotLabel) + { + if($this->equipmentExists()) { + return $this->_DCIM->getSlotIdByParentEquipmentIdSlotLabel($this->getEquipmentId(), $slotLabel); + } + else { + return false; + } + } + + /** + * @param $slotLabel null|string Slot label + * @return array All slot IDs or empty array + */ + public function getSlotIds($slotLabel = null) + { + if($this->equipmentExists()) + { + if($slotLabel === null) { + return $this->_DCIM->getSlotIdsByEquipmentId($this->getEquipmentId()); + } + else { + return $this->_DCIM->getSlotIdsByParentEquipmentIdSlotLabel($this->getEquipmentId(), $slotLabel); + } + } + else { + return array(); + } + } + + /** + * @param $slotId int Slot ID + * @return false|int Module ID + */ + public function getModuleId($slotId) + { + if($this->equipmentExists() && C\Tools::is('int&&>0', $slotId)) { + $result = $this->_DCIM->getEquipmentIdBySlotId($slotId); + return ($this->_DCIM->isValidReturn($result)) ? ((int) $result) : (false); + } + else { + return false; + } + } + + /** + * @return array All cable IDs or empty array + */ + public function getCableIds() + { + $cableIds = array(); + $portIds = $this->_DCIM->getPortIdsByEquipmentId($this->getEquipmentId()); + + foreach($portIds as $portId) + { + $result = $this->_DCIM->getConnectedCableIdByPortId($portId); + $cableId = ($this->_DCIM->isValidReturn($result)) ? ((int) $result) : (false); + + if($cableId !== false) { + $cableIds[] = $cableId; + } + } + + return $cableIds; + } + + /** + * @param $cabinetName string + * @param $side string + * @param $positionU int + * @param $template Core\Item + * @param $label string + * @param $description string + * @param $positionX int + * @return false|int Equipment ID or false if error has occured + */ + public function rack($cabinetName, $side, $positionU, C\Item $template, $label = null, $description = null, $positionX = 0) + { + $this->_errorMessage = null; + + if(!$this->equipmentExists()) + { + if($this->hasLocationId()) + { + $cabinetId = $this->_DCIM->getCabinetIdByLocationIdCabinetLabel($this->getLocationId(), $cabinetName); + + if($this->_DCIM->isValidReturn($cabinetId)) + { + if($side === Api_Cabinet::SIDE_FRONT || $side === Api_Cabinet::SIDE_REAR) + { + // @todo equipment U existe? + if(C\Tools::is('int&&>0', $positionU)) + { + $equipmentTemplate = $template->chassis; + + if($this->_DCIM->templateExists($equipmentTemplate)) + { + if($label === null && $this->hasEquipmentLabel()) { + $label = $this->getEquipmentLabel(); + } + + if(C\Tools::is('string&&!empty', $label)) + { + if(!C\Tools::is('string', $description)) { + $description = ''; + } + + if(C\Tools::is('int&&>=0', $positionX)) + { + try { + $equipmentId = $this->_DCIM->addEquipmentToCabinetId($cabinetId, $side, $positionU, $positionX, $equipmentTemplate, $label, $description); + } + catch(E\Message $e) { + $this->_errorMessage = "Unable to rack equipment '".$equipmentTemplate."' '".$label."' to position '".$positionU."'U in DCIM: ".$e->getMessage(); + $equipmentId = false; + } + + if($equipmentId !== false) + { + $this->_hardReset(false); + $this->_setObjectId($equipmentId); + + foreach(array('card', 'fan', 'power') as $extensionName) + { + if($template->key_exists($extensionName) && $template[$extensionName] instanceof C\Item && count($template[$extensionName]) > 0) + { + foreach($template[$extensionName] as $extensionDatas) + { + if($extensionDatas->key_exists('slot') && $extensionDatas->key_exists('equipment')) + { + try { + $extEquipId = $this->addModule($extensionDatas['slot'], $extensionDatas['equipment']); + } + catch(E\Message $e) { + $this->_errorMessage = "Unable to rack equipment '".$extensionDatas['equipment']."' to slot '".$extensionDatas['slot']."' in DCIM: ".$e->getMessage(); + $extEquipId = false; + } + + if($extEquipId !== false) + { + if($extensionDatas->key_exists('ports')) + { + /** + * Afin de faciliter la déclaration du template, dans celui-ci il n'est pas préciser + * le type (slot ou port) de l'objet à renommer, de ce fait il ne faut pas tester le + * status des commandes _renameSlot et _renamePort + */ + foreach($extensionDatas['ports'] as $currentName => $newName) + { + $slotStatus = $this->_renameSlot($extEquipId, $currentName, $newName); + $portStatus = $this->_renamePort($extEquipId, $currentName, $newName); + + /*if($slotStatus === false || $portStatus === false) { + $this->_errorMessage = "Unable to rename slots or ports of equipment '".$extensionDatas['equipment']."' with name '".$newName."'"; + return false; + }*/ + } + } + } + else + { + if(!$this->hasErrorMessage()) { + $this->_errorMessage = "Unable to rack equipment '".$extensionDatas['equipment']."' to slot '".$extensionDatas['slot']."'"; + } + + return false; + } + } + } + } + } + + return $equipmentId; + } + } + else { + $this->_errorMessage = "Position X '".$positionX."' must be integer greater or equal to 0"; + } + } + else { + $this->_errorMessage = "Label equipment is required"; + } + } + else { + $this->_errorMessage = "DCIM template '".$equipmentTemplate."' is missing"; + } + } + else { + $this->_errorMessage = "Position U '".$positionU."' must be integer greater to 0"; + } + } + else { + $this->_errorMessage = "Side '".$side."' is not valid"; + } + } + else { + $this->_errorMessage = "DCIM cabinet '".$cabinetName."' is missing "; + } + } + else { + $this->_errorMessage = "DCIM location is required"; + } + } + else { + $this->_errorMessage = "DCIM equipment '".$this->label."' already exists"; + } + + return false; + } + + /** + * @param $slotLabel string Slot label + * @param $templateName string Template name + * @param $moduleLabel string Module label + * @return false|int Module ID + */ + public function addModule($slotLabel, $templateName, $moduleLabel = null) + { + $this->_errorMessage = null; + return $this->_addModule($this->getEquipmentId(), $slotLabel, $templateName, $moduleLabel); + } + + protected function _addModule($equipmentId, $slotLabel, $templateName, $moduleLabel = null) + { + if($this->equipmentExists()) + { + if($this->_DCIM->templateExists($templateName)) + { + $slotIds = $this->_DCIM->getSlotIdsByParentEquipmentIdSlotLabel($equipmentId, $slotLabel); + + switch(count($slotIds)) + { + case 0: { + $this->_errorMessage = "No slot '".$slotLabel."' exists for this equipment '".$this->getEquipmentLabel()."'"; + } + case 1: + { + $slotId = current($slotIds); + $moduleId = $this->getModuleId($slotId); + + if($moduleId === false) + { + if($moduleLabel === null) { + $moduleLabel = $slotLabel; + } + + try{ + $equipmentId = $this->_DCIM->addEquipmentToSlotId($slotId, $templateName, $moduleLabel); + } + catch(E\Message $e) { + $this->_errorMessage = "Unable to rack equipment '".$templateName."' '".$moduleLabel."' to slot '".$slotLabel."' in DCIM: ".$e->getMessage(); + $equipmentId = false; + } + + if($equipmentId !== false) { + return $equipmentId; + } + } + else { + $this->_errorMessage = "There is already equipment in slot '".$slotLabel."' for this equipment '".$this->getEquipmentLabel()."'"; + } + + break; + } + default: { + $this->_errorMessage = "Many slot '".$slotLabel."' exists for this equipment '".$this->getEquipmentLabel()."'"; + } + } + } + else { + $this->_errorMessage = "The template '".$templateName."' does not exist in DCIM"; + } + } + else { + $this->_errorMessage = "The equipment '".$this->getEquipmentLabel()."' does not exist in DCIM"; + } + + return false; + } + + public function renameSlot($currentLabel, $newLabel) + { + if($this->equipmentExists()) { + return $this->_renameSlot($this->getEquipmentId(), $currentLabel, $newLabel); + } + else { + return false; + } + } + + protected function _renameSlot($equipmentId, $currentLabel, $newLabel) + { + + $slotId = $this->_DCIM->getSlotIdByEquipmentIdSlotLabel($equipmentId, $currentLabel); + + if($this->_DCIM->isValidReturn($slotId)) + { + try { + $status = $this->_DCIM->updateSlotInfos($slotId, $newLabel); + } + catch(E\Message $e) { + $this->_errorMessage = "Unable to rename slot from DCIM: ".$e->getMessage(); + $status = false; + } + + return ($status) ? ($slotId) : (false); + } + else { + return false; + } + } + + public function renamePort($currentLabel, $newLabel) + { + if($this->equipmentExists()) { + return $this->_renamePort($this->getEquipmentId(), $currentLabel, $newLabel); + } + else { + return false; + } + } + + protected function _renamePort($equipmentId, $currentLabel, $newLabel) + { + $portId = $this->_DCIM->getPortIdByEquipmentIdPortLabel($equipmentId, $currentLabel); + + if($this->_DCIM->isValidReturn($portId)) + { + try { + $status = $this->_DCIM->updatePortInfos($portId, $newLabel); + } + catch(E\Message $e) { + $this->_errorMessage = "Unable to rename port from DCIM: ".$e->getMessage(); + $status = false; + } + + return ($status) ? ($portId) : (false); + } + else { + return false; + } + } + + /** + * @param string $label + * @return bool + */ + public function renameLabel($label) + { + return $this->_updateInfos($label, $this->description); + } + + /** + * @param string $description + * @return bool + */ + public function setDescription($description) + { + return $this->_updateInfos($this->label, $description); + } + + /** + * @param string $label + * @param string $description + * @return bool + */ + public function updateInfos($label, $description) + { + return $this->_updateInfos($label, $description); + } + + /** + * @param string $label + * @param string $description + * @return bool + */ + protected function _updateInfos($label, $description) + { + $this->_errorMessage = null; + + if($this->equipmentExists()) + { + try { + $status = $this->_DCIM->updateEquipmentInfos($this->getEquipmentId(), $label, $description); + } + catch(E\Message $e) { + $this->_errorMessage = "Unable to update equipment informations from DCIM: ".$e->getMessage(); + $status = false; + } + + $this->refresh(); + return $status; + } + else { + $this->_errorMessage = "DCIM equipment does not exist"; + return false; + } + } + + /** + * @param string $serialNumber + * @return bool + */ + public function setSerialNumber($serialNumber) + { + $this->_errorMessage = null; + + if($this->equipmentExists()) + { + $snFieldName = $this->getUserAttrField('default', 'serialNumber'); + + try { + $status = $this->_DCIM->setUserAttrByEquipmentId($this->getEquipmentId(), $snFieldName, $serialNumber); + } + catch(E\Message $e) { + $this->_errorMessage = "Unable to set equipment serial number in DCIM: ".$e->getMessage(); + $status = false; + } + + $this->_serialNumber = null; + return $status; + } + else { + $this->_errorMessage = "DCIM equipment does not exist"; + return false; + } + } + + /** + * @return bool + */ + public function remove() + { + $this->_errorMessage = null; + + if($this->equipmentExists()) + { + try { + $status = $this->_DCIM->removeEquipment($this->getEquipmentId()); + } + catch(E\Message $e) { + $this->_errorMessage = "Unable to remove equipment from DCIM: ".$e->getMessage(); + $status = false; + } + + $this->_hardReset(); + return $status; + } + else { + $this->_errorMessage = "DCIM equipment does not exist"; + return false; + } + } + + /** + * @param bool $resetObjectId + * @return void + */ + protected function _hardReset($resetObjectId = false) + { + $this->_softReset($resetObjectId); + $this->_resetAttributes(); + $this->_resetLocation(); + $this->_resetCabinet(); + } + + protected function _resetAttributes() + { + $this->_serialNumber = null; + } + + protected function _resetCabinet() + { + $this->_cabinetId = null; + $this->_cabinetApi = null; + $this->_position = null; + } + + public function __get($name) + { + switch($name) + { + case 'description': { + return $this->_getField(self::FIELD_DESC, 'string&&!empty'); + } + case 'serialNumber': { + return $this->getSerialNumber(); + } + case 'locationApi': { + return $this->getLocationApi(); + } + case 'cabinetApi': { + return $this->getCabinetApi(); + } + default: { + return parent::__get($name); + } + } + } + + public function __call($method, $parameters = null) + { + if(substr($method, 0, 3) === 'get') + { + $name = substr($method, 3); + $name = mb_strtolower($name); + + switch($name) + { + case 'description': { + return $this->_getField(self::FIELD_DESC, 'string&&!empty'); + } + } + } + + return parent::__call($method, $parameters); + } + + /** + * Return all equipments and sub equipments in slot matches request + * Can return powers, cards, modules, ... + * + * @param $equipmentLabel string Equipment label, wildcard * is allowed + * @param $equipmentDesc string Equipment description, wildcard * is allowed + * @param $equipmentSN string Equipment serial number, wildcard * is allowed + * @param $cabinetId int cabinet ID + * @param $locationId int location ID + * @param $recursion bool + * @param $firstLevel bool + * @return false|array + */ + public static function searchEquipments($equipmentLabel, $equipmentDesc, $equipmentSN, $cabinetId = null, $locationId = null, $recursion = false, $firstLevel = true) + { + // /!\ Ordre important pour la détection du nom du rapport + $args = array('label' => $equipmentLabel, 'description' => $equipmentDesc, 'serialnumber' => $equipmentSN); + + $args = array_filter($args, function ($item) { + return C\Tools::is('human', $item); + }); + + $reportAttributes = array_keys($args); + + if(C\Tools::is('int&&>0', $cabinetId)) { + $reportSection = 'cabinet'; + $args['cabinetid'] = $cabinetId; + } + elseif(C\Tools::is('int&&>0', $locationId)) { + $args['locationid'] = $locationId; + $reportSection = ($recursion) ? ('subLocation') : ('location'); + } + else { + $reportSection = 'label'; + } + + $reportName = self::_getReportName($reportSection, $reportAttributes); + + if($reportName !== false) + { + $results = self::$_DCIM->getReportResults($reportName, $args); + + if($results !== false && $firstLevel == true) + { + foreach($results as $index => $result) + { + if($result['parent_entity_id'] !== '') { + unset($results[$index]); + } + } + } + + return $results; + } + else { + return false; + } + } + } \ No newline at end of file diff --git a/addons/dcim/api/equipment/abstract.php b/addons/dcim/api/equipment/abstract.php new file mode 100644 index 0000000..8194d99 --- /dev/null +++ b/addons/dcim/api/equipment/abstract.php @@ -0,0 +1,39 @@ +_objectExists !== null) { + return $this->_objectExists; + } + elseif($this->hasObjectId()) { + $this->_objectExists = ($this->getObjectLabel() !== false); + return $this->_objectExists; + } + else { + return false; + } + } + + public function getObjectLabel() + { + if($this->_objectLabel !== null) { // /!\ Ne pas appeler hasObjectLabel sinon boucle infinie + return $this->_objectLabel; + } + elseif($this->hasObjectId()) { // /!\ Ne pas appeler objectExists sinon boucle infinie + $result = $this->_DCIM->resolvToLabel(static::OBJECT_TYPE, $this->getObjectId()); + $this->_objectLabel = ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); + return $this->_objectLabel; + } + else { + return false; + } + } + + protected function _getObject() + { + return false; + } + } \ No newline at end of file diff --git a/dcim/api/equipment/port.php b/addons/dcim/api/equipment/port.php similarity index 58% rename from dcim/api/equipment/port.php rename to addons/dcim/api/equipment/port.php index 846088b..4b93d43 100644 --- a/dcim/api/equipment/port.php +++ b/addons/dcim/api/equipment/port.php @@ -1,12 +1,20 @@ 'CW - TOOLS-CLI - PortLabel', 'location' => 'CW - TOOLS-CLI - PortEquipment', ); + const FIELD_ID = 'entity_id'; + const FIELD_NAME = 'name'; + protected $_equipmentId; protected $_equipmentApi; @@ -42,24 +50,41 @@ public function getPortLabel() return $this->getObjectLabel(); } + /** + * @return bool Port is connected or not + */ public function isConnected() { return ($this->getConnectedCableId() !== false); } + /** + * Retourne l'ID du câble connecté à ce port + * /!\ Do not call isConnected otherwise risk of infinite loop + * + * @return false|int Cable ID + */ public function getConnectedCableId() { - if(!$this->hasPortId() || !$this->portExists()) { - return false; + if($this->portExists()) + { + if($this->_connectedCableId === null) { + $result = $this->_DCIM->getConnectedCableIdByPortId($this->getPortId()); + $this->_connectedCableId = ($this->_DCIM->isValidReturn($result)) ? ((int) $result) : (false); + } + + return $this->_connectedCableId; } - elseif($this->_connectedCableId === null) { - $result = $this->_DCIM->getConnectedCableIdByPortId($this->getPortId()); - $this->_connectedCableId = ($this->_DCIM->isValidReturn($result)) ? ((int) $result) : (false); + else { + return false; } - - return $this->_connectedCableId; } + /** + * Retourne l'ID du port directement connecté à ce port + * + * @return false|int Port ID + */ public function getConnectedPortId() { if(!$this->isConnected()) { @@ -73,6 +98,11 @@ public function getConnectedPortId() return $this->_connectedPortId; } + /** + * Retourne l'ID du port final connecté à ce port + * + * @return false|int Port ID + */ public function getEndConnectedPortId() { $connectedPortId = $this->getConnectedPortId(); @@ -83,22 +113,30 @@ public function getEndConnectedPortId() { $otherSidePortId = $this->_DCIM->getOtherSidePortIdByPortId($connectedPortId); - if($this->_DCIM->isValidReturn($otherSidePortId)) { - $connectedPortId = $this->_DCIM->getConnectedPortIdByPortId($otherSidePortId); - continue; + if($this->_DCIM->isValidReturn($otherSidePortId)) + { + $conPortId = $this->_DCIM->getConnectedPortIdByPortId($otherSidePortId); + + if($this->_DCIM->isValidReturn($conPortId)) { + $connectedPortId = (int) $conPortId; + continue; + } } break; } - if($this->_DCIM->isValidReturn($connectedPortId)) { - return (int) $connectedPortId; - } + return $connectedPortId; } return false; } + /** + * Return the parent equipment ID this port is on + * + * @return false|int + */ public function getParentEquipmentId() { if(!$this->hasPortId() || !$this->portExists()) { @@ -116,6 +154,11 @@ public function getParentEquipmentId() return false; } + /** + * Return the first top module equipment ID this port is on + * + * @return false|int + */ public function getModuleEquipmentId() { $parentEquipmentId = $this->getParentEquipmentId(); @@ -128,6 +171,11 @@ protected function _getModuleEquipmentId($equipmentId, $moduleId = false) return ($this->_DCIM->isValidReturn($parentEquipId)) ? ($this->_getModuleEquipmentId($parentEquipId, $equipmentId)) : ($moduleId); } + /** + * Return the top equipment ID this port is on + * + * @return false|int + */ public function getTopEquipmentId() { if($this->portExists()) @@ -144,6 +192,11 @@ public function getTopEquipmentId() } } + /** + * Return the top equipment label this port is on + * + * @return false|int + */ public function getTopEquipmentLabel() { $equipmentId = $this->getTopEquipmentId(); @@ -160,6 +213,11 @@ public function getTopEquipmentLabel() return false; } + /** + * Return the top equipment API this port is on + * + * @return false|Addon\Dcim\Api_Equipment + */ public function getEquipmentApi() { if($this->_equipmentApi === null) @@ -167,7 +225,7 @@ public function getEquipmentApi() $equipmentId = $this->getTopEquipmentId(); if($equipmentId !== false) { - $this->_equipmentApi = new Dcim_Api_Equipment($equipmentId); + $this->_equipmentApi = new Api_Equipment($equipmentId); } else { $this->_equipmentApi = false; @@ -193,7 +251,7 @@ public function getCableApi() $cableId = $this->getCableId(); if($cableId !== false) { - $this->_cableApi = new Dcim_Api_Cable($cableId); + $this->_cableApi = new Api_Cable($cableId); } else { $this->_cableApi = false; @@ -203,22 +261,39 @@ public function getCableApi() return $this->_cableApi; } - public function getUserAttr($category, $attrLabel) + /** + * @param bool $resetObjectId + * @return void + */ + protected function _hardReset($resetObjectId = false) { - $attrName = $this->_DCIM->getUserAttrName($category, $attrLabel); - $result = $this->_DCIM->getUserAttrByPortId($this->getPortId(), $attrName); + $this->_softReset($resetObjectId); + $this->_resetAttributes(); + $this->_resetEquipment(); + $this->_resetCable(); + $this->_resetPort(); + } - return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); + protected function _resetAttributes() + { } - protected function _reset($resetPortId = false) + protected function _resetEquipment() { - if($resetPortId) { - $this->_portId = null; - } + $this->_equipmentId = null; + $this->_equipmentApi = null; + } - $this->_portExists = null; - $this->_portLabel = null; + protected function _resetCable() + { + $this->_cableId = null; + $this->_cableApi = null; + $this->_connectedCableId = null; + } + + protected function _resetPort() + { + $this->_connectedPortId = null; } public function __get($name) diff --git a/addons/dcim/api/equipment/slot.php b/addons/dcim/api/equipment/slot.php new file mode 100644 index 0000000..0552fe1 --- /dev/null +++ b/addons/dcim/api/equipment/slot.php @@ -0,0 +1,162 @@ +objectIdIsValid($slotId); + } + + public function hasSlotId() + { + return $this->hasObjectId(); + } + + public function getSlotId() + { + return $this->getObjectId(); + } + + public function slotExists() + { + return $this->objectExists(); + } + + public function getSlotLabel() + { + return $this->getObjectLabel(); + } + + public function isEmpty() + { + return ($this->getChildEquipmentId() === false); + } + + public function getChildEquipmentId() + { + if(!$this->hasSlotId() || !$this->slotExists()) { + return false; + } + elseif($this->_childEquipmentId === null) { + $result = $this->_DCIM->getEquipmentIdBySlotId($this->getSlotId()); + $this->_childEquipmentId = ($this->_DCIM->isValidReturn($result)) ? ((int) $result) : (false); + } + + return $this->_childEquipmentId; + } + + /** + * Return the top equipment ID this port is on + * + * @return false|int + */ + public function getTopEquipmentId() + { + if($this->slotExists()) + { + if($this->_equipmentId === null) { + $result = $this->_DCIM->getTopEquipmentIdBySlotId($this->getSlotId()); + $this->_equipmentId = ($this->_DCIM->isValidReturn($result)) ? ((int) $result) : (false); + } + + return $this->_equipmentId; + } + else { + return false; + } + } + + /** + * Return the top equipment label this slot is on + * + * @return false|int + */ + public function getTopEquipmentLabel() + { + $equipmentId = $this->getTopEquipmentId(); + + if($equipmentId !== false) + { + $result = $this->_DCIM->resolvToLabel('equipment', $equipmentId); + + if($this->_DCIM->isValidReturn($result)) { + return (string) $result; + } + } + + return false; + } + + /** + * Return the top equipment API this slot is on + * + * @return false|Addon\Dcim\Api_Equipment + */ + public function getEquipmentApi() + { + if($this->_equipmentApi === null) + { + $equipmentId = $this->getTopEquipmentId(); + + if($equipmentId !== false) { + $this->_equipmentApi = new Api_Equipment($equipmentId); + } + else { + $this->_equipmentApi = false; + } + } + + return $this->_equipmentApi; + } + + /** + * @param bool $resetObjectId + * @return void + */ + protected function _hardReset($resetObjectId = false) + { + $this->_softReset($resetObjectId); + $this->_resetAttributes(); + $this->_resetEquipment(); + } + + protected function _resetAttributes() + { + } + + protected function _resetEquipment() + { + $this->_equipmentId = null; + $this->_equipmentApi = null; + $this->_childEquipmentId = null; + } + + public function __get($name) + { + switch($name) + { + case 'equipmentApi': { + return $this->getEquipmentApi(); + } + default: { + return parent::__get($name); + } + } + } + } \ No newline at end of file diff --git a/addons/dcim/api/location.php b/addons/dcim/api/location.php new file mode 100644 index 0000000..81cf9ce --- /dev/null +++ b/addons/dcim/api/location.php @@ -0,0 +1,502 @@ + 'CW - TOOLS-CLI - Location - Root', + 'self' => 'CW - TOOLS-CLI - Location0', + 'label' => 'CW - TOOLS-CLI - Location1', + 'location' => 'CW - TOOLS-CLI - Location2', + 'subLocation' => 'CW - TOOLS-CLI - Location3', + ); + + const FIELD_ID = 'entity_id'; + const FIELD_NAME = 'name'; + const FIELD_DESC = 'description'; + + /** + * Enable or disable cache feature + * /!\ Cache must be per type + * + * @var array + */ + protected static $_cache = array(); // DCIM server ID keys, boolean value + + /** + * All locations (cache) + * /!\ Cache must be per type + * + * @var array + */ + protected static $_objects = array(); // DCIM server ID keys, array value + + /** + * @var array + */ + static protected $_rootLocations = null; + + /** + * @var int + */ + static protected $_rootLocationId = null; + + /** + * @var int + */ + protected $_parentLocationId = null; + + /** + * @var Addon\Dcim\Api_Location + */ + protected $_parentLocationApi = null; + + /** + * Path to self object + * @var array + */ + protected $_path = null; + + + public function locationIdIsValid($locationId) + { + return $this->objectIdIsValid($locationId); + } + + public function hasLocationId() + { + return $this->hasObjectId(); + } + + public function getLocationId() + { + return $this->getObjectId(); + } + + public function locationExists() + { + return $this->objectExists(); + } + + public function setLocationLabel($locationLabel) + { + return $this->_setObjectLabel($locationLabel); + } + + public function hasLocationLabel() + { + return $this->hasObjectLabel(); + } + + public function getLocationLabel() + { + return $this->getObjectLabel(); + } + + protected function _getObject() + { + if($this->_objectExists === null || $this->objectExists()) + { + if($this->_objectDatas === null) + { + $args = array('locationid' => $this->getLocationId()); + $results = $this->_DCIM->getReportResults(self::REPORT_NAMES['self'], $args); + + if(count($results) === 1) { + $this->_objectDatas = $results[0]; + } + else { + $this->_objectDatas = false; + } + } + + return $this->_objectDatas; + } + else { + return false; + } + } + + public function getParentLocationId() + { + if($this->locationExists()) + { + if($this->_parentLocationId === null) + { + $this->_parentLocationId = false; + + $path = $this->getPath(); + $path = explode(',', $path); + + $selfClassName = static::class; + $Api_Location = new $selfClassName(); + $locationId = $Api_Location->getSubLocationId($path[0]); + + if($locationId !== false) + { + for($i=1; $i_DCIM->getLocationIdByParentLocationIdLocationLabel($locationId, $path[$i], false); + + if($locationId === false) { + break; + } + } + + if($i === count($path)) { + $this->_parentLocationId = $locationId; + } + } + } + + return $this->_parentLocationId; + } + else { + return false; + } + } + + public function getParentLocationApi() + { + if($this->_parentLocationApi === null) + { + $locationId = $this->getParentLocationId(); + + if($locationId !== false) { + $this->_parentLocationApi = new Api_Location($locationId); + } + else { + $this->_parentLocationApi = false; + } + } + + return $this->_parentLocationApi; + } + + public function getPath($includeLabel = false, $pathSeparator = false) + { + if($this->locationExists()) + { + if($this->_path === null) + { + // Ne retourne pas le chemin complet + /*$result = $this->_DCIM->getLocationPathByLocationId($this->getLocationId()); + return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false);*/ + + $args = array('locationid' => $this->getLocationId()); + $results = self::$_DCIM->getReportResults(self::REPORT_NAMES['self'], $args); + + if(count($results) === 1) { + $result = $results[0]; + $path = explode(self::SEPARATOR_PATH, $result['fullpath']); + $this->_path = array_reverse($path); + } + else { + $this->_path = false; + } + } + + if($this->_path !== false) + { + $path = $this->_path; + + if($includeLabel && $this->hasLocationLabel()) { + $path[] = $this->getLocationLabel(); + } + + if($pathSeparator === false) { + $pathSeparator = self::SEPARATOR_PATH; + } + + return implode($pathSeparator, $path); + } + } + elseif($includeLabel && $this->hasLocationLabel()) { + return $this->getLocationLabel(); + } + + return false; + } + + /** + * @todo /!\ getSubLocationIds si aucune sous location, retourne la location courante + * Ce n'est pas forcément bien, revoir cela afin de retourner array() (empty) + * + * @return array All sub location IDs or root location IDs + */ + public function getSubLocationIds() + { + if($this->locationExists()) { + return $this->_DCIM->getSubLocationIds($this->getLocationId(), false); + } + else { + return $this->getRootLocationIds(); + } + } + + public function getSubLocationId($locationLabel) + { + if($this->locationExists()) { + return $this->_DCIM->getLocationIdByParentLocationIdLocationLabel($this->getLocationId(), $locationLabel, false); + } + else { + $results = self::$_DCIM->getReportResults(self::REPORT_NAMES['root']); + $result = $this->_filterObjects($results, 'name', $locationLabel); + return (C\Tools::is('array', $result) && count($result) === 1) ? ($result[0]['entity_id']) : (false); + } + } + + public function findLocations($locationLabel, $recursion = false) + { + if($this->hasLocationId()) { + $locationId = $this->getLocationId(); + return self::searchLocations($locationLabel, $locationId, $recursion); + } + else + { + $rootLocationLabels = self::getRootLocations(); + + $locationLabel = preg_quote($locationLabel, '#'); + $locationLabel = str_ireplace('\\*', '.*', $locationLabel); + + $results = array_filter($rootLocationLabels, function(&$item) use(&$locationLabel) { + return preg_match("#".$locationLabel."#i", $item[self::FIELD_NAME]); + }); + + return array_values($results); + } + } + + /** + * @return array All cabinet IDs or empty array + */ + public function getCabinetIds() + { + if($this->locationExists()) { + return $this->_DCIM->getCabinetIdsByLocationId($this->getLocationId()); + } + else { + return array(); + } + } + + /** + * @return array All equipment labels or empty array + */ + public function getCabinetLabels() + { + if($this->locationExists()) { + return $this->_DCIM->getCabinetLabelsByLocationId($this->getLocationId()); + } + else { + return array(); + } + } + + public function getCabinetId($cabinetLabel) + { + if($this->locationExists()) { + $result = $this->_DCIM->getCabinetIdByLocationIdCabinetLabel($this->getLocationId(), $cabinetLabel); + return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); + } + else { + return false; + } + } + + public function findCabinets($cabinetLabel, $recursion = false) + { + if($this->hasLocationId()) { + $locationId = $this->getLocationId(); + return Api_Cabinet::searchCabinets($cabinetLabel, $locationId, $recursion); + } + else { + return false; + } + } + + public function getEquipmentId($equipmentLabel) + { + if($this->locationExists()) { + $result = $this->_DCIM->getEquipmentIdByLocationIdEquipmentLabel($this->getLocationId(), $equipmentLabel); + return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); + } + else { + return false; + } + } + + public function findEquipments($equipmentLabel, $equipmentDesc, $equipmentSN, $recursion = false) + { + if($this->hasLocationId()) { + $locationId = $this->getLocationId(); + return Api_Equipment::searchEquipments($equipmentLabel, $equipmentDesc, $equipmentSN, null, $locationId, $recursion); + } + else { + return false; + } + } + + /** + * @param bool $resetObjectId + * @return void + */ + protected function _hardReset($resetObjectId = false) + { + $this->_softReset($resetObjectId); + $this->_resetAttributes(); + $this->_resetLocation(); + } + + protected function _resetAttributes() + { + $this->_path = null; + } + + protected function _resetLocation() + { + $this->_parentLocationId = null; + $this->_parentLocationApi = null; + } + + public function __get($name) + { + switch($name) + { + case 'description': { + return $this->_getField(self::FIELD_DESC, 'string&&!empty'); + } + case 'parentLocationApi': { + return $this->_parentLocationApi(); + } + default: { + return parent::__get($name); + } + } + } + + public function __call($method, $parameters = null) + { + if(substr($method, 0, 3) === 'get') + { + $name = substr($method, 3); + $name = mb_strtolower($name); + + switch($name) + { + case 'description': { + return $this->_getField(self::FIELD_DESC, 'string&&!empty'); + } + } + } + + return parent::__call($method, $parameters); + } + + public static function getRootLocations() + { + if(self::$_rootLocations === null) { + self::$_rootLocations = self::_getObjectsFromReport('root', null); + } + + return self::$_rootLocations; + } + + public static function getRootLocationIds() + { + $rootLocations = self::getRootLocations(); + return array_column($rootLocations, 'entity_id'); + } + + public static function getRootLocationLabels() + { + $rootLocations = self::getRootLocations(); + return array_column($rootLocations, self::FIELD_NAME); + } + + public static function getRootLocationId() + { + if(self::$_rootLocationId === null) + { + $locations = self::getRootLocations(); + + if(C\Tools::is('array', $locations) && count($locations) === 1) { + self::$_rootLocationId = $locations[0]['entity_id']; + } + else { + throw new Exception("Unable to get root location ID", E_USER_ERROR); + } + } + + return self::$_rootLocationId; + } + + /** + * Return all locations matches request + * + * Ne pas rechercher que les locations root si locationId est égale à null + * + * @param string $locationLabel Location label, wildcard * is allowed + * @param int $locationId Location ID + * @param bool $recursion + * @return false|array + */ + public static function searchLocations($locationLabel, $locationId = null, $recursion = false) + { + $args = array('label' => $locationLabel); + + array_walk($args, function(&$item) + { + if(!C\Tools::is('human', $item)) { + $item = self::WILDCARD; + } + }); + + if(C\Tools::is('int&&>0', $locationId)) { + $args['locationid'] = $locationId; + $reportName = ($recursion) ? ('subLocation') : ('location'); + } + else { + $reportName = 'label'; + } + + $results = self::$_DCIM->getReportResults(self::REPORT_NAMES[$reportName], $args); + + foreach($results as &$result) { + $fullPath = explode(self::SEPARATOR_PATH, $result['fullpath']); + $fullPath = array_reverse($fullPath); + $result['path'] = implode(self::SEPARATOR_PATH, $fullPath); + $result['fullpath'] = $result['path']; + } + + return $results; + } + + /** + * @param Addon\Dcim\Main $DCIM + * @return bool + */ + protected static function _setObjects(C\Addon\Adapter $DCIM = null) + { + if($DCIM === null) { + $DCIM = self::$_DCIM; + } + + $id = $DCIM->getServerId(); + $result = self::searchLocations(self::WILDCARD); + + if($result !== false) { + self::$_objects[$id] = $result; + return true; + } + else { + return false; + } + } + } \ No newline at end of file diff --git a/addons/dcim/connector.php b/addons/dcim/connector.php new file mode 100644 index 0000000..251dbaf --- /dev/null +++ b/addons/dcim/connector.php @@ -0,0 +1,204 @@ +DCIM; + $this->_setCurrentConnector($connector); + + foreach($servers as $server) + { + $server = mb_strtoupper($server); + + if(!$config->servers->key_exists($server)) { + throw new Exception("Unable to retrieve DCIM server '".$server."' configuration", E_USER_ERROR); + } + else + { + $this->_config = $config->servers[$server]; + + if($this->_config->key_exists('serverLocation')) { + list($loginCredential, $passwordCredential) = $this->_getCredentials($this->_config, $server); + $this->_aDCIM[$server] = new $this->_currentConnector($server, $this->_config->serverLocation, $loginCredential, $passwordCredential, $printInfoMessages, $debug); + } + else { + throw new Exception("Unable to retrieve 'serverLocation' configuration for DCIM server '".$server."'", E_USER_ERROR); + } + } + } + + if(count($this->_aDCIM) === 1) { + $this->_oDCIM = current($this->_aDCIM); + } + } + + protected function _setCurrentConnector($connector) + { + if($connector !== null && static::_isValidConnector($connector)) { + $this->_currentConnector = $connector; + } + else { + $this->_currentConnector = static::$_defaultConnector; + } + } + + protected function _getCredentials(C\MyArrayObject $serverConfig, $server) + { + if($serverConfig->key_exists('loginCredential') && C\Tools::is('string&&!empty', $serverConfig->loginCredential)) { + $loginCredential = $serverConfig->loginCredential; + } + elseif($serverConfig->key_exists('loginEnvVarName') && C\Tools::is('string&&!empty', $serverConfig->loginEnvVarName)) + { + $loginEnvVarName = $serverConfig->loginEnvVarName; + $loginCredential = getenv($loginEnvVarName); + + if($loginCredential === false) { + throw new Exception("Unable to retrieve login credential for DCIM server '".$server."' from environment with variable name '".$loginEnvVarName."'", E_USER_ERROR); + } + } + else { + throw new Exception("Unable to retrieve 'loginCredential' or 'loginEnvVarName' configuration for DCIM server '".$server."'", E_USER_ERROR); + } + + if($serverConfig->key_exists('passwordCredential') && C\Tools::is('string&&!empty', $serverConfig->passwordCredential)) { + $passwordCredential = $serverConfig->passwordCredential; + } + elseif($serverConfig->key_exists('passwordEnvVarName') && C\Tools::is('string&&!empty', $serverConfig->passwordEnvVarName)) + { + $passwordEnvVarName = $serverConfig->passwordEnvVarName; + $passwordCredential = getenv($passwordEnvVarName); + + if($passwordCredential === false) { + throw new Exception("Unable to retrieve password credential for DCIM server '".$server."' from environment with variable name '".$passwordEnvVarName."'", E_USER_ERROR); + } + } + else { + throw new Exception("Unable to retrieve 'passwordCredential' or 'passwordEnvVarName' configuration for DCIM server '".$server."'", E_USER_ERROR); + } + + return array($loginCredential, $passwordCredential); + } + + public function getJnlpUrl($server = false, $version = 64) + { + if($server === false && $this->_oDCIM !== null) { + return $this->_oDCIM->getJnlpUrl($version); + } + elseif(array_key_exists($server, $this->_aDCIM)) { + return $this->_aDCIM[$server]->getJnlpUrl($version); + } + + return false; + } + + public function getDcim($equipLabel = null) + { + if($this->_oDCIM !== null) { + return $this->_oDCIM; + } + elseif($equipLabel !== null) + { + if(preg_match('#^(.*-[ps]-.*)$#i', $equipLabel)) { + return $this->_aDCIM['SEC']; + } + elseif(preg_match('#^(.*-[il]-.*)$#i', $equipLabel)) { + return $this->_aDCIM['CORP']; + } + elseif(preg_match('#^(.*-[d]-.*)$#i', $equipLabel)) { + return $this->_aDCIM['DEV']; + } + } + + throw new Exception('Impossible de retourner le service DCIM adapté', E_USER_ERROR); + } + + public function getAllDcim() + { + return $this->_aDCIM; + } + + public function getConfig() + { + return $this->_config; + } + + public function __get($name) + { + if($this->_oDCIM !== null) { + return $this->_oDCIM; + } + else + { + switch(mb_strtolower($name)) + { + case 'sec': + return $this->_aDCIM['SEC']; + case 'corp': + return $this->_aDCIM['CORP']; + case 'dev': + return $this->_aDCIM['DEV']; + } + } + + throw new Exception("Le DCIM ".$name." n'existe pas", E_USER_ERROR); + } + + public function __call($name, array $arguments) + { + if($this->_oDCIM !== null) { + return call_user_func_array(array($this->_oDCIM, $name), $arguments); + } + else + { + $results = array(); + + foreach($_aDCIM as $dcim) { + $result[] = call_user_func_array(array($dcim, $name), $arguments); + } + + return $results; + } + } + + public static function __callStatic($name, array $arguments) + { + $callable = array(static::$_defaultConnector, $name); + $Closure = \Closure::fromCallable($callable); + return forward_static_call_array($Closure, $arguments); + } + + public static function setDefaultConnector($connector) + { + if(strpos($connector, '\\') === false) { + $connector = __NAMESPACE__ .'\\'.$connector; + } + + if(static::_isValidConnector($connector)) { + static::$_defaultConnector = $connector; + } + } + + protected static function _isValidConnector($connector) + { + $ReflectionClass = new \ReflectionClass($connector); + return $ReflectionClass->isSubclassOf(__NAMESPACE__ .'\Connector_Abstract'); + } + } diff --git a/addons/dcim/connector/abstract.php b/addons/dcim/connector/abstract.php new file mode 100644 index 0000000..1a01f2f --- /dev/null +++ b/addons/dcim/connector/abstract.php @@ -0,0 +1,6 @@ + '/rest/locations', + 'cabinet' => '/rest/cabinets', + 'equipment' => '/rest/equipment', + 'slot' => '/rest/slots', + 'port' => '/rest/ports', + 'cable' => '/rest/cables', + 'attr' => '/rest/custom-objects', + 'search' => '/rest/find', + ); + + + const USER_ATTR_PREFIX__BASE = ''; + const USER_ATTR_PREFIX__NETWORK = 'Cloudwatt - Network - Switch -'; + const USER_ATTR_PREFIX__SYSTEM = 'Cloudwatt - System - Server -'; + + const USER_ATTR_NAME__BASE = array( + 'Serial number', + ); + + const USER_ATTR_NAME__NETWORK = array( + '01#' => 'Breakout Interfaces', + '02#' => 'Link Aggregation', + '03#' => 'MC-Link Aggregation', + '04#' => 'Link Type', + '05#' => 'Native VLAN', + '06#' => 'VLAN(s)', + '10#' => 'MC-LAG - Chassis', + '11#' => 'MC-LAG - ICCP Link', + '12#' => 'MC-LAG - ICL-PL Link', + '13#' => 'MC-LAG - System ID', + '14#' => 'MC-LAG - VLAN ID', + ); + + const USER_ATTR_NAME__SYSTEM = array( + ); + + const USER_ATTR_LIST_SEPARATOR = ':'; + + + protected $_restAPI = null; + + + public function __construct($login, $password) + { + $this->_restAPI = new ArrayObject(); + + foreach(self::REST_URN as $key => $urn) + { + $this->_restAPI->{$key} = new C\Rest('PatchManager_'.$key); + + $this->_restAPI->{$key} + ->setUrl(trim(self::REST_URL, '/').$urn) + ->setHttpAuthMethods(false) + ->setHttpAuthCredentials($login, $password); + } + } + + public function explodeReturn($return) + { + return explode(', ', trim($return, '[]')); + } + + public function isValidReturn($return) + { + return (!empty($return) && $return !== null && $return !== 'null' && $return !== false && !preg_match('#ERROR|EXCEPTION#i', $return)); + } + + public function resolvToLabel($type, $id) + { + switch(mb_strtolower($type)) + { + case 'site': + case 'sites': + case 'location': + case 'locations': + $result = $this->_restAPI->location->setUrn('ids/'.$id)->get(array('format' => 'api_location')); + $result = $this->_getCallResponse($result); + return ($result !== false) ? ($result['name']) : (false); + case 'equipment': + $result = $this->_restAPI->equipment->setUrn('ids/'.$id)->get(array('format' => 'api_equipment')); + $result = $this->_getCallResponse($result); + return ($result !== false) ? ($result['name']) : (false); + default: + throw new Exception("Ce type d'objet '".$type."' n'est pas supporté", E_USER_ERROR); + } + } + + public function isValidResponse(array $response) + { + return (!$this->isEmptyResponse($response) && !array_key_exists('Warning Message', $response) && !$this->isErrorResponse($response)); + } + + // ## http://84.39.32.144:8080/pmserver/rest/find?searchFor=Equipments&searchIn=127708&query=mx8 + public function isErrorResponse(array $response) + { + return (array_key_exists('Status', $response) && array_key_exists('Message', $response)); + } + + public function isEmptyResponse(array $response) + { + return (array_key_exists('No results found', $response)); + } + + protected function _getCallResponse($json) + { + $response = json_decode($json, true); + return ($this->isValidResponse($response)) ? ($response) : (false); + } + + protected function _cleanCallResponse($json, $entityIdFieldName = null, $entityIdToClean = null) + { + $response = json_decode($json, true); + + if($this->isValidResponse($response)) + { + if($entityIdFieldName !== null && $entityIdToClean !== null) + { + foreach($response as $index => $data) + { + if(array_key_exists($entityIdFieldName, $data) && $data[$entityIdFieldName] === (string) $entityIdToClean) { + unset($response[$index]); + } + } + } + + return $response; + } + else { + return false; + } + } + + protected function _reduceCallResponse($json) + { + $response = json_decode($json, true); + + if($this->isValidResponse($response)) { + return $this->_reduceArray($response); + } + else { + return false; + } + } + + protected function _reduceArray($array, $keepKeys = false) + { + // /!\ Utiliser current et non [0], example: {"locationId":[[{"entityId":"490652"}]],"name":[[{"name":"0"}]]} + // {"cabinetId":"490895","name":"Z2 - K01","equipmentIds":[[{"entityId":"911687"}],[{"entityId":"911695"}],[{"entityId":"540703"}], ... ]} + if(is_array($array)) + { + if(count($array) > 1) + { + foreach($array as &$part) { + $part = $this->_reduceArray($part, $keepKeys); + } + + return $array; + } + else + { + $part = current($array); + + if($keepKeys) { + return $part; + } + else { + return $this->_reduceArray($part, $keepKeys); + } + } + } + else { + return $array; + } + } + + protected function _filterCallResponse($json, $filterFieldName, $filterTestName, $filterTestValue) + { + $response = json_decode($json, true); + + if($this->isValidResponse($response)) { + return $this->_filterArray($response, $filterFieldName, $filterTestName, $filterTestValue); + } + else { + return false; + } + } + + protected function _filterArray($array, $filterFieldName, $filterTestName, $filterTestValue) + { + foreach($array as $index => $data) + { + if(array_key_exists($filterFieldName, $data) && ( + ($filterTestName !== null && C\Tools::is($filterTestName, $data[$filterFieldName])) || + ($filterTestValue !== null && $filterTestValue === $data[$filterFieldName]) + )) { + unset($array[$index]); + } + } + + return $array; + } + + protected function _mergeCallResponse($json, array $fieldNamesToMerge, $destFieldName) + { + $response = json_decode($json, true); + + if($this->isValidResponse($response)) { + return $this->_mergeArray($response, $fieldNamesToMerge, $destFieldName); + } + else { + return false; + } + } + + protected function _mergeArray(array $array, array $fieldNamesToMerge, $destFieldName) + { + $counter = null; + + foreach($fieldNamesToMerge as $fieldName) + { + if($counter === null) { + $counter = count($array[$fieldName]); + } + elseif($counter !== count($array[$fieldName])) { + throw new Exception("Les tableaux à combiner ne comporte pas tous le même nombre d'éléments", E_USER_ERROR); + } + } + + $counter = 0; + $array[$destFieldName] = array(); + + while(true) + { + foreach($fieldNamesToMerge as $fieldNameToMerge) + { + if(array_key_exists($counter, $array[$fieldNameToMerge])) + { + $part = $array[$fieldNameToMerge][$counter]; + + if(is_array($part)) + { + $key = current(array_keys($part)); + $value = current(array_values($part)); + + $array[$destFieldName][$counter][$key] = $value; + } + } + else { + break(2); + } + } + + $counter++; + } + + return array_diff_key($array, array_flip($fieldNamesToMerge)); + } + + protected function _sliceArray(array $array, array $fieldNamesToSlice) + { + foreach($array as &$part) { + $part = array_intersect_key($part, array_flip($fieldNamesToSlice)); + } + + return $array; + } + + public function getSiteId($siteName) + { + return $this->getLocationId($siteName); + } + + public function getLocationId($locationName) + { + $result = $this->_restAPI->location->get(array('nameEq' => $locationName, 'format' => 'api_location')); + $result = $this->_getCallResponse($result); + return ($result !== false) ? ($result[0]['locationId']) : (false); + } + + // ## http://84.39.32.144:8080/pmserver/rest/locations/ids/127708?format=api_location_subLocation + // ## http://84.39.32.144:8080/pmserver/rest/locations/ids/1005653?format=api_location_subLocation + public function getSubLocationId($locationId) + { + $result = $this->_restAPI->location->setUrn('ids/'.$locationId)->get(array('format' => 'api_location_subLocation')); + $result = $this->_getCallResponse($result); + + if($result !== false) + { + $result = $result['locationIds']; + $resultCount = count($result); + + if($resultCount >= 1) + { + if($resultCount >= 2) { + throw new Exception("Il existe plusieurs sous emplacement pour cet emplacement", E_USER_ERROR); + } + + return $this->getSubLocationId($result[0][0]['entityId']); + } + } + + return $locationId; + } + + /*public function getSubLocationIds($locationId) + { + $args = $this->getArgs(array($locationId)); + $subLocationId = $this->_soapInstances['getters']->getSublocationsIdsById($args)->return; + + if(!empty($subLocationId)) + { + $subLocationIds = explode(',', $subLocationId); + + foreach($subLocationIds as &$subLocationId) { + $subLocationId = (array) $this->getSubLocationId($subLocationId); + } + + return $subLocationIds; + } + + return $locationId; + }*/ + + public function getLocationIdByParentLocationIdLocationLabel($parentLocationId, $locationLabel) + { + //$result = $this->_restAPI->search->get(array('searchFor' => 'Locations', 'searchIn' => $parentLocationId, 'regex' => 'true', 'query' => '^('.preg_quote($locationLabel).')$', 'format' => 'api_find_location')); + $result = $this->_restAPI->search->get(array('searchFor' => 'Locations', 'searchIn' => $parentLocationId, 'regex' => 'true', 'query' => '('.preg_quote($locationLabel).')$', 'format' => 'api_find_location')); + $result = $this->_cleanCallResponse($result, 'locationId', $parentLocationId); + + if(count($result) > 1) { + throw new Exception("Il existe plusieurs emplacements avec ce nom dans cet emplacement", E_USER_ERROR); + } + + return ($result !== false) ? ($result[0]['locationId']) : (false); + } + + // ## http://84.39.32.144:8080/pmserver/rest/find/?searchFor=Cabinets&searchIn=490673®ex=true&query=%28Z2+%5C-+G0.*%29%24&format=api_find_cabinet + public function getCabinetIdByLocationIdCabinetLabel($locationId, $cabinetLabel) + { + //$result = $this->_restAPI->search->get(array('searchFor' => 'Cabinets', 'searchIn' => $locationId, 'regex' => 'true', 'query' => '^('.preg_quote($cabinetLabel).')$', 'format' => 'api_find_cabinet')); + $result = $this->_restAPI->search->get(array('searchFor' => 'Cabinets', 'searchIn' => $locationId, 'regex' => 'true', 'query' => '('.preg_quote($cabinetLabel).')$', 'format' => 'api_find_cabinet')); + $result = $this->_getCallResponse($result); // /!\ Pas besoin de nettoyer car on recherche des baies dans une localisation + + if(count($result) > 1) { + throw new Exception("Il existe plusieurs baies avec ce nom dans cet emplacement", E_USER_ERROR); + } + + return ($result !== false) ? ($result[0]['cabinetId']) : (false); + } + + public function getCabinetLabelsByLocationId($locationId) + { + $result = $this->_restAPI->search->get(array('searchFor' => 'Cabinets', 'searchIn' => $locationId, 'query' => '*', 'format' => 'api_find_cabinet')); + $result = $this->_getCallResponse($result); // /!\ Pas besoin de nettoyer car on recherche des baies dans une localisation + + if($result !== false) + { + foreach($result as &$_result) { + $_result = $_result['name']; + } + + return $result; + } + + return false; + } + + public function getCabinetIdByEquipmentId($equipmentId) + { + $result = $this->_restAPI->equipment->setUrn('ids/'.$equipmentId)->get(array('format' => 'api_equipment_cabinet')); + $result = $this->_getCallResponse($result); + return ($result !== false) ? ($result['cabinetId']) : (false); + } + + // ## http://84.39.32.144:8080/pmserver/rest/equipment/ids/548287/?format=api_equipment + public function getEquipmentTemplateNameByEquipmentId($equipmentId) + { + $result = $this->_restAPI->equipment->setUrn('ids/'.$equipmentId)->get(array('format' => 'api_equipment')); + $result = $this->_getCallResponse($result); + return ($result !== false) ? ($result['template']) : (false); + } + + // ## http://84.39.32.144:8080/pmserver/rest/cabinets/ids/490895/?format=api_cabinet_equipment + public function getEquipmentIdsByCabinetId($cabinetId) + { + $result = $this->_restAPI->search->get(array('searchFor' => 'Equipment', 'searchIn' => $cabinetId, 'query' => '*', 'format' => 'api_find_equipment')); + $result = $this->_filterCallResponse($result, 'slotId', 'string&&!empty', null); + + if($result !== false) { + $result = $this->_sliceArray($result, array('equipmentId')); + $result = $this->_reduceArray($result); + return array_values($result); + } + + return false; + } + + public function getEquipmentIdByCabinetIdEquipmentLabel($cabinetId, $equipmentLabel) + { + //$result = $this->_restAPI->search->get(array('searchFor' => 'Equipment', 'searchIn' => $cabinetId, 'query' => '^('.preg_quote($equipmentLabel).')$', 'format' => 'api_find_equipment')); + $result = $this->_restAPI->search->get(array('searchFor' => 'Equipment', 'searchIn' => $cabinetId, 'regex' => 'true', 'query' => '('.preg_quote($equipmentLabel).')$', 'format' => 'api_find_equipment')); + $result = $this->_filterCallResponse($result, 'slotId', 'string&&!empty', null); + + if(count($result) > 1) { + throw new Exception("Il existe plusieurs équipements avec ce nom dans cet baie", E_USER_ERROR); + } + + return ($result !== false) ? ($result[0]['equipmentId']) : (false); + } + + // ## http://84.39.32.144:8080/pmserver/rest/cabinets/ids/490895/?format=api_cabinet_equipment + public function getEquipmentIdByCabinetIdPositionU($cabinetId, $positionU) + { + $result = $this->getEquipmentIdsByCabinetId($cabinetId); + + if($result !== false) + { + foreach($result as $equipmentId) { + list($side, $U) = $this->getUByEquipmentId($equipmentId); + if((int) $U === (int) $positionU) return $equipmentId; + } + } + + return false; + } + + // ## http://84.39.32.144:8080/pmserver/rest/equipment/ids/548287/?format=api_equipment + public function getUByEquipmentId($equipmentId) + { + $result = $this->_restAPI->equipment->setUrn('ids/'.$equipmentId)->get(array('format' => 'api_equipment')); + $result = $this->_getCallResponse($result); + return ($result !== false) ? (array( + 0 => $result['positionSide'], 1 => $result['positionU'], + 'side' => $result['positionSide'], 'U' => $result['positionU']) + ) : (false); // Compatibilité list() et key [] + } + + public function getEquipmentLabelsByCabinetId($cabinetId) + { + $result = $this->_restAPI->search->get(array('searchFor' => 'Equipment', 'searchIn' => $cabinetId, 'query' => '*', 'format' => 'api_find_equipment')); + $result = $this->_filterCallResponse($result, 'slotId', 'string&&!empty', null); + + if($result !== false) { + $result = $this->_sliceArray($result, array('name')); + $result = $this->_reduceArray($result); + return array_values($result); + } + + return false; + } + + public function getEquipmentIdBySlotId($slotId) + { + //$result = $this->_restAPI->search->get(array('searchFor' => 'Equipment', 'searchIn' => $slotId, 'query' => '*', 'format' => 'api_find_equipment')); + + $args = $this->getArgs(array($slotId)); + return $this->_soapInstances['getters']->getEquipmentFromSlot($args)->return; + } + + public function getEquipmentIdByPortId($portId) + { + $args = $this->getArgs(array($portId)); + return $this->_soapInstances['getters']->getEquipmentByPort($args)->return; + } + + public function getEquipmentIdByUserAttr($userAttrName, $userAttrValue) + { + $args = $this->getArgs(array($userAttrName, $userAttrValue)); + return $this->_soapInstances['resolver']->resolveEquipmentByAttribute($args)->return; + } + + public function getParentEquipmentIdByEquipmentId($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + return $this->_soapInstances['getters']->getParentEquipmentByEquipment($args)->return; + } + + public function getParentEquipmentIdBySlotId($slotId) + { + return $this->getEquipmentIdBySlotId($slotId); + } + + public function getParentEquipmentIdByPortId($portId) + { + return $this->getEquipmentIdByPortId($portId); + } + + public function getTopEquipmentIdBySlotId($slotId) + { + return $this->getTopLevelEquipmentIdBySlotId($slotId); + } + + public function getTopEquipmentIdByPortId($portId) + { + return $this->getTopLevelEquipmentIdByPortId($portId); + } + + public function getTopLevelEquipmentIdBySlotId($slotId) + { + $args = $this->getArgs(array($slotId)); + return $this->_soapInstances['getters']->getTopLevelEquipmentBySlot($args)->return; + } + + public function getTopLevelEquipmentIdByPortId($portId) + { + $args = $this->getArgs(array($portId)); + return $this->_soapInstances['getters']->getTopLevelEquipmentByPort($args)->return; + } + + public function getParentSlotIdByEquipmentId($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + return $this->_soapInstances['getters']->getParentSlotByEquipment($args)->return; + } + + public function getSlotIdsByEquipmentId($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + $slotIds = $this->_soapInstances['getters']->getAllSlotsIDs($args)->return; + return $this->explodeReturn($slotIds); + } + + public function getSlotIdByEquipmentIdSlotLabel($equipmentId, $slotLabel) + { + $args = $this->getArgs(array($equipmentId, $slotLabel)); + return $this->_soapInstances['resolver']->resolveSlot($args)->return; + } + + public function getSlotIdByParentEquipmentIdSlotLabel($equipmentId, $slotLabel) + { + $resultSlotIds = array(); + $slotIds = $this->getSlotIdsByEquipmentId($equipmentId); + + foreach($slotIds as $slotId) + { + if($this->isValidReturn($slotId)) // /!\ Important, risque de variable empty + { + $_slotLabel = $this->resolvToLabel('Slot', $slotId); + + if(!$this->isValidReturn($_slotLabel)) { + throw new Exception("Une erreur s'est produit pendant la convertion ID vers label", E_USER_ERROR); + } + elseif((string) $slotLabel === (string) $_slotLabel) { // /!\ Cast to string for numeric label + $resultSlotIds[] = $slotId; + } + else + { + $equipmentId = $this->getSubEquipmentIdBySlotId($slotId); + + if($this->isValidReturn($equipmentId)) + { + $result = $this->getSlotIdByParentEquipmentIdSlotLabel($equipmentId, $slotLabel); + + if($result !== false) { + $resultSlotIds[] = $result; + } + } + } + } + } + + $counter = count($resultSlotIds); + + if($counter > 1) { + throw new Exception("Il existe plusieurs slot correspondant à ce nom", E_USER_ERROR); + } + elseif($counter === 1) { + return $resultSlotIds[0]; + } + else { + return false; + } + } + + public function getSlotTemplateNameBySlotId($slotId) + { + $args = $this->getArgs(array('Slot', $slotId)); // /!\ Slot avec S en majuscule! + return $this->_soapInstances['getters']->getTemplateName($args)->return; + } + + public function getEquipmentIdsByParentEquipmentId($parentEquipmentId) + { + return $this->getSubEquipmentIdsByEquipmentId($parentEquipmentId); + } + + public function getSubEquipmentIdsByEquipmentId($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + $equipmentIds = $this->_soapInstances['getters']->getEquipmentFromEquipment($args)->return; + // /!\ Returns a list of database identifiers of the FIRST LEVEL CHILD equipment of equipment + + if($this->isValidReturn($equipmentIds)) + { + $_equipmentIds = array(); + $equipmentIds = explode(',', $equipmentIds); + + foreach($equipmentIds as $equipmentId) { + $temp = $this->getSubEquipmentIdsByEquipmentId($equipmentId); + $_equipmentIds = array_merge($_equipmentIds, $temp); + } + + return array_merge($equipmentIds, $_equipmentIds); + } + else { + return array(); + } + } + + public function getEquipmentIdByParentEquipmentIdEquipmentLabel($parentEquipmentId, $equipmentLabel) + { + $equipmentIds = $this->getEquipmentIdsByParentEquipmentId($parentEquipmentId); + + foreach($equipmentIds as $equipmentId) { + $_equipmentLabel = $this->resolvToLabel('Equipment', $equipmentId); + if($equipmentLabel === $_equipmentLabel) return $equipmentId; + } + + return false; + } + + public function getEquipmentIdByParentSlotId($parentSlotId) + { + return $this->getSubEquipmentIdBySlotId($parentSlotId); + } + + public function getSubEquipmentIdBySlotId($slotId) + { + $args = $this->getArgs(array($slotId)); + return $this->_soapInstances['getters']->getEquipmentFromSlot($args)->return; + } + + public function getPortIdsByEquipmentId($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + $portIds = $this->_soapInstances['getters']->getAllPortsIDs($args)->return; + return $this->explodeReturn($portIds); + } + + public function getPortIdByEquipmentIdPortLabel($equipmentId, $portLabel) + { + $args = $this->getArgs(array($equipmentId, $portLabel)); + return $this->_soapInstances['resolver']->resolvePort($args)->return; + } + + public function getPortIdByParentEquipmentIdPortLabel($equipmentId, $portLabel) + { + $resultPortIds = array(); + $equipmentIds = $this->getSubEquipmentIdsByEquipmentId($equipmentId); + array_unshift($equipmentIds, $equipmentId); + + foreach($equipmentIds as $equipmentId) + { + if($this->isValidReturn($equipmentId)) // /!\ Important, risque de variable empty + { + $portId = $this->getPortIdByEquipmentIdPortLabel($equipmentId, $portLabel); + + if($this->isValidReturn($portId)) { + $resultPortIds[] = $portId; + } + } + } + + $counter = count($resultPortIds); + + if($counter > 1) { + throw new Exception("Il existe plusieurs ports correspondant à ce nom", E_USER_ERROR); + } + elseif($counter === 1) { + return $resultPortIds[0]; + } + else { + return false; + } + } + + public function getConnectedPortIdByPortId($portId) + { + $args = $this->getArgs(array($portId)); + return $this->_soapInstances['getters']->getPortByPort($args)->return; + } + + public function getOtherSidePortIdByPortId($portId) + { + $args = $this->getArgs(array($portId)); + return $this->_soapInstances['getters']->getOtherSidePort($args)->return; + } + + public function getConnectedCableIdByPortId($portId) + { + $args = $this->getArgs(array($portId)); + return $this->_soapInstances['getters']->getConnectedCable($args)->return; + } + + public function getCableTemplateNameByCableId($cableId) + { + $args = $this->getArgs(array('Cable', $cableId)); // /!\ Cable avec C en majuscule! + return $this->_soapInstances['getters']->getTemplateName($args)->return; + } + + public function getUserAttrByEquipmentId($equipmentId, $userAttrName) + { + return $this->getUserAttrById('equipment', $equipmentId, $userAttrName); + } + + // @todo Utiliser USER_ATTR_LIST_SEPARATOR + public function getUserAttrById($type, $id, $userAttrName) + { + $args = $this->getArgs(array($type, $id, $userAttrName)); + return $this->_soapInstances['userAttrs']->getAttribute($args)->return; + } + + // @todo Utiliser USER_ATTR_LIST_SEPARATOR + public function getUserAttrsByEquipmentId($equipmentId) + { + $args = $this->getArgs(array('equipment', $equipmentId)); + return $this->_soapInstances['userAttrs']->getAllAttributeValues($args)->return; + } + + // @todo Utiliser USER_ATTR_LIST_SEPARATOR + public function getUserAttrsByPortId($portId) + { + $args = $this->getArgs(array('port', $portId)); + return $this->_soapInstances['userAttrs']->getAllAttributeValues($args)->return; + } + + // @todo Utiliser USER_ATTR_LIST_SEPARATOR + public function getUserAttrByPortId($portId, $userAttrName) + { + $args = $this->getArgs(array($portId, $userAttrName)); + return $this->_soapInstances['userAttrs']->getIdPortAttribute($args)->return; + } + + // @todo Utiliser USER_ATTR_LIST_SEPARATOR + public function getUserAttrByUserAttr($userAttrName, $userAttrValue, $returnUserAttrName) + { + $args = $this->getArgs(array($userAttrName, $userAttrValue, $returnUserAttrName)); + return $this->_soapInstances['userAttrs']->getAttributeByAttribute($args)->return; + } + + public function getUserAttrValues($userAttrName) + { + $args = $this->getArgs(array($userAttrName)); + return $this->_soapInstances['getters']->getPossibleAttributeValues($args); + } + + public function getArgs(array $args) + { + $_args = new ArrayObject(); + + if($this->_session !== null) { + $_args->arg0 = $this->_session; + $j=1; + } else { + $j=0; + } + + for($i=0;$i{"arg".$j} = $args[$i]; + $j++; + } + + return $_args; + } + + public function getUserAttrName($category, $key) + { + switch(mb_strtolower($category)) + { + case 'base': + case 'default': + { + if(array_key_exists($key, self::USER_ATTR_NAME__BASE)) { + return trim(self::USER_ATTR_PREFIX__BASE.' '.self::USER_ATTR_NAME__BASE[$key], ' '); + } + break; + } + + case 'net': + case 'network': + { + if(substr($key, -1) !== '#') { + $key .= '#'; + } + + $key = str_pad($key, 3, '0', STR_PAD_LEFT); + + if(array_key_exists($key, self::USER_ATTR_NAME__NETWORK)) { + return $key.' '.self::USER_ATTR_PREFIX__NETWORK.' '.self::USER_ATTR_NAME__NETWORK[$key]; + } + + break; + } + + case 'sys': + case 'system': + { + if(substr($key, -1) !== '#') { + $key .= '#'; + } + + $key = str_pad($key, 3, '0', STR_PAD_LEFT); + + if(array_key_exists($key, self::USER_ATTR_NAME__SYSTEM)) { + return $key.' '.self::USER_ATTR_PREFIX__SYSTEM.' '.self::USER_ATTR_NAME__SYSTEM[$key]; + } + + break; + } + + default: { + throw new Exception('Category unknow', E_USER_ERROR); + } + } + + return false; + } + } \ No newline at end of file diff --git a/addons/dcim/connector/rest/writer.php b/addons/dcim/connector/rest/writer.php new file mode 100644 index 0000000..adbf53f --- /dev/null +++ b/addons/dcim/connector/rest/writer.php @@ -0,0 +1,171 @@ +getArgs(array($templateName)); + $result = $this->_soapInstances['resolver']->templateExist($args)->return; + return ($this->isValidReturn($result) && $result === 'true'); + } + // ------------------------------- + + // ---------- Equipment ---------- + public function addEquipmentToCabinetId($cabinetId, $side, $positionU, $positionX, $templateName, $label = null, $description = null) + { + if($label === null) { + $label = $templateName; + } + + if($description === null) { + $description = ''; + } + + $args = $this->getArgs(array($cabinetId, $templateName, $side, $label, $description, $positionU, $positionX)); + return $this->_soapInstances['equipments']->addEquipmentInCabinet($args)->return; // return equipmentId + } + + public function addEquipmentToSlotId($slotId, $templateName, $label = null, $description = null, $side = self::SIDE_FRONT) + { + if($label === null) { + $label = $templateName; + } + + if($description === null) { + $description = ''; + } + + $side = ($side === self::SIDE_FRONT) ? (self::SIDE_REAR) : (self::SIDE_FRONT); // voir documentation + + $args = $this->getArgs(array($slotId, $templateName, $label, $description, $side)); + return $this->_soapInstances['equipments']->addEquipmentInSlot($args)->return; // return equipmentId + } + + public function updateEquipmentInfos($equipmentId, $label, $description = null) + { + if($description === null) { + $description = ''; + } + + $args = $this->getArgs(array($equipmentId, $label, $description)); + $result = $this->_soapInstances['equipments']->modifyEquipment($args)->return; + return ($result === 'success') ? (true) : ($result); + } + + public function removeEquipment($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + $result = $this->_soapInstances['equipments']->deleteEquipmentCascade($args)->return; + return ($result === 'success') ? (true) : ($result); + } + // ------------------------------- + + // ------------ Slot ------------- + public function updateSlotInfos($slotId, $label = null) + { + /** + * Modifies a slot's label. If the value of label is null then no + * change is made to the label. + */ + + $args = $this->getArgs(array($slotId, $label)); + $result = $this->_soapInstances['equipments']->modifySlot($args)->return; + return ($result === 'success') ? (true) : ($result); + } + // ------------------------------- + + // ------------ Port ------------- + public function updatePortInfos($portId, $label = null, $color = null) + { + /** + * Modifies a port's label and/or color. If the value of label is + * null then no change is made to the label . If the value of color + * is null then no change is made to the color. + */ + + $args = $this->getArgs(array($portId, $label, $color)); + return $this->_soapInstances['equipments']->modifyPort($args)->return; + } + + public function disconnectPort($portId) + { + $args = $this->getArgs(array($portId)); + return $this->_soapInstances['cables']->disconnectPort($args)->return; + } + // ------------------------------- + + // ------------ Cable ------------ + public function addCable($locationId, $templateName, $label, $description = null) + { + if($description === null) { + $description = ''; + } + + $args = $this->getArgs(array($locationId, $templateName, $label, $description)); + return $this->_soapInstances['cables']->addCable($args)->return; + } + + public function connectCable($cableId, $portId) + { + $args = $this->getArgs(array($cableId, $portId)); + $result = $this->_soapInstances['cables']->connectCable($args)->return; + return ($result === 'success') ? (true) : ($result); + } + + public function updateCableInfos($cableId, $label, $description = '') + { + $args = $this->getArgs(array($cableId, $label, $description)); + return $this->_soapInstances['cables']->updateCable($args)->return; + } + + // ------------------------------- + + // ---------- User Attrs --------- + public function setUserAttrByEquipmentId($equipmentId, $userAttrName, $userAttrValue) + { + if($userAttrValue === null) { + $userAttrValue = ""; + } + elseif(is_array($userAttrValue)) { + $userAttrValue = implode(self::USER_ATTR_LIST_SEPARATOR, $userAttrValue); + } + + $args = $this->getArgs(array('Equipment', $equipmentId, $userAttrName, $userAttrValue)); + $result = $this->_soapInstances['userAttrs']->setAttribute($args)->return; + return ($result === 'success') ? (true) : ($result); + } + + public function setUserAttrByPortId($portId, $userAttrName, $userAttrValue) + { + if($userAttrValue === null) { + $userAttrValue = ""; + } + elseif(is_array($userAttrValue)) { + $userAttrValue = implode(self::USER_ATTR_LIST_SEPARATOR, $userAttrValue); + } + + $args = $this->getArgs(array($portId, $userAttrName, $userAttrValue)); + $result = $this->_soapInstances['userAttrs']->setPortAttribute($args)->return; + return ($result === 'success') ? (true) : ($result); + } + // ------------------------------- + } \ No newline at end of file diff --git a/dcim/connector/soap.php b/addons/dcim/connector/soap.php similarity index 50% rename from dcim/connector/soap.php rename to addons/dcim/connector/soap.php index aa6cfa7..8416a00 100644 --- a/dcim/connector/soap.php +++ b/addons/dcim/connector/soap.php @@ -1,715 +1,1215 @@ - 'session-api?wsdl', - 'resolver' => 'resolver-api?wsdl', - 'getters' => 'getters-api?wsdl', - 'equipments' => 'equipment-api?wsdl', - 'cables' => 'cable-api?wsdl', - 'userAttrs' => 'user-attributes-api?wsdl', - 'search' => 'search-api?wsdl', - ); - - const DCIM_INVALID_SESSION_ID = -2147483648; - - const USER_ATTR_LIST_SEPARATOR = ':'; - - protected $_config; - protected $_server; - protected $_soapAPI; - protected $_session; - - protected $_debug = false; - - - public function __construct($server, $login, $password, $printInfoMessages = true) - { - $this->_config = CONFIG::getInstance()->DCIM; - - if($printInfoMessages) { - Tools::e(PHP_EOL."Connection SOAP au DCIM @ ".$server." veuillez patienter ... ", 'blue'); - } - - $this->_server = rtrim($server, '/'); - $this->_soapAPI = new ArrayObject(); - - $httpProxy = getenv('http_proxy'); - $httpsProxy = getenv('https_proxy'); - - $this->_initSoapAPI('session', $this->_server, self::SOAP_URN['session'], $httpProxy, $httpsProxy); - - $args = $this->getArgs(array($login, $password)); - $this->_session = $this->_soapAPI->session->startSession($args)->return; - - if($this->_session !== self::DCIM_INVALID_SESSION_ID) - { - $_urn = self::SOAP_URN; - unset($_urn['session']); - - foreach($_urn as $key => $urn) { - $this->_initSoapAPI($key, $this->_server, $urn, $httpProxy, $httpsProxy); - } - } - else { - throw new Exception("Unable to authenticate to DCIM", E_USER_ERROR); - } - - if($printInfoMessages) { - Tools::e("[OK]", 'green'); - } - } - - protected function _initSoapAPI($key, $server, $urn, $httpProxy, $httpsProxy) - { - $this->_soapAPI->{$key} = new SOAP($server.'/'.$urn, 'DCIM_'.$key); - } - - public function getJnlpUrl($version = 64) - { - if($version === 32 || $version === false) { - return $this->_server.'/patchmanager-alt.jnlp'; - } - else { - return $this->_server.'/patchmanager.jnlp'; - } - } - - public function getSiteId($siteName) - { - return $this->getLocationId($siteName); - } - - public function getLocationId($locationName) - { - $args = $this->getArgs(array($locationName)); - return $this->_soapAPI->resolver->resolveLocationToId($args)->return; - } - - public function getSubLocationId($locationId, $recursively = true) - { - $args = $this->getArgs(array($locationId)); - $subLocationId = $this->_soapAPI->getters->getSublocationsIdsById($args)->return; - - if(!empty($subLocationId)) - { - if(strpos($subLocationId, ',') !== false) { - throw new Exception("Il existe plusieurs sous emplacement pour cet emplacement", E_USER_ERROR); - } - - return ($recursively) ? ($this->getSubLocationId($subLocationId, true)) : ($subLocationId); - } - - return $locationId; - } - - public function getSubLocationIds($locationId, $recursively = true) - { - $args = $this->getArgs(array($locationId)); - $subLocationId = $this->_soapAPI->getters->getSublocationsIdsById($args)->return; - - if(!empty($subLocationId)) - { - $subLocationIds = explode(',', $subLocationId); - - if($recursively) - { - $result = array(); - - foreach($subLocationIds as &$subLocationId) - { - if($this->isValidReturn($subLocationId)) { - $result = array_merge($result, (array) $this->getSubLocationId($subLocationId, true)); - } - } - - return $result; - } - else { - return $subLocationIds; - } - } - - return array($locationId); - } - - public function getLocationIdByParentLocationIdLocationLabel($parentLocationId, $locationLabel, $recursively = true) - { - $args = $this->getArgs(array($parentLocationId)); - $locationIds = $this->_soapAPI->getters->getSublocationsIdsById($args)->return; - - if($this->isValidReturn($locationIds)) - { - $locationIds = explode(',', $locationIds); - - foreach($locationIds as $locationId) - { - $_locationLabel = $this->resolvToLabel('location', $locationId); - - if($locationLabel === $_locationLabel) { - return $locationId; - } - } - - if($recursively) - { - // /!\ On test en 1er si une location possède le bon label sinon on réitère - foreach($locationIds as $locationId) - { - $result = $this->getLocationIdByParentLocationIdLocationLabel($locationId, $locationLabel, true); - - if($result !== false) { - return $result; - } - } - } - } - - return false; - } - - public function getLocationIdByEquipmentId($equipmentId) - { - $args = $this->getArgs(array($equipmentId)); - return $this->_soapAPI->getters->getLocation($args)->return; - } - - public function getLocationPathByLocationId($locationId) - { - $args = $this->getArgs(array($locationId)); - return $this->_soapAPI->getters->getLocationPath($args)->return; - } - - public function getCabinetIdsByLocationId($locationId) - { - $cabinetIds = array(); - $cabinetLabels = $this->getCabinetLabelsByLocationId($locationId); - - foreach($cabinetLabels as $index => $cabinetLabel) - { - if($this->isValidReturn($cabinetLabel)) - { - $result = $this->getCabinetIdByLocationIdCabinetLabel($locationId, $cabinetLabel); - - if($this->isValidReturn($result)) { - $cabinetIds[] = $result; - } - } - } - - return $cabinetIds; - } - - public function getCabinetLabelsByLocationId($locationId) - { - $args = $this->getArgs(array($locationId)); - $cabinetLabels = $this->_soapAPI->getters->getCabinetsById($args)->return; - return $this->explodeReturn($cabinetLabels); - } - - public function getCabinetIdByLocationIdCabinetLabel($locationId, $cabinetLabel) - { - $args = $this->getArgs(array($cabinetLabel, $locationId)); - return $this->_soapAPI->resolver->resolveCabinetToId($args)->return; - } - - public function getCabinetIdByEquipmentId($equipmentId) - { - $args = $this->getArgs(array($equipmentId)); - return $this->_soapAPI->getters->getCabinetByEquipment($args)->return; - } - - public function getEquipmentTemplateNameByEquipmentId($equipmentId) - { - $args = $this->getArgs(array('Equipment', $equipmentId)); // /!\ Equipment avec E en majuscule! - return $this->_soapAPI->getters->getTemplateName($args)->return; - } - - public function getEquipmentIdByCabinetIdPositionU($cabinetId, $positionU) - { - $equipmentIds = $this->getEquipmentIdsByCabinetId($cabinetId); - - foreach($equipmentIds as $equipmentId) { - list($side, $U) = $this->getUByEquipmentId($equipmentId); - if((int) $U === (int) $positionU) return $equipmentId; - } - - return false; - } - - public function getUByEquipmentId($equipmentId) - { - $args = $this->getArgs(array($equipmentId)); - $position = $this->_soapAPI->equipments->getCabinetUPosition($args)->return; - $result = preg_match('#^U([0-9]{1,2})\[([a-z]*)\]$#i', $position, $matches); - return ($result === 1) ? (array(0 => $matches[2], 1 => $matches[1], 'side' => $matches[2], 'U' => $matches[1])) : (false); // Compatible list() et key [] - } - - public function getEquipmentLabelsByCabinetId($cabinetId) - { - $args = $this->getArgs(array('cabinet', $cabinetId)); - $equipmentLabels = $this->_soapAPI->getters->getEquipment($args)->return; - return $this->explodeReturn($equipmentLabels); - } - - public function getEquipmentIdsByCabinetId($cabinetId) - { - $equipmentIds = array(); - $equipmentLabels = $this->getEquipmentLabelsByCabinetId($cabinetId); - - foreach($equipmentLabels as $index => $equipmentLabel) - { - if($this->isValidReturn($equipmentLabel)) - { - $result = $this->getEquipmentIdByCabinetIdEquipmentLabel($cabinetId, $equipmentLabel); - - if($this->isValidReturn($result)) { - $equipmentIds[] = $result; - } - } - } - - return $equipmentIds; - } - - public function getEquipmentIdByLocationIdEquipmentLabel($locationId, $equipmentLabel) - { - $args = $this->getArgs(array($equipmentLabel, 'location', $locationId)); - return $this->_soapAPI->resolver->resolveEquipmentToId2($args)->return; - } - - public function getEquipmentIdByCabinetIdEquipmentLabel($cabinetId, $equipmentLabel) - { - $args = $this->getArgs(array($equipmentLabel, 'cabinet', $cabinetId)); - return $this->_soapAPI->resolver->resolveEquipmentToId2($args)->return; - } - - public function getEquipmentIdBySlotId($slotId) - { - $args = $this->getArgs(array($slotId)); - return $this->_soapAPI->getters->getEquipmentFromSlot($args)->return; - } - - public function getEquipmentIdByPortId($portId) - { - $args = $this->getArgs(array($portId)); - return $this->_soapAPI->getters->getEquipmentByPort($args)->return; - } - - public function getEquipmentIdByUserAttr($userAttrName, $userAttrValue) - { - $args = $this->getArgs(array($userAttrName, $userAttrValue)); - return $this->_soapAPI->resolver->resolveEquipmentByAttribute($args)->return; - } - - public function getParentEquipmentIdByEquipmentId($equipmentId) - { - $args = $this->getArgs(array($equipmentId)); - return $this->_soapAPI->getters->getParentEquipmentByEquipment($args)->return; - } - - public function getParentEquipmentIdBySlotId($slotId) - { - return $this->getEquipmentIdBySlotId($slotId); - } - - public function getParentEquipmentIdByPortId($portId) - { - return $this->getEquipmentIdByPortId($portId); - } - - public function getTopEquipmentIdBySlotId($slotId) - { - return $this->getTopLevelEquipmentIdBySlotId($slotId); - } - - public function getTopEquipmentIdByPortId($portId) - { - return $this->getTopLevelEquipmentIdByPortId($portId); - } - - public function getTopLevelEquipmentIdBySlotId($slotId) - { - $args = $this->getArgs(array($slotId)); - return $this->_soapAPI->getters->getTopLevelEquipmentBySlot($args)->return; - } - - public function getTopLevelEquipmentIdByPortId($portId) - { - $args = $this->getArgs(array($portId)); - return $this->_soapAPI->getters->getTopLevelEquipmentByPort($args)->return; - } - - public function getParentSlotIdByEquipmentId($equipmentId) - { - $args = $this->getArgs(array($equipmentId)); - return $this->_soapAPI->getters->getParentSlotByEquipment($args)->return; - } - - public function getSlotIdsByEquipmentId($equipmentId) - { - $args = $this->getArgs(array($equipmentId)); - $slotIds = $this->_soapAPI->getters->getAllSlotsIDs($args)->return; - return $this->explodeReturn($slotIds); - } - - public function getSlotIdByEquipmentIdSlotLabel($equipmentId, $slotLabel) - { - $args = $this->getArgs(array($equipmentId, $slotLabel)); - return $this->_soapAPI->resolver->resolveSlot($args)->return; - } - - public function getSlotIdByParentEquipmentIdSlotLabel($equipmentId, $slotLabel) - { - $resultSlotIds = array(); - $slotIds = $this->getSlotIdsByEquipmentId($equipmentId); - - foreach($slotIds as $slotId) - { - if($this->isValidReturn($slotId)) // /!\ Important, risque de variable empty - { - $_slotLabel = $this->resolvToLabel('Slot', $slotId); - - if(!$this->isValidReturn($_slotLabel)) { - throw new Exception("Une erreur s'est produit pendant la convertion ID vers label", E_USER_ERROR); - } - elseif((string) $slotLabel === (string) $_slotLabel) { // /!\ Cast to string for numeric label - $resultSlotIds[] = $slotId; - } - else - { - $equipmentId = $this->getSubEquipmentIdBySlotId($slotId); - - if($this->isValidReturn($equipmentId)) - { - $result = $this->getSlotIdByParentEquipmentIdSlotLabel($equipmentId, $slotLabel); - - if($result !== false) { - $resultSlotIds[] = $result; - } - } - } - } - } - - $counter = count($resultSlotIds); - - if($counter > 1) { - throw new Exception("Il existe plusieurs slot correspondant à ce nom", E_USER_ERROR); - } - elseif($counter === 1) { - return $resultSlotIds[0]; - } - else { - return false; - } - } - - public function getSlotTemplateNameBySlotId($slotId) - { - $args = $this->getArgs(array('Slot', $slotId)); // /!\ Slot avec S en majuscule! - return $this->_soapAPI->getters->getTemplateName($args)->return; - } - - public function getEquipmentIdsByParentEquipmentId($parentEquipmentId) - { - return $this->getSubEquipmentIdsByEquipmentId($parentEquipmentId); - } - - public function getSubEquipmentIdsByEquipmentId($equipmentId) - { - $args = $this->getArgs(array($equipmentId)); - $equipmentIds = $this->_soapAPI->getters->getEquipmentFromEquipment($args)->return; - // /!\ Returns a list of database identifiers of the FIRST LEVEL CHILD equipment of equipment - - if($this->isValidReturn($equipmentIds)) - { - $_equipmentIds = array(); - $equipmentIds = explode(',', $equipmentIds); - - foreach($equipmentIds as $equipmentId) { - $temp = $this->getSubEquipmentIdsByEquipmentId($equipmentId); - $_equipmentIds = array_merge($_equipmentIds, $temp); - } - - return array_merge($equipmentIds, $_equipmentIds); - } - else { - return array(); - } - } - - public function getEquipmentIdByParentEquipmentIdEquipmentLabel($parentEquipmentId, $equipmentLabel) - { - $equipmentIds = $this->getEquipmentIdsByParentEquipmentId($parentEquipmentId); - - foreach($equipmentIds as $equipmentId) { - $_equipmentLabel = $this->resolvToLabel('Equipment', $equipmentId); - if($equipmentLabel === $_equipmentLabel) return $equipmentId; - } - - return false; - } - - public function getEquipmentIdByParentSlotId($parentSlotId) - { - return $this->getSubEquipmentIdBySlotId($parentSlotId); - } - - public function getSubEquipmentIdBySlotId($slotId) - { - $args = $this->getArgs(array($slotId)); - return $this->_soapAPI->getters->getEquipmentFromSlot($args)->return; - } - - public function getPortIdsByEquipmentId($equipmentId) - { - $args = $this->getArgs(array($equipmentId)); - $portIds = $this->_soapAPI->getters->getAllPortsIDs($args)->return; - return $this->explodeReturn($portIds); - } - - public function getPortIdByEquipmentIdPortLabel($equipmentId, $portLabel) - { - $args = $this->getArgs(array($equipmentId, $portLabel)); - return $this->_soapAPI->resolver->resolvePort($args)->return; - } - - public function getPortIdByParentEquipmentIdPortLabel($equipmentId, $portLabel) - { - $resultPortIds = array(); - $equipmentIds = $this->getSubEquipmentIdsByEquipmentId($equipmentId); - array_unshift($equipmentIds, $equipmentId); - - foreach($equipmentIds as $equipmentId) - { - if($this->isValidReturn($equipmentId)) // /!\ Important, risque de variable empty - { - $portId = $this->getPortIdByEquipmentIdPortLabel($equipmentId, $portLabel); - - if($this->isValidReturn($portId)) { - $resultPortIds[] = $portId; - } - } - } - - $counter = count($resultPortIds); - - if($counter > 1) { - throw new Exception("Il existe plusieurs ports correspondant à ce nom", E_USER_ERROR); - } - elseif($counter === 1) { - return $resultPortIds[0]; - } - else { - return false; - } - } - - public function getConnectedPortIdByPortId($portId) - { - $args = $this->getArgs(array($portId)); - return $this->_soapAPI->getters->getPortByPort($args)->return; - } - - public function getOtherSidePortIdByPortId($portId) - { - $args = $this->getArgs(array($portId)); - return $this->_soapAPI->getters->getOtherSidePort($args)->return; - } - - public function getConnectedCableIdByPortId($portId) - { - $args = $this->getArgs(array($portId)); - return $this->_soapAPI->getters->getConnectedCable($args)->return; - } - - public function getCableTemplateNameByCableId($cableId) - { - $args = $this->getArgs(array('Cable', $cableId)); // /!\ Cable avec C en majuscule! - return $this->_soapAPI->getters->getTemplateName($args)->return; - } - - public function getUserAttrByEquipmentId($equipmentId, $userAttrName) - { - return $this->getUserAttrById('equipment', $equipmentId, $userAttrName); - } - - // @todo Utiliser USER_ATTR_LIST_SEPARATOR - public function getUserAttrById($type, $id, $userAttrName) - { - $args = $this->getArgs(array($type, $id, $userAttrName)); - return $this->_soapAPI->userAttrs->getAttribute($args)->return; - } - - // @todo Utiliser USER_ATTR_LIST_SEPARATOR - public function getUserAttrsByEquipmentId($equipmentId) - { - $args = $this->getArgs(array('equipment', $equipmentId)); - return $this->_soapAPI->userAttrs->getAllAttributeValues($args)->return; - } - - // @todo Utiliser USER_ATTR_LIST_SEPARATOR - public function getUserAttrsByPortId($portId) - { - $args = $this->getArgs(array('port', $portId)); - return $this->_soapAPI->userAttrs->getAllAttributeValues($args)->return; - } - - // @todo Utiliser USER_ATTR_LIST_SEPARATOR - public function getUserAttrByPortId($portId, $userAttrName) - { - $args = $this->getArgs(array($portId, $userAttrName)); - return $this->_soapAPI->userAttrs->getIdPortAttribute($args)->return; - } - - // @todo Utiliser USER_ATTR_LIST_SEPARATOR - public function getUserAttrByUserAttr($userAttrName, $userAttrValue, $returnUserAttrName) - { - $args = $this->getArgs(array($userAttrName, $userAttrValue, $returnUserAttrName)); - return $this->_soapAPI->userAttrs->getAttributeByAttribute($args)->return; - } - - public function getUserAttrValues($userAttrName) - { - $args = $this->getArgs(array($userAttrName)); - return $this->_soapAPI->getters->getPossibleAttributeValues($args); - } - - public function getReportResults($reportName, array $wildCards = null) - { - if($wildCards !== null) - { - array_walk($wildCards, function(&$value, $key) { - $value = preg_replace('#([^.])\*#i', '$1.*', $value); - $value = mb_strtolower($key).'-'.$value; - }); - - $wildCards = implode(',', $wildCards); - } - else { - $wildCards = ''; - } - - $args = $this->getArgs(array($reportName, $wildCards, 'csv', false, false, '')); - $results = $this->_soapAPI->search->reportToClient($args); - - if($this->isValidReturn($results)) { - $bytes = explode(';', $results->return); - //$csv = implode(array_map("chr", $bytes)); - $csv = pack('C*', ...$bytes); - $csv = str_replace("\n\000", '', $csv); - $csv = explode("\n", $csv); - array_walk($csv, function(&$line, $key) { - $line = str_getcsv($line, ';'); - }); - $keys = array_shift($csv); - array_walk($keys, function(&$key) { - $key = mb_strtolower($key); - $key = str_replace(' ', '_', $key); - }); - array_walk($csv, function(&$value, $key, $keys) { - $value = array_combine($keys, $value); - }, $keys); - return $csv; - - } - else { - return false; - } - } - - public function getArgs(array $args) - { - $_args = new ArrayObject(); - - if($this->_session !== null) { - $_args->arg0 = $this->_session; - $j=1; - } else { - $j=0; - } - - for($i=0;$i{"arg".$j} = $args[$i]; - $j++; - } - - return $_args; - } - - public function explodeReturn($return) - { - return explode(', ', trim($return, '[]')); - } - - public function isValidReturn($return) - { - /* - class stdClass#17 (1) { - public $return => - string(83) "[ERROR] java.io.FileNotFoundException: ./files/search/. (No such file or directory)" - } - */ - if($return instanceof stdClass) { - $return = $return->return; - } - - // /!\ Ne pas utiliser empty: var_dump(empty(0)) --> bool(true), un étage peut être 0 par exemple - return ($return !== "" && $return !== null && $return !== 'null' && $return !== false && !preg_match('#ERROR|EXCEPTION#i', $return)); - } - - public function resolvToLabel($type, $id) - { - $args = $this->getArgs(array($type, $id)); - return $this->_soapAPI->resolver->resolveToLabel($args)->return; - } - - public function getUserAttrName($category, $key) - { - switch(mb_strtolower($category)) - { - case 'base': - case 'common': - case 'default': - { - if(array_key_exists($key, $this->_config->userAttrs->default->labels)) { - return trim($this->_config->userAttrs->default->prefix.' '.$this->_config->userAttrs->default->labels[$key], ' '); - } - break; - } - - default: - { - if(array_key_exists($key, $this->_config->userAttrs->{$category}->labels)) { - return trim($this->_config->userAttrs->{$category}->prefix.' '.$this->_config->userAttrs->{$category}->labels[$key], ' '); - } - break; - } - } - - return false; - } - - public function debug($debug = true) - { - $this->_debug = (bool) $debug; - - foreach(self::SOAP_URN as $key => $urn) { - $this->_soapAPI->{$key}->debug($this->_debug); - } - - return $this; - } - - public function close() - { - $this->_soapAPI->session->closeSession($this->_session); - return $this; - } - - public function __destruct() - { - $this->close(); - } + 'session-api?wsdl', + 'resolver' => 'resolver-api?wsdl', + 'getters' => 'getters-api?wsdl', + 'equipments' => 'equipment-api?wsdl', + 'cables' => 'cable-api?wsdl', + 'userAttrs' => 'user-attributes-api?wsdl', + 'search' => 'search-api?wsdl', + ); + + const DCIM_INVALID_SESSION_ID = -2147483648; + + const USER_ATTR_LIST_SEPARATOR = ':'; + + const SIDE_FRONT = 'front'; + const SIDE_REAR = 'rear'; + + const FIBER_LC = 'fiber_lc'; + const FIBER_SC = 'fiber_sc'; + const FIBER_MM = 'fiber_multimode'; + const FIBER_SM = 'fiber_monomode'; + + const ETHERNET_RJ45 = 'ethernet_rj45'; + const ETHERNET_CAT6 = 'ethernet_cat6'; + + const CABLE_SIMPLEX = 'cable_simplex'; + const CABLE_DUPLEX = 'cable_duplex'; + + /** + * @var string + */ + protected $_id; + + /** + * DCIM configuration + * @var Core\Config + */ + protected $_config; + + /** + * @var string + */ + protected $_server; + + /** + * Core\Soap API + * @var \ArrayObject + */ + protected $_soapAPI; + + /** + * @var int + */ + protected $_session; + + /** + * CSV delimiter must be identical in GUI preference + * DCIM > Preferences > CSV delimiter + * + * @var string + */ + protected $_reportCsvDelimiter; + + /** + * @var bool + */ + protected $_debug = false; + + + public function __construct($id, $server, $login, $password, $printInfoMessages = true, $debug = false) + { + /** + * Pourra servir plus tard pour sélectionner une configuration + * différente en fonction de l'ID à partir de CONFIG + */ + $this->_id = $id; + $this->debug($debug); + + $this->_config = C\Config::getInstance()->DCIM; + + if($printInfoMessages) { + C\Tools::e(PHP_EOL."Connection SOAP au DCIM @ ".$server." veuillez patienter ... ", 'blue'); + } + + $this->_server = rtrim($server, '/'); + $this->_soapAPI = new ArrayObject(); + + $httpProxy = getenv('http_proxy'); + $httpsProxy = getenv('https_proxy'); + + $this->_initSoapAPI('session', $this->_server, self::SOAP_URN['session'], $httpProxy, $httpsProxy); + + $args = $this->getArgs(array($login, $password)); + $this->_session = $this->_soapAPI->session->startSession($args)->return; + + if($this->_session !== self::DCIM_INVALID_SESSION_ID) + { + $_urn = self::SOAP_URN; + unset($_urn['session']); + + foreach($_urn as $key => $urn) { + $this->_initSoapAPI($key, $this->_server, $urn, $httpProxy, $httpsProxy); + } + } + else { + throw new Exception("Unable to authenticate to DCIM", E_USER_ERROR); + } + + $this->_reportCsvDelimiter = $this->_config->preferences->report->csvDelimiter; + + if($printInfoMessages) { + C\Tools::e("[OK]", 'green'); + } + } + + protected function _initSoapAPI($key, $server, $urn, $httpProxy, $httpsProxy) + { + $this->_soapAPI->{$key} = new C\Soap($server.'/'.$urn, 'DCIM_'.$key, $this->_debug); + } + + public function getServerId() + { + return $this->_id; + } + + public function getJnlpUrl($version = 64) + { + if($version === 32 || $version === false) { + return $this->_server.'/patchmanager-alt.jnlp'; + } + else { + return $this->_server.'/patchmanager.jnlp'; + } + } + + // =========== READER ============ + public function getSiteId($siteName) + { + return $this->getLocationId($siteName); + } + + public function getLocationId($locationName) + { + $args = $this->getArgs(array($locationName)); + return $this->_soapAPI->resolver->resolveLocationToId($args)->return; + } + + public function getSubLocationId($locationId, $recursively = true) + { + $args = $this->getArgs(array($locationId)); + $subLocationId = $this->_soapAPI->getters->getSublocationsIdsById($args)->return; + + if(!empty($subLocationId)) + { + if(strpos($subLocationId, ',') !== false) { + throw new Exception("Il existe plusieurs sous emplacement pour cet emplacement", E_USER_ERROR); + } + + return ($recursively) ? ($this->getSubLocationId($subLocationId, true)) : ($subLocationId); + } + + return $locationId; + } + + /** + * @param $locationId int Location ID + * @param $recursively bool Recursively or not + * @return array All sub location IDs or array of the current location ID + */ + public function getSubLocationIds($locationId, $recursively = true) + { + $args = $this->getArgs(array($locationId)); + $subLocationId = $this->_soapAPI->getters->getSublocationsIdsById($args)->return; + + if(!empty($subLocationId)) + { + $subLocationIds = explode(',', $subLocationId); + + if($recursively) + { + $result = array(); + + foreach($subLocationIds as &$subLocationId) + { + if($this->isValidReturn($subLocationId)) { + $result = array_merge($result, (array) $this->getSubLocationId($subLocationId, true)); + } + } + + return $result; + } + else { + return $subLocationIds; + } + } + + return array($locationId); + } + + public function getLocationIdByParentLocationIdLocationLabel($parentLocationId, $locationLabel, $recursively = true) + { + $args = $this->getArgs(array($parentLocationId)); + $locationIds = $this->_soapAPI->getters->getSublocationsIdsById($args)->return; + + if($this->isValidReturn($locationIds)) + { + $locationIds = explode(',', $locationIds); + + foreach($locationIds as $locationId) + { + $_locationLabel = $this->resolvToLabel('location', $locationId); + + if($locationLabel === $_locationLabel) { + return $locationId; + } + } + + if($recursively) + { + // /!\ On test en 1er si une location possède le bon label sinon on réitère + foreach($locationIds as $locationId) + { + $result = $this->getLocationIdByParentLocationIdLocationLabel($locationId, $locationLabel, true); + + if($result !== false) { + return $result; + } + } + } + } + + return false; + } + + public function getLocationIdByEquipmentId($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + return $this->_soapAPI->getters->getLocation($args)->return; + } + + public function getLocationPathByLocationId($locationId) + { + $args = $this->getArgs(array($locationId)); + return $this->_soapAPI->getters->getLocationPath($args)->return; + } + + public function getCabinetTemplateNameByCabinetId($cabinetId) + { + $args = $this->getArgs(array('Cabinet', $cabinetId)); // /!\ Cabinet avec C en majuscule! + return $this->_soapAPI->getters->getTemplateName($args)->return; + } + + /** + * @param $locationId int Location ID + * @return array All cabinet IDs or empty array + */ + public function getCabinetIdsByLocationId($locationId) + { + $cabinetIds = array(); + $cabinetLabels = $this->getCabinetLabelsByLocationId($locationId); + + foreach($cabinetLabels as $index => $cabinetLabel) + { + if($this->isValidReturn($cabinetLabel)) + { + $result = $this->getCabinetIdByLocationIdCabinetLabel($locationId, $cabinetLabel); + + if($this->isValidReturn($result)) { + $cabinetIds[] = $result; + } + } + } + + return $cabinetIds; + } + + /** + * @param $locationId int Location ID + * @return array All cabinet labels or empty array + */ + public function getCabinetLabelsByLocationId($locationId) + { + $args = $this->getArgs(array($locationId)); + $cabinetLabels = $this->_soapAPI->getters->getCabinetsById($args)->return; + $cabinetLabels = $this->explodeReturn($cabinetLabels); + return $this->_castToString($cabinetLabels); + } + + public function getCabinetIdByLocationIdCabinetLabel($locationId, $cabinetLabel) + { + $args = $this->getArgs(array($cabinetLabel, $locationId)); + return $this->_soapAPI->resolver->resolveCabinetToId($args)->return; + } + + public function getCabinetIdByEquipmentId($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + return $this->_soapAPI->getters->getCabinetByEquipment($args)->return; + } + + public function getEquipmentTemplateNameByEquipmentId($equipmentId) + { + $args = $this->getArgs(array('Equipment', $equipmentId)); // /!\ Equipment avec E en majuscule! + return $this->_soapAPI->getters->getTemplateName($args)->return; + } + + public function getEquipmentIdByCabinetIdPositionU($cabinetId, $positionU) + { + $equipmentIds = $this->getEquipmentIdsByCabinetId($cabinetId); + + foreach($equipmentIds as $equipmentId) { + list($side, $U) = $this->getUByEquipmentId($equipmentId); + if((int) $U === (int) $positionU) return $equipmentId; + } + + return false; + } + + // @todo cast U to int + public function getUByEquipmentId($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + $position = $this->_soapAPI->equipments->getCabinetUPosition($args)->return; + $result = preg_match('#^U([0-9]{1,2})\[([a-z]*)\]$#i', $position, $matches); + return ($result === 1) ? (array(0 => $matches[2], 1 => $matches[1], 'side' => $matches[2], 'U' => $matches[1])) : (false); // Compatible list() et key [] + } + + /** + * @param $cabinetId int Cabinet ID + * @return array All equipment labels or empty array + */ + public function getEquipmentLabelsByCabinetId($cabinetId) + { + $args = $this->getArgs(array('cabinet', $cabinetId)); + $equipmentLabels = $this->_soapAPI->getters->getEquipment($args)->return; + $equipmentLabels = $this->explodeReturn($equipmentLabels); + return $this->_castToString($equipmentLabels); + } + + /** + * @param $cabinetId int Cabinet ID + * @return array All equipment IDs or empty array + */ + public function getEquipmentIdsByCabinetId($cabinetId) + { + $equipmentIds = array(); + $equipmentLabels = $this->getEquipmentLabelsByCabinetId($cabinetId); + + foreach($equipmentLabels as $index => $equipmentLabel) + { + if($this->isValidReturn($equipmentLabel)) + { + // May return [ERROR] More than one Equipment found for identifier *** + $result = $this->getEquipmentIdByCabinetIdEquipmentLabel($cabinetId, $equipmentLabel); + + if($this->isValidReturn($result)) { + $equipmentIds[] = $result; + } + } + } + + return $equipmentIds; + } + + public function getEquipmentIdByLocationIdEquipmentLabel($locationId, $equipmentLabel) + { + $args = $this->getArgs(array($equipmentLabel, 'location', $locationId)); + return $this->_soapAPI->resolver->resolveEquipmentToId2($args)->return; + } + + public function getEquipmentIdByCabinetIdEquipmentLabel($cabinetId, $equipmentLabel) + { + $args = $this->getArgs(array($equipmentLabel, 'cabinet', $cabinetId)); + return $this->_soapAPI->resolver->resolveEquipmentToId2($args)->return; + } + + public function getEquipmentIdBySlotId($slotId) + { + $args = $this->getArgs(array($slotId)); + return $this->_soapAPI->getters->getEquipmentFromSlot($args)->return; + } + + public function getEquipmentIdByPortId($portId) + { + $args = $this->getArgs(array($portId)); + return $this->_soapAPI->getters->getEquipmentByPort($args)->return; + } + + public function getEquipmentIdsByCableId($cableId) + { + $args = $this->getArgs(array($cableId)); + $equipmentIds = $this->_soapAPI->getters->getEquipmentIdByCable($args)->return; + + if(!$this->isValidReturn($equipmentIds)) { + return array(); + } + + $equipmentIds = $this->explodeReturn($equipmentIds); + return $this->_castToInt($equipmentIds); + } + + public function getEquipmentIdByUserAttr($userAttrName, $userAttrValue) + { + $args = $this->getArgs(array($userAttrName, $userAttrValue)); + return $this->_soapAPI->resolver->resolveEquipmentByAttribute($args)->return; + } + + public function getParentEquipmentIdByEquipmentId($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + return $this->_soapAPI->getters->getParentEquipmentByEquipment($args)->return; + } + + public function getParentEquipmentIdBySlotId($slotId) + { + return $this->getEquipmentIdBySlotId($slotId); + } + + public function getParentEquipmentIdByPortId($portId) + { + return $this->getEquipmentIdByPortId($portId); + } + + public function getTopEquipmentIdBySlotId($slotId) + { + return $this->getTopLevelEquipmentIdBySlotId($slotId); + } + + public function getTopEquipmentIdByPortId($portId) + { + return $this->getTopLevelEquipmentIdByPortId($portId); + } + + public function getTopLevelEquipmentIdBySlotId($slotId) + { + $args = $this->getArgs(array($slotId)); + return $this->_soapAPI->getters->getTopLevelEquipmentBySlot($args)->return; + } + + public function getTopLevelEquipmentIdByPortId($portId) + { + $args = $this->getArgs(array($portId)); + return $this->_soapAPI->getters->getTopLevelEquipmentByPort($args)->return; + } + + public function getParentSlotIdByEquipmentId($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + return $this->_soapAPI->getters->getParentSlotByEquipment($args)->return; + } + + /** + * @param $equipmentId int Equipment ID + * @return array All slot IDs or empty array + */ + public function getSlotIdsByEquipmentId($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + $slotIds = $this->_soapAPI->getters->getAllSlotsIDs($args)->return; + $slotIds = $this->explodeReturn($slotIds); + return $this->_castToInt($slotIds); + } + + public function getSlotIdsByEquipmentIdSlotLabel($equipmentId, $slotLabel) + { + $resultSlotIds = array(); + $slotIds = $this->getSlotIdsByEquipmentId($equipmentId); + + foreach($slotIds as $slotId) + { + $_slotLabel = $this->resolvToLabel('Slot', $slotId); + + if(!$this->isValidReturn($_slotLabel)) { + throw new Exception("Unable to retrieve slot label from id '".$slotId."': ".$_slotLabel, E_USER_ERROR); + } + elseif((string) $slotLabel === (string) $_slotLabel) { // /!\ Cast to string for numeric label + $resultSlotIds[] = $slotId; + } + } + + return $resultSlotIds; + } + + public function getSlotIdByEquipmentIdSlotLabel($equipmentId, $slotLabel) + { + $args = $this->getArgs(array($equipmentId, $slotLabel)); + return $this->_soapAPI->resolver->resolveSlot($args)->return; + + /* + $slotIds = $this->getSlotIdsByEquipmentIdSlotLabel($equipmentId, $slotLabel); + return (count($slotIds) === 1) ? (current($slotIds)) : (false); + */ + } + + /** + * @param $equipmentId int Equipment ID + * @param $slotLabel string Slot label + * @return array All slot IDs or empty array + */ + public function getSlotIdsByParentEquipmentIdSlotLabel($equipmentId, $slotLabel) + { + $resultSlotIds = array(); + $slotIds = $this->getSlotIdsByEquipmentId($equipmentId); + + foreach($slotIds as $slotId) + { + $_slotLabel = $this->resolvToLabel('Slot', $slotId); + + if(!$this->isValidReturn($_slotLabel)) { + throw new Exception("Unable to retrieve slot label from id '".$slotId."': ".$_slotLabel, E_USER_ERROR); + } + elseif((string) $slotLabel === (string) $_slotLabel) { // /!\ Cast to string for numeric label + $resultSlotIds[] = $slotId; + } + + // Un slot peut contenir d'autres équipements, il faut donc les parcourir + $equipmentId = $this->getSubEquipmentIdBySlotId($slotId); + + if($this->isValidReturn($equipmentId)) + { + $results = $this->getSlotIdsByParentEquipmentIdSlotLabel($equipmentId, $slotLabel); + + if($results !== false) { + $resultSlotIds = array_merge($resultSlotIds, $results); + } + } + } + + return $resultSlotIds; + } + + public function getSlotIdByParentEquipmentIdSlotLabel($equipmentId, $slotLabel) + { + $slotIds = $this->getSlotIdsByParentEquipmentIdSlotLabel($equipmentId, $slotLabel); + return (count($slotIds) === 1) ? (current($slotIds)) : (false); + } + + public function getSlotTemplateNameBySlotId($slotId) + { + $args = $this->getArgs(array('Slot', $slotId)); // /!\ Slot avec S en majuscule! + return $this->_soapAPI->getters->getTemplateName($args)->return; + } + + public function getEquipmentIdsByParentEquipmentId($parentEquipmentId) + { + return $this->getSubEquipmentIdsByEquipmentId($parentEquipmentId); + } + + public function getSubEquipmentIdsByEquipmentId($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + $subEquipmentIds = $this->_soapAPI->getters->getEquipmentFromEquipment($args)->return; + // /!\ Returns a list of database identifiers of the FIRST LEVEL CHILD equipment of equipment + + if($this->isValidReturn($subEquipmentIds)) + { + $results = $subEquipmentIds; + //$subEquipmentIds = explode(',', $subEquipmentIds); + $subEquipmentIds = $this->explodeReturn($subEquipmentIds); + $subEquipmentIds = $this->_castToInt($subEquipmentIds); + + foreach($subEquipmentIds as $subEquipmentId) { + $equipmentIds = $this->getSubEquipmentIdsByEquipmentId($subEquipmentId); + $results = array_merge($results, $equipmentIds); + } + + return $results; + } + else { + return array(); + } + } + + public function getEquipmentIdByParentEquipmentIdEquipmentLabel($parentEquipmentId, $equipmentLabel) + { + $equipmentIds = $this->getEquipmentIdsByParentEquipmentId($parentEquipmentId); + + foreach($equipmentIds as $equipmentId) { + $_equipmentLabel = $this->resolvToLabel('Equipment', $equipmentId); + if($equipmentLabel === $_equipmentLabel) return $equipmentId; + } + + return false; + } + + public function getEquipmentIdByParentSlotId($parentSlotId) + { + return $this->getSubEquipmentIdBySlotId($parentSlotId); + } + + public function getSubEquipmentIdBySlotId($slotId) + { + $args = $this->getArgs(array($slotId)); + return $this->_soapAPI->getters->getEquipmentFromSlot($args)->return; + } + + public function getPortTemplateNameByPortId($portId) + { + $args = $this->getArgs(array('Port', $portId)); // /!\ Port avec P en majuscule! + return $this->_soapAPI->getters->getTemplateName($args)->return; + } + + /** + * Return all port IDs of equipment and sub equipments + * Do not browse sub equipments to get port IDs + * + * @param $equipmentId int Equipment ID + * @return array All port IDs or empty array + */ + public function getPortIdsByEquipmentId($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + $portIds = $this->_soapAPI->getters->getAllPortsIDs($args)->return; + $portIds = $this->explodeReturn($portIds); + return $this->_castToInt($portIds); + } + + public function getPortIdsByEquipmentIdPortLabel($equipmentId, $portLabel) + { + $resultPortIds = array(); + $portIds = $this->getPortIdsByEquipmentId($equipmentId); + + foreach($portIds as $portId) + { + $_portLabel = $this->resolvToLabel('Port', $portId); + + if(!$this->isValidReturn($_portLabel)) { + throw new Exception("Unable to retrieve port label from id '".$portId."': ".$_portLabel, E_USER_ERROR); + } + elseif((string) $portLabel === (string) $_portLabel) { // /!\ Cast to string for numeric label + $resultPortIds[] = $portId; + } + } + + return $resultPortIds; + } + + public function getPortIdByEquipmentIdPortLabel($equipmentId, $portLabel) + { + $args = $this->getArgs(array($equipmentId, $portLabel)); + return $this->_soapAPI->resolver->resolvePort($args)->return; + + /* + $portIds = $this->getPortIdsByEquipmentIdPortLabel($equipmentId, $portLabel); + return (count($portIds) === 1) ? (current($portIds)) : (false); + */ + } + + /** + * @param $equipmentId int Equipment ID + * @param $portLabel string Port label + * @return array All port IDs or empty array + */ + public function getPortIdsByParentEquipmentIdPortLabel($equipmentId, $portLabel) + { + return $this->getPortIdsByEquipmentIdPortLabel($equipmentId, $portLabel); + + // Un équipement peut contenir d'autres équipements, il faut donc les parcourir + /*$equipmentIds = $this->getSubEquipmentIdsByEquipmentId($equipmentId); + + foreach($equipmentIds as $equipmentId) + { + if($this->isValidReturn($equipmentId)) { + $results = $this->getPortIdsByParentEquipmentIdPortLabel($equipmentId, $portLabel); + $resultPortIds = array_merge($resultPortIds, $results); + } + } + + return $resultPortIds;*/ + } + + public function getPortIdByParentEquipmentIdPortLabel($equipmentId, $portLabel) + { + $portIds = $this->getPortIdsByParentEquipmentIdPortLabel($equipmentId, $portLabel); + return (count($portIds) === 1) ? (current($portIds)) : (false); + } + + public function getConnectedPortIdByPortId($portId) + { + $args = $this->getArgs(array($portId)); + return $this->_soapAPI->getters->getPortByPort($args)->return; + } + + public function getOtherSidePortIdByPortId($portId) + { + $args = $this->getArgs(array($portId)); + return $this->_soapAPI->getters->getOtherSidePort($args)->return; + } + + public function getConnectedCableIdByPortId($portId) + { + $args = $this->getArgs(array($portId)); + return $this->_soapAPI->getters->getConnectedCable($args)->return; + } + + public function getCableTemplateNameByCableId($cableId) + { + $args = $this->getArgs(array('Cable', $cableId)); // /!\ Cable avec C en majuscule! + return $this->_soapAPI->getters->getTemplateName($args)->return; + } + + public function getUserAttrsByEquipmentId($equipmentId) + { + return $this->getUserAttrsById('equipment', $equipmentId); + } + + public function getUserAttrByEquipmentId($equipmentId, $userAttrName) + { + return $this->getUserAttrById('equipment', $equipmentId, $userAttrName); + } + + // @todo Utiliser USER_ATTR_LIST_SEPARATOR + public function getUserAttrBySlotId($slotId, $userAttrName) + { + $args = $this->getArgs(array($slotId, $userAttrName)); + return $this->_soapAPI->userAttrs->getIdSlotAttribute($args)->return; + } + + // @todo Utiliser USER_ATTR_LIST_SEPARATOR + public function getUserAttrByPortId($portId, $userAttrName) + { + $args = $this->getArgs(array($portId, $userAttrName)); + return $this->_soapAPI->userAttrs->getIdPortAttribute($args)->return; + } + + // @todo Utiliser USER_ATTR_LIST_SEPARATOR + public function getUserAttrsById($type, $id) + { + $args = $this->getArgs(array($type, $id)); + return $this->_soapAPI->userAttrs->getAllAttributeValues($args)->return; + } + + // @todo Utiliser USER_ATTR_LIST_SEPARATOR + public function getUserAttrById($type, $id, $userAttrName) + { + $args = $this->getArgs(array($type, $id, $userAttrName)); + return $this->_soapAPI->userAttrs->getAttribute($args)->return; + } + + // @todo Utiliser USER_ATTR_LIST_SEPARATOR + public function getUserAttrByUserAttr($userAttrName, $userAttrValue, $returnUserAttrName) + { + $args = $this->getArgs(array($userAttrName, $userAttrValue, $returnUserAttrName)); + return $this->_soapAPI->userAttrs->getAttributeByAttribute($args)->return; + } + + public function getUserAttrValues($userAttrName) + { + $args = $this->getArgs(array($userAttrName)); + return $this->_soapAPI->getters->getPossibleAttributeValues($args); + } + + public function getReportResults($reportName, array $wildCards = null) + { + if($wildCards !== null) + { + array_walk($wildCards, function(&$value, $key) { + $value = preg_quote($value); + $value = str_ireplace('\\*', '.*', $value); + $value = mb_strtolower($key).'-'.$value; + }); + + $wildCards = implode(',', $wildCards); + } + else { + $wildCards = ''; + } + + $args = $this->getArgs(array($reportName, $wildCards, 'csv', false, false, '')); + $results = $this->_soapAPI->search->reportToClient($args); + + // [ERROR] [ERROR] Incorrect format of the Wild Cards. + if($this->isValidReturn($results)) { + $bytes = explode(';', $results->return); + //$csv = implode(array_map("chr", $bytes)); + $csv = pack('C*', ...$bytes); + $csv = str_replace("\n\000", '', $csv); + $csv = explode("\n", $csv); + array_walk($csv, function(&$line, $key) { + $line = str_getcsv($line, $this->_reportCsvDelimiter); + }); + $keys = array_shift($csv); + array_walk($keys, function(&$key) { + $key = mb_strtolower($key); + $key = str_replace(' ', '_', $key); + }); + array_walk($csv, function(&$value, $key, $keys) { + $value = array_combine($keys, $value); + }, $keys); + return $csv; + + } + else { + return false; + } + } + + public function getArgs(array $args) + { + $_args = new ArrayObject(); + + if($this->_session !== null) { + $_args->arg0 = $this->_session; + $j=1; + } else { + $j=0; + } + + for($i=0;$i{"arg".$j} = $args[$i]; + $j++; + } + + return $_args; + } + + public function explodeReturn($return) + { + return explode(', ', trim($return, '[]')); + } + + public function isValidReturn($return) + { + /* + class stdClass#17 (1) { + public $return => + string(83) "[ERROR] java.io.FileNotFoundException: ./files/search/. (No such file or directory)" + } + */ + if($return instanceof \stdClass) { + $return = $return->return; + } + + // /!\ Ne pas utiliser empty: var_dump(empty(0)) --> bool(true), un étage peut être 0 par exemple + return ($return !== "" && $return !== null && $return !== 'null' && $return !== false && !preg_match('#ERROR|EXCEPTION#i', $return)); + } + + public function resolvToLabel($type, $id) + { + $args = $this->getArgs(array($type, $id)); + return $this->_soapAPI->resolver->resolveToLabel($args)->return; + } + + public function resolvToTemplate($type, $id) + { + $args = $this->getArgs(array(ucfirst($type), $id)); + return $this->_soapAPI->getters->getTemplateName($args)->return; + } + + /** + * @param string $category + * @param string $key + * @return false|string + */ + public function getUserAttrName($category, $key) + { + switch(mb_strtolower($category)) + { + case 'base': + case 'common': + case 'default': + { + if($this->_config->userAttrs->default->labels->key_exists($key)) { + return trim($this->_config->userAttrs->default->prefix.' '.$this->_config->userAttrs->default->labels[$key], ' '); + } + break; + } + + case 'net': + case 'network': + { + if(substr($key, -1) !== '#') { + $key .= '#'; + } + + $key = str_pad($key, 3, '0', STR_PAD_LEFT); + + if($this->_config->userAttrs->network->labels->key_exists($key)) { + return $key.' '.$this->_config->userAttrs->network->prefix.' '.$this->_config->userAttrs->network->labels[$key]; + } + + break; + } + + case 'sys': + case 'system': + { + if(substr($key, -1) !== '#') { + $key .= '#'; + } + + $key = str_pad($key, 3, '0', STR_PAD_LEFT); + + if($this->_config->userAttrs->system->labels->key_exists($key)) { + return $key.' '.$this->_config->userAttrs->system->prefix.' '.$this->_config->userAttrs->system->labels[$key]; + } + + break; + } + + default: + { + if($this->_config->userAttrs->{$category}->labels->key_exists($key)) { + return trim($this->_config->userAttrs->{$category}->prefix.' '.$this->_config->userAttrs->{$category}->labels[$key], ' '); + } + break; + } + } + + return false; + } + // =============================== + + // =========== WRITER ============ + // ---------- Template ----------- + public function templateExists($templateName) + { + $args = $this->getArgs(array($templateName)); + $result = $this->_soapAPI->resolver->templateExist($args)->return; + return ($this->isValidReturn($result) && $result === 'true'); + } + // ------------------------------- + + // ---------- Equipment ---------- + public function addEquipmentToCabinetId($cabinetId, $side, $positionU, $positionX, $templateName, $label = null, $description = null) + { + if($label === null) { + $label = $templateName; + } + + if($description === null) { + $description = ''; + } + + $args = $this->getArgs(array($cabinetId, $templateName, $side, $label, $description, $positionU, $positionX)); + $result = $this->_soapAPI->equipments->addEquipmentInCabinet($args)->return; // return equipmentId or error + + if($this->isValidReturn($result)) { + return $result; + } + else { + throw new E\Message($result, E_USER_ERROR); + } + } + + public function addEquipmentToSlotId($slotId, $templateName, $label = null, $description = null, $side = self::SIDE_FRONT) + { + if($label === null) { + $label = $templateName; + } + + if($description === null) { + $description = ''; + } + + $side = ($side === self::SIDE_FRONT) ? (self::SIDE_REAR) : (self::SIDE_FRONT); // voir documentation + + $args = $this->getArgs(array($slotId, $templateName, $label, $description, $side)); + $result = $this->_soapAPI->equipments->addEquipmentInSlot($args)->return; // return equipmentId or error + + if($this->isValidReturn($result)) { + return $result; + } + else { + throw new E\Message($result, E_USER_ERROR); + } + } + + public function updateEquipmentInfos($equipmentId, $label, $description = null) + { + $args = $this->getArgs(array($equipmentId, $label, $description)); + $result = $this->_soapAPI->equipments->modifyEquipment($args)->return; + + if($result === 'success') { + return true; + } + else { + throw new E\Message($result, E_USER_ERROR); + } + } + + public function removeEquipment($equipmentId) + { + $args = $this->getArgs(array($equipmentId)); + $result = $this->_soapAPI->equipments->deleteEquipmentCascade($args)->return; + + if($result === 'success') { + return true; + } + else { + throw new E\Message($result, E_USER_ERROR); + } + } + // ------------------------------- + + // ------------ Slot ------------- + public function updateSlotInfos($slotId, $label = null) + { + /** + * Modifies a slot's label. If the value of label is null then no + * change is made to the label. + */ + + $args = $this->getArgs(array($slotId, $label)); + $result = $this->_soapAPI->equipments->modifySlot($args)->return; + + if($result === 'success') { + return true; + } + else { + throw new E\Message($result, E_USER_ERROR); + } + } + // ------------------------------- + + // ------------ Port ------------- + public function updatePortInfos($portId, $label = null, $color = null) + { + /** + * Modifies a port's label and/or color. If the value of label is + * null then no change is made to the label . If the value of color + * is null then no change is made to the color. + */ + + $args = $this->getArgs(array($portId, $label, $color)); + $result = $this->_soapAPI->equipments->modifyPort($args)->return; + + if($result === 'success') { + return true; + } + else { + throw new E\Message($result, E_USER_ERROR); + } + } + + public function disconnectPort($portId) + { + $args = $this->getArgs(array($portId)); + $result = $this->_soapAPI->cables->disconnectPort($args)->return; + + if($result === 'success') { + return true; + } + else { + throw new E\Message($result, E_USER_ERROR); + } + } + // ------------------------------- + + // ------------ Cable ------------ + public function addCable($locationId, $templateName, $label, $description = '') + { + $args = $this->getArgs(array($locationId, $templateName, $label, $description)); + $result = $this->_soapAPI->cables->addCable($args)->return; // return cableId or error + + if($this->isValidReturn($result)) { + return $result; + } + else { + throw new E\Message($result, E_USER_ERROR); + } + } + + public function connectCable($cableId, $portId) + { + $args = $this->getArgs(array($cableId, $portId)); + $result = $this->_soapAPI->cables->connectCable($args)->return; + + if($result === 'success') { + return true; + } + else { + throw new E\Message($result, E_USER_ERROR); + } + } + + public function updateCableInfos($cableId, $label = null, $description = '') + { + $args = $this->getArgs(array($cableId, $label, $description)); + $result = $this->_soapAPI->cables->updateCable($args)->return; + + if($result === 'success') { + return true; + } + else { + throw new E\Message($result, E_USER_ERROR); + } + } + + public function removeCable($cableId) + { + $args = $this->getArgs(array($cableId)); + $result = $this->_soapAPI->cables->deleteCable($args)->return; + + if($result === 'success') { + return true; + } + else { + throw new E\Message($result, E_USER_ERROR); + } + } + // ------------------------------- + + // ---------- User Attrs --------- + public function setUserAttrByEquipmentId($equipmentId, $userAttrName, $userAttrValue) + { + if($userAttrValue === null) { + $userAttrValue = ""; + } + elseif(is_array($userAttrValue)) { + $userAttrValue = implode(self::USER_ATTR_LIST_SEPARATOR, $userAttrValue); + } + + $args = $this->getArgs(array('Equipment', $equipmentId, $userAttrName, $userAttrValue)); + $result = $this->_soapAPI->userAttrs->setAttribute($args)->return; + + if($result === 'success') { + return true; + } + else { + throw new E\Message($result, E_USER_ERROR); + } + } + + public function setUserAttrByPortId($portId, $userAttrName, $userAttrValue) + { + if($userAttrValue === null) { + $userAttrValue = ""; + } + elseif(is_array($userAttrValue)) { + $userAttrValue = implode(self::USER_ATTR_LIST_SEPARATOR, $userAttrValue); + } + + $args = $this->getArgs(array($portId, $userAttrName, $userAttrValue)); + $result = $this->_soapAPI->userAttrs->setPortAttribute($args)->return; + + if($result === 'success') { + return true; + } + else { + throw new E\Message($result, E_USER_ERROR); + } + } + // ------------------------------- + // =============================== + + /** + * @param bool $debug + * @return $this + */ + public function debug($debug = true) + { + $this->_debug = (bool) $debug; + + foreach(self::SOAP_URN as $key => $urn) + { + if(isset($this->_soapAPI->{$key})) { + $this->_soapAPI->{$key}->debug($this->_debug); + } + } + + return $this; + } + + public function close() + { + $this->_soapAPI->session->closeSession($this->_session); + return $this; + } + + public function __destruct() + { + $this->close(); + } + + protected function _castToInt(array $datas) + { + foreach($datas as $index => &$data) + { + if($this->isValidReturn($data)) { // /!\ Risque de variable empty + $data = (int) $data; + } + else { + unset($datas[$index]); + } + } + + return $datas; + } + + protected function _castToString(array $datas) + { + foreach($datas as $index => &$data) + { + if($this->isValidReturn($data)) { // /!\ Risque de variable empty + $data = (string) $data; + } + else { + unset($datas[$index]); + } + } + + return $datas; + } } \ No newline at end of file diff --git a/addons/dcim/equipment.php b/addons/dcim/equipment.php new file mode 100644 index 0000000..78d5ee3 --- /dev/null +++ b/addons/dcim/equipment.php @@ -0,0 +1,492 @@ +_equipmentId = (int) $equipmentId; + $this->_equipmentApi = new Api_Equipment($this->_equipmentId); // /!\ Ne pas passer null + } + + public static function getInstance($equipmentId) + { + $Api_Equipment = new Api_Equipment($equipmentId); + $hostName = self::_getHostName($Api_Equipment); + return (static::isEquipment($hostName)) ? (new static($equipmentId)) : (false); + } + + public function declareSlot(Equipment_Slot $Equipment_Slot) + { + $slotKey = $Equipment_Slot->getSlotKey(); + + if(array_key_exists($slotKey, $this->_slots)) { + throw new Exception("Ce slot est déjà déclaré @ ".$slotKey, E_USER_ERROR); + } + + $this->_slots[$slotKey] = $Equipment_Slot; + return $this; + } + + abstract public function declarePort(Equipment_Port $Equipment_Port); + + public function undeclarePort(Equipment_Port $Equipment_Port) + { + $portKey = $Equipment_Port->getPortKey(); + unset($this->{$portKey}); + + $this->_datas = array(); + $this->_portsDatas = null; + $this->_intsDatas = null; + + return $this; + } + + public function declareInterface(Equipment_Interface $Equipment_Interface) + { + $intKey = $Equipment_Interface->getIntKey(); + $intIndex = $Equipment_Interface->getIntIndex(); + + if($intIndex !== false) { $intKey .= '__'.$intIndex; } + + if(array_key_exists($intKey, $this->_ints)) { + throw new Exception("Cette interface est déjà déclarée @ ".$intKey, E_USER_ERROR); + } + + $this->_ints[$intKey] = $Equipment_Interface; + return $this; + } + + public function getSlot($slotKey) + { + return (array_key_exists($slotKey, $this->_slots)) ? ($this->_slots[$slotKey]) : (false); + } + + public function getPort($portKey) + { + return (array_key_exists($portKey, $this->_ports)) ? ($this->_ports[$portKey]) : (false); + } + + // /!\ On peut demander une interface physique comme virtuelle + public function getInterface($intKey, $intIndex = false) + { + // /!\ On doit traiter les 2 cas + $intKey = str_replace(Equipment_Interface_Physical::INT_SEPARATOR, '__', $intKey, $countPort); + $intKey = str_replace(Equipment_Interface_Virtual::INT_SEPARATOR, '__', $intKey, $countInt); + + if($countPort === 0 && $countInt === 0 && $intIndex !== false) { + $intKey .= '__'.$intIndex; + } + + return (array_key_exists($intKey, $this->_ints)) ? ($this->_ints[$intKey]) : (false); + } + + /*public function getPortKeys() + { + return array_keys($this->ports); + } + + public function getIntKeys() + { + return array_keys($this->ints); + }*/ + + public function getEquipmentId() + { + return $this->_equipmentId; + } + + public function getHostName() + { + if(!array_key_exists('hostName', $this->_datas)) { + $this->_datas['hostName'] = self::_getHostName($this->_equipmentApi); + } + + return $this->_datas['hostName']; + } + + protected function _getSlots() + { + if($this->_slotsDatas === null) + { + $this->_slotsDatas = array(); // /!\ Important + + foreach($this->slots as $slot) { + C\Tools::merge($this->_slotsDatas, $slot->getDatas()); + } + } + + return $this->_slotsDatas; + } + + protected function _getPorts() + { + if($this->_portsDatas === null) + { + $this->_portsDatas = array(); // /!\ Important + + foreach($this->ports as $port) { + $datas = $port->getDatas(); + $nbDatas = $port->getNeighborDatas(); + $allDatas = array_merge_recursive($datas, $nbDatas); + C\Tools::merge($this->_portsDatas, $allDatas); + } + } + + return $this->_portsDatas; + } + + /** + * Retourne les interfaces suivantes: + * Port, LA, L3 + **/ + protected function _getInts() + { + if($this->_intsDatas === null) + { + $this->_intsDatas = array(); // /!\ Important + + foreach($this->ints as $int) { + $datas = $int->getDatas(); + $nbDatas = $int->getNeighborDatas(); + $allDatas = array_merge_recursive($datas, $nbDatas); + C\Tools::merge($this->_intsDatas, $allDatas); + } + } + + return $this->_intsDatas; + } + + public function getInterfaces() + { + if(!array_key_exists('interfaces', $this->_datas)) + { + $this->_datas['interfaces'] = array(); // /!\ Important + + $slotDatas = $this->_getSlots(); + $portDatas = $this->_getPorts(); + $intDatas = $this->_getInts(); + +/*echo "\r\nDEBUG 0\r\n\t";var_dump($slotDatas); +echo "\r\n\t";var_dump($portDatas); +echo "\r\n\t";var_dump($intDatas);echo "\r\nEND 0\r\n";*/ + + $slotKeys = array_keys($slotDatas); + $portKeys = array_keys($portDatas); + $dualSlotPort = array_intersect($slotKeys, $portKeys); + + /** + * /!\ Exemple port em0 d'un Juniper QFX5100 + */ + foreach($dualSlotPort as $key) + { + $slotIsEmpty = $this->getSlot($key)->isEmpty(); + $portIsConnected = $this->getPort($key)->isConnected(); + + if($slotIsEmpty && !$portIsConnected) { + unset($portDatas[$key]); + } + elseif(!$slotIsEmpty && !$portIsConnected) { + unset($portDatas[$key]); + } + elseif($slotIsEmpty && $portIsConnected) { + unset($slotDatas[$key]); + } + else { + throw new Exception("Un dual port slot ne peut avoir qu'un connecteur actif à la fois", E_USER_ERROR); + } + } + + $this->_datas['interfaces'] = $slotDatas; + + /** + * /!\ Les datas de interface sont prioritaires sur celles de port + * Example, les uplinks dont les vlans sont renseignés dans interface + * + * /!\ Un port possède obligatoirement son interface + * On se base donc sur les données des interfaces + * + * /!\ On garde les clés des interfaces donc attention au séparateur + */ + foreach($intDatas as $key => &$datas) + { + $key = str_replace(Equipment_Interface_Virtual::INT_SEPARATOR, Equipment_Interface_Physical::INT_SEPARATOR, $key); + + if(array_key_exists($key, $portDatas)) { + $datas = array_merge($portDatas[$key], $datas); + } + } + + C\Tools::merge($this->_datas['interfaces'], $intDatas); + } + + return $this->_datas['interfaces']; + } + + public function getDatas() + { + $this->getHostname(); + $this->getInterfaces(); + + return $this->_datas; + } + + public function offsetSet($offset, $value) + { + if($value instanceof Equipment_Port) { + $this->declarePort($value); + } + } + + public function offsetExists($offset) + { + return $this->issetPort($offset); + } + + public function offsetUnset($offset) + { + $this->unsetPort($offset); + } + + public function offsetGet($offset) + { + return ($this->issetPort($offset)) ? ($this->_ports[$offset]) : (null); + } + + public function getIterator() + { + return new \ArrayIterator($this->_ports); + } + + public function count() + { + return count($this->_ports); + } + + public function __get($name) + { + switch($name) + { + case 'slots': + return $this->_slots; + case 'ports': + return $this->_ports; + case 'ints': + return $this->_ints; + default: + return $this->getPort($name); + } + } + + public function __set($name, $value) + { + if((is_object($value)) && $value instanceof Equipment_Port) { + $this->declarePort($value); + } + } + + public function __isset($name) + { + return $this->issetPort($name); + } + + public function __unset($name) + { + $this->unsetPort($name); + } + + public function issetSlot($name) + { + if(is_object($name)) + { + if($name instanceof Equipment_Slot) { + $name = $name->getSlotKey(); + } + else { + throw new Exception("Slot name must be a string or an Equipment_Slot object", E_USER_ERROR); + } + } + + return (array_key_exists($name, $this->_slots)); + } + + public function issetPort($name) + { + if(is_object($name)) + { + if($name instanceof Equipment_Port) { + $name = $name->getPortKey(); + } + else { + throw new Exception("Port name must be a string or an Equipment_Port object", E_USER_ERROR); + } + } + + return (array_key_exists($name, $this->_ports)); + } + + public function issetInt($name) + { + return $this->issetInterface($name); + } + + public function issetInterface($name) + { + if(is_object($name)) + { + if($name instanceof Equipment_Interface) { + $name = $name->getIntKey(); + } + else { + throw new Exception("Interface name must be a string or an Equipment_Interface object", E_USER_ERROR); + } + } + + return (array_key_exists($name, $this->_ints)); + } + + // @todo a utiliser ou a supprimer + /*public function isset($object) + { + $ReflectionClass = new \ReflectionClass($object); + $ReflectionClass = $ReflectionClass->getParentClass(); + + switch($ReflectionClass->getShortName()) + { + case 'Equipment_Slot': + return $this->issetSlot($object); + case 'Equipment_Port': + return $this->issetPort($object); + case 'Equipment_Interface': + return $this->issetInterface($object); + default: + throw new Exception('Cet object "'.get_class($object).'" n\'est pas reconnu.', E_USER_ERROR); + } + }*/ + + public function unsetSlot($name) + { + if(is_object($name)) + { + if($name instanceof Equipment_Slot) { + $name = $name->getSlotKey(); + } + else { + throw new Exception("Slot name must be a string or an Equipment_Slot object", E_USER_ERROR); + } + } + + unset($this->_slots[$name]); + return $this; + } + + public function unsetPort($name) + { + if(is_object($name)) + { + if($name instanceof Equipment_Port) { + $name = $name->getPortKey(); + } + else { + throw new Exception("Port name must be a string or an Equipment_Port object", E_USER_ERROR); + } + } + + unset($this->_ports[$name]); + return $this; + } + + public function unsetInt($name) + { + return $this->unsetInterface($name); + } + + public function unsetInterface($name) + { + if(is_object($name)) + { + if($name instanceof Equipment_Interface) { + $name = $name->getIntKey(); + } + else { + throw new Exception("Interface name must be a string or an Equipment_Interface object", E_USER_ERROR); + } + } + + unset($this->_ints[$name]); + return $this; + } + + protected static function _getHostName(Api_Equipment $Api_Equipment) + { + $hostName = $Api_Equipment->getEquipmentLabel(); + + if($hostName === false) { + $equipmentId = $Api_Equipment->getEquipmentId(); + throw new Exception("Impossible de résoudre le label pour l'équipement ID \"".$equipmentId."\"", E_USER_ERROR); + } + + return current(explode('.', $hostName, 2)); + } + + abstract public static function isEquipment($label); + + public static function setEnvs(array $environments) + { + self::$_environments = $environments; + } + } \ No newline at end of file diff --git a/addons/dcim/equipment/interface.php b/addons/dcim/equipment/interface.php new file mode 100644 index 0000000..26f03c7 --- /dev/null +++ b/addons/dcim/equipment/interface.php @@ -0,0 +1,332 @@ +_mode = self::INT_PHYSICAL; + $this->_equipmentPort = $port; + + $portKey = $port->getPortKey(); + $this->_setIntKey($portKey); // /!\ Si un index existe, il sera traité par _setIntKey + + $this->setHostName($port->getHostName()); + $this->setIntName($port->getPortName()); + } + elseif(C\Tools::is('string&&!empty', $port)) + { + $this->_mode = self::INT_VIRTUAL; + + $this->_setIntKey($port); // /!\ Si un index existe, il sera traité par _setIntKey + $this->setIntName($port); + } + else { + throw new Exception("Impossible d'instancier une interface", E_USER_ERROR); + } + + $this->_setup(); + } + + protected function _setup() + { + } + + protected function _isPhysical() + { + return ($this->_mode === self::INT_PHYSICAL); + } + + protected function _setIntKey($intKey) + { + if($this->hasPort()) { + $Equipment_Port = get_class($this->getPort()); + $separator = $Equipment_Port::INT_SEPARATOR; + } + else { + $separator = Equipment_Interface_Physical::INT_SEPARATOR; + } + + // /!\ Si la clé possède un index; Séparateur physique si elle vient du port + $intKey = str_replace($separator, self::INT_SEPARATOR, $intKey); + $intKeyParts = explode(self::INT_SEPARATOR, $intKey, 2); + + $this->_intKey = mb_strtolower($intKeyParts[0]); + + if(count($intKeyParts) > 1) { + $this->_setIntIndex($intKeyParts[1]); + } + + return $this; + } + + public function getIntKey() + { + return $this->_intKey; + } + + protected function _setIntIndex($intIndex) + { + if($this->_indexIsValid($intIndex)) { + $this->_intIndex = $intIndex; + } + return $this; + } + + public function getIntIndex() + { + return ($this->_intIndex !== null) ? ($this->_intIndex) : (false); + } + + public function getIntId() + { + $intKey = $this->getIntKey(); + $intIndex = $this->getIntIndex(); + + return ($intIndex !== false) ? ($intKey.self::INT_SEPARATOR.$intIndex) : ($intKey); + } + + protected function _getKey() + { + return $this->getIntId(); + } + + public function hasPort() + { + return isset($this->_equipmentPort); + } + + public function getPort() + { + // @todo a corriger + if($this->hasPort() !== $this->_isPhysical()) { + throw new Exception("", E_USER_ERROR); + } + elseif($this->hasPort() && $this->_isPhysical()) { + return $this->_equipmentPort; + } + else { + return false; + } + } + + public function getPortId() + { + $intKey = $this->getIntKey(); + $intIndex = $this->getIntIndex(); + + return ($intIndex !== false) ? ($intKey.Equipment_Port::INT_SEPARATOR.$intIndex) : ($intKey); + } + + public function setHostName($hostName) + { + if(C\Tools::is('string&&!empty', $hostName)) { + $this->_datas['hostName'] = $hostName; + } + return $this; + } + + public function getHostName() + { + return (array_key_exists('hostName', $this->_datas)) ? ($this->_datas['hostName']) : (false); + } + + public function setIntName($intName) + { + if(C\Tools::is('string&&!empty', $intName)) { + $this->_datas['intName'] = $intName; + $this->_datas['portName'] = $intName; // /!\ compatibilité + } + return $this; + } + + public function getIntName() + { + /** + * /!\ Depuis le constructor on renseigne le nom de l'interface + * /!\ Le nom du port ne doit pas pouvoir être changé depuis le port + */ + return $this->_datas['intName']; + } + + /** + * Permet d'indiquer la description de l'interface voisine + */ + public function setDescription($desc) + { + if(C\Tools::is('string&&!empty', $desc)) { + $this->_datas['description'] = $desc; + } + return $this; + } + + /** + * /!\ Ne surtout pas retourner la description de datas + * La description retournée doit être celle de cette interface + * Dans datas, la description est potentiellement celle du voisin + */ + public function getDescription() + { + if($this->_description === null) { + $this->_description = $this->getHostName()." ".$this->getIntName(); + } + + return $this->_description; + } + + // /!\ Doit retourner un tableau + public function getDatas() + { + $datas = array(); + + $this->getHostName(); + $this->getIntName(); + $this->getAttributes(); + $this->getDescription(); + + $datas[$this->getIntId()] = $this->_datas; + + return $datas; + } + + // /!\ Doit retourner un tableau + // @todo faire comme port sauvegarder dans array + public function getNeighborDatas() + { + if(($port = $this->getPort()) !== false) + { + $nbPort = $port->getNeighborPort(); + + if($nbPort !== false) + { + $nbInt = $nbPort->getInterface(); + + if($nbInt !== false) + { + $datas = array(); + + $leftIntKey = $this->getIntId(); + $rightIntKey = $nbInt->getIntId(); + $nbDatas = $nbInt->getDatas(); + +//echo "\r\nDEBUG 0\r\n\t";var_dump($nbDatas);echo "\r\nEND 0\r\n"; + + $nbDesc = $nbInt->getDescription(); + $datas[$leftIntKey]['description'] = $nbDesc; + + foreach(array_keys(current($nbDatas)) as $key) + { + switch($key) + { + case 'hostName': + case 'intName': + case 'intId': + case 'intIndex': + case 'intIndex2': + case 'intType': { + $value = $nbDatas[$rightIntKey][$key]; + // /!\ Important la clé doit être la clé actuelle côté gauche + $datas[$leftIntKey]['conTo'.ucfirst($key)] = $value; + break; + } + } + } + +//echo "\r\nDEBUG 1\r\n\t";var_dump($datas);echo "\r\nEND 1\r\n"; + + return $datas; + } + } + } + + return array(); + } + + protected function _indexIsValid($index) + { + return C\Tools::is('int&&>=0', $index); + } + + public function offsetSet($offset, $value) + { + } + + public function offsetExists($offset) + { + return isset($this->{$offset}); + } + + public function offsetUnset($offset) + { + } + + public function offsetGet($offset) + { + $data = $this->{$offset}; + return ($data !== false) ? ($data) : (null); + } + + public function getIterator() + { + $datas = $this->getDatas(); + return new \ArrayIterator($datas); + } + + public function count() + { + $datas = $this->getDatas(); + return count($datas); + } + + public function __get($name) + { + $datas = $this->getDatas(); + + if(array_key_exists($name, $datas)) { + return $datas[$key]; + } + + return false; + } + + public function __isset($name) + { + $datas = $this->getDatas(); + return array_key_exists($name, $datas); + } + } \ No newline at end of file diff --git a/addons/dcim/equipment/interface/abstract.php b/addons/dcim/equipment/interface/abstract.php new file mode 100644 index 0000000..ffc0bf2 --- /dev/null +++ b/addons/dcim/equipment/interface/abstract.php @@ -0,0 +1,67 @@ + 0) + { + $intKey = $this->_getKey(); + + foreach(static::INT_ALLOWED_REGEXP as $regexp) { + if(preg_match('#'.$regexp.'#i', $intKey)) return false; + } + + return true; + } + else { + return false; + } + } + + /** + * /!\ Le traitement est insensible à la casse donc on peut utiliser le nom ou la clé + */ + public function getAttributes() + { + if($this->_attributes === null) + { + $regex = "^([a-z]*)-?(([0-9]{1,4}/){0,}([0-9]{1,4}))(".preg_quote(static::INT_SEPARATOR, '#')."([0-9]))?$"; + + $matches = array(); + preg_match('#'.$regex.'#i', $this->_getKey(), $matches); + + $intInfos = array(); + $intInfos['intType'] = (isset($matches[1])) ? ($matches[1]) : (null); + + $intInfos['intId'] = (isset($matches[2])) ? ($matches[2]) : (null); + if(isset($matches[5])) { $intInfos['intId'] .= $matches[5]; } + + if(isset($matches[6])) { + $index = $matches[6]; + } + elseif(isset($matches[4])) { + $index = $matches[4]; + } + + $intInfos['intIndex'] = (isset($index)) ? ($index) : (null); + $intInfos['intIndex2'] = (isset($index)) ? (str_pad($index, 2, 0, STR_PAD_LEFT)) : (null); + + $this->_attributes = $intInfos; + C\Tools::merge($this->_datas, $intInfos); + } + + return $this->_attributes; + } + } \ No newline at end of file diff --git a/addons/dcim/equipment/interface/physical.php b/addons/dcim/equipment/interface/physical.php new file mode 100644 index 0000000..f592c2d --- /dev/null +++ b/addons/dcim/equipment/interface/physical.php @@ -0,0 +1,7 @@ +_portId = (int) $portId; + $this->_equipmentPortApi = new Api_Equipment_Port($this->_portId); // /!\ Ne pas passer null + } + + public function skipPort() + { + return $this->_skipInt(); + } + + public function isConnected() + { + return $this->_equipmentPortApi->isConnected(); + } + + public function setInterface(Equipment_Interface $Equipment_Interface) + { + if($this->_equipmentInterface === null) { + $this->_equipmentInterface = $Equipment_Interface; + } + + return $this; + } + + public function getInterface() + { + if($this->_equipmentInterface === null) { + throw new Exception("L'interface de ce port n'est pas déclarée", E_USER_ERROR); + } + + return $this->_equipmentInterface; + } + + public function getPortId() + { + return $this->_portId; + } + + protected function _getKey() + { + return $this->getPortKey(); + } + + public function getPortKey() + { + if($this->_portKey === null) { + $this->_portKey = $this->_nameToKey(); + } + + return $this->_portKey; + } + + protected function _nameToKey($portName = null) + { + if($portName === null) { + $portName = $this->getPortName(); + } + + return mb_strtolower($portName); + } + + public function getStatus() + { + if(!array_key_exists('status', $this->_datas)) { + $this->_datas['status'] = $this->isConnected(); + } + + return $this->_datas['status']; + } + + public function getHostName($portKey = null) + { + if(!array_key_exists('hostName', $this->_datas)) + { + $hostName = $this->_equipmentPortApi->getTopEquipmentLabel(); + + if($hostName === false) { + $equipmentId = $this->_equipmentPortApi->getTopEquipmentId(); + throw new Exception("Impossible de résoudre le label pour l'équipement ID \"".$equipmentId."\"", E_USER_ERROR); + } + + $this->_datas['hostName'] = current(explode('.', $hostName, 2)); + } + + $datas = $this->_getPortDatasByKey($portKey); + + if(!array_key_exists('hostName', $datas)) { + $datas['hostName'] = $this->_datas['hostName']; + } + + return $datas['hostName']; + } + + public function getPortName($portKey = null) + { + if(!array_key_exists('portName', $this->_datas)) + { + $portName = $this->_equipmentPortApi->getPortLabel(); + + if($portName === false) { + $portId = $this->_equipmentPortApi->getPortId(); + throw new Exception("Impossible de résoudre le label du port ID \"".$portId."\"", E_USER_ERROR); + } + + $this->_datas['portName'] = $portName; + } + + $datas = $this->_getPortDatasByKey($portKey); + + if(!array_key_exists('portName', $datas)) { + $datas['portName'] = $this->_datas['portName']; + } + + return $datas['portName']; + } + + public function getDescription($portKey = null) + { + if($portKey === null) { + $portKey = $this->getPortKey(); + } + + if(!array_key_exists($portKey, $this->_description)) { + $this->_description[$portKey] = $this->getHostName($portKey)." ".$this->getPortName($portKey); + } + + return $this->_description[$portKey]; + } + + // /!\ Doit retourner un tableau + public function getDatas() + { + if(!$this->skipPort()) + { + $datas = array(); + + $this->getStatus(); + $this->getHostname(); + $this->getPortName(); + $this->getAttributes(); + $this->getDescription(); + + $datas[$this->getPortKey()] = $this->_datas; + + return $datas; + } + else { + throw new Exception("Ce port ne doit pas être traité", E_USER_ERROR); + } + } + + public function getKeys() + { + return array_keys($this->getDatas()); + } + + public function getEquipmentId($portId = null) + { + if($portId === null || (int) $portId === $this->getPortId()) { + return $this->_equipmentPortApi->getTopEquipmentId(); + } + else { + $Api_Equipment_Port = new Api_Equipment_Port($portId); + return $Api_Equipment_Port->getTopEquipmentId(); + } + } + + public function getModuleId($portId = null) + { + if($portId === null || (int) $portId === $this->getPortId()) { + return $this->_equipmentPortApi->getModuleEquipmentId(); + } + else { + $Api_Equipment_Port = new Api_Equipment_Port($portId); + return $Api_Equipment_Port->getModuleEquipmentId(); + } + } + + public function getNeighborEquipId($portId = null) + { + if($portId === null) { + $portId = $this->getNeighborPortId(); + } + + return $this->getEquipmentId($portId); + } + + public function getNeighborPortId($portId = null) + { + if($portId === null || (int) $portId === $this->getPortId()) { + $Api_Equipment_Port = $this->_equipmentPortApi; + } + else { + $Api_Equipment_Port = new Api_Equipment_Port($portId); + } + + return $Api_Equipment_Port->getEndConnectedPortId(); + } + + public function hasNeighborPort() + { + return ($this->_neighborPort !== null); + } + + public function getNeighborPort() + { + return ($this->hasNeighborPort()) ? ($this->_neighborPort) : (false); + } + + public function setNeighborPort(Equipment_Port $portEquipment) + { + if(!$this->hasNeighborPort()) { + $this->_neighborPort = $portEquipment; + $this->_nbDatas = $this->_getNeighborInfos(); + } + + return $this; + } + + protected function _getNeighborInfos() + { + $port = $this->getNeighborPort(); + + if($port !== false) + { + if($this->getPortId() === $port->getNeighborPortId()) + { + $datas = array(); + + $leftKeys = $this->getKeys(); + $rightKeys = $port->getKeys(); + $rightDatas = $port->getDatas(); + + foreach($rightKeys as $index => $rightKey) + { + $leftKey = $leftKeys[$index]; + + $rightDesc = $port->getDescription($rightKey); + $datas[$leftKey]['description'] = $rightDesc; + + foreach(array_keys($rightDatas[$rightKey]) as $key) + { + switch($key) + { + case 'hostName': + case 'portName': + case 'intId': + case 'intIndex': + case 'intIndex2': + case 'intType': { + $value = $rightDatas[$rightKey][$key]; + // /!\ Important la clé doit être la clé actuelle côté gauche + $datas[$leftKey]['conTo'.ucfirst($key)] = $value; + break; + } + } + } + } + + return $datas; + } + else { + throw new Exception("L'ID du port voisin ne correspond pas à l'ID du port déclaré", E_USER_ERROR); + } + } + else { + $portName = $this->getPortName(); + throw new Exception("Le port voisin du port '".$portName."' n'est pas déclaré", E_USER_ERROR); + } + } + + // /!\ Doit retourner un tableau + public function getNeighborDatas() + { + return ($this->hasNeighborPort()) ? ($this->_nbDatas) : (array()); + } + + public function setNeighborDatas(array $datas) + { + throw new Exception("Il est interdit de changer les données du port voisin", E_USER_ERROR); + //return $this; + } + + protected function &_getPortDatasByIndex($index = null) + { + if($index === null || $index === -1) { + return $this->_datas; + } + else { + throw new Exception("L'index du port est invalide", E_USER_ERROR); + } + } + + protected function &_getPortDatasByKey($key = null) + { + if($key === null || $key === $this->getPortKey()) { + return $this->_datas; + } + else { + throw new Exception("La clé du port est invalide", E_USER_ERROR); + } + } + + protected function _indexIsValid($index) + { + return C\Tools::is('int&&>=0', $index); + } + + public function offsetSet($offset, $value) + { + } + + public function offsetExists($offset) + { + return isset($this->{$offset}); + } + + public function offsetUnset($offset) + { + } + + public function offsetGet($offset) + { + $data = $this->{$offset}; + return ($data !== false) ? ($data) : (null); + } + + public function getIterator() + { + $datas = $this->getDatas(); + return new \ArrayIterator($datas); + } + + public function count() + { + $datas = $this->getDatas(); + return count($datas); + } + + public function __get($name) + { + $datas = $this->getDatas(); + $key = $this->_nameToKey($name); + + if(array_key_exists($key, $datas)) { + return $datas[$key]; + } + + return false; + } + + public function __isset($name) + { + $keys = $this->getKeys(); + $key = $this->_nameToKey($name); + return in_array($key, $keys, true); + } + } \ No newline at end of file diff --git a/addons/dcim/equipment/slot.php b/addons/dcim/equipment/slot.php new file mode 100644 index 0000000..2ce7a53 --- /dev/null +++ b/addons/dcim/equipment/slot.php @@ -0,0 +1,199 @@ +_slotId = (int) $slotId; + $this->_equipmentSlotApi = new Api_Equipment_Slot($this->_slotId); // /!\ Ne pas passer null + } + + public function skipSlot() + { + return $this->_skipInt(); + } + + public function isEmpty() + { + return $this->_equipmentSlotApi->isEmpty(); + } + + public function getSlotId() + { + return $this->_slotId; + } + + protected function _getKey() + { + return $this->getSlotKey(); + } + + public function getSlotKey() + { + if($this->_slotKey === null) { + $this->_slotKey = $this->_nameToKey(); + } + + return $this->_slotKey; + } + + protected function _nameToKey($slotName = null) + { + if($slotName === null) { + $slotName = $this->getSlotName(); + } + + return mb_strtolower($slotName); + } + + public function getEquipmentId() + { + return $this->_equipmentSlotApi->getTopEquipmentId(); + } + + public function getStatus() + { + if(!array_key_exists('status', $this->_datas)) { + $this->_datas['status'] = !$this->isEmpty(); + } + + return $this->_datas['status']; + } + + public function getHostName() + { + if(!array_key_exists('hostName', $this->_datas)) + { + $hostName = $this->_equipmentSlotApi->getTopEquipmentLabel(); + + if($hostName === false) { + $equipmentId = $this->_Api_Equipment_Port->getTopEquipmentId(); + throw new Exception("Impossible de résoudre le label pour l'équipement ID \"".$equipmentId."\"", E_USER_ERROR); + } + + $this->_datas['hostName'] = current(explode('.', $hostName, 2)); + } + + return $this->_datas['hostName']; + } + + public function getSlotName() + { + if(!array_key_exists('slotName', $this->_datas)) + { + $slotName = $this->_equipmentSlotApi->getSlotLabel(); + + if($slotName === false) { + $slotId = $this->_equipmentSlotApi->getSlotId(); + throw new Exception("Impossible de résoudre le label du slot ID \"".$slotId."\"", E_USER_ERROR); + } + + $this->_datas['slotName'] = $slotName; + } + + return $this->_datas['slotName']; + } + + public function getDescription() + { + if($this->_description === null) { + $this->_description = $this->getHostName()." ".$this->getSlotName(); + } + + return $this->_description; + } + + // /!\ Doit retourner un tableau + public function getDatas() + { + if(!$this->skipSlot()) + { + $datas = array(); + + $this->getStatus(); + $this->getHostname(); + $this->getSlotName(); + $this->getAttributes(); + $this->getDescription(); + + $datas[$this->getSlotKey()] = $this->_datas; + + return $datas; + } + else { + throw new Exception("Ce slot ne doit pas être traité", E_USER_ERROR); + } + } + + public function offsetSet($offset, $value) + { + } + + public function offsetExists($offset) + { + return isset($this->{$offset}); + } + + public function offsetUnset($offset) + { + } + + public function offsetGet($offset) + { + $data = $this->{$offset}; + return ($data !== false) ? ($data) : (null); + } + + public function getIterator() + { + $datas = $this->getDatas(); + return new ArrayIterator($datas); + } + + public function count() + { + $datas = $this->getDatas(); + return count($datas); + } + + public function __get($name) + { + $datas = $this->getDatas(); + $key = $this->_nameToKey($name); + + if(array_key_exists($key, $datas)) { + return $datas[$key]; + } + + return false; + } + + public function __isset($name) + { + $keys = $this->getKeys(); + $key = $this->_nameToKey($name); + return in_array($key, $keys, true); + } + } \ No newline at end of file diff --git a/addons/dcim/exception.php b/addons/dcim/exception.php new file mode 100644 index 0000000..64a7dcf --- /dev/null +++ b/addons/dcim/exception.php @@ -0,0 +1,6 @@ + + + CW - TOOLS-CLI - Cabinet + INFTSK-5007 + + + cabinet.entityId + + + cabinet.name + + + cabinet.description + + + cabinet.location + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {qname} + + + + cabinet.location.entityId + + + cabinet.location.name + + + cabinet.location.ancestors*.name + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + + + cabinet.template.height + com.patchmanager.shared.beans.dataformat.renderer.DimensionRenderer + + 2 + U + + + + + + cabinet.location + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {qname} + + + + cabinet.name + + + diff --git a/addons/dcim/ressources/formats/CW - TOOLS-CLI - Cable.xml b/addons/dcim/ressources/formats/CW - TOOLS-CLI - Cable.xml new file mode 100644 index 0000000..108049d --- /dev/null +++ b/addons/dcim/ressources/formats/CW - TOOLS-CLI - Cable.xml @@ -0,0 +1,28 @@ + + + CW - TOOLS-CLI - Cable + INFTSK-5007 + + + cable.entityId + + + cable.label + + + cable.description + + + cable.locationsOrdered*.entityId + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + + + diff --git a/addons/dcim/ressources/formats/CW - TOOLS-CLI - Equipment.xml b/addons/dcim/ressources/formats/CW - TOOLS-CLI - Equipment.xml new file mode 100644 index 0000000..4d4b3c0 --- /dev/null +++ b/addons/dcim/ressources/formats/CW - TOOLS-CLI - Equipment.xml @@ -0,0 +1,49 @@ + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.description + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + equipment.equipmentTemplate.height + com.patchmanager.shared.beans.dataformat.renderer.DimensionRenderer + + 2 + U + + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + diff --git a/ressources/dcim/formats/CW - TOOLS-CLI - Location.xml b/addons/dcim/ressources/formats/CW - TOOLS-CLI - Location.xml similarity index 69% rename from ressources/dcim/formats/CW - TOOLS-CLI - Location.xml rename to addons/dcim/ressources/formats/CW - TOOLS-CLI - Location.xml index c52c990..9dda507 100644 --- a/ressources/dcim/formats/CW - TOOLS-CLI - Location.xml +++ b/addons/dcim/ressources/formats/CW - TOOLS-CLI - Location.xml @@ -9,6 +9,9 @@ location.name + + location.description + location.parent com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer @@ -16,6 +19,18 @@ {qname} + + location.ancestors* + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cabinet0.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cabinet0.xml new file mode 100644 index 0000000..7f9e5cb --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cabinet0.xml @@ -0,0 +1,70 @@ + + + CW - TOOLS-CLI - Cabinet0 + INFTSK-5007 + + + + CW - TOOLS-CLI - Cabinet0 + 0 + + + cabinet.entityId + NUMBER + EQUALS + + + + + + CW - TOOLS-CLI - Cabinet + INFTSK-5007 + + + cabinet.entityId + + + cabinet.name + + + cabinet.location + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {qname} + + + + cabinet.location.entityId + + + cabinet.location.name + + + cabinet.location.ancestors*.name + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + + + + + cabinet.location + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {qname} + + + + cabinet.name + + + + + + diff --git a/ressources/dcim/reports/CW - TOOLS-CLI - Cabinet1.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cabinet1.xml similarity index 68% rename from ressources/dcim/reports/CW - TOOLS-CLI - Cabinet1.xml rename to addons/dcim/ressources/reports/CW - TOOLS-CLI - Cabinet1.xml index 86ddb8d..43e1723 100644 --- a/ressources/dcim/reports/CW - TOOLS-CLI - Cabinet1.xml +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cabinet1.xml @@ -33,6 +33,24 @@ {qname} + + cabinet.location.entityId + + + cabinet.location.name + + + cabinet.location.ancestors*.name + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + diff --git a/ressources/dcim/reports/CW - TOOLS-CLI - Cabinet2.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cabinet2.xml similarity index 71% rename from ressources/dcim/reports/CW - TOOLS-CLI - Cabinet2.xml rename to addons/dcim/ressources/reports/CW - TOOLS-CLI - Cabinet2.xml index a2967b8..b073c39 100644 --- a/ressources/dcim/reports/CW - TOOLS-CLI - Cabinet2.xml +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cabinet2.xml @@ -39,6 +39,24 @@ {qname} + + cabinet.location.entityId + + + cabinet.location.name + + + cabinet.location.ancestors*.name + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + diff --git a/ressources/dcim/reports/CW - TOOLS-CLI - Cabinet3.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cabinet3.xml similarity index 73% rename from ressources/dcim/reports/CW - TOOLS-CLI - Cabinet3.xml rename to addons/dcim/ressources/reports/CW - TOOLS-CLI - Cabinet3.xml index 5160e6a..c508d5e 100644 --- a/ressources/dcim/reports/CW - TOOLS-CLI - Cabinet3.xml +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cabinet3.xml @@ -45,6 +45,24 @@ {qname} + + cabinet.location.entityId + + + cabinet.location.name + + + cabinet.location.ancestors*.name + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cable0.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cable0.xml new file mode 100644 index 0000000..220499f --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cable0.xml @@ -0,0 +1,45 @@ + + + CW - TOOLS-CLI - Cable0 + INFTSK-5007 + + + + CW - TOOLS-CLI - Cable0 + 0 + + + cable.entityId + NUMBER + EQUALS + + + + + + CW - TOOLS-CLI - Cable + INFTSK-5007 + + + cable.entityId + + + cable.label + + + cable.locationsOrdered*.entityId + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cable1.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cable1.xml new file mode 100644 index 0000000..16d47bf --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Cable1.xml @@ -0,0 +1,45 @@ + + + CW - TOOLS-CLI - Cable1 + INFTSK-5007 + + + + CW - TOOLS-CLI - Cable1 + 0 + + + cable.label + STRING + MATCHES + + + + + + CW - TOOLS-CLI - Cable + INFTSK-5007 + + + cable.entityId + + + cable.label + + + cable.locationsOrdered*.entityId + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment0.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment0.xml new file mode 100644 index 0000000..56871c9 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment0.xml @@ -0,0 +1,58 @@ + + + CW - TOOLS-CLI - Equipment0 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment0 + 0 + + + equipment.entityId + NUMBER + EQUALS + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-0.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-0.xml new file mode 100644 index 0000000..192f47f --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-0.xml @@ -0,0 +1,58 @@ + + + CW - TOOLS-CLI - Equipment1-0 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment1-0 + 0 + + + equipment.label + STRING + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-1.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-1.xml new file mode 100644 index 0000000..572a2d4 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-1.xml @@ -0,0 +1,58 @@ + + + CW - TOOLS-CLI - Equipment1-1 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment1-1 + 0 + + + equipment.description + STRING + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-2.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-2.xml new file mode 100644 index 0000000..0b0d998 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-2.xml @@ -0,0 +1,59 @@ + + + CW - TOOLS-CLI - Equipment1-2 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment1-2 + 0 + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-3.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-3.xml new file mode 100644 index 0000000..c694e21 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-3.xml @@ -0,0 +1,64 @@ + + + CW - TOOLS-CLI - Equipment1-3 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment1-3 + 0|1 + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-4.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-4.xml new file mode 100644 index 0000000..ae0ddc4 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-4.xml @@ -0,0 +1,65 @@ + + + CW - TOOLS-CLI - Equipment1-4 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment1-4 + 0|1 + + + equipment.label + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-5.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-5.xml new file mode 100644 index 0000000..d463685 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-5.xml @@ -0,0 +1,65 @@ + + + CW - TOOLS-CLI - Equipment1-5 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment1-5 + 0|1 + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-6.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-6.xml new file mode 100644 index 0000000..2cdbba8 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1-6.xml @@ -0,0 +1,71 @@ + + + CW - TOOLS-CLI - Equipment1-6 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment1-6 + 0|1|2 + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/ressources/dcim/reports/CW - TOOLS-CLI - Equipment1.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1.xml similarity index 100% rename from ressources/dcim/reports/CW - TOOLS-CLI - Equipment1.xml rename to addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment1.xml diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-0.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-0.xml new file mode 100644 index 0000000..9232841 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-0.xml @@ -0,0 +1,64 @@ + + + CW - TOOLS-CLI - Equipment2-0 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment2-0 + 0&1 + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-1.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-1.xml new file mode 100644 index 0000000..a0e8153 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-1.xml @@ -0,0 +1,64 @@ + + + CW - TOOLS-CLI - Equipment2-1 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment2-1 + 0&1 + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.description + STRING + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-2.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-2.xml new file mode 100644 index 0000000..fc48a53 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-2.xml @@ -0,0 +1,65 @@ + + + CW - TOOLS-CLI - Equipment2-2 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment2-2 + 0&1 + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-3.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-3.xml new file mode 100644 index 0000000..e8a937e --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-3.xml @@ -0,0 +1,70 @@ + + + CW - TOOLS-CLI - Equipment2-3 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment2-3 + 0&(1|2) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-4.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-4.xml new file mode 100644 index 0000000..8420919 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-4.xml @@ -0,0 +1,71 @@ + + + CW - TOOLS-CLI - Equipment2-4 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment2-4 + 0&(1|2) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-5.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-5.xml new file mode 100644 index 0000000..9858ff6 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-5.xml @@ -0,0 +1,71 @@ + + + CW - TOOLS-CLI - Equipment2-5 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment2-5 + 0&(1|2) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-6.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-6.xml new file mode 100644 index 0000000..9a81f83 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2-6.xml @@ -0,0 +1,77 @@ + + + CW - TOOLS-CLI - Equipment2-6 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment2-6 + 0&(1|2|3) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/ressources/dcim/reports/CW - TOOLS-CLI - Equipment2.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2.xml similarity index 77% rename from ressources/dcim/reports/CW - TOOLS-CLI - Equipment2.xml rename to addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2.xml index bc869b8..2c2fd7e 100644 --- a/ressources/dcim/reports/CW - TOOLS-CLI - Equipment2.xml +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment2.xml @@ -42,9 +42,22 @@ equipment.entityId + + equipment.position.slot.topLevelEquipment.entityId + equipment.label + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-0.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-0.xml new file mode 100644 index 0000000..499b752 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-0.xml @@ -0,0 +1,70 @@ + + + CW - TOOLS-CLI - Equipment3-0 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment3-0 + (0|1)&2 + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.label + STRING + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-1.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-1.xml new file mode 100644 index 0000000..9cb7dce --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-1.xml @@ -0,0 +1,70 @@ + + + CW - TOOLS-CLI - Equipment3-1 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment3-1 + (0|1)&2 + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.description + STRING + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-2.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-2.xml new file mode 100644 index 0000000..5bca030 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-2.xml @@ -0,0 +1,71 @@ + + + CW - TOOLS-CLI - Equipment3-2 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment3-2 + (0|1)&2 + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-3.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-3.xml new file mode 100644 index 0000000..bdbf584 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-3.xml @@ -0,0 +1,76 @@ + + + CW - TOOLS-CLI - Equipment3-3 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment3-3 + (0|1)&(2|3) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-4.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-4.xml new file mode 100644 index 0000000..b7e5cf3 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-4.xml @@ -0,0 +1,77 @@ + + + CW - TOOLS-CLI - Equipment3-4 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment3-4 + (0|1)&(2|3) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.label + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-5.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-5.xml new file mode 100644 index 0000000..9b1d72c --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-5.xml @@ -0,0 +1,77 @@ + + + CW - TOOLS-CLI - Equipment3-5 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment3-5 + (0|1)&(2|3) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-6.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-6.xml new file mode 100644 index 0000000..e528247 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3-6.xml @@ -0,0 +1,83 @@ + + + CW - TOOLS-CLI - Equipment3-6 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment3-6 + (0|1)&(2|3|4) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/ressources/dcim/reports/CW - TOOLS-CLI - Equipment3.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3.xml similarity index 79% rename from ressources/dcim/reports/CW - TOOLS-CLI - Equipment3.xml rename to addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3.xml index 324137f..4a15ec3 100644 --- a/ressources/dcim/reports/CW - TOOLS-CLI - Equipment3.xml +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment3.xml @@ -48,9 +48,22 @@ equipment.entityId + + equipment.position.slot.topLevelEquipment.entityId + equipment.label + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-0.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-0.xml new file mode 100644 index 0000000..9edb471 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-0.xml @@ -0,0 +1,64 @@ + + + CW - TOOLS-CLI - Equipment4-0 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment4-0 + 0&1 + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-1.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-1.xml new file mode 100644 index 0000000..9012305 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-1.xml @@ -0,0 +1,64 @@ + + + CW - TOOLS-CLI - Equipment4-1 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment4-1 + 0&1 + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.description + STRING + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-2.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-2.xml new file mode 100644 index 0000000..d80edcc --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-2.xml @@ -0,0 +1,65 @@ + + + CW - TOOLS-CLI - Equipment4-2 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment4-2 + 0&1 + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-3.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-3.xml new file mode 100644 index 0000000..1c7977b --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-3.xml @@ -0,0 +1,70 @@ + + + CW - TOOLS-CLI - Equipment4-3 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment4-3 + 0&(1|2) + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-4.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-4.xml new file mode 100644 index 0000000..5788d3e --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-4.xml @@ -0,0 +1,71 @@ + + + CW - TOOLS-CLI - Equipment4-4 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment4-4 + 0&(1|2) + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-5.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-5.xml new file mode 100644 index 0000000..f06bc37 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-5.xml @@ -0,0 +1,71 @@ + + + CW - TOOLS-CLI - Equipment4-5 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment4-5 + 0&(1|2) + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-6.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-6.xml new file mode 100644 index 0000000..9f20d14 --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4-6.xml @@ -0,0 +1,77 @@ + + + CW - TOOLS-CLI - Equipment4-6 + INFTSK-5007 + + + + CW - TOOLS-CLI - Equipment4-6 + 0&(1|2|3) + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + + + CW - TOOLS-CLI - Equipment + INFTSK-5007 + + + equipment.entityId + + + equipment.position.slot.topLevelEquipment.entityId + + + equipment.label + + + equipment.position.cabinet.entityId + + + equipment.position.cabinetPosition.side + com.patchmanager.shared.beans.dataformat.renderer.SideRenderer + + + equipment.position.cabinetPosition.uPositionInteger + + + + + equipment.position + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {container} ({details}) + + + + equipment.label + + + + + + diff --git a/ressources/dcim/reports/CW - TOOLS-CLI - Equipment4.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4.xml similarity index 100% rename from ressources/dcim/reports/CW - TOOLS-CLI - Equipment4.xml rename to addons/dcim/ressources/reports/CW - TOOLS-CLI - Equipment4.xml diff --git a/ressources/dcim/reports/CW - TOOLS-CLI - Location - Root.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Location - Root.xml similarity index 80% rename from ressources/dcim/reports/CW - TOOLS-CLI - Location - Root.xml rename to addons/dcim/ressources/reports/CW - TOOLS-CLI - Location - Root.xml index 5b77592..09be3e0 100644 --- a/ressources/dcim/reports/CW - TOOLS-CLI - Location - Root.xml +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Location - Root.xml @@ -41,6 +41,18 @@ {qname} + + location.ancestors* + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + diff --git a/addons/dcim/ressources/reports/CW - TOOLS-CLI - Location0.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Location0.xml new file mode 100644 index 0000000..d9151bc --- /dev/null +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Location0.xml @@ -0,0 +1,71 @@ + + + CW - TOOLS-CLI - Location0 + INFTSK-5007 + + + + CW - TOOLS-CLI - Location0 + 0 + + + location.entityId + NUMBER + EQUALS + + + + + + CW - TOOLS-CLI - Location + INFTSK-5007 + + + location.entityId + + + location.name + + + location.parent + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {qname} + + + + location.ancestors* + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + + + + + location.template + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {name} + + + + location.parent + com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer + + {qname} + + + + location.name + + + + + + diff --git a/ressources/dcim/reports/CW - TOOLS-CLI - Location1.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Location1.xml similarity index 78% rename from ressources/dcim/reports/CW - TOOLS-CLI - Location1.xml rename to addons/dcim/ressources/reports/CW - TOOLS-CLI - Location1.xml index ce9b5e4..6aa1953 100644 --- a/ressources/dcim/reports/CW - TOOLS-CLI - Location1.xml +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Location1.xml @@ -33,6 +33,18 @@ {qname} + + location.ancestors* + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + diff --git a/ressources/dcim/reports/CW - TOOLS-CLI - Location2.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Location2.xml similarity index 80% rename from ressources/dcim/reports/CW - TOOLS-CLI - Location2.xml rename to addons/dcim/ressources/reports/CW - TOOLS-CLI - Location2.xml index a625a33..6f59e36 100644 --- a/ressources/dcim/reports/CW - TOOLS-CLI - Location2.xml +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Location2.xml @@ -39,6 +39,18 @@ {qname} + + location.ancestors* + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + diff --git a/ressources/dcim/reports/CW - TOOLS-CLI - Location3.xml b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Location3.xml similarity index 82% rename from ressources/dcim/reports/CW - TOOLS-CLI - Location3.xml rename to addons/dcim/ressources/reports/CW - TOOLS-CLI - Location3.xml index 731c10c..4916987 100644 --- a/ressources/dcim/reports/CW - TOOLS-CLI - Location3.xml +++ b/addons/dcim/ressources/reports/CW - TOOLS-CLI - Location3.xml @@ -45,6 +45,18 @@ {qname} + + location.ancestors* + + NONE + n + n + com.patchmanager.shared.beans.Location + n + + , + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Cabinet0.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Cabinet0.xml new file mode 100644 index 0000000..4982671 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Cabinet0.xml @@ -0,0 +1,13 @@ + + + CW - TOOLS-CLI - Cabinet0 + 0 + + + cabinet.entityId + NUMBER + EQUALS + + + + diff --git a/ressources/dcim/searches/CW - TOOLS-CLI - Cabinet1.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Cabinet1.xml similarity index 100% rename from ressources/dcim/searches/CW - TOOLS-CLI - Cabinet1.xml rename to addons/dcim/ressources/searches/CW - TOOLS-CLI - Cabinet1.xml diff --git a/ressources/dcim/searches/CW - TOOLS-CLI - Cabinet2.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Cabinet2.xml similarity index 100% rename from ressources/dcim/searches/CW - TOOLS-CLI - Cabinet2.xml rename to addons/dcim/ressources/searches/CW - TOOLS-CLI - Cabinet2.xml diff --git a/ressources/dcim/searches/CW - TOOLS-CLI - Cabinet3.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Cabinet3.xml similarity index 100% rename from ressources/dcim/searches/CW - TOOLS-CLI - Cabinet3.xml rename to addons/dcim/ressources/searches/CW - TOOLS-CLI - Cabinet3.xml diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Cable0.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Cable0.xml new file mode 100644 index 0000000..c511392 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Cable0.xml @@ -0,0 +1,13 @@ + + + CW - TOOLS-CLI - Cable0 + 0 + + + cable.entityId + NUMBER + EQUALS + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Cable1.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Cable1.xml new file mode 100644 index 0000000..9e3e5cf --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Cable1.xml @@ -0,0 +1,13 @@ + + + CW - TOOLS-CLI - Cable1 + 0 + + + cable.label + STRING + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment0.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment0.xml new file mode 100644 index 0000000..9aa2b95 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment0.xml @@ -0,0 +1,13 @@ + + + CW - TOOLS-CLI - Equipment0 + 0 + + + equipment.entityId + NUMBER + EQUALS + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-0.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-0.xml new file mode 100644 index 0000000..674990d --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-0.xml @@ -0,0 +1,13 @@ + + + CW - TOOLS-CLI - Equipment1-0 + 0 + + + equipment.label + STRING + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-1.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-1.xml new file mode 100644 index 0000000..2b28b68 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-1.xml @@ -0,0 +1,13 @@ + + + CW - TOOLS-CLI - Equipment1-1 + 0 + + + equipment.description + STRING + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-2.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-2.xml new file mode 100644 index 0000000..4a81f5a --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-2.xml @@ -0,0 +1,14 @@ + + + CW - TOOLS-CLI - Equipment1-2 + 0 + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-3.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-3.xml new file mode 100644 index 0000000..9df03da --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-3.xml @@ -0,0 +1,19 @@ + + + CW - TOOLS-CLI - Equipment1-3 + 0|1 + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-4.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-4.xml new file mode 100644 index 0000000..cbd610a --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-4.xml @@ -0,0 +1,20 @@ + + + CW - TOOLS-CLI - Equipment1-4 + 0|1 + + + equipment.label + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-5.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-5.xml new file mode 100644 index 0000000..71a5ab4 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-5.xml @@ -0,0 +1,20 @@ + + + CW - TOOLS-CLI - Equipment1-5 + 0|1 + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-6.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-6.xml new file mode 100644 index 0000000..bb77578 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1-6.xml @@ -0,0 +1,26 @@ + + + CW - TOOLS-CLI - Equipment1-6 + 0|1|2 + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/ressources/dcim/searches/CW - TOOLS-CLI - Equipment1.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1.xml similarity index 100% rename from ressources/dcim/searches/CW - TOOLS-CLI - Equipment1.xml rename to addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment1.xml diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-0.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-0.xml new file mode 100644 index 0000000..5388aa0 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-0.xml @@ -0,0 +1,19 @@ + + + CW - TOOLS-CLI - Equipment2-0 + 0&1 + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-1.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-1.xml new file mode 100644 index 0000000..1931a61 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-1.xml @@ -0,0 +1,19 @@ + + + CW - TOOLS-CLI - Equipment2-1 + 0&1 + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.description + STRING + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-2.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-2.xml new file mode 100644 index 0000000..ecd328d --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-2.xml @@ -0,0 +1,20 @@ + + + CW - TOOLS-CLI - Equipment2-2 + 0&1 + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-3.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-3.xml new file mode 100644 index 0000000..81080b1 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-3.xml @@ -0,0 +1,25 @@ + + + CW - TOOLS-CLI - Equipment2-3 + 0&(1|2) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-4.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-4.xml new file mode 100644 index 0000000..7520f38 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-4.xml @@ -0,0 +1,26 @@ + + + CW - TOOLS-CLI - Equipment2-4 + 0&(1|2) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-5.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-5.xml new file mode 100644 index 0000000..fa3fefd --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-5.xml @@ -0,0 +1,26 @@ + + + CW - TOOLS-CLI - Equipment2-5 + 0&(1|2) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-6.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-6.xml new file mode 100644 index 0000000..29eff1a --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2-6.xml @@ -0,0 +1,32 @@ + + + CW - TOOLS-CLI - Equipment2-6 + 0&(1|2|3) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/ressources/dcim/searches/CW - TOOLS-CLI - Equipment2.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2.xml similarity index 100% rename from ressources/dcim/searches/CW - TOOLS-CLI - Equipment2.xml rename to addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment2.xml diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-0.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-0.xml new file mode 100644 index 0000000..aafbeac --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-0.xml @@ -0,0 +1,25 @@ + + + CW - TOOLS-CLI - Equipment3-0 + (0|1)&2 + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.label + STRING + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-1.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-1.xml new file mode 100644 index 0000000..372541c --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-1.xml @@ -0,0 +1,25 @@ + + + CW - TOOLS-CLI - Equipment3-1 + (0|1)&2 + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.description + STRING + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-2.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-2.xml new file mode 100644 index 0000000..8cec0b8 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-2.xml @@ -0,0 +1,26 @@ + + + CW - TOOLS-CLI - Equipment3-2 + (0|1)&2 + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-3.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-3.xml new file mode 100644 index 0000000..33cb1a4 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-3.xml @@ -0,0 +1,31 @@ + + + CW - TOOLS-CLI - Equipment3-3 + (0|1)&(2|3) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-4.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-4.xml new file mode 100644 index 0000000..c49a9cc --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-4.xml @@ -0,0 +1,32 @@ + + + CW - TOOLS-CLI - Equipment3-4 + (0|1)&(2|3) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.label + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-5.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-5.xml new file mode 100644 index 0000000..85f614d --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-5.xml @@ -0,0 +1,32 @@ + + + CW - TOOLS-CLI - Equipment3-5 + (0|1)&(2|3) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-6.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-6.xml new file mode 100644 index 0000000..925feda --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3-6.xml @@ -0,0 +1,38 @@ + + + CW - TOOLS-CLI - Equipment3-6 + (0|1)&(2|3|4) + + + equipment.position.location.entityId + NUMBER + EQUALS + + + + equipment.position.location.ancestors.entityId + NUMBER + EQUALS + at-least-one + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/ressources/dcim/searches/CW - TOOLS-CLI - Equipment3.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3.xml similarity index 100% rename from ressources/dcim/searches/CW - TOOLS-CLI - Equipment3.xml rename to addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment3.xml diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-0.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-0.xml new file mode 100644 index 0000000..557dd8b --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-0.xml @@ -0,0 +1,19 @@ + + + CW - TOOLS-CLI - Equipment4-0 + 0&1 + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-1.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-1.xml new file mode 100644 index 0000000..3dc1c83 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-1.xml @@ -0,0 +1,19 @@ + + + CW - TOOLS-CLI - Equipment4-1 + 0&1 + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.description + STRING + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-2.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-2.xml new file mode 100644 index 0000000..d588ff5 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-2.xml @@ -0,0 +1,20 @@ + + + CW - TOOLS-CLI - Equipment4-2 + 0&1 + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-3.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-3.xml new file mode 100644 index 0000000..7f83e77 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-3.xml @@ -0,0 +1,25 @@ + + + CW - TOOLS-CLI - Equipment4-3 + 0&(1|2) + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-4.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-4.xml new file mode 100644 index 0000000..2c050c4 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-4.xml @@ -0,0 +1,26 @@ + + + CW - TOOLS-CLI - Equipment4-4 + 0&(1|2) + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-5.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-5.xml new file mode 100644 index 0000000..88ead14 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-5.xml @@ -0,0 +1,26 @@ + + + CW - TOOLS-CLI - Equipment4-5 + 0&(1|2) + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-6.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-6.xml new file mode 100644 index 0000000..04731d9 --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4-6.xml @@ -0,0 +1,32 @@ + + + CW - TOOLS-CLI - Equipment4-6 + 0&(1|2|3) + + + equipment.position.cabinet.entityId + NUMBER + EQUALS + + + + equipment.label + STRING + MATCHES + + + + equipment.description + STRING + MATCHES + + + + equipment.exportAttributeValues + ATTRIBUTES + {Serial number} + MATCHES + + + + diff --git a/ressources/dcim/searches/CW - TOOLS-CLI - Equipment4.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4.xml similarity index 100% rename from ressources/dcim/searches/CW - TOOLS-CLI - Equipment4.xml rename to addons/dcim/ressources/searches/CW - TOOLS-CLI - Equipment4.xml diff --git a/ressources/dcim/searches/CW - TOOLS-CLI - Location - Root.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Location - Root.xml similarity index 100% rename from ressources/dcim/searches/CW - TOOLS-CLI - Location - Root.xml rename to addons/dcim/ressources/searches/CW - TOOLS-CLI - Location - Root.xml diff --git a/addons/dcim/ressources/searches/CW - TOOLS-CLI - Location0.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Location0.xml new file mode 100644 index 0000000..383351d --- /dev/null +++ b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Location0.xml @@ -0,0 +1,13 @@ + + + CW - TOOLS-CLI - Location0 + 0 + + + location.entityId + NUMBER + EQUALS + + + + diff --git a/ressources/dcim/searches/CW - TOOLS-CLI - Location1.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Location1.xml similarity index 100% rename from ressources/dcim/searches/CW - TOOLS-CLI - Location1.xml rename to addons/dcim/ressources/searches/CW - TOOLS-CLI - Location1.xml diff --git a/ressources/dcim/searches/CW - TOOLS-CLI - Location2.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Location2.xml similarity index 100% rename from ressources/dcim/searches/CW - TOOLS-CLI - Location2.xml rename to addons/dcim/ressources/searches/CW - TOOLS-CLI - Location2.xml diff --git a/ressources/dcim/searches/CW - TOOLS-CLI - Location3.xml b/addons/dcim/ressources/searches/CW - TOOLS-CLI - Location3.xml similarity index 100% rename from ressources/dcim/searches/CW - TOOLS-CLI - Location3.xml rename to addons/dcim/ressources/searches/CW - TOOLS-CLI - Location3.xml diff --git a/addons/dcim/tools.php b/addons/dcim/tools.php new file mode 100644 index 0000000..e014ae6 --- /dev/null +++ b/addons/dcim/tools.php @@ -0,0 +1,6 @@ + array( + 'location', 'cabinet', 'equipment', + ), + 'show' => array( + 'location', 'cabinet', 'equipment', + /*'system', 'sys', 'server', + 'network', 'net', 'appliance'*/ + ), + 'modify' => array( + 'equipment', + ), + 'refresh' => array( + 'caches' + ), + 'patchmanager' + ); + + /** + * Arguments ne commencant pas par - mais étant dans le flow de la commande + * + * ls mon/chemin/a/lister + * cd mon/chemin/ou/aller + * find ou/lancer/ma/recherche + */ + protected $_inlineArgCmds = array( + 'ls' => "#^\"?([a-z0-9\-_/\\\\~. ]+)\"?$#i", + 'll' => "#^\"?([a-z0-9\-_/\\\\~. ]+)\"?$#i", + 'cd' => "#^\"?([a-z0-9\-_/\\\\~. ]+)\"?$#i", + 'search' => array( + 0 => array('location', 'cabinet', 'equipment'), + 1 => "#^\"?([a-z0-9\-_.:* ]+)\"?$#i" + ), + 'find' => array( + 0 => "#^\"?([a-z0-9\-_. /~]+)\"?$#i", + 1 => array('location', 'cabinet', 'equipment'), + 2 => "#^\"?([a-z0-9\-_.:* ]+)\"?$#i" + ), + 'list location' => "#^\"?([a-z0-9\-_. ]+)\"?$#i", + 'list cabinet' => array(0 => "#^\"?([a-z0-9\-_. ]+)\"?$#i", 1 => array('front', 'rear', 'both'), 2 => array('summary', 'full')), + 'list equipment' => "#^\"?([a-z0-9\-_. ]+)\"?$#i", + 'show location' => "#^\"?([a-z0-9\-_. ]+)\"?$#i", + 'show cabinet' => array(0 => "#^\"?([a-z0-9\-_. ]+)\"?$#i", 1 => array('front', 'rear', 'both'), 2 => array('summary', 'full')), + 'show equipment' => "#^\"?([a-z0-9\-_. ]+)\"?$#i", + 'modify equipment' => array( + "#^\"?([a-z0-9\-_. ]+)\"?$#i", + array('label', 'name', 'description', 'sn', 'serialnumber'), + "#^\"?(.+)\"?$#i" + ), + ); + + /** + * Arguments commencant pas par - ou -- donc hors flow de la commande + * + * find ... -type [type] -name [name] + */ + protected $_outlineArgCmds = array( + ); + + protected $_manCommands = array( + 'history' => "Affiche l'historique des commandes", + 'ls' => "Affiche la liste des éléments disponibles", + 'll' => "Alias de ls", + 'cd' => "Permet de naviguer dans l'arborescence", + 'pwd' => "Affiche la position actuelle dans l'arborescence", + 'search' => "Recherche avancée d'éléments. Utilisation: search [type] [recherche]", + 'find' => "Recherche avancée d'éléments. Utilisation: find [localisation|.] [type] [recherche]", + 'exit' => "Ferme le shell", + 'quit' => "Alias de exit", + 'list' => "Affiche un type d'éléments; Dépend de la localisation actuelle. Utilisation: list [location|cabinet|equipment] [object]", + 'list location' => "Affiche les informations d'une localisation; Dépend de la localisation", + 'list cabinet' => "Affiche les informations d'une baie; Dépend de la localisation. Utilisation: list cabinet [name] [front|rear|both] [summury|full]", + 'list equipment' => "Affiche les informations d'un équipement; Dépend de la localisation", + 'show' => "Affiche un type d'éléments; Ne dépend pas de la localisation actuelle. Utilisation: show [location|cabinet|equipment] [object]", + 'show location' => "Affiche les informations d'une localisation", + 'show cabinet' => "Affiche les informations d'une baie. Utilisation: show cabinet [name] [front|rear|both] [summury|full]", + 'show equipment' => "Affiche les informations d'un équipement", + 'modify equipment' => "Modifie les informations d'un équipement. Utilisation: modify equipment [label|SN|.] [name|description|serialnumber] [value]", + /*'show system' => "Affiche les informations d'un équipement", + 'show server' => "Alias de show system", + 'show sys' => "Alias de show system", + 'show network' => "Affiche les informations d'un équipement", + 'show appliance' => "Alias de show network", + 'show net' => "Alias de show network",*/ + 'refresh caches' => "Rafraîchi les caches des objets du DCIM", + 'patchmanager' => "Lance la GUI de PatchManager", + ); + + /** + * @var bool + */ + protected $_objectCaching = false; + + + public function __construct($configFilename, $server, $autoInitialisation = true) + { + parent::__construct($configFilename); + + if(!$this->isOneShotCall()) { + $printInfoMessages = true; + ob_end_flush(); + } + else { + $printInfoMessages = false; + } + + try { + // /!\ Compatible mono-serveur donc $server ne peut pas être un array + $DCIM = new Dcim\Connector(array($server), $printInfoMessages, null, $this->_addonDebug); + } + catch(\Exception $e) { + $this->error("Impossible de se connecter ou de s'authentifier au service DCIM:".PHP_EOL.$e->getMessage(), 'red'); + exit; + } + + $this->_DCIM = $DCIM->getDcim(); + Dcim\Api_Abstract::setDcim($this->_DCIM); + + $this->_objectCaching = (bool) $DCIM->getConfig()->objectCaching; + $this->_initAllApiCaches($this->_objectCaching); + + $this->_PROGRAM = new Shell_Program_Dcim($this, $this->_TERMINAL); + + foreach(array('ls', 'll', 'cd') as $cmd) { + $this->_inlineArgCmds[$cmd] = Closure::fromCallable(array($this->_PROGRAM, 'shellAutoC_cd')); + $this->_TERMINAL->setInlineArg($cmd, $this->_inlineArgCmds[$cmd]); + } + + if($autoInitialisation) { + $this->_init(); + } + } + + protected function _initAllApiCaches($state) + { + if($state) + { + $classes = array( + 'Addon\Dcim\Api_Location', + 'Addon\Dcim\Api_Cabinet', + 'Addon\Dcim\Api_Equipment', + ); + + foreach($classes as $class) + { + $this->EOL(); + $class::cache(true); + + $this->print("Initialisation du cache pour les objets ".$class::OBJECT_NAME." ...", 'blue'); + $status = $class::refreshCache($this->_DCIM); + $this->_TERMINAL->deleteMessage(1, true); + + if($status === true) { + $this->print("Initialisation du cache pour les objets ".$class::OBJECT_NAME." [OK]", 'green'); + } + else { + $this->error("Initialisation du cache pour les objets ".$class::OBJECT_NAME." [KO]", 'red'); + $class::cache(false); + $this->print("Désactivation du cache pour les objets ".$class::OBJECT_NAME." [OK]", 'orange'); + } + } + } + else { + $this->error("Le cache des objets est désactivé, pour l'activer éditez la configuration", 'orange'); + } + } + + protected function _preLauchingShell($welcomeMessage = true) + { + parent::_preLauchingShell($welcomeMessage); + + /** + * /!\ Les rapports pour le DCIM sont au format CSV + * L'utilisateur peut changer la conf du séparateur CSV depuis la GUI du DCIM + * Ce test permet de déterminer si la config de l'addon DCIM est correcte ou non + */ + $rootLocations = Dcim\Api_Location::getRootLocations(); + + if(count($rootLocations) > 0 && count($rootLocations[0]) === 1) { + $csvDelimiter = $this->_CONFIG->DCIM->preferences->report->csvDelimiter; + $outputExample = current(array_keys($rootLocations[0])); + $errorMsg = "La configuration de l'addon DCIM pour le séparateur CSV (DCIM > preferences > report > csvDelimiter) '".$csvDelimiter."' "; + $errorMsg .= "ne semble pas correspondre aux préférences de l'utilisateur dans le DCIM."; + $errorMsg .= PHP_EOL.PHP_EOL."Voici ce que retourne le DCIM: ".$outputExample; + $this->error($errorMsg, 'red'); + exit; + } + } + + protected function _routeShellCmd($cmd, array $args) + { + $exit = false; + + switch($cmd) + { + case 'search': { + array_unshift($args, DIRECTORY_SEPARATOR); + $status = $this->_PROGRAM->printSearchObjects($args); + break; + } + case 'find': { + $status = $this->_PROGRAM->printSearchObjects($args); + break; + } + case 'list location': { + $status = $this->_PROGRAM->printLocationInfos($args, true); + break; + } + case 'list cabinet': { + $status = $this->_PROGRAM->printCabinetInfos($args, true); + break; + } + case 'list equipment': { + $status = $this->_PROGRAM->printEquipmentInfos($args, true); + break; + } + case 'show location': { + $status = $this->_PROGRAM->printLocationInfos($args, false); + break; + } + case 'show cabinet': { + $status = $this->_PROGRAM->printCabinetInfos($args, false); + break; + } + case 'show equipment': { + $status = $this->_PROGRAM->printEquipmentInfos($args, false); + break; + } + case 'modify equipment': { + $status = $this->_PROGRAM->modifyEquipment($args); + break; + } + case 'refresh caches': { + $this->_initAllApiCaches($this->_objectCaching); + $status = true; + break; + } + case 'patchmanager': + { + // @todo configurable + $jnlp = ROOT_DIR ."/tmp/patchmanager.jnlp"; + + if(!file_exists($jnlp)) + { + $jnlpUrl = $this->_DCIM->getJnlpUrl(64); + + // @todo configurable + $options = array( + "ssl" => array( + "verify_peer" => false, + "verify_peer_name" => false + ) + ); + + $context = stream_context_create($options); + $ressource = fopen($jnlpUrl, 'r', false, $context); + $status = file_put_contents($jnlp, $ressource); + + if($status === false) { + $this->error("Impossible de télécharger le JNLP [".$jnlpUrl."]", 'red'); + break; + } + } + + $this->deleteWaitingMsg(); + $cmd = $this->_CONFIG->DEFAULT->sys->javawsCmd; + $handle = popen($cmd.' "'.$jnlp.'" > /dev/null 2>&1', 'r'); + pclose($handle); + break; + } + default: { + $exit = parent::_routeShellCmd($cmd, $args); + } + } + + if(isset($status)) { + $this->_routeShellStatus($cmd, $status); + } + + return $exit; + } + + protected function _moveToRoot() + { + if($this->_pathIds === null || $this->_pathApi === null) + { + $Dcim_Api_Location = new Dcim\Api_Location(); + $Dcim_Api_Location->setLocationLabel(DIRECTORY_SEPARATOR); + + $this->_pathIds[] = null; + $this->_pathApi[] = $Dcim_Api_Location; + } + + return parent::_moveToRoot(); + } + + public function browser(array &$pathIds, array &$pathApi, $path) + { + if(C\Tools::is('string', $path)) { + $path = explode(DIRECTORY_SEPARATOR, $path); + } + + $cases = array( + 'Addon\Dcim\Api_Location' => array( + 'Addon\Dcim\Api_Location' => 'getSubLocationId', + 'Addon\Dcim\Api_Cabinet' => 'getCabinetId', + ), + 'Addon\Dcim\Api_Cabinet' => array( + 'Addon\Dcim\Api_Equipment' => 'getEquipmentId', + ), + ); + + foreach($path as $index => $part) + { + switch($part) + { + case '': + case '~': + { + if($index === 0) { + array_splice($pathIds, 1); + array_splice($pathApi, 1); + } + break; + } + case '.': { + break; + } + case '..': + { + if(count($pathApi) > 1) { + array_pop($pathIds); + array_pop($pathApi); + } + break; + } + default: + { + $objectApi = end($pathApi); + $objectApiClass = get_class($objectApi); + + if(array_key_exists($objectApiClass, $cases)) + { + foreach($cases[$objectApiClass] as $objectClass => $objectMethod) + { + $objectId = call_user_func(array($objectApi, $objectMethod), $part); + + if($objectId !== false) { + $pathIds[] = $objectId; + $pathApi[] = new $objectClass($objectId); + break; + } + } + } + } + } + } + } + } \ No newline at end of file diff --git a/applications/dcim/shell/program/dcim.php b/applications/dcim/shell/program/dcim.php new file mode 100644 index 0000000..ef5c7c8 --- /dev/null +++ b/applications/dcim/shell/program/dcim.php @@ -0,0 +1,980 @@ + array( + 'fields' => array('name'), + ), + 'cabinet' => array( + 'fields' => array('name'), + ), + 'equipment' => array( + 'fields' => array('name'), + ) + ); + + protected $_LIST_TITLES = array( + 'location' => 'LOCATIONS', + 'cabinet' => 'CABINETS', + 'equipment' => 'EQUIPMENTS', + 'cable' => 'CABLES', + ); + + protected $_LIST_FIELDS = array( + 'location' => array( + 'fields' => array('name'), + 'format' => '%s' + ), + 'cabinet' => array( + 'fields' => array('name'), + 'format' => '%s' + ), + 'equipment' => array( + //'fields' => array('name', 'side', 'positionU', 'serialNumber'), + //'format' => '[%2$s] (U%3$d) %1$s {%4$s}' + 'fields' => false, + 'format' => false + ), + 'cable' => array( + 'fields' => array('port', 'name', 'nbPort', 'nbName'), + 'format' => '[%s] <-- %s --> [%s] {%s}' + ) + ); + + protected $_PRINT_TITLES = array( + 'location' => 'LOCATIONS', + 'cabinet' => 'CABINETS', + 'equipment' => 'EQUIPMENTS', + 'cable' => 'CABLES', + ); + + protected $_PRINT_FIELDS = array( + 'location' => array( + 'header' => '%s', + 'name' => PHP_EOL.'Nom: %s', + 'path' => 'Emplacement: %s', + ), + 'cabinet' => array( + 'header' => '%s', + 'name' => PHP_EOL.'Nom: %s', + 'path' => 'Emplacement: %s', + ), + 'equipment' => array( + 'header' => '%s', + 'templateName' => PHP_EOL.'Template: %s', + 'name' => 'Nom: %s', + 'description' => 'Description: %s', + 'serialNumber' => 'N° série: %s', + 'locationName' => 'Localisation: %s', + 'cabinetName' => 'Baie: %s', + 'position' => 'Position: %s / U%d', + 'path' => 'Emplacement: %s', + ), + ); + + protected $_searchfromCurrentPath = true; + + + protected function _getObjects($context = null) + { + $path = $context; + + $items = array( + Dcim\Api_Location::OBJECT_KEY => array(), + Dcim\Api_Cabinet::OBJECT_KEY => array(), + Dcim\Api_Equipment::OBJECT_KEY => array(), + Dcim\Api_Cable::OBJECT_KEY => array(), + ); + + $currentApi = $this->_browser($path); + $currentApiClass = get_class($currentApi); + + $cases = array( + 'Addon\Dcim\Api_Location' => array( + 'Addon\Dcim\Api_Location' => 'getSubLocationIds', + 'Addon\Dcim\Api_Cabinet' => 'getCabinetIds', + ), + 'Addon\Dcim\Api_Cabinet' => array(false), + 'Addon\Dcim\Api_Equipment' => array(false), + ); + + if(array_key_exists($currentApiClass, $cases)) + { + foreach($cases[$currentApiClass] as $objectClass => $objectMethod) + { + if($objectMethod !== false) { + $objects = call_user_func(array($currentApi, $objectMethod)); + } + else { + $objects = false; + } + + if($objects !== false && count($objects) > 0) + { + foreach($objects as $object) + { + switch($objectClass) + { + case 'Addon\Dcim\Api_Location': { + $Dcim_Api_Location = new Dcim\Api_Location($object); + $objectName = $Dcim_Api_Location->getLocationLabel(); + break; + } + case 'Addon\Dcim\Api_Cabinet': { + $Dcim_Api_Cabinet = new Dcim\Api_Cabinet($object); + $objectName = $Dcim_Api_Cabinet->getCabinetLabel(); + break; + } + default: { + throw new Exception("Object class '".$objectClass."' is not valid", E_USER_ERROR); + } + } + + $items[$objectClass::OBJECT_KEY][] = array('name' => $objectName); + } + } + elseif($currentApi instanceof Dcim\Api_Cabinet) + { + $equipments = $currentApi->getEquipmentIds(); + + foreach($equipments as $equipment) + { + $Dcim_Api_Equipment = new Dcim\Api_Equipment($equipment); + + $objectName = $Dcim_Api_Equipment->getLabel(); + $position = $Dcim_Api_Equipment->getPosition(); + $templateU = $Dcim_Api_Equipment->getTemplateU(); + $serialNumber = $Dcim_Api_Equipment->getSerialNumber(); + + $items[Dcim\Api_Equipment::OBJECT_KEY][] = array( + 'name' => $objectName, + 'side' => $position['side'], + 'positionU' => $position['U'], + 'templateU' => $templateU, + 'serialNumber' => $serialNumber, + ); + } + } + elseif($currentApi instanceof Dcim\Api_Equipment) + { + $ports = $currentApi->getConnectedPortIds(); + + foreach($ports as $port) + { + $portApi = new Dcim\Api_Equipment_Port($port); + $nbPort = $portApi->getEndConnectedPortId(); + + if($nbPort !== false) + { + $nbPortApi = new Dcim\Api_Equipment_Port($nbPort); + + $items[Dcim\Api_Cable::OBJECT_KEY][] = array( + 'port' => $portApi->getLabel(), + 'name' => $portApi->cableApi->getLabel(), + 'nbPort' => $nbPortApi->getLabel(), + 'nbName' => $nbPortApi->equipmentApi->getLabel(), + ); + } + } + } + } + } + + /** + * /!\ index 0 doit toujours être le nom de l'objet ou l'identifiant (VlanID, IP) + */ + $compare = function($a, $b) { + return strnatcasecmp(current($a), current($b)); + }; + + usort($items[Dcim\Api_Location::OBJECT_KEY], $compare); + usort($items[Dcim\Api_Cabinet::OBJECT_KEY], $compare); + usort($items[Dcim\Api_Cable::OBJECT_KEY], $compare); + + /*$compare = function($a, $b) + { + if($a['side'] !== $b['side']) { + return (mb_strtolower($a['side']) === Dcim\Api_Cabinet::SIDE_FRONT) ? (-1) : (1); + } + elseif($a['positionU'] !== $b['positionU']) { + return ($a['positionU'] < $b['positionU']) ? (1) : (-1); // On souhaite avoir les U en haut en 1er + } + else { + return strnatcasecmp($a['name'], $b['name']); + } + }; + + usort($items[Dcim\Api_Equipment::OBJECT_KEY], $compare);*/ + + $items[Dcim\Api_Equipment::OBJECT_KEY] = $this->_formatCabinetEquipments($currentApi, $items[Dcim\Api_Equipment::OBJECT_KEY]); + + return array( + 'location' => $items[Dcim\Api_Location::OBJECT_KEY], + 'cabinet' => $items[Dcim\Api_Cabinet::OBJECT_KEY], + 'equipment' => $items[Dcim\Api_Equipment::OBJECT_KEY], + 'cable' => $items[Dcim\Api_Cable::OBJECT_KEY] + ); + } + + protected function _formatCabinetEquipments(Dcim\Api_Abstract $currentApi, array $equipments) + { + $results = array(); + + if($currentApi instanceof Dcim\Api_Cabinet) + { + $templateU = $currentApi->getTemplateU(); + + /** + * On souhaite avoir les U en haut en 1er + */ + for($i=$templateU; $i>0; $i--) + { + $results[$i] = array( + null, null, $i, '<-- front', " ", 'rear -->', $i, null, null + ); + } + + foreach($equipments as $equipment) + { + if(array_key_exists((int) $equipment['positionU'], $results)) + { + $j = ($equipment['side'] === Dcim\Api_Cabinet::SIDE_FRONT) ? (0) : (7); + + for($i=0; $i<$equipment['templateU']; $i++) + { + if($results[$equipment['positionU']+$i][0+$j] === null) { + $results[$equipment['positionU']+$i][0+$j] = $equipment['name']; + $results[$equipment['positionU']+$i][1+$j] = $equipment['serialNumber']; + } + else { + $results[$equipment['positionU']+$i][0+$j] .= PHP_EOL.$equipment['name']; + $results[$equipment['positionU']+$i][1+$j] .= PHP_EOL.$equipment['serialNumber']; + } + } + } + } + } + + return $results; + } + + public function printObjectInfos(array $args, $fromCurrentContext = true) + { + // /!\ ls AUB --> On ne doit pas afficher AUB mais le contenu de AUB ! + /*$objectApi = end($this->_pathApi); + + switch(get_class($objectApi)) + { + case 'Addon\Dcim\Api_Location': + $cases = array( + 'location' => '_getLocationInfos', + 'cabinet' => '_getCabinetInfos', + 'equipment' => '_getEquipmentInfos', // Des équipements pourraient être directement dans une location + ); + break; + case 'Addon\Dcim\Api_Cabinet': + $cases = array( + 'equipment' => '_getEquipmentInfos' + ); + break; + default: + $cases = array(); + }*/ + + $cases = array( + 'equipment' => '_getEquipmentInfos' + ); + + $result = $this->_printObjectInfos($cases, $args, $fromCurrentContext); + + if($result !== false) + { + list($status, $objectType, $infos) = $result; + + /** + * /!\ Attention aux doublons lorsque printObjectsList est appelé manuellement + * Voir code pour ls ou ll dans services/browser méthode _routeShellCmd + */ + /*if($status && $objectType === 'equipment') { + $this->printEquipmentExtra($infos); + }*/ + + return $status; + } + else { + return false; + } + } + + public function printLocationInfos(array $args, $fromCurrentPath = true, $recursion = false) + { + if(isset($args[0])) + { + $infos = $this->_getLocationInfos($args[0], $fromCurrentPath, null, $recursion); + $status = $this->_printInformations('location', $infos); + + if($status === false) { + $this->_SHELL->error("Localisation introuvable", 'orange'); + } + + return true; + } + + return false; + } + + public function printCabinetInfos(array $args, $fromCurrentPath = true, $recursion = false) + { + if(isset($args[0])) + { + $infos = $this->_getCabinetInfos($args[0], $fromCurrentPath, null, $recursion); + $status = $this->_printInformations('cabinet', $infos); + + if($status === false) { + $this->_SHELL->error("Baie introuvable", 'orange'); + } + elseif(count($infos) === 1) + { + $side = null; + $view = null; + + // @todo a coder + if(isset($args[1])) + { + $args[1] = mb_strtolower($args[1]); + + if($args[1] === 'front' || $args[1] === 'rear') { + $side = $args[1]; + } + } + + // @todo a coder + if(isset($args[2])) + { + $args[2] = mb_strtolower($args[2]); + + if($args[2] === 'summary' || $args[2] === 'full') { + $view = $args[2]; + } + } + + $path = $infos[0]['path'].'/'.$infos[0]['name']; + $this->printObjectsList($path); + } + + return true; + } + + return false; + } + + public function printEquipmentInfos(array $args, $fromCurrentPath = true, $recursion = false) + { + if(isset($args[0])) + { + $infos = $this->_getEquipmentInfos($args[0], $fromCurrentPath, null, $recursion); + $status = $this->_printInformations('equipment', $infos); + + if($status === false) { + $this->_SHELL->error("Equipement introuvable", 'orange'); + } + else { + $this->printEquipmentExtra($infos); + } + + return true; + } + + return false; + } + + protected function printEquipmentExtra(array $infos) + { + if(count($infos) === 1) { + $path = $infos[0]['path'].'/'.$infos[0]['name']; + $this->printObjectsList($path); + } + } + + protected function _getLocationInfos($location, $fromCurrentPath = true, $path = null, $recursion = false) + { + $items = array(); + $locations = array(); + + if($fromCurrentPath) + { + $pathApi = $this->_browser($path, false); + $currentApi = $this->_getLastLocationPath($pathApi); + + if($currentApi instanceof Dcim\Api_Location) { + $locationId = $currentApi->getLocationId(); + $locations = Dcim\Api_Location::searchLocations($location, $locationId, $recursion); + } + } + else { + $locations = Dcim\Api_Location::searchLocations($location); + } + + + foreach($locations as $location) + { + //$Dcim_Api_Location = new Dcim\Api_Location($location['entity_id']); + + $item = array(); + $item['header'] = $location['name']; + $item['name'] = $location['name']; + $item['path'] = '/'.str_replace(Dcim\Api_Location::SEPARATOR_PATH, '/', $location['path']); + $items[] = $item; + } + + return $items; + } + + protected function _getCabinetInfos($cabinet, $fromCurrentPath = true, $path = null, $recursion = false) + { + $items = array(); + $cabinets = array(); + + if($fromCurrentPath) + { + $pathApi = $this->_browser($path, false); + $currentApi = $this->_getLastLocationPath($pathApi); + + if($currentApi instanceof Dcim\Api_Location) { + $locationId = $currentApi->getLocationId(); + $cabinets = Dcim\Api_Cabinet::searchCabinets($cabinet, $locationId, $recursion); + } + } + else { + $cabinets = Dcim\Api_Cabinet::searchCabinets($cabinet); + } + + + foreach($cabinets as $cabinet) + { + //$Dcim_Api_Cabinet = new Dcim\Api_Cabinet($cabinet['entity_id']); + + $item = array(); + $item['header'] = $cabinet['name']; + $item['name'] = $cabinet['name']; + $item['path'] = DIRECTORY_SEPARATOR.str_replace(Dcim\Api_Cabinet::SEPARATOR_PATH, DIRECTORY_SEPARATOR, $cabinet['path']); + $items[] = $item; + } + + return $items; + } + + protected function _getEquipmentInfos($equipment, $fromCurrentPath = true, $path = null, $recursion = false) + { + $items = array(); + $equipments = array(); + + if($fromCurrentPath) + { + $currentApi = $this->_browser($path); + + if($currentApi instanceof Dcim\Api_Cabinet) { + $cabinetId = $currentApi->getCabinetId(); + $equipments = Dcim\Api_Equipment::searchEquipments($equipment, $equipment, $equipment, $cabinetId, null); + } + elseif($currentApi instanceof Dcim\Api_Location) { + $locationId = $currentApi->getLocationId(); + $equipments = Dcim\Api_Equipment::searchEquipments($equipment, $equipment, $equipment, null, $locationId, $recursion); + } + } + else { + $equipments = Dcim\Api_Equipment::searchEquipments($equipment, $equipment, $equipment); + } + + foreach($equipments as $equipment) + { + $Dcim_Api_Equipment = new Dcim\Api_Equipment($equipment['entity_id']); + + $item = array(); + $item['header'] = $Dcim_Api_Equipment->getLabel(); + $item['templateName'] = $Dcim_Api_Equipment->getTemplateName(); + $item['name'] = $Dcim_Api_Equipment->getLabel(); + //$item['description'] = $Dcim_Api_Equipment->getDescription(); + $item['serialNumber'] = $Dcim_Api_Equipment->getSerialNumber(); + $item['locationName'] = $Dcim_Api_Equipment->locationApi->getLabel(); + $item['cabinetName'] = $Dcim_Api_Equipment->cabinetApi->getLabel(); + $item['path'] = DIRECTORY_SEPARATOR.str_replace(Dcim\Api_Equipment::SEPARATOR_PATH, DIRECTORY_SEPARATOR, $Dcim_Api_Equipment->getPath()); + + $position = $Dcim_Api_Equipment->getPosition(); + $item['position'] = array($position['side'], $position['U']); + + $items[] = $item; + } + + return $items; + } + + public function printSearchObjects(array $args) + { + if(count($args) === 3) + { + $time1 = microtime(true); + $objects = $this->_searchObjects($args[0], $args[1], $args[2]); + $time2 = microtime(true); + + if($objects !== false) + { + $this->_RESULTS->append($objects); + $this->_SHELL->print('RECHERCHE ('.round($time2-$time1).'s)', 'black', 'white', 'bold'); + + if(!$this->_SHELL->isOneShotCall()) + { + if(isset($objects['locations'])) + { + $counter = count($objects['locations']); + $this->_SHELL->EOL()->print('LOCATIONS ('.$counter.')', 'black', 'white'); + + if($counter > 0) + { + foreach($objects['locations'] as $location) + { + $text1 = '['.$location['path'].']'; + $text1 .= C\Tools::t($text1, "\t", 2, 0, 8); + $text2 = $location['header']; + $this->_SHELL->print($text1.$text2, 'grey'); + } + } + else { + $this->_SHELL->error('Aucun résultat', 'orange'); + } + } + + if(isset($objects['cabinets'])) + { + $counter = count($objects['cabinets']); + $this->_SHELL->EOL()->print('CABINETS ('.$counter.')', 'black', 'white'); + + if($counter > 0) + { + foreach($objects['cabinets'] as $cabinet) + { + $text1 = '['.$cabinet['path'].']'; + $text1 .= C\Tools::t($text1, "\t", 2, 0, 8); + $text2 = $cabinet['header']; + $this->_SHELL->print($text1.$text2, 'grey'); + } + } + else { + $this->_SHELL->error('Aucun résultat', 'orange'); + } + } + + if(isset($objects['equipments'])) + { + $counter = count($objects['equipments']); + $this->_SHELL->EOL()->print('EQUIPMENTS ('.$counter.')', 'black', 'white'); + + if($counter > 0) + { + foreach($objects['equipments'] as $equipment) + { + $text1 = '['.$equipment['path'].']'; + $text1 .= C\Tools::t($text1, "\t", 7, 0, 8); + $text2 = $equipment['templateName']; + $text2 .= C\Tools::t($text2, "\t", 4, 0, 8); + $text3 = $equipment['header'].' {'.$equipment['serialNumber'].'}'; + $this->_SHELL->print($text1.$text2.$text3, 'grey'); + } + } + else { + $this->_SHELL->error('Aucun résultat', 'orange'); + } + } + + $this->_SHELL->EOL(); + } + } + else { + $this->_SHELL->error("Aucun résultat trouvé", 'orange'); + } + + return true; + } + + return false; + } + + protected function _searchObjects($path, $objectType, $objectSearch) + { + switch($objectType) + { + case 'location': + { + $locations = $this->_getLocationInfos($objectSearch, $this->_searchfromCurrentPath, $path, true); + return array('locations' => $locations); + break; + } + case 'cabinet': + { + $cabinets = $this->_getCabinetInfos($objectSearch, $this->_searchfromCurrentPath, $path, true); + return array('cabinets' => $cabinets); + break; + } + case 'equipment': + { + $equipments = $this->_getEquipmentInfos($objectSearch, $this->_searchfromCurrentPath, $path, true); + return array('equipments' => $equipments); + break; + } + case 'all': + { + $locations = $this->_searchObjects($path, 'location', $objectSearch); + $cabinets = $this->_searchObjects($path, 'cabinet', $objectSearch); + $equipments = $this->_searchObjects($path, 'equipment', $objectSearch); + return array_merge($locations, $cabinets, $equipments); + break; + } + default: { + throw new Exception("Search item '".$objectType."' is unknow", E_USER_ERROR); + } + } + } + + protected function _getLastLocationPath(array $pathApi) + { + return $this->_searchLastPathApi($pathApi, 'Addon\Dcim\Api_Location'); + } + + // MODIFY + // -------------------------------------------------- + public function modifyEquipment(array $args) + { + if(count($args) >= 3) + { + if($args[0] === '.') + { + $refreshPrompt = true; + $Dcim_Api_Equipment = $this->_getCurrentPathApi(); + + if(!$Dcim_Api_Equipment instanceof Dcim\Api_Equipment) { + $this->_SHELL->error("L'emplacement actuel n'est pas un équipement, merci de vous déplacer jusqu'à l'équipement concerné ou indiquez son nom", 'orange'); + unset($Dcim_Api_Equipment); + } + } + else + { + $refreshPrompt = false; + $equipments = Dcim\Api_Equipment::searchEquipments($args[0], null, $args[0]); + + if($equipments !== false) + { + switch(count($equipments)) + { + case 0: { + $this->_SHELL->error("Aucun équipement n'a été trouvé durant la recherche de '".$args[0]."'", 'orange'); + break; + } + case 1: { + $Dcim_Api_Equipment = new Dcim\Api_Equipment($equipments[0][Dcim\Api_Equipment::FIELD_ID]); + break; + } + default: { + $this->_SHELL->error("Plusieurs équipements ont été trouvés durant la recherche de '".$args[0]."'", 'orange'); + } + } + } + else { + $this->_SHELL->error("Une erreur s'est produite durant la recherche de l'équipement '".$args[0]."'", 'orange'); + } + } + + if(isset($Dcim_Api_Equipment)) + { + switch($args[1]) + { + case 'name': + case 'label': { + $status = $Dcim_Api_Equipment->renameLabel($args[2]); + break; + } + case 'description': { + $status = $Dcim_Api_Equipment->setDescription($args[2]); + break; + } + case 'sn': + case 'serialnumber': { + $status = $Dcim_Api_Equipment->setSerialNumber($args[2]); + break; + } + default: { + $this->_SHELL->error("L'attribut '".$args[1]."' n'est pas valide pour un équipement", 'orange'); + return false; + } + } + + if($status) { + $this->_SHELL->print("L'équipement '".$Dcim_Api_Equipment->label."' a été modifié!", 'green'); + } + else + { + if($Dcim_Api_Equipment->hasErrorMessage()) { + $this->_SHELL->error($Dcim_Api_Equipment->getErrorMessage(), 'orange'); + } + else { + $this->_SHELL->error("L'équipement '".$Dcim_Api_Equipment->label."' n'a pas pu être modifié!", 'orange'); + } + } + + if($refreshPrompt) { + $this->_SHELL->refreshPrompt(); + } + } + + return true; + } + else { + return false; + } + } + // -------------------------------------------------- + + // ----------------- AutoCompletion ----------------- + public function shellAutoC_cd($cmd, $search = null) + { + $Core_StatusValue = new C\StatusValue(false, array()); + + if($search === null) { + $search = ''; + } + elseif($search === false) { + return $Core_StatusValue; + } + + /** + * /!\ Pour eviter le double PHP_EOL (celui du MSG et de la touche ENTREE) + * penser à désactiver le message manuellement avec un lineUP + */ + $this->_SHELL->displayWaitingMsg(true, false, 'Searching DCIM objects'); + + if($search !== '' && $search !== DIRECTORY_SEPARATOR && substr($search, -1, 1) !== DIRECTORY_SEPARATOR) { + $search .= DIRECTORY_SEPARATOR; + } + + $input = $search; + $firstChar = substr($search, 0, 1); + + if($firstChar === DIRECTORY_SEPARATOR) { + $mode = 'absolute'; + $input = substr($input, 1); // Pour le explode / implode + $search = substr($search, 1); // Pour le explode / foreach + $baseApi = $this->_getRootPathApi(); + $pathApi = array($baseApi); + } + elseif($firstChar === '~') { + return $Core_StatusValue; + } + else { + $mode = 'relative'; + $pathApi = $this->_getPathApi(); + $baseApi = $this->_getCurrentPathApi(); + } + + /*$this->_SHELL->print('MODE: '.$mode.PHP_EOL, 'green'); + $this->_SHELL->print('PATH: '.$baseApi->getPath(true, DIRECTORY_SEPARATOR).PHP_EOL, 'orange'); + $this->_SHELL->print('INPUT: '.$input.PHP_EOL, 'green'); + $this->_SHELL->print('SEARCH: '.$search.PHP_EOL, 'green');*/ + + $searchParts = explode(DIRECTORY_SEPARATOR, $search); + + foreach($searchParts as $index => $search) + { + $baseApi = end($pathApi); + + if($search === '..') + { + if(count($pathApi) > 1) { + $status = false; + $results = array(); + array_pop($pathApi); + } + else { + continue; + } + } + else + { + $Core_StatusValue__browser = $this->_shellAutoC_cd_browser($baseApi, $search); + + $status = $Core_StatusValue__browser->status; + $result = $Core_StatusValue__browser->result; + + if(is_array($result)) + { + if($status === false && count($result) === 0) + { + // empty directory + if($search === '') { + $status = true; + $results = array(''); // Workaround retourne un seul resultat avec en clé input et en valeur '' + } + // no result found + else + { + $Core_StatusValue__browser = $this->_shellAutoC_cd_browser($baseApi, null); + + if($Core_StatusValue__browser instanceof C\StatusValue) { + $status = $Core_StatusValue__browser->status; + $results = $Core_StatusValue__browser->results; + } + // /!\ Ne doit jamais se réaliser! + else { + return $Core_StatusValue; + } + } + + break; + } + else { + $status = false; + $results = $result; + break; + } + } + elseif($result instanceof Dcim\Api_Abstract) + { + $pathApi[] = $result; + $results = array(''); // Workaround retourne un seul resultat avec en clé input et en valeur '' + + /** + * Ne surtout pas arrêter le traitement afin que l'on trouve un répertoire vide + * Cela permet d'enclencher le workaround et de terminer proprement l'algorithme + */ + /*if($result instanceof Dcim\Api_Equipment) { + break; + }*/ + } + // /!\ Ne doit jamais se réaliser! + else { + return $Core_StatusValue; + } + } + } + + $parts = explode(DIRECTORY_SEPARATOR, $input); + array_splice($parts, $index, count($parts), ''); + $input = implode(DIRECTORY_SEPARATOR, $parts); + + /*$this->_SHELL->print('index: '.$index.PHP_EOL, 'red'); + $this->_SHELL->print('count: '.count($parts).PHP_EOL, 'red');*/ + + if($mode === 'absolute') { + $input = DIRECTORY_SEPARATOR.$input; + } + + //$this->_SHELL->print('INPUT: '.$input.PHP_EOL, 'blue'); + + $options = array(); + + foreach($results as $result) + { + if($result !== '') { + $result .= DIRECTORY_SEPARATOR; + } + + $options[$input.$result] = $result; + } + + /*$this->_SHELL->print('STATUS: '.$status.PHP_EOL, 'blue'); + $this->_SHELL->print('OPTIONS: '.PHP_EOL, 'blue'); + var_dump($options); $this->_SHELL->EOL();*/ + + $Core_StatusValue->setStatus($status); + $Core_StatusValue->setOptions($options); + + // Utile car la désactivation doit s'effectuer avec un lineUP, voir message plus haut + $this->_SHELL->deleteWaitingMsg(true); + + return $Core_StatusValue; + } + + /** + * @param Addon\Dcim\Api_Abstract $baseApi + * @param null|string $search + * @return Core\StatusValue + */ + protected function _shellAutoC_cd_browser($baseApi, $search = null) + { + $locations = true; + $cabinets = true; + $equipments = true; + + $status = false; + $results = array(); + $baseApiClassName = get_class($baseApi); + + if($baseApiClassName === 'Addon\Dcim\Api_Location') + { + $locations = $baseApi->findLocations($search.'*', false); + + if($locations !== false) + { + $locations = array_column($locations, Dcim\Api_Location::FIELD_NAME, Dcim\Api_Location::FIELD_ID); + + if(($locationId = array_search($search, $locations, true)) !== false) { + $results = new Dcim\Api_Location($locationId); + } + elseif(count($locations) > 0) { + $results = array_merge($results, array_values($locations)); + } + } + + $cabinets = $baseApi->findCabinets($search.'*', false); + + if($cabinets !== false) + { + $cabinets = array_column($cabinets, Dcim\Api_Cabinet::FIELD_NAME, Dcim\Api_Cabinet::FIELD_ID); + + if(($cabinetId = array_search($search, $cabinets, true)) !== false) { + $results = new Dcim\Api_Cabinet($cabinetId); + } + elseif(count($cabinets) > 0) { + $results = array_merge($results, array_values($cabinets)); + } + } + } + + //if($baseApiClassName === 'Addon\Dcim\Api_Location' || $baseApiClassName === 'Addon\Dcim\Api_Cabinet') + if($baseApiClassName === 'Addon\Dcim\Api_Cabinet') + { + $equipments = $baseApi->findEquipments($search.'*', null, null, false, true); + + if($equipments !== false) + { + $equipments = array_column($equipments, Dcim\Api_Equipment::FIELD_NAME, Dcim\Api_Equipment::FIELD_ID); + + if(($equipmentId = array_search($search, $equipments, true)) !== false) { + $status = true; + $results = new Dcim\Api_Equipment($equipmentId); + } + elseif(count($equipments) > 0) { + $results = array_merge($results, array_values($equipments)); + } + } + } + + if(is_array($results)) + { + /** + * Si aucun des recherches ne fonctionnent ou si plusieurs résultats ont été trouvés mais qu'aucun ne correspond à la recherche + * alors cela signifie qu'on est arrivé au bout du traitement, on ne pourrait pas aller plus loin, donc on doit retourner true + */ + $status = (($locations === false && $cabinets === false && $equipments === false) || count($results) > 0); + } + + return new C\StatusValue($status, $results); + } + // -------------------------------------------------- + } \ No newline at end of file diff --git a/classes/soap.php b/classes/soap.php deleted file mode 100644 index 7856c8a..0000000 --- a/classes/soap.php +++ /dev/null @@ -1,96 +0,0 @@ -_server = $server; - $this->_service = (Tools::is('string&&!empty', $service)) ? ($service) : ('Unknown'); - - $this->_init(); - } - - protected function _init() - { - $this->resetOpts(); - } - - public function enableTrace() - { - $this->_options['trace'] = 1; - return $this; - } - - public function disableTrace() - { - $this->_options['trace'] = 0; - return $this; - } - - public function resetOpts() - { - $this->_options = array('trace' => 1); - return $this; - } - - public function getOpt($optName) - { - if(array_key_exists($optName, $this->_options)) { - return $this->_options[$optName]; - } - else { - return false; - } - } - - public function getOpts() - { - return $this->_options; - } - - public function setOpt($optName, $optValue) - { - $this->_options[$optName] = $optValue; - return $this; - } - - public function setOpts(array $opts) - { - $this->_options = $opts; - return $this; - } - - public function start() - { - if($this->_handle === null) { - $this->_handle = new SoapClient($this->_server, $this->_options); - } - - return true; - } - - public function __call($name, array $arguments) - { - $status = $this->start(); - - if($status) { - return call_user_func_array(array($this->_handle, $name), $arguments); - } - else { - throw new Exception("It is not possible to execute SOAP call for ".$this->_service." service", E_USER_ERROR); - } - } - - public function debug($debug = true) - { - $this->_debug = (bool) $debug; - return $this; - } - } \ No newline at end of file diff --git a/configurations/config.json.example b/configurations/config.json.example deleted file mode 100644 index 820e1cb..0000000 --- a/configurations/config.json.example +++ /dev/null @@ -1,24 +0,0 @@ -{ - "DEFAULT": { - "sys": { - "browserCmd": "xdg-open", - "secureShellCmd": "ssh" - } - }, - - "DCIM": { - "servers": { - "[DCIM_SERVER_KEY]": "https://myPatchManagerServerAddress.ext", - "myPmKey": "https://patchmanager.com/pmserver/" - }, - - "userAttrs": { - "default": { - "prefix": "", - "labels": { - "serialNumber": "[PM_ATTR_SN]" - } - } - } - } -} diff --git a/configurations/dcim.json.example b/configurations/dcim.json.example new file mode 100644 index 0000000..7df5a8b --- /dev/null +++ b/configurations/dcim.json.example @@ -0,0 +1,45 @@ +{ + "DEFAULT": { + "sys": { + "browserCmd": "xdg-open", + "secureShellCmd": "ssh", + "javawsCmd": "javaws" + } + }, + + "DCIM": { + "servers": { + "[DCIM_SERVER_KEY]": { + "loginCredential": false, + "loginEnvVarName": "DCIM_[DCIM_SERVER_KEY]_LOGIN", + "passwordCredential": false, + "passwordEnvVarName": "DCIM_[DCIM_SERVER_KEY]_PASSWORD", + "serverLocation": "https://myPatchManagerServerAddress.ext", + "objectCaching" : false + }, + "myPmKey": { + "loginCredential": false, + "loginEnvVarName": "DCIM_myPmKey_LOGIN", + "passwordCredential": false, + "passwordEnvVarName": "DCIM_myPmKey_PASSWORD", + "serverLocation": "https://patchmanager.com/pmserver/", + "objectCaching" : false + } + }, + + "userAttrs": { + "default": { + "prefix": "", + "labels": { + "serialNumber": "[PM_ATTR_SN]" + } + } + }, + + "preferences": { + "report": { + "csvDelimiter": "," + } + } + } +} diff --git a/configurations/dcim.user.json.example b/configurations/dcim.user.json.example new file mode 100644 index 0000000..2dca253 --- /dev/null +++ b/configurations/dcim.user.json.example @@ -0,0 +1,15 @@ +{ + "DEFAULT": { + "sys": { + "browserCmd": "python -mwebbrowser" + } + }, + + "DCIM": { + "preferences": { + "report": { + "csvDelimiter": "," + } + } + } +} diff --git a/dcim.php.example b/dcim.php.example index aacf375..442a588 100644 --- a/dcim.php.example +++ b/dcim.php.example @@ -1,29 +1,23 @@ Saut de ligne avant un texte et non après! - */ - echo "\033[1A"; + require_once(APP_DIR . '/launchers/dcim.php'); + $Launcher = new \App\Dcim\Launcher_Dcim(); /** * Change [DCIM_SERVER_KEY] with the key of your PatchManager server in configuration file * Example: $MAIN = new Service_Dcim(__DIR__ . '/config.json', 'myPmKey'); */ - $MAIN = new Service_Dcim($configurations, '[DCIM_SERVER_KEY]'); + $SHELL = new \App\Dcim\Shell_Dcim($configurations, '[DCIM_SERVER_KEY]'); echo PHP_EOL; exit(); \ No newline at end of file diff --git a/dcim/abstract.php b/dcim/abstract.php deleted file mode 100644 index 3ebe28c..0000000 --- a/dcim/abstract.php +++ /dev/null @@ -1,116 +0,0 @@ -DCIM; - - foreach($servers as $server) - { - $server = mb_strtoupper($server); - - if(!$config->servers->key_exists($server)) { - throw new Exception("Unable to retreive DCIM server @ ".$server, E_USER_ERROR); - } - else - { - $login = getenv('DCIM_'.$server.'_LOGIN'); - $password = getenv('DCIM_'.$server.'_PASSWORD'); - - if($login === false || $password === false) { - throw new Exception("Unable to retreive DCIM credentials for [".$server."] from env", E_USER_ERROR); - } - - $this->_aDCIM[$server] = new DCIM_Connector_Soap($config->servers[$server], $login, $password, $printInfoMessages); - } - } - - if(count($this->_aDCIM) === 1) { - $this->_oDCIM = current($this->_aDCIM); - } - } - - public function getJnlpUrl($server = false, $version = 64) - { - if($server === false && $this->_oDCIM !== null) { - return $this->_oDCIM->getJnlpUrl($version); - } - elseif(array_key_exists($server, $this->_aDCIM)) { - return $this->_aDCIM[$server]->getJnlpUrl($version); - } - - return false; - } - - public function getDcim($equipLabel = null) - { - if($this->_oDCIM !== null) { - return $this->_oDCIM; - } - elseif($equipLabel !== null) - { - if(preg_match('#^(.*-[ps]-.*)$#i', $equipLabel)) { - return $this->_aDCIM['SEC']; - } - elseif(preg_match('#^(.*-[il]-.*)$#i', $equipLabel)) { - return $this->_aDCIM['CORP']; - } - elseif(preg_match('#^(.*-[d]-.*)$#i', $equipLabel)) { - return $this->_aDCIM['DEV']; - } - } - - throw new Exception('Impossible de retourner le service DCIM adapté', E_USER_ERROR); - } - - public function __get($name) - { - if($this->_oDCIM !== null) { - return $this->_oDCIM; - } - else - { - switch(mb_strtolower($name)) - { - case 'sec': - return $this->_aDCIM['SEC']; - case 'corp': - return $this->_aDCIM['CORP']; - case 'dev': - return $this->_aDCIM['DEV']; - } - } - - throw new Exception("Le DCIM ".$name." n'existe pas", E_USER_ERROR); - } - - public function __call($name, array $arguments) - { - if($this->_oDCIM !== null) { - return call_user_func_array(array($this->_oDCIM, $name), $arguments); - } - else - { - $results = array(); - - foreach($_aDCIM as $dcim) { - $result[] = call_user_func_array(array($dcim, $name), $arguments); - } - - return $results; - } - } - - public static function __callStatic($name, array $arguments) - { - return forward_static_call_array(array('DCIM_Connector_Soap', $name), $arguments); - } - } diff --git a/dcim/api/abstract.php b/dcim/api/abstract.php deleted file mode 100644 index 0b350dd..0000000 --- a/dcim/api/abstract.php +++ /dev/null @@ -1,154 +0,0 @@ -objectIdIsValid($objectId)) { - $this->_objectId = (int) $objectId; - $this->objectExists(); - } - elseif($objectId !== null) { - throw new Exception("This object ID must be an integer, '".gettype($objectId)."' is not valid", E_USER_ERROR); - } - } - - public function getObjectType() - { - return static::OBJECT_TYPE; - } - - public function objectIdIsValid($objectId) - { - return Tools::is('int&&>0', $objectId); - } - - public function hasObjectId() - { - return ($this->_objectId !== null); - } - - public function getObjectId() - { - return $this->_objectId; - } - - public function objectExists() - { - if(!$this->hasObjectId()) { - return false; - } - elseif($this->_objectExists === null) { - $this->_objectExists = ($this->getObjectLabel() !== false); - } - return $this->_objectExists; - } - - public function getObjectLabel() - { - if(!$this->hasObjectId()) { // /!\ Ne pas appeler equipmentExists sinon boucle infinie - return false; - } - elseif($this->_objectLabel === null) { - $result = $this->_DCIM->resolvToLabel(static::OBJECT_TYPE, $this->getObjectId()); - $this->_objectLabel = ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); - } - return $this->_objectLabel; - } - - public function getLabel() - { - return $this->getObjectLabel(); - } - - public function getTemplateName() - { - if($this->objectExists()) { - $result = $this->_DCIM->getEquipmentTemplateNameByEquipmentId($this->getObjectId()); - return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); - } - else { - return false; - } - } - - public function getUserAttr($category, $attrLabel) - { - if($this->objectExists()) - { - if(Tools::is('string&&!empty', $category)) { - $attrName = $this->_DCIM->getUserAttrName($category, $attrLabel); - } - else { - $attrName = $attrLabel; - } - - $result = $this->_DCIM->getUserAttrById(static::OBJECT_TYPE, $this->getObjectId(), $attrName); - return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); - } - else { - return false; - } - } - - protected function _getSubObjects($objects, $fieldName, $name) - { - if($objects !== false) - { - if($name !== null) - { - $subObjects = array(); - - foreach($objects as $object) - { - if($object[$fieldName] === $name) { - $subObjects[] = $object; - } - } - - return $subObjects; - } - else { - return $objects; - } - } - else { - return false; - } - } - - public function __get($name) - { - switch(mb_strtolower($name)) - { - case 'dcim': - case '_dcim': { - return self::$_DCIM; - } - - default: { - throw new Exception("This attribute '".$name."' does not exist", E_USER_ERROR); - } - } - } - - public function getErrorMessage() - { - return $this->_errorMessage; - } - - public static function setDcim(DCIM_Main $DCIM) - { - self::$_DCIM = $DCIM; - } - } \ No newline at end of file diff --git a/dcim/api/cabinet.php b/dcim/api/cabinet.php deleted file mode 100644 index f7fee12..0000000 --- a/dcim/api/cabinet.php +++ /dev/null @@ -1,133 +0,0 @@ - 'CW - TOOLS-CLI - Cabinet1', - 'location' => 'CW - TOOLS-CLI - Cabinet2', - 'subLocation' => 'CW - TOOLS-CLI - Cabinet3', - ); - - protected $_locationId; - protected $_locationApi; - - - public function cabinetIdIsValid($cabinetId) - { - return $this->objectIdIsValid($cabinetId); - } - - public function hasCabinetId() - { - return $this->hasObjectId(); - } - - public function getCabinetId() - { - return $this->getObjectId(); - } - - public function cabinetExists() - { - return $this->objectExists(); - } - - public function getCabinetLabel() - { - return $this->getObjectLabel(); - } - - public function getLocationId() - { - if($this->cabinetExists()) - { - if($this->_locationId === null) - { - $equipmentIds = $this->getEquipmentIds(); - - if(Tools::is('array&&count>0', $equipmentIds)) - { - $equipmentId = current($equipmentIds); - - $Dcim_Api_Equipment = new Dcim_Api_Equipment($equipmentId); - $locationId = $Dcim_Api_Equipment->getLocationId(); - $this->_locationId = ($locationId !== false) ? ($locationId) : (false); - } - else { - $this->_locationId = false; - } - } - - return $this->_locationId; - } - else { - return false; - } - } - - public function getLocationApi() - { - if($this->_locationApi === null) - { - $locationId = $this->getEquipmentLocationId(); - - if($locationId !== false) { - $this->_locationApi = new Dcim_Api_Location($locationId); - } - else { - $this->_locationApi = false; - } - } - - return $this->_locationApi; - } - - public function getEquipmentIds() - { - if($this->cabinetExists()) { - return $this->_DCIM->getEquipmentIdsByCabinetId($this->getCabinetId()); - } - else { - return false; - } - } - - public function getEquipmentId($equipmentLabel) - { - if($this->cabinetExists()) { - $result = $this->_DCIM->getEquipmentIdByCabinetIdEquipmentLabel($this->getCabinetId(), $equipmentLabel); - return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); - } - else { - return false; - } - } - - public function __get($name) - { - switch($name) - { - case 'locationApi': { - return $this->getLocationApi(); - } - default: { - return parent::__get($name); - } - } - } - - public static function searchCabinets($cabinetLabel, $locationId = null, $recursion = false) - { - $args = array('label' => $cabinetLabel); - - if(Tools::is('int&&>0', $locationId)) { - $args['locationid'] = $locationId; - $reportName = ($recursion) ? ('subLocation') : ('location'); - } - else { - $reportName = 'label'; - } - - return self::$_DCIM->getReportResults(self::REPORT_NAMES[$reportName], $args); - } - } \ No newline at end of file diff --git a/dcim/api/cable.php b/dcim/api/cable.php deleted file mode 100644 index 648ec08..0000000 --- a/dcim/api/cable.php +++ /dev/null @@ -1,35 +0,0 @@ - 'CW - TOOLS-CLI - CableLabel', - 'equipment' => 'CW - TOOLS-CLI - CableEquipment', - ); - - - public function cableIdIsValid($cableId) - { - return $this->objectIdIsValid($cableId); - } - - public function hasCableId() - { - return $this->hasObjectId(); - } - - public function getCableId() - { - return $this->getObjectId(); - } - - public function cableExists() - { - return $this->objectExists(); - } - - public function getCableLabel() - { - return $this->getObjectLabel(); - } - } \ No newline at end of file diff --git a/dcim/api/equipment.php b/dcim/api/equipment.php deleted file mode 100644 index 8f75973..0000000 --- a/dcim/api/equipment.php +++ /dev/null @@ -1,286 +0,0 @@ - 'CW - TOOLS-CLI - Equipment1', - 'cabinet' => 'CW - TOOLS-CLI - Equipment4', - 'location' => 'CW - TOOLS-CLI - Equipment2', - 'subLocation' => 'CW - TOOLS-CLI - Equipment3', - ); - - const TEMPLATE_PATH = '/../../templates/'; - const TEMPLATE_EXT = 'yaml'; - - protected static $_templates = array(); - - protected $_locationId; - protected $_cabinetId; - - protected $_locationApi; - protected $_cabinetApi; - - protected $_template = null; - - - public function equipmentIdIsValid($equipmentId) - { - return $this->objectIdIsValid($equipmentId); - } - - public function hasEquipmentId() - { - return $this->hasObjectId(); - } - - public function getEquipmentId() - { - return $this->getObjectId(); - } - - public function equipmentExists() - { - return $this->objectExists(); - } - - public function getEquipmentLabel() - { - return $this->getObjectLabel(); - } - - public function setLocationId($locationId) - { - if(!$this->equipmentExists() && Tools::is('int&&>0', $locationId)) { - $this->_locationId = $locationId; - return $this; - } - - return false; - } - - public function hasLocationId() - { - return ($this->_locationId !== null); - } - - public function getLocationId() - { - if($this->equipmentExists()) - { - if(!$this->hasLocationId()) { - $result = $this->_DCIM->getLocationIdByEquipmentId($this->getEquipmentId()); - $this->_locationId = ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); - } - - return $this->_locationId; - } - elseif($this->hasLocationId()) { - return $this->_locationId; - } - else { - return false; - } - } - - public function getLocationApi() - { - if($this->_locationApi === null) - { - $locationId = $this->getLocationId(); - - if($locationId !== false) { - $this->_locationApi = new Dcim_Api_Location($locationId); - } - else { - $this->_locationApi = false; - } - } - - return $this->_locationApi; - } - - public function getCabinetId() - { - if($this->equipmentExists()) { - $result = $this->_DCIM->getCabinetIdByEquipmentId($this->getEquipmentId()); - return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); - } - else { - return false; - } - } - - public function getCabinetApi() - { - if($this->_cabinetApi === null) - { - $cabinetId = $this->getCabinetId(); - - if($cabinetId !== false) { - $this->_cabinetApi = new Dcim_Api_Cabinet($cabinetId); - } - else { - $this->_cabinetApi = false; - } - } - - return $this->_cabinetApi; - } - - public function getPath() - { - $path = ""; - $locationApi = $this->getLocationApi(); - $cabinetApi = $this->getCabinetApi(); - - if($locationApi !== false) { - $path .= $locationApi->getPath(); - } - - if($cabinetApi !== false) { - $path .= ','.$cabinetApi->getLabel(); - } - - return $path; - } - - public function getPosition() - { - if($this->equipmentExists()) { - return $this->_DCIM->getUByEquipmentId($this->getEquipmentId()); - } - else { - return false; - } - } - - public function getSerialNumber() - { - return $this->getUserAttr('default', 'serialNumber'); - } - - public function getPortIds() - { - return $this->_DCIM->getPortIdsByEquipmentId($this->getEquipmentId()); - } - - public function getConnectedPortIds() - { - $conPortIds = array(); - $portIds = $this->getPortIds(); - - foreach($portIds as $portId) - { - $result = $this->_DCIM->getConnectedPortIdByPortId($portId); - $nbPortId = ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); - - if($nbPortId !== false) { - $conPortIds[$portId] = $nbPortId; - } - } - - return $conPortIds; - } - - public function getCableIds() - { - $cableIds = array(); - $portIds = $this->_DCIM->getPortIdsByEquipmentId($this->getEquipmentId()); - - foreach($portIds as $portId) - { - $result = $this->_DCIM->getConnectedCableIdByPortId($portId); - $cableId = ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); - - if($cableId !== false) { - $cableIds[] = $cableId; - } - } - - return $cableIds; - } - - // /!\ rename est reserve - public function renameLabel($label) - { - if($this->equipmentExists()) { - $result = $this->_DCIM->updateEquipmentInfos($this->getEquipmentId(), $label); - return ($result === true); - } - else { - return false; - } - } - - protected function _loadTemplate($templateName) - { - if(!array_key_exists($templateName, self::$_templates)) - { - $file = realpath(__DIR__.'/'.self::TEMPLATE_PATH); - $file .= '/'.$templateName.'.'.self::TEMPLATE_EXT; - - if(file_exists($file) && is_file($file) && is_readable($file)) - { - $yaml = yaml_parse_file($file); - - if($yaml !== false) { - self::$_templates[$templateName] = $this->_template = $yaml; - } - else { - throw new Exception("Impossible de parser le template YAML @ ".$file, E_USER_ERROR); - } - } - else { - throw new Exception("Impossible de lire le template YAML @ ".$file, E_USER_ERROR); - } - } - else { - $this->_template = self::$_templates[$templateName]; - } - } - - protected function _reset($resetEquipmentId = false) - { - if($resetEquipmentId) { - $this->_objectId = null; - } - - $this->_objectExists = null; - $this->_objectLabel = null; - } - - public function __get($name) - { - switch($name) - { - case 'locationApi': { - return $this->getLocationApi(); - } - case 'cabinetApi': { - return $this->getCabinetApi(); - } - default: { - return parent::__get($name); - } - } - } - - public static function searchEquipments($equipmentLabel, $equipmentDesc, $equipmentSN, $cabinetId = null, $locationId = null, $recursion = false) - { - $args = array('label' => $equipmentLabel, 'description' => $equipmentDesc, 'serialnumber' => $equipmentSN); - - if(Tools::is('int&&>0', $cabinetId)) { - $reportName = 'cabinet'; - $args['cabinetid'] = $cabinetId; - } - elseif(Tools::is('int&&>0', $locationId)) { - $args['locationid'] = $locationId; - $reportName = ($recursion) ? ('subLocation') : ('location'); - } - else { - $reportName = 'label'; - } - - return self::$_DCIM->getReportResults(self::REPORT_NAMES[$reportName], $args); - } - } \ No newline at end of file diff --git a/dcim/api/location.php b/dcim/api/location.php deleted file mode 100644 index 437fa04..0000000 --- a/dcim/api/location.php +++ /dev/null @@ -1,241 +0,0 @@ - 'CW - TOOLS-CLI - Location - Root', - 'label' => 'CW - TOOLS-CLI - Location1', - 'location' => 'CW - TOOLS-CLI - Location2', - 'subLocation' => 'CW - TOOLS-CLI - Location3', - ); - - static protected $_rootLocationId = null; - static protected $_rootLocationIds = null; - - protected $_parentLocationId; - protected $_parentLocationApi; - - - public function locationIdIsValid($locationId) - { - return $this->objectIdIsValid($locationId); - } - - public function hasLocationId() - { - return $this->hasObjectId(); - } - - public function getLocationId() - { - return $this->getObjectId(); - } - - public function locationExists() - { - return $this->objectExists(); - } - - public function getLocationLabel() - { - return $this->getObjectLabel(); - } - - public function getParentLocationId() - { - if($this->locationExists()) - { - if($this->_parentLocationId === null) - { - $this->_parentLocationId = false; - - $path = $this->getPath(); - $path = explode(',', $path); - - $selfClassName = static::class; - $Dcim_Api_Location = new $selfClassName(); - $locationId = $Dcim_Api_Location->getSubLocationId($path[0]); - - if($locationId !== false) - { - for($i=1; $i_DCIM->getLocationIdByParentLocationIdLocationLabel($locationId, $path[$i], false); - - if($locationId === false) { - break; - } - } - - if($i === count($path)) { - $this->_parentLocationId = $locationId; - } - } - } - - return $this->_parentLocationId; - } - else { - return false; - } - } - - public function getParentLocationApi() - { - if($this->_parentLocationApi === null) - { - $locationId = $this->getParentLocationId(); - - if($locationId !== false) { - $this->_parentLocationApi = new Dcim_Api_Location($locationId); - } - else { - $this->_parentLocationApi = false; - } - } - - return $this->_parentLocationApi; - } - - public function getPath() - { - if($this->locationExists()) { - $result = $this->_DCIM->getLocationPathByLocationId($this->getLocationId()); - return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); - } - else { - return false; - } - } - - public function getSubLocationIds() - { - if($this->locationExists()) { - return $this->_DCIM->getSubLocationIds($this->getLocationId(), false); - } - else { - return $this->getRootLocationIds(); - } - } - - public function getSubLocationId($locationLabel) - { - if($this->locationExists()) { - return $this->_DCIM->getLocationIdByParentLocationIdLocationLabel($this->getLocationId(), $locationLabel, false); - } - else { - $results = self::$_DCIM->getReportResults(self::REPORT_NAMES['root']); - $result = $this->_getSubObjects($results, 'name', $locationLabel); - return (Tools::is('array', $result) && count($result) === 1) ? ($result[0]['entity_id']) : (false); - } - } - - public function getCabinetIds() - { - if($this->locationExists()) { - return $this->_DCIM->getCabinetIdsByLocationId($this->getLocationId()); - } - else { - return false; - } - } - - public function getCabinetId($cabinetLabel) - { - if($this->locationExists()) { - $result = $this->_DCIM->getCabinetIdByLocationIdCabinetLabel($this->getLocationId(), $cabinetLabel); - return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); - } - else { - return false; - } - } - - public function getEquipmentId($equipmentLabel) - { - if($this->locationExists()) { - $result = $this->_DCIM->getEquipmentIdByLocationIdEquipmentLabel($this->getLocationId(), $equipmentLabel); - return ($this->_DCIM->isValidReturn($result)) ? ($result) : (false); - } - else { - return false; - } - } - - public function __call($method, $parameters = null) - { - switch($method) - { - default: { - throw new Exception('Method '.$method.' does not exist', E_USER_ERROR); - } - } - } - - public function __get($name) - { - switch($name) - { - case 'parentLocationApi': { - return $this->_parentLocationApi(); - } - default: { - return parent::__get($name); - } - } - } - - public static function getRootLocationId() - { - if(self::$_rootLocationId === null) - { - $results = self::$_DCIM->getReportResults(self::REPORT_NAMES['root']); - - if(Tools::is('array', $results) && count($results) === 1) { - self::$_rootLocationId = $results[0]['entity_id']; - } - else { - throw new Exception("Unable to get root location ID", E_USER_ERROR); - } - } - - return self::$_rootLocationId; - } - - public static function getRootLocationIds() - { - if(self::$_rootLocationIds === null) - { - $results = self::$_DCIM->getReportResults(self::REPORT_NAMES['root']); - - if(Tools::is('array&&count>0', $results)) - { - array_walk($results, function(&$item) { - $item = $item['entity_id']; - }); - - self::$_rootLocationIds = $results; - } - else { - throw new Exception("Unable to retreive root location IDs", E_USER_ERROR); - } - } - - return self::$_rootLocationIds; - } - - public static function searchLocations($locationLabel, $locationId = null, $recursion = false) - { - $args = array('label' => $locationLabel); - - if(Tools::is('int&&>0', $locationId)) { - $args['locationid'] = $locationId; - $reportName = ($recursion) ? ('subLocation') : ('location'); - } - else { - $reportName = 'label'; - } - - return self::$_DCIM->getReportResults(self::REPORT_NAMES[$reportName], $args); - } - } \ No newline at end of file diff --git a/dcim/connector/abstract.php b/dcim/connector/abstract.php deleted file mode 100644 index a3405fe..0000000 --- a/dcim/connector/abstract.php +++ /dev/null @@ -1,4 +0,0 @@ - - - CW - TOOLS-CLI - Cabinet - INFTSK-5007 - - - cabinet.entityId - - - cabinet.name - - - cabinet.location - com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer - - {qname} - - - - - - cabinet.location - com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer - - {qname} - - - - cabinet.name - - - diff --git a/ressources/dcim/formats/CW - TOOLS-CLI - Equipment.xml b/ressources/dcim/formats/CW - TOOLS-CLI - Equipment.xml deleted file mode 100644 index b7a581e..0000000 --- a/ressources/dcim/formats/CW - TOOLS-CLI - Equipment.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - CW - TOOLS-CLI - Equipment - INFTSK-5007 - - - equipment.entityId - - - equipment.label - - - - - equipment.position - com.patchmanager.shared.beans.dataformat.renderer.ExpressionRenderer - - {container} ({details}) - - - - equipment.label - - - diff --git a/services/abstract.php b/services/abstract.php deleted file mode 100644 index f17e7f5..0000000 --- a/services/abstract.php +++ /dev/null @@ -1,388 +0,0 @@ -_debug = (bool) $debug; - } - - $this->_CONFIG = CONFIG::getInstance(); - $this->_CONFIG->loadConfigurations($configFilename, false); - - $this->_SHELL = new SHELL($this->_commands, $this->_inlineArgCmds, $this->_outlineArgCmds, $this->_manCommands); - $this->_SHELL->debug($this->_debug)->setHistoryFilename(static::SHELL_HISTORY_FILENAME); - } - - public function test($cmd, array $args = array()) - { - $this->_isOneShotCall = true; - $this->waitingMsgFeature(false); - $this->_preLauchingShell(false); - - $this->_preRoutingShellCmd($cmd, $args); - $exit = $this->_routeShellCmd($cmd, $args); - $this->_postRoutingShellCmd($cmd, $args); - - echo json_encode($this->_lastCmdResult); - - $this->_postLauchingShell(false); - } - - protected function _init() - { - $this->_oneShotCall(); - - $this->_preLauchingShell(); - $this->_launchShell(); - $this->_postLauchingShell(); - - return $this; - } - - public function isOneShotCall() - { - if($this->_isOneShotCall === null) { - $this->_isOneShotCall = ($_SERVER['argc'] > 1); - } - - return $this->_isOneShotCall; - } - - protected function _oneShotCall() - { - if($this->isOneShotCall()) - { - $this->waitingMsgFeature(false); - $this->_preLauchingShell(false); - - if($_SERVER['argc'] === 2) - { - $cmd = $_SERVER['argv'][1]; - $status = $this->_routeCliCmdCall($cmd); - - if($status) { - echo json_encode($this->_lastCmdResult); - $exitCode = 0; - } - else { - $this->error("Commande invalide", 'red', false, 'bold'); - $this->_SHELL->help(); - $exitCode = 1; - } - } - else { - $exitCode = $this->_dispatchCliCall(); - } - - $this->_postLauchingShell(false); - exit($exitCode); - } - } - - protected function _dispatchCliCall() - { - $this->_isOneShotCall = false; - $this->waitingMsgFeature(true); - - $options = getopt($this->_cliOptions['short'], $this->_cliOptions['long']); - - // Permet de garantir l'ordre d'exécution des commandes - foreach($this->_cliOptions['long'] as $cli) - { - $cli = str_replace(':', '', $cli); - - if(isset($options[$cli])) - { - $option = (array) $options[$cli]; - - foreach($option as $_option) - { - $status = $this->_cliOptToCmdArg($cli, $_option); - - if(!$status) { - return 1; - } - } - } - } - - return 0; - } - - protected function _cliOptToCmdArg($cli, $option) - { - return 1; - } - - protected function _routeCliCmdCall($cmd) - { - $Shell_Autocompletion = new Shell_Autocompletion($this->_commands, $this->_inlineArgCmds, $this->_outlineArgCmds, $this->_manCommands); - $Shell_Autocompletion->debug($this->_debug); - - $status = $Shell_Autocompletion->_($cmd); - - if($status) - { - $cmd = $Shell_Autocompletion->command; - $args = $Shell_Autocompletion->arguments; - - $this->_preRoutingShellCmd($cmd, $args); - $this->_routeShellCmd($cmd, $args); - $this->_postRoutingShellCmd($cmd, $args); - return $this->_lastCmdStatus; - } - else { - return false; - } - } - - protected function _preLauchingShell($welcomeMessage = true) - { - if($welcomeMessage) { - $this->EOL(); - $this->print("CTRL+C ferme le shell, utilisez ALT+C à la place", 'blue', false, 'italic'); - $this->print("Utilisez UP et DOWN afin de parcourir votre historique de commandes", 'blue', false, 'italic'); - $this->print("Utilisez TAB pour l'autocomplétion et ? afin d'obtenir davantage d'informations", 'blue', false, 'italic'); - $this->EOL(); - } - } - - abstract protected function _launchShell(); - - protected function _postLauchingShell($goodbyeMessage = true) - { - if($goodbyeMessage) { - $this->EOL(); - $this->print("Merci d'avoir utilisé TOOLS-CLI by NOC", 'blue', false, 'italic'); - $this->EOL(); - } - } - - protected function _preRoutingShellCmd(&$cmd, array &$args) - { - /** - * Dans certains cas, un espace peut être autocomplété à la fin de la commande afin de faciliter à l'utilisateur la CLI. - * Exemple: show => array('host', 'subnet') --> "show " afin que l'utilisateur puisse poursuivre la commande - * - * Cependant, si l'on souhaite autoriser "show" comme commande valide alors il faut nettoyer l'autocompletion - * - * Ce traitement est à réaliser pour les commandes OneShot, CLI et SHELL. - * De ce fait il ne faut pas le réaliser dans Shell_Abstract sinon les commandes OneShot ne seront pas nettoyées - */ - $cmd = rtrim($cmd, ' '); - - foreach($args as &$arg) { - $arg = preg_replace('#^("|\')|("|\')$#i', '', $arg); - } - - $this->displayWaitingMsg(false, false); - } - - protected function _routeShellCmd($cmd, array $args) - { - switch($cmd) - { - case '': { - $this->print("Tape help for help !", 'blue'); - break; - } - case 'history': { - $this->deleteWaitingMsg(); - $this->_SHELL->history(); - $this->EOL(); - break; - } - case 'help': { - $this->deleteWaitingMsg(); - $this->_SHELL->help(); - $this->EOL(); - break; - } - case 'exit': - case 'quit': { - $this->deleteWaitingMsg(); - return true; - } - default: { - $this->error("Commande inconnue... [".$cmd."]", 'red'); - } - } - - return false; - } - - protected function _postRoutingShellCmd($cmd, array $args) {} - - public function displayWaitingMsg($startEOL = true, $finishEOL = false, $infos = null) - { - if($this->waitingMsgFeature() && !$this->_waitingMsgState) - { - /** - * /!\ Ne pas inclure les sauts de lignes dans le traitement de la police - * $infos ne doit pas contenir de saut de lignes sinon la desactivation ne fonctionnera pas complètement - */ - $message = ($startEOL) ? (PHP_EOL) : (''); - - $message .= Tools::e("Veuillez patienter ...", 'orange', false, 'bold', true); - if($infos !== null) { $message .= Tools::e(' ('.$infos.')', 'orange', false, 'bold', true); } - - if($finishEOL) { $message .= PHP_EOL; } - $this->_SHELL->insertMessage($message); - $this->_waitingMsgState = true; - return true; - } - else { - return false; - } - } - - public function deleteWaitingMsg($lineUP = true) - { - if($this->waitingMsgFeature() && $this->_waitingMsgState) { - $this->_SHELL->deleteMessage(1, $lineUP); - $this->_waitingMsgState = false; - return true; - } - else { - return false; - } - } - - public function waitingMsgFeature($status = null) - { - if($status === true || $status === false) { - $this->_waitingMsgFeature = $status; - } - return $this->_waitingMsgFeature; - } - - public function setLastCmdResult($result) - { - $this->_lastCmdResult = $result; - return $this; - } - - protected function _e($text, $textColor = false, $bgColor = false, $textStyle = false, $doNotPrint = false) - { - return ($this->_isOneShotCall) ? ($text) : (Tools::e($text, $textColor, $bgColor, $textStyle, $doNotPrint)); - } - - public function format($text, $textColor = 'green', $bgColor = false, $textStyle = false) - { - return $this->_e($text, $textColor, $bgColor, $textStyle, true); - } - - public function EOL($multiplier = 1, $textColor = false, $bgColor = false, $textStyle = false, $autoDelWaitingMsg = true) - { - if($autoDelWaitingMsg) { - $this->deleteWaitingMsg(); - } - - $this->_e(str_repeat(PHP_EOL, $multiplier), $textColor, $bgColor, $textStyle, false); - return $this; // /!\ Important - } - - public function print($text, $textColor = 'green', $bgColor = false, $textStyle = false, $autoDelWaitingMsg = true) - { - if($autoDelWaitingMsg) { - $this->deleteWaitingMsg(); - } - - /** - * /!\ Ne doit pas être formaté comme le texte - * /!\ Ne pas supprimer le message d'attente: - * - Déjà traité dans cette méthode - * - Si $autoDelWaitingMsg === false - */ - $this->EOL(1, false, false, false, false); - return $this->_e($text, $textColor, $bgColor, $textStyle, false); - } - - public function error($text, $textColor = 'red', $bgColor = false, $textStyle = false, $autoDelWaitingMsg = true) - { - if($autoDelWaitingMsg) { - $this->deleteWaitingMsg(); - } - - /** - * /!\ Ne doit pas être formaté comme le texte - * /!\ Ne pas supprimer le message d'attente: - * - Déjà traité dans cette méthode - * - Si $autoDelWaitingMsg === false - */ - $this->EOL(1, false, false, false, false); - return $this->_e($text, $textColor, $bgColor, $textStyle, false); - } - - protected function _throwException(Exception $exception) - { - Tools::e(PHP_EOL.PHP_EOL."Exception --> ".$exception->getMessage()." [".$exception->getFile()."] {".$exception->getLine()."}", 'red'); - } - - public static function errorHandler($errno, $errstr, $errfile, $errline) - { - throw new ErrorException($errstr, 0, $errno, $errfile, $errline); - } - } \ No newline at end of file diff --git a/services/browser.php b/services/browser.php deleted file mode 100644 index 4db9a12..0000000 --- a/services/browser.php +++ /dev/null @@ -1,151 +0,0 @@ -_moveToRoot(); - } - - protected function _routeShellCmd($cmd, array $args) - { - switch($cmd) - { - case 'ls': - case 'll': - { - $isPrinted = $this->_Service_Shell->printObjectInfos($args, true); - - if(!$isPrinted || $this->_printBothObjectAndList) - { - if(!$isPrinted) { - $this->deleteWaitingMsg(true); // Fix PHP_EOL lié au double message d'attente successif lorsque la commande precedente n'a rien affichée - } - - $path = (isset($args[0])) ? ($args[0]) : (null); - $objects = $this->_Service_Shell->printObjectsList($path); - $this->setLastCmdResult($objects); - } - break; - } - case 'cd': - { - if(isset($args[0])) - { - $path = $args[0]; - $path = explode('/', $path); - - if($path[0] === "" || $path[0] === '~') { - array_shift($path); - $this->_moveToRoot(); - } - - $this->_moveToPath($path); - } - else { - $this->_moveToRoot(); - } - - $this->deleteWaitingMsg(); - break; - } - case 'pwd': - { - $currentPath = $this->_getCurrentPath(); - - $this->print($currentPath, 'white'); - $this->setLastCmdResult($currentPath); - break; - } - case 'cdautocomplete': - { - if(isset($args[0])) - { - switch($args[0]) - { - case 'en': - case 'enable': - $this->_cdautocomplete = true; - break; - case 'dis': - case 'disable': - $this->_cdautocomplete = false; - break; - } - } - else { - $this->_cdautocomplete = !$this->_cdautocomplete; - } - - if(!$this->_cdautocomplete) { - $this->_SHELL->setInlineArg('cd', $this->_inlineArgCmds['cd']); - } - - $cdAutoCompleteStatut = ($this->_cdautocomplete) ? ('activée') : ('désactivée'); - $this->print("L'autocomplétion de la commande CD est ".$cdAutoCompleteStatut, 'green'); - break; - } - default: { - return parent::_routeShellCmd($cmd, $args); - } - } - - return false; - } - - protected function _setObjectAutocomplete(array $fields = null) - { - if($this->_cdautocomplete && count($fields) > 0) { - $options = $this->_Service_Shell->getOptions(); - $this->_SHELL->setInlineArg('cd', array(0 => $options)); - } - else { - $this->_SHELL->setInlineArg('cd', $this->_inlineArgCmds['cd']); - } - return $this; - } - - protected function _moveToRoot() - { - array_splice($this->_pathIds, 1); - array_splice($this->_pathApi, 1); - - $this->_Service_Shell->updatePath($this->_pathIds, $this->_pathApi); - - $this->_setObjectAutocomplete(); - $this->_SHELL->setShellPrompt('/'); - return $this->_pathApi[0]; - } - - protected function _moveToPath($path) - { - $this->browser($this->_pathIds, $this->_pathApi, $path); - $this->_Service_Shell->updatePath($this->_pathIds, $this->_pathApi); - - $this->_setObjectAutocomplete(); - $currentPath = $this->_getCurrentPath(); - $this->_SHELL->setShellPrompt($currentPath); - - return end($this->_pathApi); - } - - protected function _getCurrentPath() - { - $pathname = '/'; - - for($i=1; $i_pathApi); $i++) { - $pathname .= $this->_pathApi[$i]->getObjectLabel().'/'; - } - - return $pathname; - } - } \ No newline at end of file diff --git a/services/dcim.php b/services/dcim.php deleted file mode 100644 index 1a47420..0000000 --- a/services/dcim.php +++ /dev/null @@ -1,286 +0,0 @@ - array( - 'location', 'cabinet', 'equipment', - ), - 'show' => array( - 'location', 'cabinet', 'equipment', - /*'system', 'sys', 'server', - 'network', 'net', 'appliance'*/ - ), - 'patchmanager' - ); - - /** - * Arguments ne commencant pas par - mais étant dans le flow de la commande - * - * ls mon/chemin/a/lister - * cd mon/chemin/ou/aller - * find ou/lancer/ma/recherche - */ - protected $_inlineArgCmds = array( - 'cdautocomplete' => array(0 => array('enable', 'en', 'disable', 'dis')), - 'ls' => "#^\"?([a-z0-9\-_/~. ]+)\"?$#i", - 'll' => "#^\"?([a-z0-9\-_/~. ]+)\"?$#i", - 'cd' => "#^\"?([a-z0-9\-_/~. ]+)\"?$#i", - 'find' => array(0 => "#^\"?([a-z0-9\-_. /~]+)\"?$#i", 1 => array('location', 'cabinet', 'equipment'), 2 => "#^\"?([a-z0-9\-_.:* ]+)\"?$#i"), - 'list location' => "#^\"?([a-z0-9\-_. ]+)\"?$#i", - 'list cabinet' => array(0 => "#^\"?([a-z0-9\-_. ]+)\"?$#i", 1 => array('summary', 'full')), - 'list equipment' => "#^\"?([a-z0-9\-_. ]+)\"?$#i", - 'show location' => "#^\"?([a-z0-9\-_. ]+)\"?$#i", - 'show cabinet' => array(0 => "#^\"?([a-z0-9\-_. ]+)\"?$#i", 1 => array('summary', 'full')), - 'show equipment' => "#^\"?([a-z0-9\-_. ]+)\"?$#i", - ); - - /** - * Arguments commencant pas par - ou -- donc hors flow de la commande - * - * find ... -type [type] -name [name] - */ - protected $_outlineArgCmds = array( - ); - - protected $_manCommands = array( - 'history' => "Affiche l'historique des commandes", - 'cdautocomplete' => "Active (enable|en) ou désactive (disable|dis) l'autocompletion de la commande cd", - 'ls' => "Affiche la liste des éléments disponibles", - 'll' => "Alias de ls", - 'cd' => "Permet de naviguer dans l'arborescence", - 'pwd' => "Affiche la position actuelle dans l'arborescence", - 'find' => "Recherche avancée d'éléments. Utilisation: find [localisation|.] [type] [recherche]", - 'exit' => "Ferme le shell", - 'quit' => "Alias de exit", - 'list' => "Affiche un type d'éléments; Dépend de la localisation actuelle. Utilisation: list [location|cabinet|equipment] [object]", - 'list location' => "Affiche les informations d'une localisation; Dépend de la localisation", - 'list cabinet' => "Affiche les informations d'une baie; Dépend de la localisation", - 'list equipment' => "Affiche les informations d'un équipement; Dépend de la localisation", - 'show' => "Affiche un type d'éléments; Ne dépend pas de la localisation actuelle. Utilisation: show [location|cabinet|equipment] [object]", - 'show location' => "Affiche les informations d'une localisation", - 'show cabinet' => "Affiche les informations d'une baie", - 'show equipment' => "Affiche les informations d'un équipement", - /*'show system' => "Affiche les informations d'un équipement", - 'show server' => "Alias de show system", - 'show sys' => "Alias de show system", - 'show network' => "Affiche les informations d'un équipement", - 'show appliance' => "Alias de show network", - 'show net' => "Alias de show network",*/ - 'patchmanager' => "Lance la GUI de PatchManager", - ); - - // /!\ Ne pas activer par défaut afin d'accélerer la navigation - protected $_cdautocomplete = false; - - - public function __construct($configFilename, $server, $autoInitialisation = true) - { - parent::__construct($configFilename); - - $printInfoMessages = !$this->isOneShotCall(); - - $DCIM = new DCIM(array($server), $printInfoMessages); - $this->_DCIM = $DCIM->getDcim(); - Dcim_Api_Abstract::setDcim($this->_DCIM); - - $this->_Service_Shell = new Service_Shell_Dcim($this, $this->_SHELL); - - if($autoInitialisation) { - $this->_init(); - } - } - - protected function _launchShell() - { - $exit = false; - - while(!$exit) - { - list($cmd, $args) = $this->_SHELL->launch(); - - $this->_preRoutingShellCmd($cmd, $args); - $exit = $this->_routeShellCmd($cmd, $args); - $this->_postRoutingShellCmd($cmd, $args); - } - } - - protected function _routeShellCmd($cmd, array $args) - { - $exit = false; - - switch($cmd) - { - case 'find': { - $status = $this->_Service_Shell->printSearchObjects($args); - break; - } - case 'list location': { - $status = $this->_Service_Shell->printLocationInfos($args, true); - break; - } - case 'list cabinet': { - $status = $this->_Service_Shell->printCabinetInfos($args, true); - break; - } - case 'list equipment': { - $status = $this->_Service_Shell->printEquipmentInfos($args, true); - break; - } - case 'show location': { - $status = $this->_Service_Shell->printLocationInfos($args, false); - break; - } - case 'show cabinet': { - $status = $this->_Service_Shell->printCabinetInfos($args, false); - break; - } - case 'show equipment': { - $status = $this->_Service_Shell->printEquipmentInfos($args, false); - break; - } - case 'patchmanager': - { - $jnlp = __DIR__ . "/../patchmanager.jnlp"; - - if(!file_exists($jnlp)) - { - $jnlpUrl = $this->_DCIM->getJnlpUrl(64); - $status = file_put_contents($jnlp, fopen($jnlpUrl, 'r')); - - if($status === false) { - $this->error("Impossible de télécharger le JNLP [".$jnlpUrl."]", 'red'); - break; - } - } - - $this->deleteWaitingMsg(); - $handle = popen('javaws "'.$jnlp.'" > /dev/null 2>&1', 'r'); - pclose($handle); - break; - } - default: { - $exit = parent::_routeShellCmd($cmd, $args); - } - } - - if(isset($status)) - { - $this->_lastCmdStatus = $status; - - if(!$status && !$this->_isOneShotCall) - { - if(array_key_exists($cmd, $this->_manCommands)) { - $this->error($this->_manCommands[$cmd], 'red'); - } - else { - $this->error("Une erreur s'est produit lors de l'exécution de cette commande", 'red'); - } - } - } - - return $exit; - } - - protected function _setObjectAutocomplete(array $fields = null) - { - if($fields === null) { - $fields = array('location', 'cabinet', 'equipment'); - } - return parent::_setObjectAutocomplete($fields); - } - - protected function _moveToRoot() - { - if($this->_pathIds === null || $this->_pathApi === null) { - $this->_pathIds[] = null; - $this->_pathApi[] = new Dcim_Api_Location(); - } - - return parent::_moveToRoot(); - } - - public function browser(array &$pathIds, array &$pathApi, $path) - { - if(Tools::is('string', $path)) { - $path = explode('/', $path); - } - - foreach($path as $index => $part) - { - switch($part) - { - case '': - case '~': - { - if($index === 0) { - array_splice($pathIds, 1); - array_splice($pathApi, 1); - } - break; - } - case '.': { - break; - } - case '..': - { - if(count($pathApi) > 1) { - array_pop($pathIds); - array_pop($pathApi); - } - break; - } - default: - { - $objectApi = end($pathApi); - $objectApiClass = get_class($objectApi); - - $cases = array( - 'Dcim_Api_Location' => array( - 'Dcim_Api_Location' => 'getSubLocationId', - 'Dcim_Api_Cabinet' => 'getCabinetId', - ), - 'Dcim_Api_Cabinet' => array( - 'Dcim_Api_Equipment' => 'getEquipmentId', - ), - ); - - if(array_key_exists($objectApiClass, $cases)) - { - foreach($cases[$objectApiClass] as $objectClass => $objectMethod) - { - $objectId = $objectApi->{$objectMethod}($part); - - if($objectId !== false) { - $pathIds[] = $objectId; - $pathApi[] = new $objectClass($objectId); - break; - } - } - } - } - } - } - } - } \ No newline at end of file diff --git a/services/shell/abstract.php b/services/shell/abstract.php deleted file mode 100644 index 717a502..0000000 --- a/services/shell/abstract.php +++ /dev/null @@ -1,167 +0,0 @@ -_MAIN = $MAIN; - $this->_SHELL = $SHELL; - $this->_CONFIG = CONFIG::getInstance(); - } - - // @todo optimiser garder en cache en fonction de context - abstract protected function _getObjects($context = null); - - /** - * Affiche les informations d'un seul type d'éléments ou d'objets - * Le code doit pouvoir fonctionner sur un tableau simple ou sur un tableau d'objets - */ - protected function _printInformations($type, $items, $title = false) - { - if($items !== false && Tools::is('array&&count>0', $items)) - { - $results = array(); - - if($title === false) - { - if(array_key_exists($type, $this->_PRINT_TITLES)) { - $title = $this->_PRINT_TITLES[$type]; - } - else { - $title = 'INFORMATIONS'; - } - } - - $this->_MAIN->EOL()->print($title, 'black', 'white', 'bold'); - - /** - * /!\ item peut être un objet donc il faut que le code qui le concerne puisse fonctionner sur un objet - * Par exemple: array_key_exists ne peut pas fonctionner, mais isset oui grâce à __isset - */ - foreach($items as $index => $item) - { - /** - * Il faut réinitialiser $infos pour chaque item - * Permet aussi de garder l'ordre de _PRINT_FIELDS - */ - $infos = array(); - - foreach($this->_PRINT_FIELDS[$type] as $key => $format) - { - // /!\ Code compatible array et object ! - if((is_array($item) && array_key_exists($key, $item)) || isset($item[$key])) - { - $field = $item[$key]; - $field = vsprintf($format, $field); - - switch($key) - { - case 'header': - $field = $this->_MAIN->format($field, 'green', false, 'bold'); - break; - } - - $infos[] = $field; - } - } - - if(count($infos) > 0) { - $results[] = $infos; - $this->_MAIN->EOL()->print(implode(PHP_EOL, $infos), 'grey'); - } - } - - $this->_MAIN->EOL(); - $this->_MAIN->setLastCmdResult($results); - return true; - } - else { - $this->_MAIN->error("Aucun élément à afficher", 'orange'); - } - - return false; - } - - abstract public function printObjectInfos(array $args, $fromCurrentContext = true); - - /** - * Récupère les informations d'un seul type d'éléments ou d'objets puis les affiche - * Le code doit pouvoir fonctionner sur un tableau simple ou sur un tableau d'objets - */ - protected function _printObjectInfos(array $cases, array $args, $fromCurrentContext = true) - { - if(isset($args[0])) - { - foreach($cases as $type => $method) - { - $objects = $this->{$method}($args[0], $fromCurrentContext); - - if(count($objects) > 0) { - $objectType = $type; - break; - } - } - - if(isset($objectType)) { - $status = $this->_printInformations($objectType, $objects); - return array($status, $objectType, $objects); - } - } - - $this->_MAIN->deleteWaitingMsg(); // Garanti la suppression du message - return false; - } - - /** - * Récupère les informations de tous les éléments ou objets puis les affiche - */ - public function printObjectsList($context = null) - { - $this->_MAIN->displayWaitingMsg(); - $objects = $this->_getObjects($context); - return $this->_printObjectsList($objects); - } - - /** - * Affiche les informations de plusieurs types d'éléments ou d'objets - * Le code doit pouvoir fonctionner sur un tableau simple ou sur un tableau d'objets - */ - protected function _printObjectsList(array $objects) - { - foreach($objects as $type => &$items) - { - if(count($items) > 0) - { - $this->_MAIN->EOL()->print($this->_LIST_TITLES[$type], 'black', 'white', 'bold'); - - $items = Tools::arrayFilter($items, $this->_LIST_FIELDS[$type]['fields']); - - foreach($items as &$item) - { - /** - * /!\ L'ordre de base dans item est conservé ce qui rend le résultat incertain - * Préférer l'utilisation de la méthode Tools::arrayFilter qui filtre et garanti l'ordre - */ - //$item = array_intersect_key($item, array_flip($this->_LIST_FIELDS[$type]['fields'])); - - $item = vsprintf($this->_LIST_FIELDS[$type]['format'], $item); - - $item = preg_replace_callback("#([^\t]*)(\t+)#i", function(array $matches) { - return $matches[1].Tools::t($matches[1], "\t", mb_strlen($matches[2]), 0, 8); - } - , $item); - } - - $this->_MAIN->EOL()->print(implode(PHP_EOL, $items), 'grey'); - $this->_MAIN->EOL(); - } - } - - $this->_MAIN->deleteWaitingMsg(); // Garanti la suppression du message - return $objects; - } - } \ No newline at end of file diff --git a/services/shell/browser.php b/services/shell/browser.php deleted file mode 100644 index 429e64f..0000000 --- a/services/shell/browser.php +++ /dev/null @@ -1,66 +0,0 @@ -_pathIds = $pathIds; - $this->_pathApi = $pathApi; - return $this; - } - - protected function _browser($path = null, $returnCurrentApi = true) - { - $pathIds = $this->_pathIds; - $pathApi = $this->_pathApi; - - if($path !== null) { - // /!\ browser modifie pathIds et pathApi, passage par référence - $this->_MAIN->browser($pathIds, $pathApi, $path); - } - - return ($returnCurrentApi) ? (end($pathApi)) : ($pathApi); - } - - public function getOptions($path = null) - { - $options = array(); - $objects = $this->_getObjects($path); - - foreach($objects as $type => $list) - { - if(count($list) > 0) - { - foreach($list as $fields) - { - if(array_key_exists($type, $this->_OPTION_FIELDS)) { - $optFields = array_flip($this->_OPTION_FIELDS[$type]['fields']); - $option = array_intersect_key($fields, $optFields); - $options = array_merge($options, array_values($option)); - } - } - } - } - - return $options; - } - - protected function _getLastApiPath(array $pathApi, $apiClassName) - { - $pathApi = array_reverse($pathApi); - - foreach($pathApi as $api) - { - if(get_class($api) === $apiClassName) { - return $api; - } - } - - return false; - } - } \ No newline at end of file diff --git a/services/shell/dcim.php b/services/shell/dcim.php deleted file mode 100644 index fbea2cd..0000000 --- a/services/shell/dcim.php +++ /dev/null @@ -1,580 +0,0 @@ - array( - 'fields' => array('name'), - ), - 'cabinet' => array( - 'fields' => array('name'), - ), - 'equipment' => array( - 'fields' => array('name'), - ) - ); - - protected $_LIST_TITLES = array( - 'location' => 'LOCATIONS', - 'cabinet' => 'CABINETS', - 'equipment' => 'EQUIPMENTS', - 'cable' => 'CABLES', - ); - - protected $_LIST_FIELDS = array( - 'location' => array( - 'fields' => array('name'), - 'format' => '%s' - ), - 'cabinet' => array( - 'fields' => array('name'), - 'format' => '%s' - ), - 'equipment' => array( - 'fields' => array('name', 'side', 'positionU', 'serialNumber'), - 'format' => '[%2$s] (U%3$d) %1$s {%4$s}' - ), - 'cable' => array( - 'fields' => array('port', 'name', 'nbPort', 'nbName'), - 'format' => '[%s] <-- %s --> [%s] {%s}' - ) - ); - - protected $_PRINT_TITLES = array( - 'location' => 'LOCATIONS', - 'cabinet' => 'CABINETS', - 'equipment' => 'EQUIPMENTS', - 'cable' => 'CABLES', - ); - - protected $_PRINT_FIELDS = array( - 'location' => array( - 'header' => '%s', - 'name' => PHP_EOL.'Nom: %s', - 'path' => 'Emplacement: %s', - ), - 'cabinet' => array( - 'header' => '%s', - 'name' => PHP_EOL.'Nom: %s', - 'path' => 'Emplacement: %s', - ), - 'equipment' => array( - 'header' => '%s', - 'templateName' => PHP_EOL.'Template: %s', - 'name' => 'Nom: %s', - 'description' => 'Description: %s', - 'serialNumber' => 'N° série: %s', - 'locationName' => 'Localisation: %s', - 'cabinetName' => 'Baie: %s', - 'position' => 'Position: %s / U%d', - 'path' => 'Emplacement: %s', - ), - ); - - protected $_searchfromCurrentPath = true; - - - protected function _getObjects($context = null) - { - $path = $context; - - $items = array( - 'Dcim_Api_Location' => array(), - 'Dcim_Api_Cabinet' => array(), - 'Dcim_Api_Equipment' => array(), - 'Dcim_Api_Cable' => array(), - ); - - $currentApi = $this->_browser($path); - - $cases = array( - 'Dcim_Api_Location' => array( - 'Dcim_Api_Location' => 'getSubLocationIds', - 'Dcim_Api_Cabinet' => 'getCabinetIds', - ), - 'Dcim_Api_Cabinet' => array(false), - 'Dcim_Api_Equipment' => array(false), - ); - - foreach($cases[get_class($currentApi)] as $objectClass => $objectMethod) - { - if($objectMethod !== false) { - $objects = $currentApi->{$objectMethod}(); - } - else { - $objects = false; - } - - if($objects !== false && count($objects) > 0) - { - foreach($objects as $object) - { - switch($objectClass) - { - case 'Dcim_Api_Location': { - $Dcim_Api_Location = new Dcim_Api_Location($object); - $objectName = $Dcim_Api_Location->getLocationLabel(); - break; - } - case 'Dcim_Api_Cabinet': { - $Dcim_Api_Cabinet = new Dcim_Api_Cabinet($object); - $objectName = $Dcim_Api_Cabinet->getCabinetLabel(); - break; - } - } - - $items[$objectClass][] = array('name' => $objectName); - } - } - elseif($currentApi instanceof Dcim_Api_Cabinet) - { - $equipments = $currentApi->getEquipmentIds(); - - if($equipments !== false) - { - foreach($equipments as $equipment) - { - $Dcim_Api_Equipment = new Dcim_Api_Equipment($equipment); - - $objectName = $Dcim_Api_Equipment->getLabel(); - $position = $Dcim_Api_Equipment->getPosition(); - $serialNumber = $Dcim_Api_Equipment->getSerialNumber(); - - $items['Dcim_Api_Equipment'][] = array( - 'name' => $objectName, - 'side' => $position['side'], - 'positionU' => $position['U'], - 'serialNumber' => $serialNumber, - ); - } - } - } - elseif($currentApi instanceof Dcim_Api_Equipment) - { - $ports = $currentApi->getConnectedPortIds(); - - if($ports !== false) - { - foreach($ports as $port => $nbPort) - { - $portApi = new Dcim_Api_Equipment_Port($port); - $nbPortApi = new Dcim_Api_Equipment_Port($nbPort); - - $items['Dcim_Api_Cable'][] = array( - 'port' => $portApi->getLabel(), - 'name' => $portApi->cableApi->getLabel(), - 'nbPort' => $nbPortApi->getLabel(), - 'nbName' => $nbPortApi->equipmentApi->getLabel(), - ); - } - } - } - } - - /** - * /!\ index 0 doit toujours être le nom de l'objet ou l'identifiant (VlanID, IP) - */ - $compare = function($a, $b) { - return strnatcasecmp(current($a), current($b)); - }; - - usort($items['Dcim_Api_Location'], $compare); - usort($items['Dcim_Api_Cabinet'], $compare); - usort($items['Dcim_Api_Cable'], $compare); - - $compare = function($a, $b) - { - if($a['side'] !== $b['side']) { - return (mb_strtolower($a['side']) === 'front') ? (-1) : (1); - } - elseif($a['positionU'] !== $b['positionU']) { - return ($a['positionU'] < $b['positionU']) ? (1) : (-1); // On souhaite avoir les U en haut en 1er - } - else { - return strnatcasecmp($a['name'], $b['name']); - } - }; - - usort($items['Dcim_Api_Equipment'], $compare); - - return array( - 'location' => $items['Dcim_Api_Location'], - 'cabinet' => $items['Dcim_Api_Cabinet'], - 'equipment' => $items['Dcim_Api_Equipment'], - 'cable' => $items['Dcim_Api_Cable'] - ); - } - - public function printObjectInfos(array $args, $fromCurrentContext = true) - { - // /!\ ls AUB --> On ne doit pas afficher AUB mais le contenu de AUB ! - /*$objectApi = end($this->_pathApi); - - switch(get_class($objectApi)) - { - case 'Dcim_Api_Location': - $cases = array( - 'location' => '_getLocationInfos', - 'cabinet' => '_getCabinetInfos', - 'equipment' => '_getEquipmentInfos', // Des équipements pourraient être directement dans une location - ); - break; - case 'Dcim_Api_Cabinet': - $cases = array( - 'equipment' => '_getEquipmentInfos' - ); - break; - default: - $cases = array(); - }*/ - - $cases = array( - 'equipment' => '_getEquipmentInfos' - ); - - $result = $this->_printObjectInfos($cases, $args, $fromCurrentContext); - - if($result !== false) - { - list($status, $objectType, $infos) = $result; - - /** - * /!\ Attention aux doublons lorsque printObjectsList est appelé manuellement - * Voir code pour ls ou ll dans services/browser méthode _routeShellCmd - */ - /*if($status && $objectType === 'equipment') { - $this->printEquipmentExtra($infos); - }*/ - - return $status; - } - else { - return false; - } - } - - public function printLocationInfos(array $args, $fromCurrentPath = true, $recursion = false) - { - if(isset($args[0])) - { - $infos = $this->_getLocationInfos($args[0], $fromCurrentPath, null, $recursion); - $status = $this->_printInformations('location', $infos); - - if($status === false) { - $this->_MAIN->error("Localisation introuvable", 'orange'); - } - - return true; - } - - return false; - } - - public function printCabinetInfos(array $args, $fromCurrentPath = true, $recursion = false) - { - if(isset($args[0])) - { - $infos = $this->_getCabinetInfos($args[0], $fromCurrentPath, null, $recursion); - $status = $this->_printInformations('cabinet', $infos); - - if($status === false) { - $this->_MAIN->error("Baie introuvable", 'orange'); - } - elseif(count($infos) === 1) - { - $full = false; - - if(isset($args[1])) - { - switch(mb_strtolower($args[1])) - { - case 'full': - $full = true; - break; - } - } - - // @todo $full affiche tous les U de la baie - $path = $infos[0]['path'].'/'.$infos[0]['name']; - $this->printObjectsList($path); - } - - return true; - } - - return false; - } - - public function printEquipmentInfos(array $args, $fromCurrentPath = true, $recursion = false) - { - if(isset($args[0])) - { - $infos = $this->_getEquipmentInfos($args[0], $fromCurrentPath, null, $recursion); - $status = $this->_printInformations('equipment', $infos); - - if($status === false) { - $this->_MAIN->error("Equipement introuvable", 'orange'); - } - else { - $this->printEquipmentExtra($infos); - } - - return true; - } - - return false; - } - - protected function printEquipmentExtra(array $infos) - { - if(count($infos) === 1) { - $path = $infos[0]['path'].'/'.$infos[0]['name']; - $this->printObjectsList($path); - } - } - - protected function _getLocationInfos($location, $fromCurrentPath = true, $path = null, $recursion = false) - { - $items = array(); - $locations = array(); - - if($fromCurrentPath) - { - $pathApi = $this->_browser($path, false); - $currentApi = $this->_getLastLocationPath($pathApi); - - if($currentApi instanceof Dcim_Api_Location) { - $locationId = $currentApi->getLocationId(); - $locations = Dcim_Api_Location::searchLocations($location, $locationId, $recursion); - } - } - else { - $locations = Dcim_Api_Location::searchLocations($location); - } - - - foreach($locations as $location) - { - //$Dcim_Api_Location = new Dcim_Api_Location($location['entity_id']); - - $item = array(); - $item['header'] = $location['name']; - $item['name'] = $location['name']; - $item['path'] = '/'.str_replace(',', '/', $location['path']); - $items[] = $item; - } - - return $items; - } - - protected function _getCabinetInfos($cabinet, $fromCurrentPath = true, $path = null, $recursion = false) - { - $items = array(); - $cabinets = array(); - - if($fromCurrentPath) - { - $pathApi = $this->_browser($path, false); - $currentApi = $this->_getLastLocationPath($pathApi); - - if($currentApi instanceof Dcim_Api_Location) { - $locationId = $currentApi->getLocationId(); - $cabinets = Dcim_Api_Cabinet::searchCabinets($cabinet, $locationId, $recursion); - } - } - else { - $cabinets = Dcim_Api_Cabinet::searchCabinets($cabinet); - } - - - foreach($cabinets as $cabinet) - { - //$Dcim_Api_Cabinet = new Dcim_Api_Cabinet($cabinet['entity_id']); - - $item = array(); - $item['header'] = $cabinet['name']; - $item['name'] = $cabinet['name']; - $item['path'] = '/'.str_replace(',', '/', $cabinet['path']); - $items[] = $item; - } - - return $items; - } - - protected function _getEquipmentInfos($equipment, $fromCurrentPath = true, $path = null, $recursion = false) - { - $items = array(); - $equipments = array(); - - if($fromCurrentPath) - { - $currentApi = $this->_browser($path); - - if($currentApi instanceof Dcim_Api_Cabinet) { - $cabinetId = $currentApi->getCabinetId(); - $equipments = Dcim_Api_Equipment::searchEquipments($equipment, $equipment, $equipment, $cabinetId, null); - } - elseif($currentApi instanceof Dcim_Api_Location) { - $locationId = $currentApi->getLocationId(); - $equipments = Dcim_Api_Equipment::searchEquipments($equipment, $equipment, $equipment, null, $locationId, $recursion); - } - } - else { - $equipments = Dcim_Api_Equipment::searchEquipments($equipment, $equipment, $equipment); - } - - foreach($equipments as $equipment) - { - $Dcim_Api_Equipment = new Dcim_Api_Equipment($equipment['entity_id']); - - $item = array(); - $item['header'] = $Dcim_Api_Equipment->getLabel(); - $item['templateName'] = $Dcim_Api_Equipment->getTemplateName(); - $item['name'] = $Dcim_Api_Equipment->getLabel(); - //$item['description'] = $Dcim_Api_Equipment->getUserAttr(null, 'description'); - $item['serialNumber'] = $Dcim_Api_Equipment->getUserAttr('default', 'serialNumber'); - $item['locationName'] = $Dcim_Api_Equipment->locationApi->getLabel(); - $item['cabinetName'] = $Dcim_Api_Equipment->cabinetApi->getLabel(); - $item['path'] = '/'.str_replace(',', '/', $Dcim_Api_Equipment->getPath()); - - $position = $Dcim_Api_Equipment->getPosition(); - $item['position'] = array($position['side'], $position['U']); - - $items[] = $item; - } - - return $items; - } - - public function printSearchObjects(array $args) - { - if(count($args) === 3) - { - $time1 = microtime(true); - $objects = $this->_searchObjects($args[0], $args[1], $args[2]); - $time2 = microtime(true); - - if($objects !== false) - { - $this->_MAIN->setLastCmdResult($objects); - $this->_MAIN->print('RECHERCHE ('.round($time2-$time1).'s)', 'black', 'white', 'bold'); - - if(!$this->_MAIN->isOneShotCall()) - { - if(isset($objects['locations'])) - { - $counter = count($objects['locations']); - $this->_MAIN->EOL()->print('LOCATIONS ('.$counter.')', 'black', 'white'); - - if($counter > 0) - { - foreach($objects['locations'] as $location) - { - $text1 = '['.$location['path'].']'; - $text1 .= Tools::t($text1, "\t", 2, 0, 8); - $text2 = $location['header']; - $this->_MAIN->print($text1.$text2, 'grey'); - } - } - else { - $this->_MAIN->error('Aucun résultat', 'orange'); - } - } - - if(isset($objects['cabinets'])) - { - $counter = count($objects['cabinets']); - $this->_MAIN->EOL()->print('CABINETS ('.$counter.')', 'black', 'white'); - - if($counter > 0) - { - foreach($objects['cabinets'] as $cabinet) - { - $text1 = '['.$cabinet['path'].']'; - $text1 .= Tools::t($text1, "\t", 2, 0, 8); - $text2 = $cabinet['header']; - $this->_MAIN->print($text1.$text2, 'grey'); - } - } - else { - $this->_MAIN->error('Aucun résultat', 'orange'); - } - } - - if(isset($objects['equipments'])) - { - $counter = count($objects['equipments']); - $this->_MAIN->EOL()->print('EQUIPMENTS ('.$counter.')', 'black', 'white'); - - if($counter > 0) - { - foreach($objects['equipments'] as $equipment) - { - $text1 = '['.$equipment['path'].']'; - $text1 .= Tools::t($text1, "\t", 7, 0, 8); - $text2 = $equipment['templateName']; - $text2 .= Tools::t($text2, "\t", 4, 0, 8); - $text3 = $equipment['header'].' {'.$equipment['serialNumber'].'}'; - $this->_MAIN->print($text1.$text2.$text3, 'grey'); - } - } - else { - $this->_MAIN->error('Aucun résultat', 'orange'); - } - } - - $this->_MAIN->EOL(); - } - } - else { - $this->_MAIN->error("Aucun résultat trouvé", 'orange'); - } - - return true; - } - - return false; - } - - protected function _searchObjects($path, $objectType, $objectSearch) - { - switch($objectType) - { - case 'location': - { - $locations = $this->_getLocationInfos($objectSearch, $this->_searchfromCurrentPath, $path, true); - return array('locations' => $locations); - break; - } - case 'cabinet': - { - $cabinets = $this->_getCabinetInfos($objectSearch, $this->_searchfromCurrentPath, $path, true); - return array('cabinets' => $cabinets); - break; - } - case 'equipment': - { - $equipments = $this->_getEquipmentInfos($objectSearch, $this->_searchfromCurrentPath, $path, true); - return array('equipments' => $equipments); - break; - } - case 'all': - { - $locations = $this->_searchObjects($path, 'location', $objectSearch); - $cabinets = $this->_searchObjects($path, 'cabinet', $objectSearch); - $equipments = $this->_searchObjects($path, 'equipment', $objectSearch); - return array_merge($locations, $cabinets, $equipments); - break; - } - default: { - throw new Exception("Search item '".$objectType."' is unknow", E_USER_ERROR); - } - } - } - - protected function _getLastLocationPath(array $pathApi) - { - return $this->_getLastApiPath($pathApi, 'Dcim_Api_Location'); - } - } \ No newline at end of file