From 49a7d96d8f04aa5130c185ae24791ca080f41043 Mon Sep 17 00:00:00 2001 From: Colin Johnson Date: Sun, 22 Jul 2012 18:29:45 +0000 Subject: [PATCH] include MySQL create sql file, modify mysql db to use variable names that are consistent with code. --- ec2-cost-calculate-ruby/ec2-cost-calculate.rb | 52 ++++++++---------- .../ec2cc-mysql/ec2cc-table-create.sql | 27 +++++++++ ec2-cost-calculate-ruby/ec2cc-mysql/ec2cc.mwb | Bin 0 -> 4989 bytes 3 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 ec2-cost-calculate-ruby/ec2cc-mysql/ec2cc-table-create.sql create mode 100644 ec2-cost-calculate-ruby/ec2cc-mysql/ec2cc.mwb diff --git a/ec2-cost-calculate-ruby/ec2-cost-calculate.rb b/ec2-cost-calculate-ruby/ec2-cost-calculate.rb index f1a9df2..ea4ca0a 100755 --- a/ec2-cost-calculate-ruby/ec2-cost-calculate.rb +++ b/ec2-cost-calculate-ruby/ec2-cost-calculate.rb @@ -46,9 +46,8 @@ class Instance when "screen" print outputstring when "mysql" - #print "mysqloutputcalled\n" - ec2cc_object_insert = ec2cc_resources[:mysql_connection_object].prepare("insert into costs (instanceid,region,platform,status,cost,name,autoscalinggroup,date) values (?,?,?,?,?,?,?,?)") - ec2cc_object_insert.execute("#{ec2_object.id}","#{ec2_object.region}","#{ec2_object.platform}","#{ec2_object.status}","#{ec2_object.price}","#{ec2_object.name}","#{ec2_object.asg}",Time.now) + ec2cc_object_insert = ec2cc_resources[:mysql_connection_object].prepare("insert into costs (id,region,platform,instance_type,status,cost,name,autoscalinggroup,date) values (?,?,?,?,?,?,?,?,?)") + ec2cc_object_insert.execute("#{ec2_object.id}","#{ec2_object.region}","#{ec2_object.platform}","#{ec2_object.instance_type}","#{ec2_object.status}","#{ec2_object.price}","#{ec2_object.name}","#{ec2_object.asg}",Time.now) else $stderr.print "error with output.\n" exit 1 @@ -189,42 +188,37 @@ optparse = OptionParser.new do |opts| end #MySQL Configuration opts.on("--mysqluser MYSQLUSER","username to be used when connecting to MySQL database") do |mysql_user| - #forces option to lowercase - easier to evaluate variables when always lowercase - if (mysql_user.length == 0 ) - $stderr.print "The mysql username specified with the --mysqluser flag was blank.\n" - exit 64 - else - mysql_connection_info[:mysql_user] = mysql_user - end + mysql_connection_info[:mysql_user] = mysql_user end opts.on("--mysqlpass MYSQLPASS","password to be used when connecting to MySQL database") do |mysql_pass| - if (mysql_pass.length == 0 ) - $stderr.print "The mysql password specified with the --mysqlpassword flag was blank.\n" - exit 64 - else - mysql_connection_info[:mysql_pass] = mysql_pass - end + mysql_connection_info[:mysql_pass] = mysql_pass end opts.on("--mysqlhost MYSQLHOST","host to be used when connecting to MySQL database") do |mysql_host| - if (mysql_host.length == 0 ) - $stderr.print "The mysql hostname specified with the --mysqlhost flag was blank.\n" - exit 64 - else - mysql_connection_info[:mysql_host] = mysql_host - end + mysql_connection_info[:mysql_host] = mysql_host end opts.on("--mysqlport MYSQLPORT","port to be used when connecting to MySQL database") do |mysql_port| - if (mysql_port.length == 0 ) - $stderr.print "The mysql port specified with the --mysqlport is required to be a number.\n" - exit 64 - else - mysql_connection_info[:mysql_port] = mysql_port.to_i - end + mysql_connection_info[:mysql_port] = mysql_port.to_i end end optparse.parse! -#case statement deterimnes the location where AWS credentials should be gotten. Defaults to "env" (environment) if set to "file" will read from a user provided file. +#ensures that if output is mysql that mysqluser, mysqlpass and mysqlhost are set +if options[:output] == "mysql" + if mysql_connection_info[:mysql_user].nil? + $stderr.print "If you are outputing to MySQL using \"--output mysql\" you must specify a mysql username using \"--mysqluser.\"\n" + exit 64; + end + if mysql_connection_info[:mysql_pass].nil? + $stderr.print "If you are outputing to MySQL using \"--output mysql\" you must specify a mysql password using \"--mysqlpass.\"\n" + exit 64; + end + if mysql_connection_info[:mysql_host].nil? + $stderr.print "If you are outputing to MySQL using \"--output mysql\" you must specify a mysql hostname using \"--mysqlhost.\"\n" + exit 64; + end +end + +#case statement determines the location where AWS credentials should be gotten. Defaults to "env" (environment) if set to "file" will read from a user provided file. case options[:awscredentialssource] when "env" credentialfile = ENV["AWS_CREDENTIAL_FILE"] diff --git a/ec2-cost-calculate-ruby/ec2cc-mysql/ec2cc-table-create.sql b/ec2-cost-calculate-ruby/ec2cc-mysql/ec2cc-table-create.sql new file mode 100644 index 0000000..548633b --- /dev/null +++ b/ec2-cost-calculate-ruby/ec2cc-mysql/ec2cc-table-create.sql @@ -0,0 +1,27 @@ +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL'; + +CREATE SCHEMA IF NOT EXISTS `ec2cc` DEFAULT CHARACTER SET utf8 ; +USE `ec2cc` ; + +-- ----------------------------------------------------- +-- Table `ec2cc`.`costs` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `ec2cc`.`costs` ( + `id` VARCHAR(10) NOT NULL , + `region` VARCHAR(9) NOT NULL , + `platform` VARCHAR(7) NOT NULL , + `instance_type` VARCHAR(13) NOT NULL , + `status` VARCHAR(7) NOT NULL , + `cost` FLOAT NOT NULL , + `name` VARCHAR(40) NULL , + `autoscalinggroup` VARCHAR(40) NULL , + `date` DATETIME NOT NULL ) +ENGINE = InnoDB; + + + +SET SQL_MODE=@OLD_SQL_MODE; +SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; +SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; diff --git a/ec2-cost-calculate-ruby/ec2cc-mysql/ec2cc.mwb b/ec2-cost-calculate-ruby/ec2cc-mysql/ec2cc.mwb new file mode 100644 index 0000000000000000000000000000000000000000..246552cc0999389be24795714b9168f0ac7fbd4e GIT binary patch literal 4989 zcmZ{obx;)Ux5k&HmXKIv0jUM)ZV*9WkyyHG>7|yG?i3Lakdp51PLYzOghe_;P)bTt z5sg+R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