slicehost 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +28 -0
- data/README.txt +12 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +17 -0
- data/lib/slicehost.rb +172 -0
- data/lib/slicehost/version.rb +9 -0
- data/local/slicehost.rb +2 -0
- data/local/slicehost.rb.sample +2 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_admin.rb +13 -0
- data/test/test_helper.rb +17 -0
- data/test/test_slices.rb +31 -0
- data/test/test_zones.rb +96 -0
- data/website/index.html +93 -0
- data/website/index.txt +39 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +88 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 Dr Nic Williams
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
lib/slicehost.rb
|
9
|
+
lib/slicehost/version.rb
|
10
|
+
local/slicehost.rb
|
11
|
+
local/slicehost.rb.sample
|
12
|
+
log/debug.log
|
13
|
+
script/destroy
|
14
|
+
script/generate
|
15
|
+
script/txt2html
|
16
|
+
setup.rb
|
17
|
+
tasks/deployment.rake
|
18
|
+
tasks/environment.rake
|
19
|
+
tasks/website.rake
|
20
|
+
test/test_admin.rb
|
21
|
+
test/test_helper.rb
|
22
|
+
test/test_slices.rb
|
23
|
+
test/test_zones.rb
|
24
|
+
website/index.html
|
25
|
+
website/index.txt
|
26
|
+
website/javascripts/rounded_corners_lite.inc.js
|
27
|
+
website/stylesheets/screen.css
|
28
|
+
website/template.rhtml
|
data/README.txt
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
= Slicehost Helper API
|
2
|
+
|
3
|
+
This library provides a simple set of helper methods
|
4
|
+
to manage slices and DNS zones/records on your Slicehost
|
5
|
+
account (http://slicehost.com).
|
6
|
+
|
7
|
+
The current API is very alpha. It was just the simplest thing that worked.
|
8
|
+
There are unit tests demonstrating it working and everything.
|
9
|
+
|
10
|
+
Future releases will have a nicer, class-based API.
|
11
|
+
|
12
|
+
Contact: Dr Nic Williams, drnicwilliams@gmail.com
|
data/Rakefile
ADDED
data/config/hoe.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'slicehost/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Dr Nic Williams' # can also be an array of Authors
|
4
|
+
EMAIL = "drnicwilliams@gmail.com"
|
5
|
+
GEM_NAME = 'slicehost' # what ppl will type to install your gem
|
6
|
+
RUBYFORGE_PROJECT = 'slicehost' # The unix name for your project
|
7
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
8
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
9
|
+
|
10
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
11
|
+
@config = nil
|
12
|
+
RUBYFORGE_USERNAME = "unknown"
|
13
|
+
def rubyforge_username
|
14
|
+
unless @config
|
15
|
+
begin
|
16
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
17
|
+
rescue
|
18
|
+
puts <<-EOS
|
19
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
20
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
21
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
22
|
+
EOS
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
end
|
26
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
REV = nil
|
31
|
+
# UNCOMMENT IF REQUIRED:
|
32
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
33
|
+
VERS = Slicehost::VERSION::STRING + (REV ? ".#{REV}" : "")
|
34
|
+
RDOC_OPTS = ['--quiet', '--title', 'slicehost documentation',
|
35
|
+
"--opname", "index.html",
|
36
|
+
"--line-numbers",
|
37
|
+
"--main", "README",
|
38
|
+
"--inline-source"]
|
39
|
+
|
40
|
+
class Hoe
|
41
|
+
def extra_deps
|
42
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
43
|
+
@extra_deps
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Generate all the Rake tasks
|
48
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
49
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
50
|
+
p.author = AUTHOR
|
51
|
+
p.description = p.paragraphs_of("README.txt", 1..3).join("\n\n")
|
52
|
+
p.email = EMAIL
|
53
|
+
p.summary = p.description
|
54
|
+
p.url = HOMEPATH
|
55
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
56
|
+
p.test_globs = ["test/**/test_*.rb"]
|
57
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
58
|
+
|
59
|
+
# == Optional
|
60
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
61
|
+
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
62
|
+
|
63
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
68
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
69
|
+
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
70
|
+
hoe.rsync_args = '-av --delete --ignore-errors'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
16
|
+
|
17
|
+
require 'slicehost'
|
data/lib/slicehost.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'mechanize'
|
5
|
+
|
6
|
+
module Slicehost
|
7
|
+
end
|
8
|
+
|
9
|
+
class Slicehost::Helper
|
10
|
+
Base = "https://manage.slicehost.com"
|
11
|
+
|
12
|
+
# Slice images
|
13
|
+
Arch200708 = 9
|
14
|
+
CentOS5 = 2
|
15
|
+
DebianEtch = 4
|
16
|
+
Fedora8 = 5
|
17
|
+
UbuntuDapper = 6
|
18
|
+
UbuntuGutsy = 8
|
19
|
+
|
20
|
+
# Slice sizes
|
21
|
+
Slice256 = 1
|
22
|
+
Slice512 = 2
|
23
|
+
Slice1024 = 3
|
24
|
+
Slice2048 = 4
|
25
|
+
|
26
|
+
attr_reader :agent, :page
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@agent = WWW::Mechanize.new
|
30
|
+
end
|
31
|
+
# !> `&' interpreted as argument prefix
|
32
|
+
def login(email, password)
|
33
|
+
@page = agent.get("#{Base}/login")
|
34
|
+
form = page.form(nil)
|
35
|
+
form.email = email
|
36
|
+
form.password = password
|
37
|
+
@page = agent.submit(form)
|
38
|
+
end
|
39
|
+
|
40
|
+
def zone?(url)
|
41
|
+
zone_info(url)
|
42
|
+
end
|
43
|
+
|
44
|
+
def zone_info(url)
|
45
|
+
dotted_url = "#{url}."
|
46
|
+
@page = agent.get("#{Base}/zones")
|
47
|
+
if row = (page/"#dns tr").select { |tr| td = (tr/"td").first; td && td.inner_html == dotted_url }.first
|
48
|
+
info = {}
|
49
|
+
details_td = (row/"td").last
|
50
|
+
info["records"] = (details_td/"a").first.get_attribute("href")
|
51
|
+
info["zone_id"] = info["records"].match(/\d+/)[0].to_i
|
52
|
+
info["delete_url"] = (details_td/"a").last.get_attribute("href")
|
53
|
+
delete_click = (details_td/"a").last.get_attribute("onclick")
|
54
|
+
match = delete_click.match(/s\.setAttribute\('name', 'authenticity_token'\); s\.setAttribute\('value', '(\w+)'\);/)
|
55
|
+
info["authenticity_token"] = match[1]
|
56
|
+
info
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_zone(url)
|
61
|
+
page = agent.get("#{Base}/zones/new")
|
62
|
+
form = page.form(nil)
|
63
|
+
form.origin = url
|
64
|
+
form.ttl = 3600
|
65
|
+
agent.submit(form)
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete_zone(url)
|
69
|
+
return unless info = zone?(url)
|
70
|
+
agent.post(info["delete_url"], {
|
71
|
+
"_method" => "delete",
|
72
|
+
"authenticity_token" => info["authenticity_token"]
|
73
|
+
})
|
74
|
+
end
|
75
|
+
|
76
|
+
def record_info(url)
|
77
|
+
return [] unless info = zone_info(url)
|
78
|
+
@page = agent.get(info["records"])
|
79
|
+
(page/"#dns tr")[1..-1].inject([]) do |mem, tr|
|
80
|
+
name, data, record_type = (tr/"td")[0..2].map { |td| td.inner_html }
|
81
|
+
mem << { "name" => name, "data" => data, "record_type" => record_type }
|
82
|
+
mem
|
83
|
+
end.sort { |a, b| a["record_type"] <=> b["record_type"] }
|
84
|
+
end
|
85
|
+
|
86
|
+
def create_record(url, options)
|
87
|
+
return unless info = zone_info(url)
|
88
|
+
dotted_url = "#{url}."
|
89
|
+
options["record_type"] ||= "A"
|
90
|
+
options["name"] ||= dotted_url
|
91
|
+
options.each_pair { |name, val| options[name] = [val] unless val.is_a?(Array) }
|
92
|
+
@page = agent.get("#{info['records']}/new")
|
93
|
+
form = page.form(nil)
|
94
|
+
form.set_fields(options)
|
95
|
+
@page = agent.submit(form)
|
96
|
+
end
|
97
|
+
|
98
|
+
def create_records(url, option_list)
|
99
|
+
option_list.each do |options|
|
100
|
+
create_record(url, options)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def create_simple_zone(url, ipaddr)
|
105
|
+
create_record(url, "data" => ipaddr)
|
106
|
+
create_record(url, "name" => "www", "data" => ipaddr)
|
107
|
+
(1..3).to_a.each do |ns|
|
108
|
+
create_record(url, "data" => "ns#{ns}.slicehost.net.", "record_type" => "NS")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def create_googleapps_mx(url)
|
113
|
+
dotted_url = "#{url}."
|
114
|
+
mx_records = <<-RECORD
|
115
|
+
ASPMX.L.GOOGLE.COM.
|
116
|
+
ALT1.ASPMX.L.GOOGLE.COM.
|
117
|
+
ALT2.ASPMX.L.GOOGLE.COM.
|
118
|
+
ASPMX2.GOOGLEMAIL.COM.
|
119
|
+
ASPMX3.GOOGLEMAIL.COM.
|
120
|
+
RECORD
|
121
|
+
mx_records = mx_records.split("\n").map { |mx| mx.strip }
|
122
|
+
mx_aux = %w[1 3 3 5 5 5 ]
|
123
|
+
aux_count = 0
|
124
|
+
create_records(url, mx_records.inject([]) do |mem, mx|
|
125
|
+
mem << { "name" => dotted_url, "data" => mx, "record_type" => "MX", "aux" => mx_aux[aux_count] }
|
126
|
+
aux_count =+ 1
|
127
|
+
mem
|
128
|
+
end)
|
129
|
+
end
|
130
|
+
|
131
|
+
# WARNING: Calling this method will add a new slice to your account!
|
132
|
+
# YOU WILL BE BILLED BY SLICEHOST.
|
133
|
+
# +name+ can be an empty string, Slicehost will allocated a random name to your new slice
|
134
|
+
def create_slice(name, options = {})
|
135
|
+
options["name"] = name
|
136
|
+
options["image_id"] ||= UbuntuDapper
|
137
|
+
options["image_id"] = options["image_id"].to_i.to_s # raise error if not Fixnum
|
138
|
+
options["flavor"] ||= Slice256
|
139
|
+
options["flavor"] = options["flavor"].to_i.to_s # raise error if not Fixnum
|
140
|
+
@page = agent.get("#{Base}/slices/new")
|
141
|
+
form = page.form(nil)
|
142
|
+
form.set_fields(options)
|
143
|
+
@page = agent.submit(form)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Output is an Array of:
|
147
|
+
# {"status"=>"active", "name"=>"slicehost01", "url"=>"/slices/1234",
|
148
|
+
# "bandwidth"=>{"total"=>"2.15GB", "inout"=>"0.17 in / 1.99 out"},
|
149
|
+
# "backups"=>"On", "ip"=>"123.456.789.012", "ram"=>"512MB", "age"=>"6 months"}
|
150
|
+
def slices
|
151
|
+
@page = agent.get("#{Base}/slices")
|
152
|
+
(page/"#slice_list tr")[1..-1].map do |tr|
|
153
|
+
td_list = tr/"td"
|
154
|
+
slice_name = (td_list[0]/"a").first
|
155
|
+
slice = {
|
156
|
+
"name" => slice_name.inner_html,
|
157
|
+
"url" => slice_name.get_attribute("href"),
|
158
|
+
"status" => (td_list[1]/"span").first.inner_html.strip,
|
159
|
+
"ram" => td_list[2].inner_html,
|
160
|
+
"ip" => (td_list[3]/"span").first.children.first.to_s.strip,
|
161
|
+
"backups" => td_list[5].inner_html,
|
162
|
+
"age" => td_list[6].inner_html
|
163
|
+
}
|
164
|
+
bandwidth = td_list[4]
|
165
|
+
slice["bandwidth"] = {
|
166
|
+
"total" => bandwidth.children.first,
|
167
|
+
"inout" => bandwidth.children.last.inner_html
|
168
|
+
}
|
169
|
+
slice
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
data/local/slicehost.rb
ADDED
data/log/debug.log
ADDED
File without changes
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/script/txt2html
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
begin
|
5
|
+
require 'newgem'
|
6
|
+
rescue LoadError
|
7
|
+
puts "\n\nGenerating the website requires the newgem RubyGem"
|
8
|
+
puts "Install: gem install newgem\n\n"
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
require 'redcloth'
|
12
|
+
require 'syntax/convertors/html'
|
13
|
+
require 'erb'
|
14
|
+
require File.dirname(__FILE__) + '/../lib/slicehost/version.rb'
|
15
|
+
|
16
|
+
version = Slicehost::VERSION::STRING
|
17
|
+
download = 'http://rubyforge.org/projects/slicehost'
|
18
|
+
|
19
|
+
class Fixnum
|
20
|
+
def ordinal
|
21
|
+
# teens
|
22
|
+
return 'th' if (10..19).include?(self % 100)
|
23
|
+
# others
|
24
|
+
case self % 10
|
25
|
+
when 1: return 'st'
|
26
|
+
when 2: return 'nd'
|
27
|
+
when 3: return 'rd'
|
28
|
+
else return 'th'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Time
|
34
|
+
def pretty
|
35
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def convert_syntax(syntax, source)
|
40
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
41
|
+
end
|
42
|
+
|
43
|
+
if ARGV.length >= 1
|
44
|
+
src, template = ARGV
|
45
|
+
template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
|
46
|
+
|
47
|
+
else
|
48
|
+
puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
|
49
|
+
exit!
|
50
|
+
end
|
51
|
+
|
52
|
+
template = ERB.new(File.open(template).read)
|
53
|
+
|
54
|
+
title = nil
|
55
|
+
body = nil
|
56
|
+
File.open(src) do |fsrc|
|
57
|
+
title_text = fsrc.readline
|
58
|
+
body_text = fsrc.read
|
59
|
+
syntax_items = []
|
60
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
61
|
+
ident = syntax_items.length
|
62
|
+
element, syntax, source = $1, $2, $3
|
63
|
+
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
64
|
+
"syntax-temp-#{ident}"
|
65
|
+
}
|
66
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
67
|
+
body = RedCloth.new(body_text).to_html
|
68
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
69
|
+
end
|
70
|
+
stat = File.stat(src)
|
71
|
+
created = stat.ctime
|
72
|
+
modified = stat.mtime
|
73
|
+
|
74
|
+
$stdout << template.result(binding)
|