rs-api-tools 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/.DS_Store +0 -0
- data/bin/rs-clone-deployment +58 -0
- data/bin/rs-clone-rightscript +79 -0
- data/bin/rs-clone-server +2 -0
- data/bin/rs-describe-alerts +42 -0
- data/bin/rs-describe-attached-vols +83 -0
- data/bin/rs-describe-deployment +85 -0
- data/bin/rs-describe-deployments +42 -0
- data/bin/rs-describe-ec2-ebs-snapshots +41 -0
- data/bin/rs-describe-ec2-ebs-volumes +42 -0
- data/bin/rs-describe-ec2-security-groups +42 -0
- data/bin/rs-describe-keys +42 -0
- data/bin/rs-describe-multi-cloud-images +42 -0
- data/bin/rs-describe-rightscript +81 -0
- data/bin/rs-describe-rightscripts +42 -0
- data/bin/rs-describe-server +97 -0
- data/bin/rs-describe-server-array +80 -0
- data/bin/rs-describe-server-arrays +42 -0
- data/bin/rs-describe-server-self +67 -0
- data/bin/rs-describe-server-templates +42 -0
- data/bin/rs-describe-servers +42 -0
- data/bin/rs-fetch-rightscripts +126 -0
- data/bin/rs-get-array-instances +64 -0
- data/bin/rs-get-server-input +2 -0
- data/bin/rs-get-server-monitoring +64 -0
- data/bin/rs-get-server-sketchy-data +42 -0
- data/bin/rs-launch-deployment +2 -0
- data/bin/rs-launch-server +2 -0
- data/bin/rs-ping-active-servers +44 -0
- data/bin/rs-reboot-deployment +2 -0
- data/bin/rs-reboot-server +75 -0
- data/bin/rs-relaunch-deployment +2 -0
- data/bin/rs-relaunch-server +74 -0
- data/bin/rs-run-all-boot-executables +94 -0
- data/bin/rs-run-rightscript +98 -0
- data/bin/rs-search-tags +69 -0
- data/bin/rs-start-deployment +2 -0
- data/bin/rs-start-server +75 -0
- data/bin/rs-stop-deployment +2 -0
- data/bin/rs-stop-server +2 -0
- data/bin/rs-terminate-all +2 -0
- data/bin/rs-terminate-deployment +2 -0
- data/bin/rs-terminate-self +70 -0
- data/bin/rs-terminate-server +90 -0
- data/bin/rs-update-input +71 -0
- data/bin/rs-update-inputs +71 -0
- data/bin/rs-update-server-array +63 -0
- metadata +194 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# rs-describe-server-self [--settings]
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'getoptlong'
|
7
|
+
require 'json'
|
8
|
+
require 'rest_connection'
|
9
|
+
|
10
|
+
def usage
|
11
|
+
puts("usage: rs-describe-server-self [[--settings]]")
|
12
|
+
puts(" [[--verbose]]")
|
13
|
+
end
|
14
|
+
|
15
|
+
def usage_exit
|
16
|
+
usage; exit
|
17
|
+
end
|
18
|
+
|
19
|
+
def help
|
20
|
+
usage
|
21
|
+
puts ''
|
22
|
+
puts 'Describes the server from the aws-id of the local instance.'
|
23
|
+
puts ''
|
24
|
+
puts "examples: rs-describe-server-self --settings"
|
25
|
+
puts ''
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
|
29
|
+
opts = GetoptLong.new(
|
30
|
+
[ '--settings', '-s', GetoptLong::OPTIONAL_ARGUMENT ],
|
31
|
+
[ '--xml', '-x', GetoptLong::OPTIONAL_ARGUMENT ],
|
32
|
+
[ '--json', '-j', GetoptLong::OPTIONAL_ARGUMENT ]
|
33
|
+
)
|
34
|
+
|
35
|
+
settings = false
|
36
|
+
json = false
|
37
|
+
xml = false
|
38
|
+
verbose = false
|
39
|
+
|
40
|
+
opts.each do |opt, arg|
|
41
|
+
case opt
|
42
|
+
when '--settings'
|
43
|
+
settings = ".settings"
|
44
|
+
when '--verbose'
|
45
|
+
verbose = true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
instance_id = File.read('/var/spool/cloud/meta-data/instance-id')
|
50
|
+
|
51
|
+
# server-side filtering
|
52
|
+
if settings
|
53
|
+
server = Server.find_with_filter('aws_id' => "#{instance_id}")[0].settings
|
54
|
+
else
|
55
|
+
server = Server.find_with_filter('aws_id' => "#{instance_id}")[0]
|
56
|
+
end
|
57
|
+
|
58
|
+
# client-side filtering=expensive and lengthy on accounts with many servers
|
59
|
+
#server = Server.find(:all) {|server| server.settings['aws-id'] == "#{instance_id}"}
|
60
|
+
|
61
|
+
if server
|
62
|
+
puts "Found server, '#{server['nickname']}'."
|
63
|
+
puts server.to_yaml
|
64
|
+
else
|
65
|
+
puts 'Server not found, exiting.'
|
66
|
+
exit 1
|
67
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# rs-describe-server-templates
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'getoptlong'
|
7
|
+
require 'json'
|
8
|
+
require 'rest_connection'
|
9
|
+
require 'active_support' #for to_xml()
|
10
|
+
require 'xmlsimple'
|
11
|
+
|
12
|
+
def usage
|
13
|
+
puts("#{$0} [--xml] [--json]")
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
opts = GetoptLong.new(
|
18
|
+
[ '--xml', '-x', GetoptLong::OPTIONAL_ARGUMENT ],
|
19
|
+
[ '--json', '-j', GetoptLong::OPTIONAL_ARGUMENT ]
|
20
|
+
)
|
21
|
+
|
22
|
+
json = false
|
23
|
+
xml = false
|
24
|
+
|
25
|
+
opts.each do |opt, arg|
|
26
|
+
case opt
|
27
|
+
when '--json'
|
28
|
+
json = true
|
29
|
+
when '--xml'
|
30
|
+
xml = true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
server_templates = ServerTemplate.find_all()
|
35
|
+
|
36
|
+
if json
|
37
|
+
puts server_templates.to_json
|
38
|
+
elsif xml
|
39
|
+
puts JSON.parse(server_templates.to_json).to_xml(:root => 'server_template', :skip_instruct => true)
|
40
|
+
else
|
41
|
+
puts server_templates.to_yaml
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# rs-describe-servers
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'getoptlong'
|
7
|
+
require 'json'
|
8
|
+
require 'rest_connection'
|
9
|
+
require 'active_support' #for to_xml()
|
10
|
+
require 'xmlsimple'
|
11
|
+
|
12
|
+
def usage
|
13
|
+
puts("#{$0} [--xml] [--json]")
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
opts = GetoptLong.new(
|
18
|
+
[ '--xml', '-x', GetoptLong::OPTIONAL_ARGUMENT ],
|
19
|
+
[ '--json', '-j', GetoptLong::OPTIONAL_ARGUMENT ]
|
20
|
+
)
|
21
|
+
|
22
|
+
json = false
|
23
|
+
xml = false
|
24
|
+
|
25
|
+
opts.each do |opt, arg|
|
26
|
+
case opt
|
27
|
+
when '--json'
|
28
|
+
json = true
|
29
|
+
when '--xml'
|
30
|
+
xml = true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
servers = Server.find_all()
|
35
|
+
|
36
|
+
if json
|
37
|
+
puts servers.to_json
|
38
|
+
elsif xml
|
39
|
+
puts JSON.parse(servers.to_json).to_xml(:root => 'servers', :skip_instruct => true)
|
40
|
+
else
|
41
|
+
puts servers.to_yaml
|
42
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# rs-fetch-rightscripts
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'getoptlong'
|
7
|
+
require 'json'
|
8
|
+
require 'rest_connection'
|
9
|
+
require 'activesupport' #for to_xml()
|
10
|
+
require 'xmlsimple'
|
11
|
+
|
12
|
+
def usage
|
13
|
+
puts("rs-fetch-rightscripts [ --id <server_template_id> | --name <server_template_name>] [ OPTIONS ]")
|
14
|
+
puts("e.g. rs-fetch-rightscripts --name 'RightScale Linux Server RL 5.7 -v --xml'")
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
opts = GetoptLong.new(
|
19
|
+
[ '--id', '-i', GetoptLong::OPTIONAL_ARGUMENT ],
|
20
|
+
[ '--name', '-n', GetoptLong::OPTIONAL_ARGUMENT ],
|
21
|
+
[ '--verbose', '-v', GetoptLong::OPTIONAL_ARGUMENT ],
|
22
|
+
[ '--json', '-j', GetoptLong::OPTIONAL_ARGUMENT ],
|
23
|
+
[ '--xml', '-x', GetoptLong::OPTIONAL_ARGUMENT ],
|
24
|
+
)
|
25
|
+
|
26
|
+
name = false
|
27
|
+
id = false
|
28
|
+
show_help = false
|
29
|
+
verbose = false
|
30
|
+
xml = false
|
31
|
+
json = false
|
32
|
+
|
33
|
+
opts.each do |opt, arg|
|
34
|
+
case opt
|
35
|
+
when '--name'
|
36
|
+
name = arg
|
37
|
+
when '--id'
|
38
|
+
id = arg
|
39
|
+
when '--verbose'
|
40
|
+
verbose = true
|
41
|
+
when '--json'
|
42
|
+
json = true
|
43
|
+
when '--xml'
|
44
|
+
xml = true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
usage if !(name || id)
|
49
|
+
|
50
|
+
def sanitize_filename(filename)
|
51
|
+
filename.strip do |name|
|
52
|
+
# NOTE: File.basename doesn't work right with Windows paths on Unix
|
53
|
+
# get only the filename, not the whole path
|
54
|
+
name.gsub! /^.*(\\|\/)/, ''
|
55
|
+
|
56
|
+
# Finally, replace all non alphanumeric, underscore
|
57
|
+
# or periods with underscore
|
58
|
+
# name.gsub! /[^\w\.\-]/, '_'
|
59
|
+
# Basically strip out the non-ascii alphabets too
|
60
|
+
# and replace with x.
|
61
|
+
# You don't want all _ :)
|
62
|
+
name.gsub!(/[^0-9A-Za-z.\-]/, 'x')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Awesome truncate
|
67
|
+
# First regex truncates to the length, plus the rest of that word, if any.
|
68
|
+
# Second regex removes any trailing whitespace or punctuation (except ;).
|
69
|
+
# Unlike the regular truncate method, this avoids the problem with cutting
|
70
|
+
# in the middle of an entity ex.: truncate("this & that",9) => "this &am..."
|
71
|
+
# though it will not be the exact length.
|
72
|
+
def awesome_truncate(text, length = 30, truncate_string = "...")
|
73
|
+
return if text.nil?
|
74
|
+
l = length - truncate_string.mb_chars.length
|
75
|
+
text.mb_chars.length > length ? text[/\A.{#{l}}\w*\;?/m][/.*[\w\;]/m] + truncate_string : text
|
76
|
+
end
|
77
|
+
|
78
|
+
server_template = false
|
79
|
+
|
80
|
+
# get servertemplate
|
81
|
+
if name
|
82
|
+
puts "Finding ServerTemplate: '%#{name}%'." unless ! verbose
|
83
|
+
server_template = ServerTemplate.find(:first) { |s| s.nickname =~ /#{name}/ }
|
84
|
+
elsif id
|
85
|
+
puts "Fetching ServerTemplate; ID: #{id}." unless ! verbose
|
86
|
+
server_template = ServerTemplate.find(id.to_i)
|
87
|
+
end
|
88
|
+
|
89
|
+
if server_template
|
90
|
+
puts "Located ServerTemplate, '#{server_template.nickname}'." unless ! verbose
|
91
|
+
puts server_template.to_yaml unless ! verbose
|
92
|
+
else
|
93
|
+
puts "No ServerTemplate found."
|
94
|
+
exit 1
|
95
|
+
end
|
96
|
+
|
97
|
+
# get executables (RightScripts) of template
|
98
|
+
executables = server_template.fetch_executables
|
99
|
+
|
100
|
+
if json
|
101
|
+
puts executables.to_json
|
102
|
+
elsif xml
|
103
|
+
#puts JSON.parse(executables.to_json).to_xml(:root => 'right_scripts', :skip_instruct => true)
|
104
|
+
executables.each do |exec|
|
105
|
+
puts "<right_script>"
|
106
|
+
puts " <position>#{exec.position}</position>"
|
107
|
+
puts " <name>#{exec.name}</name>"
|
108
|
+
puts " <recipe>#{! exec.recipe.to_s.empty? ? exec.recipe : 'n/a'}</recipe>"
|
109
|
+
puts " <href>#{exec.href}</href>"
|
110
|
+
puts " <description>#{exec.right_script.description}</description>"
|
111
|
+
puts " <created_at>#{exec.right_script.created_at}</created_at>"
|
112
|
+
puts " <updated_at>#{exec.right_script.updated_at}</updated_at>"
|
113
|
+
puts " <version>#{exec.right_script.version == 0 ? 'HEAD' : exec.right_script.version}</version>"
|
114
|
+
puts " <phase>#{exec.apply}</phase>"
|
115
|
+
puts " <filename>#{sanitize_filename(exec.name).gsub(' ', '_')}</filename>"
|
116
|
+
puts " <script>#{awesome_truncate(exec.right_script.script)}</script>"
|
117
|
+
puts "</right_script>"
|
118
|
+
end
|
119
|
+
# puts "--- #{exec.position} #{! exec.recipe.to_s.empty? ? exec.recipe : '*'} #{exec.name} #{exec.right_script.version == 0 ? 'HEAD' : 'rev'+exec.right_script.version.to_s} #{exec.description} #{exec.href} #{exec.right_script.created_at} #{exec.right_script.updated_at} #{exec.apply}"
|
120
|
+
# puts "- #{sanitize_filename(exec.name)}: "
|
121
|
+
# puts "#{awesome_truncate(exec.right_script.script)}"
|
122
|
+
# puts '---'
|
123
|
+
# puts
|
124
|
+
else
|
125
|
+
puts executables.to_yaml
|
126
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
# rs-get-array-instances
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'getoptlong'
|
7
|
+
require 'json'
|
8
|
+
require 'rest_connection'
|
9
|
+
#require 'active_support' #for to_xml()
|
10
|
+
|
11
|
+
def usage
|
12
|
+
puts("#{$0} [--xml] [--json]")
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
opts = GetoptLong.new(
|
17
|
+
[ '--xml', '-x', GetoptLong::OPTIONAL_ARGUMENT ],
|
18
|
+
[ '--json', '-j', GetoptLong::OPTIONAL_ARGUMENT ],
|
19
|
+
[ '--api', '-a', GetoptLong::OPTIONAL_ARGUMENT ],
|
20
|
+
[ '--id', '-i', GetoptLong::OPTIONAL_ARGUMENT ]
|
21
|
+
)
|
22
|
+
|
23
|
+
json = false
|
24
|
+
xml = false
|
25
|
+
id = false
|
26
|
+
api_version = '1.0'
|
27
|
+
|
28
|
+
opts.each do |opt, arg|
|
29
|
+
case opt
|
30
|
+
when '--json'
|
31
|
+
json = true
|
32
|
+
when '--xml'
|
33
|
+
xml = true
|
34
|
+
when '--id'
|
35
|
+
id = arg
|
36
|
+
when '--api'
|
37
|
+
api_version = arg
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
unless id
|
42
|
+
puts 'No server array ID provided, exiting.'
|
43
|
+
usage
|
44
|
+
end
|
45
|
+
|
46
|
+
puts "Getting server array, #{id}."
|
47
|
+
unless api_version == '1.5'
|
48
|
+
array = Ec2ServerArray.find(id.to_i)
|
49
|
+
puts 'Fetching current array instances.'
|
50
|
+
array_instances = array.instances
|
51
|
+
else
|
52
|
+
array = McServerArray.find(id.to_i)
|
53
|
+
puts 'Fetching current array instances.'
|
54
|
+
array_instances = array.current_instances
|
55
|
+
end
|
56
|
+
puts array.to_yaml
|
57
|
+
|
58
|
+
if json
|
59
|
+
puts array_instances.to_json
|
60
|
+
elsif xml
|
61
|
+
puts JSON.parse(array_instances.to_json).to_xml(:root => 'ec2-instances', :skip_instruct => true)
|
62
|
+
else
|
63
|
+
puts array_instances.to_yaml
|
64
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# rs-get-server-monitoring
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'getoptlong'
|
7
|
+
require 'json'
|
8
|
+
require 'rest_connection'
|
9
|
+
require 'active_support' #for to_xml()
|
10
|
+
require 'xmlsimple'
|
11
|
+
|
12
|
+
def usage
|
13
|
+
puts("#{$0} [--xml] [--json]")
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
opts = GetoptLong.new(
|
18
|
+
[ '--name', '-n', GetoptLong::OPTIONAL_ARGUMENT ],
|
19
|
+
[ '--id', '-i', GetoptLong::OPTIONAL_ARGUMENT ],
|
20
|
+
[ '--xml', '-x', GetoptLong::OPTIONAL_ARGUMENT ],
|
21
|
+
[ '--json', '-j', GetoptLong::OPTIONAL_ARGUMENT ]
|
22
|
+
)
|
23
|
+
|
24
|
+
server_name = false
|
25
|
+
server_id = false
|
26
|
+
show_help = false
|
27
|
+
verbose = false
|
28
|
+
json = false
|
29
|
+
xml = false
|
30
|
+
|
31
|
+
opts.each do |opt, arg|
|
32
|
+
case opt
|
33
|
+
when '--name'
|
34
|
+
server_name = arg
|
35
|
+
when '--id'
|
36
|
+
server_id = arg
|
37
|
+
when '--json'
|
38
|
+
json = true
|
39
|
+
when '--xml'
|
40
|
+
xml = true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# get server
|
45
|
+
if server_name
|
46
|
+
puts "Finding server: '%#{server_name}%'"
|
47
|
+
server = Server.find(:first) { |s| s.nickname =~ /#{server_name}/ }
|
48
|
+
puts "Found server, '#{server.nickname}'."
|
49
|
+
puts server.to_yaml if verbose
|
50
|
+
elsif server_id
|
51
|
+
server = Server.find(server_id.to_i)
|
52
|
+
else
|
53
|
+
usage_exit
|
54
|
+
end
|
55
|
+
|
56
|
+
monitoring = server.monitoring
|
57
|
+
|
58
|
+
if json
|
59
|
+
puts monitoring.to_json
|
60
|
+
elsif xml
|
61
|
+
puts JSON.parse(monitoring.to_json).to_xml(:root => 'monitoring', :skip_instruct => true)
|
62
|
+
else
|
63
|
+
puts monitoring.to_yaml
|
64
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# rs-describe-deployments
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'getoptlong'
|
7
|
+
require 'json'
|
8
|
+
require 'rest_connection'
|
9
|
+
require 'active_support' #for to_xml()
|
10
|
+
require 'xmlsimple'
|
11
|
+
|
12
|
+
def usage
|
13
|
+
puts("#{$0} [--xml] [--json]")
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
opts = GetoptLong.new(
|
18
|
+
[ '--xml', '-x', GetoptLong::OPTIONAL_ARGUMENT ],
|
19
|
+
[ '--json', '-j', GetoptLong::OPTIONAL_ARGUMENT ]
|
20
|
+
)
|
21
|
+
|
22
|
+
json = false
|
23
|
+
xml = false
|
24
|
+
|
25
|
+
opts.each do |opt, arg|
|
26
|
+
case opt
|
27
|
+
when '--json'
|
28
|
+
json = true
|
29
|
+
when '--xml'
|
30
|
+
xml = true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
deployments = Deployment.find_all()
|
35
|
+
|
36
|
+
if json
|
37
|
+
puts deployments.to_json
|
38
|
+
elsif xml
|
39
|
+
puts JSON.parse(deployments.to_json).to_xml(:root => 'deployments', :skip_instruct => true)
|
40
|
+
else
|
41
|
+
puts deployments.to_yaml
|
42
|
+
end
|