Last active
August 29, 2015 14:04
-
-
Save mmay/eeeae5bf30ece643e2c9 to your computer and use it in GitHub Desktop.
ruby script to create a fastly domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env ruby | |
## | |
# fastly_upload_vcl - upload raw VCL files to Fastly | |
# | |
# Author:: Fastly Inc <[email protected]> | |
# Copyright:: Copyright (c) 2011 Fastly Inc | |
# License:: Distributes under the same terms as Ruby | |
# | |
# = USAGE | |
# | |
# fastly_create_domain --api_key=<key> <service id> <domain name> | |
# | |
require 'rubygems' | |
require 'fastly' | |
def get_options | |
options = {} | |
while (ARGV.size>0 && ARGV[0] =~ /^-+(\w+)\=(\w+)$/) do | |
options[$1.to_sym] = $2; | |
ARGV.shift; | |
end | |
raise "Couldn't find options from command line arguments unless options.size>0 | |
options; | |
end | |
# :nodoc: | |
def die(message) | |
warn message | |
exit -1 | |
end | |
params = get_options | |
service_id = ARGV.shift || die("You must pass in a service id") | |
domain_name = ARGV.shift || die("You must pass in a domain name") | |
die("Couldn't find any of the config files - #{configs.join(',')}") unless params.keys.size>0 | |
fastly = Fastly.new(params) | |
service = fastly.get_service(service_id) || die("Couldn't find service #{service_id}") | |
version = service.version | |
cloned_version = version.clone | |
domain = fastly.create_domain(:service_id => service.id, :version => cloned_version.number, :name => domain_name) | |
cloned_version.activate! | |
puts "Done! Created Domain: #{domain.name}. Active Version: #{domain.version.number}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment