include MySQL create sql file, modify mysql db to use variable names that are consistent with code.
This commit is contained in:
		
							parent
							
								
									13b4842614
								
							
						
					
					
						commit
						49a7d96d8f
					
				@ -46,9 +46,8 @@ class Instance
 | 
				
			|||||||
    when "screen"
 | 
					    when "screen"
 | 
				
			||||||
      print outputstring
 | 
					      print outputstring
 | 
				
			||||||
    when "mysql"
 | 
					    when "mysql"
 | 
				
			||||||
      #print "mysqloutputcalled\n"
 | 
					      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 = 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.instance_type}","#{ec2_object.status}","#{ec2_object.price}","#{ec2_object.name}","#{ec2_object.asg}",Time.now)
 | 
				
			||||||
      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)
 | 
					 | 
				
			||||||
    else 
 | 
					    else 
 | 
				
			||||||
      $stderr.print "error with output.\n"
 | 
					      $stderr.print "error with output.\n"
 | 
				
			||||||
      exit 1
 | 
					      exit 1
 | 
				
			||||||
@ -189,42 +188,37 @@ optparse = OptionParser.new do |opts|
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
  #MySQL Configuration
 | 
					  #MySQL Configuration
 | 
				
			||||||
  opts.on("--mysqluser MYSQLUSER","username to be used when connecting to MySQL database") do |mysql_user|
 | 
					  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
 | 
					    mysql_connection_info[:mysql_user] = mysql_user
 | 
				
			||||||
    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
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  opts.on("--mysqlpass MYSQLPASS","password to be used when connecting to MySQL database") do |mysql_pass|
 | 
					  opts.on("--mysqlpass MYSQLPASS","password to be used when connecting to MySQL database") do |mysql_pass|
 | 
				
			||||||
    if (mysql_pass.length == 0 )
 | 
					    mysql_connection_info[:mysql_pass] = mysql_pass
 | 
				
			||||||
      $stderr.print "The mysql password specified with the --mysqlpassword flag was blank.\n"
 | 
					 | 
				
			||||||
      exit 64
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
      mysql_connection_info[:mysql_pass] = mysql_pass
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  opts.on("--mysqlhost MYSQLHOST","host to be used when connecting to MySQL database") do |mysql_host|
 | 
					  opts.on("--mysqlhost MYSQLHOST","host to be used when connecting to MySQL database") do |mysql_host|
 | 
				
			||||||
    if (mysql_host.length == 0 )
 | 
					    mysql_connection_info[:mysql_host] = mysql_host
 | 
				
			||||||
      $stderr.print "The mysql hostname specified with the --mysqlhost flag was blank.\n"
 | 
					 | 
				
			||||||
      exit 64
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
      mysql_connection_info[:mysql_host] = mysql_host
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  opts.on("--mysqlport MYSQLPORT","port to be used when connecting to MySQL database") do |mysql_port|
 | 
					  opts.on("--mysqlport MYSQLPORT","port to be used when connecting to MySQL database") do |mysql_port|
 | 
				
			||||||
    if (mysql_port.length == 0 )
 | 
					    mysql_connection_info[:mysql_port] = mysql_port.to_i
 | 
				
			||||||
      $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
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
optparse.parse!
 | 
					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]
 | 
					case options[:awscredentialssource]
 | 
				
			||||||
when "env"
 | 
					when "env"
 | 
				
			||||||
  credentialfile = ENV["AWS_CREDENTIAL_FILE"]
 | 
					  credentialfile = ENV["AWS_CREDENTIAL_FILE"]
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										27
									
								
								ec2-cost-calculate-ruby/ec2cc-mysql/ec2cc-table-create.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								ec2-cost-calculate-ruby/ec2cc-mysql/ec2cc-table-create.sql
									
									
									
									
									
										Normal file
									
								
							@ -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;
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								ec2-cost-calculate-ruby/ec2cc-mysql/ec2cc.mwb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								ec2-cost-calculate-ruby/ec2cc-mysql/ec2cc.mwb
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user