Example #1
0
 public function buildQueryUrl($queryObj, $array)
 {
     $region = RSArgParser::getRegionAccount();
     $queryUrl = RS_BASE_APIURL . "/clouds/{$region}/instances";
     $queryUrl .= "?filter[]=parent_href==/api/server_arrays/{$array}";
     $queryObj->setQueryUrl($queryUrl);
 }
Example #2
0
 public function execute($response)
 {
     $jsonObj = json_decode($response);
     $results = array();
     $datacenter = RSArgParser::getRegion();
     foreach ($jsonObj as $tmpObj) {
         if ($tmpObj->state != RSArgParser::getState()) {
             continue;
         }
         if (isset($tmpObj->current_instance)) {
             /* Deployment Lookup */
             $tmpArray = array();
             $tmpArray['host_name'] = RSHelperFuncs::buildCloudHostname($tmpObj->name, $datacenter);
             if (count($tmpObj->current_instance->public_ip_addresses) > 0) {
                 $tmpArray['address'] = $tmpObj->current_instance->public_ip_addresses[0];
             } else {
                 $tmpArray['address'] = $tmpObj->current_instance->private_ip_addresses[0];
             }
             $tmpArray['action_url'] = RSHelperFuncs::buildCloudHostUrl($tmpObj->links);
         } else {
             /* Server Array Lookup */
             $tmpArray['host_name'] = RSHelperFuncs::buildCloudHostname($tmpObj->name, $datacenter);
             if (count($tmpObj->public_ip_addresses) > 0) {
                 $tmpArray['address'] = $tmpObj->public_ip_addresses[0];
             } else {
                 $tmpArray['address'] = $tmpObj->private_ip_addresses[0];
             }
             $tmpArray['action_url'] = RSHelperFuncs::buildCloudHostUrl($tmpObj->links);
         }
         $results[] = $tmpArray;
     }
     return $results;
 }
 /**
  * execute 
  *      Main wrapper command for executing rightscale fetches
  *
  * @param mixed $className 
  * @static
  * @access public
  * @return void
  */
 public static function execute($className, $forceRelogin = false)
 {
     if (!preg_match(self::CLASSNAME_REGEX, $className)) {
         $className = RS_LOC_PREFIX . $className;
     }
     if (!class_exists($className)) {
         throw new RSQueryWrapperException($className . self::MISSING_CLASS);
     } else {
         if ($className == RS_LOC_PREFIX) {
             throw new RSQueryWrapperException(self::COLLISION . RS_LOC_PREFIX);
         }
     }
     $result = null;
     $queryObj = new RSQueryObj();
     $rootClass = new $className($queryObj);
     if ($className == 'RSMultiAD') {
         $rs = new RS(NULL);
         RSDataGrouperCache::init();
         foreach ($queryObj->getArrayLoop() as $loop) {
             $rootClass->buildQueryUrl('array', $queryObj, $loop);
             $rs->addObserver($queryObj);
             RSLoginWrapper::login($rs);
             $rs->fetch($queryObj);
         }
         foreach ($queryObj->getDeploymentLoop() as $loop) {
             $rootClass->buildQueryUrl('deployment', $queryObj, $loop);
             $rs->addObserver($queryObj);
             RSLoginWrapper::login($rs);
             $rs->fetch($queryObj);
         }
         $cache = RSDataGrouperCache::getCache(true);
         if (!!($executor = RSArgParser::getExecutor())) {
             $executorObj = new $executor();
             $result = $executorObj->execute($cache);
         }
     } else {
         $rs = new RS(NULL);
         RSDataGrouperCache::init();
         foreach ($queryObj->getLoop() as $loop) {
             $rootClass->buildQueryUrl($queryObj, $loop);
             $rs->addObserver($queryObj);
             RSLoginWrapper::login($rs, $forceRelogin);
             $rs->fetch($queryObj);
         }
         $cache = RSDataGrouperCache::getCache(true);
         if (!!($executor = RSArgParser::getExecutor())) {
             $executorObj = new $executor();
             $result = $executorObj->execute($cache);
         }
     }
     return $result;
 }
Example #4
0
 public function buildQueryUrl($mode, $queryObj, $data)
 {
     if ($mode == 'array') {
         $region = RSArgParser::getRegionAccount();
         $queryUrl = RS_BASE_APIURL . "/clouds/{$region}/instances";
         $queryUrl .= "?filter[]=parent_href==/api/server_arrays/{$data}";
         $queryObj->setQueryUrl($queryUrl);
     } elseif ($mode == 'deployment') {
         $queryUrl = RS_BASE_APIURL . "/deployments/{$data}/servers";
         $queryUrl .= "?view=instance_detail";
         $queryObj->setQueryUrl($queryUrl);
     }
 }
Example #5
0
 public function getSearchResults($input)
 {
     $results = array();
     if (preg_match("/^RS-(\\w+)-(\\w+)/", $input->location, $matches)) {
         if ($matches[2] == 'deployment') {
             $inputArray = array('exec' => 'rsnagios', 'region' => $matches[1], 'deployment' => $input->srchparam);
         } elseif ($matches[2] == 'serverarray') {
             $inputArray = array('exec' => 'rsnagios', 'region' => $matches[1], 'array' => $input->srchparam);
         } else {
             return $results;
         }
         RSArgParser::setRSArgs($inputArray);
         $output = RSQueryWrapper::execute(RSArgParser::getQueryLocation(), true);
         foreach ($output as $idx => $hostData) {
             if (empty($hostData) || !isset($hostData['host_name']) || !isset($hostData['address'])) {
                 continue;
             }
             $host = $hostData['host_name'];
             $results[$host] = $hostData;
         }
     }
     return $results;
 }
Example #6
0
 /**
  * setRSArgs 
  *      function that actually sets all of the key => value pairs in the globalArgs array
  *
  * @param array $argArray 
  * @static
  * @access public
  * @return void
  */
 public static function setRSArgs(array $argArray)
 {
     self::$m_globalArgs = array();
     /* Nullify incase of existance and processing a new request */
     foreach ($argArray as $key => $value) {
         if (isset(self::$m_globalArgs[$key]) && !is_array(self::$m_globalArgs[$key])) {
             $results = array();
             array_push($results, self::$m_globalArgs[$key]);
             array_push($results, $value);
             self::$m_globalArgs[$key] = $results;
         } elseif (isset(self::$m_globalArgs[$key]) && is_array(self::$m_globalArgs[$key])) {
             array_push(self::$m_globalArgs[$key], $value);
         } else {
             self::$m_globalArgs[$key] = $value;
         }
     }
     self::buildRegions();
 }
 /**
  * getPostData 
  * 
  * @access public
  * @return void
  */
 public function getPostData()
 {
     $results = self::$m_postData;
     $results['refresh_token'] = RSArgParser::getRegionToken();
     return $results;
 }