Skip to content

Commit

Permalink
Perl script that collects info on EC2 instance types.
Browse files Browse the repository at this point in the history
  • Loading branch information
vex21 committed Dec 15, 2017
1 parent b7f54d4 commit 945f1ac
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>useful_scripts</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
useful_scripts
==============

My useful scripts
random useful scripts
69 changes: 69 additions & 0 deletions ec2/describe_instance_type.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/perl
# AWS CLI doesn't offer a way to describe instance types.
# This script scrapes that information from AWS website by parsing HTML tables,
# then it creates yaml files that are going to be used by project: https://github.com/RedHatQE/dva

use locale;
use strict;
use warnings;

use DBI;
use HTML::TreeBuilder::XPath;
use Data::Dumper;

binmode STDOUT, ":utf8";

my $html_file = 'ec2_types.html';
my @variants_table;
my $variants;
my @variant;
my $memory_zeroes;
my $number_of_columns;
my $ec2_url = 'https://aws.amazon.com/ec2/instance-types/';

system ('wget', $ec2_url, "--output-document=$html_file", '--user-agent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0"') and print "error - cannot load \n";


unless (-e $html_file) {
print "File Doesn't Exist!";
exit();
}

my $tree = HTML::TreeBuilder::XPath->new;

$tree->parse_file($html_file);

@variants_table = $tree->findnodes('//div[@class="aws-table"]/table/tbody/tr');

for $variants ( @variants_table ) {

@variant = $variants->findvalues('./td');

$number_of_columns = $#variant;
if ($number_of_columns!=11 && $number_of_columns!=12) {
print "wrong table, skipping...\n";
next;
}

# skip the first table row
if ($variant[0] eq 'Instance Type') { next; }

if ($variant[2] =~ m/0\./) { $memory_zeroes = '00000'; }
else { $memory_zeroes = '000000'; }

$variant[2] =~ s/0\.//;

$variant[0] =~ s/\s+//;

print $variant[0];
print ": ";
print $variant[2] . " GB";
print "\n";

open FILE, ">", "x86_64_hvm_" . $variant[0] . ".yaml" or die $!;

print FILE "- {arch: 'x86_64', cpu: '".$variant[1]."', memory: '".$variant[2]. $memory_zeroes ."', cloudhwname: ".$variant[0].", virtualization: 'hvm'}\n";

close FILE;
}
$tree->delete;

0 comments on commit 945f1ac

Please sign in to comment.