Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 58 lines (49 sloc) 2.032 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#!perl
use strict;
use warnings;
use Net::RackSpace::CloudServers;
use Net::RackSpace::CloudServers::Server;

my $user = $ENV{'CLOUDSERVERS_USER'} or die "Need CLOUDSERVERS_USER environment variable set";
my $key = $ENV{'CLOUDSERVERS_KEY'} or die "Need CLOUDSERVERS_KEY environment variable set";

my $CS = Net::RackSpace::CloudServers->new(
  user => $user,
  key => $key,
);
$Net::RackSpace::CloudServers::DEBUG = 0;
my @servers = $CS->get_server_detail;
if ( grep { $_->name eq 'perlmfapitest' } @servers ) {
  die "you already have a server named perlmfapitest, quitting\n";
}

my @flavors = $CS->get_flavor_detail;
my @images = $CS->get_image_detail;

## Provision a new server
$Net::RackSpace::CloudServers::DEBUG = 1;
my $srv;
{
  my $tmp = Net::RackSpace::CloudServers::Server->new(
    cloudservers => $CS,
    name => 'perlmfapitest',
    flavorid => ( grep { $_->ram == 256 } @flavors )[0]->id,
    imageid => ( grep { $_->name =~ /karmic/ } @images )[0]->id,
    personality => [ { path => '/root/test.txt', contents => 'dGVzdCAxMjMK' } ], # "test 123\n"
  );
  $srv = $tmp->create_server();
}

$Net::RackSpace::CloudServers::DEBUG = 0;
my $adminpass = $srv->adminpass; # will not be returned afterwards!
print "Created server ID ", $srv->id, ", root password is: ", $adminpass, "\n";
print "Available at public IP: @{$srv->public_address}\n";
{
  my @tmpservers = $CS->get_server_detail();
  $srv = ( grep { $_->name eq 'perlmfapitest' } @tmpservers )[0];

}

## unusable until ->status will be ACTIVE, from BUILD
do {
  print "Status: ", $srv->status // '?', " progress: ", $srv->progress // '?', "\n";
  my @tmpservers = $CS->get_server_detail();
  $srv = ( grep { $_->name eq 'perlmfapitest' } @tmpservers )[0];
  sleep 2 if ( ( $srv->status // '' ) ne 'ACTIVE' );
} while ( ( $srv->status // '' ) ne 'ACTIVE' );

print "Server is now built and available:\n";
print "Server ID ", $srv->id, ", root password is: ", $adminpass, "\n";
print "Available at public IP: @{$srv->public_address}\n";
Something went wrong with that request. Please try again.