Skip to content

Instantly share code, notes, and snippets.

@IngussNeilands
Forked from nesquena/linode_fog.rb
Created December 16, 2016 14:32
Show Gist options
  • Save IngussNeilands/96b94d7922ee96ce9d9a1a33ddbdbd64 to your computer and use it in GitHub Desktop.
Save IngussNeilands/96b94d7922ee96ce9d9a1a33ddbdbd64 to your computer and use it in GitHub Desktop.
Linode and Fog Samples
## DNS
@dns = Fog::DNS.new(:provider => 'Linode', :linode_api_key => LINODE_KEY)
if @zone = @dns.zones.all.find { |z| z.domain == ZONE }
puts "Found zone #{@zone.inspect}"
else
@zone = @dns.zones.create(:domain => ZONE, :email => ZONE_EMAIL)
puts "Creating zone #{@zone.inspect}"
end
@zone.records.create(:value => '67.255.240.224', :name => 'foo', :type => 'A')
@zone.records.create(:value => 'foo.wordpress.com', :name => 'blog', :type => 'CNAME')
## COMPUTE
@compute = Fog::Compute.new(:provider => 'Linode', :linode_api_key => LINODE_KEY)
puts @compute.servers.map { |s| puts s.inspect }
puts "Create linode"
data_center = @compute.data_centers.find { |dc| dc.location =~ /Dallas/ }
flavor = @compute.flavors.find { |f| f.ram == 1024 }
image = @compute.images.find { |i| i.name == "Ubuntu 11.04 64bit" }
kernel = @compute.kernels.find { |k| k.name == "3.0.4-x86_64-linode21" }
server = @compute.servers.create(:data_center => data_center, :flavor => flavor, :payment_terms => 1, :name => "testbox",
:image => image, :kernel => kernel, :password => "secret")
puts "Created #{server.id}"
puts "Delete linode"
server = @compute.servers.get(1)
puts server.inspect
server.destroy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment