Skip to content

Adding sample code for creating a server and retrieving its IP address. #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2014

Conversation

ycombinator
Copy link
Contributor

Adding a code sample showing how to create a server, wait for it to become ACTIVE and then retrieve its IP address, per @maxlinc's request.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 2a693b3 on ycombinator:compute-samples into c9ace7c on rackspace:working.

ycombinator added a commit that referenced this pull request Oct 14, 2014
Adding sample code for creating a server and retrieving its IP address.
@ycombinator ycombinator merged commit c929695 into rackspace:working Oct 14, 2014
@ycombinator ycombinator deleted the compute-samples branch October 14, 2014 18:18
@gecampbell
Copy link
Contributor

There should be a helper function you can use to retrieve either the V4 or V6 IP address. ->ip(x) where x is either 4 or 6 (I think it defaults to 4). Possibly better than hitting the property directly, especially if Neutron is installed.

use Guzzle\Http\Exception\BadResponseException;

// 1. Instantiate a Rackspace client.
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, but what would be super-awesome for me is if examples are endpoint agnostic. That makes the sample portable - US/UK, staging environments, or with test servers like Pacto or Mimic.

My preferred way is to support the standard OpenStack variables used by OpenStack CLI tools and other programs. This little trick works:

// 1. Instantiate a Rackspace client.
$endpoint = getenv('OS_AUTH_URL') ? getenv('OS_AUTH_URL') : Rackspace::US_IDENTITY_ENDPOINT;
$client = new Rackspace($endpoint, array(
    'username' => getenv('RAX_USERNAME'),
    'apiKey'   => getenv('RAX_API_KEY')
));

It'd be great to use that in all samples - that small addition is all I need to automate testing of samples. Feel free to clean it up if there's a more readable option than the ternary operator... I was disappointed you can't pass a default value to getenv(...).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxlinc Our newer samples are now endpoint-agnostic. See any of the samples in https://github.com/ycombinator/php-opencloud/tree/orchestration/samples/Orchestration (part of PR #390). We just need to go back through older samples and update them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants