<commit_before>require 'json'
require 'swirl'
require 'pp'

c = Swirl::EC2.new

CONFIG = ARGV[0]
USERDATA = ARGV[1]

config = JSON.parse File.read ARGV[0]
throw "No config" unless config

avail_zone = config["availability_zone"] || "us-east-1c"

ebs = config["volumes"].select {|v| v["media"] == "ebs"}

# XXX: check that the ebs group is ok before starting to create volumes

snapshots = []
devices = []
sizes = []
ebs.each do |v|
  puts "Adding a volume of #{v["size"]} to be mounted at #{v["device"]}."
#  volumeId = c.call("CreateVolume", "Size" => v["size"].to_s,  "AvailabilityZone" => avail_zone)["volumeId"]
#  snapshotId = c.call("CreateSnapshot", "VolumeId" => volumeId)["snapshotId"]
#  snapshots << snapshotId
  snapshots << "snap-87fcd7ef" # an empty snapshot
  devices << v["device"]
  sizes << v["size"].to_s
end

opt = {
  "Placement.AvailabilityZone" => avail_zone,
  "MinCount" => "1",
  "MaxCount" => "1",
  "KeyName" => "default",
  "ImageId" => config["ami32"],
  "BlockDeviceMapping.#.Ebs.SnapshotId" => snapshots,
  "BlockDeviceMapping.#.Ebs.VolumeSize" => sizes,
  "BlockDeviceMapping.#.DeviceName" => devices
}

if USERDATA && data = File.read(USERDATA)
  puts "Including userdata."
  opt.merge!({ "UserData" => Base64.encode64(data)})<commit_msg>use a public snapshot instead.<commit_after>require 'json'
require 'swirl'
require 'pp'

c = Swirl::EC2.new

CONFIG = ARGV[0]
USERDATA = ARGV[1]

config = JSON.parse File.read ARGV[0]
throw "No config" unless config

avail_zone = config["availability_zone"] || "us-east-1c"

ebs = config["volumes"].select {|v| v["media"] == "ebs"}

# XXX: check that the ebs group is ok before starting to create volumes

snapshots = []
devices = []
sizes = []
ebs.each do |v|
  puts "Adding a volume of #{v["size"]} to be mounted at #{v["device"]}."
  snapshots << "snap-ab600ac2" # a public snapshot described as "empty snapshot for provisioning"
  devices << v["device"]
  sizes << v["size"].to_s
end

opt = {
  "Placement.AvailabilityZone" => avail_zone,
  "MinCount" => "1",
  "MaxCount" => "1",
  "KeyName" => "default",
  "ImageId" => config["ami32"],
  "BlockDeviceMapping.#.Ebs.SnapshotId" => snapshots,
  "BlockDeviceMapping.#.Ebs.VolumeSize" => sizes,
  "BlockDeviceMapping.#.DeviceName" => devices
}

if USERDATA && data = File.read(USERDATA)
  puts "Including userdata."
  opt.merge!({ "UserData" => Base64.encode64(data)})
{'fraction_non_alphanumeric': 0.1797658862876254, 'fraction_numerical': 0.013795986622073578, 'mean_word_length': 4.752403846153846, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2284986', 'n_tokens_mistral': 886, 'n_tokens_neox': 858, 'n_words': 213}