Created
May 31, 2011 02:55
Revisions
-
zircote revised this gist
Oct 2, 2011 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,9 +22,9 @@ * require_once 'Zircote/Service/Ec2/Metadata.php'; * $metadata = new Zircote_Service_Ec2_Metadata; * try{ * file_put_contents('php://stdout',$metadata->__get($_SERVER['argv'][1])); * } catch (Exception $e){ * file_put_contents('php://stderr', $e->getMessage()); * exit(0); * } * </code> @@ -60,7 +60,8 @@ public function __get($name) if(!array_key_exists($name, $this->_methods)){ throw new Exception(sprintf('method [%s] does not exist', $name)); } self::getHttpClient()->setUri($this->_endpoint) ->getUri()->setPath($this->_methods[$name]); $result = self::getHttpClient()->request(); if($result->getStatus() == 200){ return $result->getBody(); -
zircote revised this gist
Oct 2, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,7 +58,7 @@ class Zircote_Service_Ec2_Metadata extends Zend_Service_Abstract public function __get($name) { if(!array_key_exists($name, $this->_methods)){ throw new Exception(sprintf('method [%s] does not exist', $name)); } self::getHttpClient()->getUri()->setPath($this->_methods[$name]); $result = self::getHttpClient()->request(); -
zircote revised this gist
Oct 2, 2011 . 2 changed files with 34 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,36 @@ <?php require_once 'Zend/Service/Abstract.php'; /** * * * @author [email protected] * * <code> * <?php * $metadata = new Zircote_Service_Ec2_Metadata; * echo $metadata->amiID; * echo $metadata->hostname; * echo $metadata->instanceId * echo $metadata->kernelId * echo $metadata->userData; * echo $metadata->publicHostname; * </code> * <p>CLI example (but note curl -s would probably be more suitable)</p> * <code> * #!/usr/bin/env php * <?php * require_once 'Zircote/Service/Ec2/Metadata.php'; * $metadata = new Zircote_Service_Ec2_Metadata; * try{ * echo $metadata->__get($_SERVER['argv'][1]); * } catch (Exception $e){ * echo $e->getMessage(); * exit(0); * } * </code> */ class Zircote_Service_Ec2_Metadata extends Zend_Service_Abstract { protected $_endpoint = 'http://169.254.169.254'; protected $_methods = array( 'amiID' => '/latest/meta-data/ami-id', @@ -29,23 +54,18 @@ class Zircote_Service_Ec2 'securityGroups' => '/latest/meta-data/security-groups', 'userData' => '/latest/user-data', ); public function __get($name) { if(!array_key_exists($name, $this->_methods)){ throw new Exception(sprintf('value [%s] does not exist', $name)); } self::getHttpClient()->getUri()->setPath($this->_methods[$name]); $result = self::getHttpClient()->request(); if($result->getStatus() == 200){ return $result->getBody(); } else { return false; } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +0,0 @@ -
zircote renamed this gist
Oct 2, 2011 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
zircote revised this gist
Oct 2, 2011 . 2 changed files with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ <?php class Zircote_Service_Ec2 { /** * This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/usr/bin/env php <?php require_once 'Zircote/Service/Ec2.php'; $ec2 = new Zircote_Service_Ec2(); echo $ec2->__get($_SERVER['argv'][1]); -
zircote revised this gist
Oct 2, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ <?php class Service_Ec2 { /** * -
zircote revised this gist
May 31, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ #!/usr/bin/env php <?php require_once 'library/Jazsl/Service/Ec2.php'; $ec2 = new Jazsl_Service_Ec2(); -
zircote revised this gist
May 31, 2011 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ #!/bin/env php <?php require_once 'library/Jazsl/Service/Ec2.php'; $ec2 = new Jazsl_Service_Ec2(); echo $ec2->__get($_SERVER['argv'][1]); -
zircote created this gist
May 31, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ <?php class Jazsl_Service_Ec2 { /** * * @var Zend_Http_Client */ protected $_httpClient; protected $_endpoint = 'http://169.254.169.254'; protected $_methods = array( 'amiID' => '/latest/meta-data/ami-id', 'amiLaunchIndex' => '/latest/meta-data/ami-launch-index', 'amiManifestPath' => '/latest/meta-data/ami-manifest-path', 'ancestorAmiIds' => '/latest/meta-data/ancestor-ami-ids', 'blockDeviceMapping' => '/latest/meta-data/block-device-mapping/', 'hostname' => '/latest/meta-data/hostname', 'instanceAction' => '/latest/meta-data/instance-action', 'instanceId' => '/latest/meta-data/instance-id', 'instanceType' => '/latest/meta-data/instance-type', 'kernelId' => '/latest/meta-data/kernel-id', 'localHostname' => '/latest/meta-data/local-hostname', 'localIpv4' => '/latest/meta-data/local-ipv4', 'placement' => '/latest/meta-data/placement/', 'publicHostname' => '/latest/meta-data/public-hostname', 'publicIpv4' => '/latest/meta-data/public-ipv4', 'publicKeys' => '/latest/meta-data/public-keys/', 'ramdiskId' => '/latest/meta-data/ramdisk-id', 'reservationId' => '/latest/meta-data/reservation-id', 'securityGroups' => '/latest/meta-data/security-groups', 'userData' => '/latest/user-data', ); public function __construct () { require_once 'Zend/Http/Client.php'; $this->_httpClient = new Zend_Http_Client($this->_endpoint); } public function __get($name) { if(!array_key_exists($name, $this->_methods)){ throw new Exception(sprintf('value [%s] does not exist', $name)); } $this->_httpClient->getUri()->setPath($this->_methods[$name]); $result = $this->_httpClient->request(); if($result->getStatus() == 200){ return $result->getBody(); } else { return false; } } }