Skip to content

Instantly share code, notes, and snippets.

@NachoMan
Created September 10, 2010 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NachoMan/573061 to your computer and use it in GitHub Desktop.
Save NachoMan/573061 to your computer and use it in GitHub Desktop.
#!perl
use 5.010;
use LWP::UserAgent;
use Getopt::Long;
use YAML::XS;
$ENV{JAVA_HOME} = 'C:\Program Files\Java\jdk1.6.0_21';
$ENV{ANT_HOME} = 'C:\SeleniumGrid\apache-ant-1.8.1';
$ENV{SELENIUM_HOME} = 'C:\SeleniumGrid\selenium-grid-1.0.8';
$ENV{PATH} = qq($ENV{JAVA_HOME}\\bin;$ENV{PATH};"$ENV{ANT_HOME}\\bin");
my $hub = undef;
my $hostname = undef;
my @environments = ();
GetOptions(
"hub=s" => \$hub,
"hostname=s" => \$hostname,
);
@environments = @ARGV;
my $ua = LWP::UserAgent->new;
$ua->timeout(2);
my $response = $ua->get("http://169.254.169.254/1.0/user-data");
if ($response->is_success) {
my $yaml = $response->content . "\n";
$yaml = "---\n$yaml" unless $yaml =~ /---/;
$yaml =~ s/\t/ /g;
my $config = Load($yaml);
@environments = @{ $config->{environments} };
$hub ||= $config->{hub};
}
$response = $ua->get("http://169.254.169.254/latest/meta-data/public-hostname");
if ($response->is_success) {
$hostname = $response->content;
}
unless (defined $hostname) {
$hostname = `hostname`;
chomp $hostname;
unless ($hostname =~ /\./) {
my @netinfo = `ipconfig -all`;
my ($domain) = grep { /Primary Dns Suffix/i } @netinfo;
if ($domain =~ /:\s*(\S+)/) {
$hostname .= ".$1";
}
}
}
chdir $ENV{SELENIUM_HOME};
foreach my $env (@environments) {
state $port = 5555;
my $cmd = sprintf(
q{start "%s" /MIN ant -Dhost="%s" -Dport=%s -Denvironment="%s" -DhubURL=%s launch-remote-control},
$env,
$hostname,
++$port,
$env,
$hub,
);
system($cmd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment