bbgcli 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.md +30 -0
- data/Rakefile +1 -0
- data/bbgcli.gemspec +25 -0
- data/bin/bbgcli +30 -0
- data/lib/bbgapi/blocks.rb +43 -0
- data/lib/bbgapi/blocks_products.rb +36 -0
- data/lib/bbgapi/blocks_templates.rb +48 -0
- data/lib/bbgapi/client.rb +134 -0
- data/lib/bbgapi/config.rb +67 -0
- data/lib/bbgapi/lb_applications.rb +65 -0
- data/lib/bbgapi/lb_backends.rb +87 -0
- data/lib/bbgapi/lb_easy.rb +35 -0
- data/lib/bbgapi/lb_services.rb +99 -0
- data/lib/bbgapi/servers.rb +59 -0
- data/lib/bbgapi.rb +16 -0
- data/lib/bbgcli.rb +6 -0
- data/rebuild.sh +3 -0
- metadata +98 -0
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Summary
|
2
|
+
======
|
3
|
+
|
4
|
+
This is a command line interface for the blue box api.
|
5
|
+
|
6
|
+
Installing
|
7
|
+
-------
|
8
|
+
|
9
|
+
git clone git@github.com:petey5king/bbgcli.git
|
10
|
+
cd bbgcli
|
11
|
+
gem build bbgcli.gemspec
|
12
|
+
gem install bbgcli-0.0.1.gem
|
13
|
+
|
14
|
+
Running
|
15
|
+
-------
|
16
|
+
|
17
|
+
cd bbgcli
|
18
|
+
ruby bbgcli --api <opts here>
|
19
|
+
|
20
|
+
Initial code only allows for --api lb
|
21
|
+
|
22
|
+
|
23
|
+
Todo
|
24
|
+
----
|
25
|
+
|
26
|
+
* Finish load balancer commands other than list
|
27
|
+
* Start the servers api code
|
28
|
+
* Start the blocks api code
|
29
|
+
* Remember default ids in yaml
|
30
|
+
* Find a way to query the api url less for load concerns/speed
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bbgcli.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "bbgcli"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "bbgcli"
|
7
|
+
s.version = Bbgcli::VERSION
|
8
|
+
s.authors = ["Pete Shima"]
|
9
|
+
s.email = ["pete@kingofweb.com"]
|
10
|
+
s.homepage = "https://github.com/petey5king/bbgcli"
|
11
|
+
s.summary = %q{An interactive cli for the blue box api}
|
12
|
+
s.description = %q{An interactive cli for the blue box api in ruby}
|
13
|
+
|
14
|
+
s.rubyforge_project = "bbgcli"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency "trollop"
|
22
|
+
s.add_dependency "httparty"
|
23
|
+
s.add_dependency "highline"
|
24
|
+
|
25
|
+
end
|
data/bin/bbgcli
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bbgcli'
|
4
|
+
require 'trollop'
|
5
|
+
|
6
|
+
opts = Trollop::options do
|
7
|
+
version "bbgcli 0.0.1 - Pete Shima <pete@kingofweb.com>"
|
8
|
+
banner <<-EOS
|
9
|
+
This program gives you an interactive cli to the Blue Box Group api
|
10
|
+
|
11
|
+
Usage:
|
12
|
+
test [options] <filenames>+
|
13
|
+
where [options] are:
|
14
|
+
EOS
|
15
|
+
|
16
|
+
opt :api, "lb|blocks|servers", :type => String
|
17
|
+
opt :object, "Be interactive", :type => String
|
18
|
+
opt :action, "obkect action", :type => String
|
19
|
+
opt :item, "File to process", :type => String
|
20
|
+
opt :debug, "Debug Mode", :default => false
|
21
|
+
end
|
22
|
+
|
23
|
+
Trollop::die :api, "You must specify an API" if opts[:api] == ""
|
24
|
+
|
25
|
+
client = BBGAPI::Client.new("#{ENV['HOME']}/bluebox.yaml")
|
26
|
+
client.parseopt(opts[:api],opts[:action])
|
27
|
+
|
28
|
+
for i in 0..5
|
29
|
+
client.parseopt(opts[:api],opts[:action])
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module BBGAPI
|
2
|
+
class Blocks
|
3
|
+
def self.menulist
|
4
|
+
choose do |menu|
|
5
|
+
puts "Blocks"
|
6
|
+
puts "----------------------------------------"
|
7
|
+
menu.prompt = "Which Action?"
|
8
|
+
|
9
|
+
menu.choices(:list) {self.list}
|
10
|
+
menu.choices(:create) {self.tbi}
|
11
|
+
menu.choices(:update) {self.tbi}
|
12
|
+
menu.choices(:delete) {self.tbi}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.list
|
17
|
+
partial = '/api/blocks'
|
18
|
+
api_response = BBGAPI::Client.geturl(partial,"")
|
19
|
+
pp api_response
|
20
|
+
# apps = []
|
21
|
+
# api_response.each {|x|
|
22
|
+
# apps << {"name" => "#{x["name"]}","id" => "#{x["id"]}"}
|
23
|
+
# puts "\n"
|
24
|
+
# puts "Name: #{x["name"]}"
|
25
|
+
# puts "ID: #{x["id"]}"
|
26
|
+
# puts "Description: #{x["description"]}"
|
27
|
+
# puts "External IP: #{x["ip_v4"]}"
|
28
|
+
# puts "Internal IP: #{x["source_ip_v4"]}"
|
29
|
+
# puts "Created: #{x["created"]}"
|
30
|
+
# }
|
31
|
+
# puts "\n"
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
def self.tbi
|
39
|
+
puts "This is not yet implemented"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module BBGAPI
|
2
|
+
class Blocks_Products
|
3
|
+
def self.menulist
|
4
|
+
choose do |menu|
|
5
|
+
puts "Blocks"
|
6
|
+
puts "----------------------------------------"
|
7
|
+
menu.prompt = "Which Action?"
|
8
|
+
|
9
|
+
menu.choices(:list) {self.list}
|
10
|
+
menu.choices(:create) {self.tbi}
|
11
|
+
menu.choices(:update) {self.tbi}
|
12
|
+
menu.choices(:delete) {self.tbi}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.list
|
17
|
+
partial = '/api/block_products'
|
18
|
+
api_response = BBGAPI::Client.geturl(partial,"")
|
19
|
+
|
20
|
+
api_response.each {|x|
|
21
|
+
puts "\n"
|
22
|
+
puts "Cost: #{x["cost"]}"
|
23
|
+
puts "ID: #{x["id"]}"
|
24
|
+
puts "Description: #{x["description"]}"
|
25
|
+
}
|
26
|
+
puts "\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
def self.tbi
|
33
|
+
puts "This is not yet implemented"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module BBGAPI
|
2
|
+
class Blocks_Templates
|
3
|
+
def self.menulist
|
4
|
+
choose do |menu|
|
5
|
+
puts "Block Templates"
|
6
|
+
puts "----------------------------------------"
|
7
|
+
menu.prompt = "Which Action?"
|
8
|
+
|
9
|
+
menu.choices(:list) {self.list}
|
10
|
+
menu.choices(:create) {self.tbi}
|
11
|
+
menu.choices(:update) {self.tbi}
|
12
|
+
menu.choices(:delete) {self.tbi}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.list
|
17
|
+
partial = '/api/block_templates'
|
18
|
+
api_response = BBGAPI::Client.geturl(partial,"")
|
19
|
+
|
20
|
+
srv = api_response.find_all{|item| !item["public"] }
|
21
|
+
sorted = srv.sort_by {|a| a["created"]}.reverse
|
22
|
+
|
23
|
+
puts "Last 10 Images:"
|
24
|
+
|
25
|
+
sorted.each_with_index {|x,i|
|
26
|
+
break if i == 10;
|
27
|
+
puts "#{x["description"]} - #{x["id"]}"
|
28
|
+
}
|
29
|
+
puts "\n"
|
30
|
+
|
31
|
+
pubsrv = api_response.find_all{|item| item["public"] }
|
32
|
+
pubsorted = pubsrv.sort_by {|a| a["description"]}
|
33
|
+
|
34
|
+
puts "Public Images (limit 10):"
|
35
|
+
|
36
|
+
pubsorted.each_with_index {|x,i|
|
37
|
+
break if i == 10;
|
38
|
+
puts "#{x["description"]} - #{x["id"]}"
|
39
|
+
}
|
40
|
+
puts "\n"
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.tbi
|
45
|
+
puts "This is not yet implemented"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
|
2
|
+
module BBGAPI
|
3
|
+
class Client
|
4
|
+
|
5
|
+
API_URL = "https://boxpanel.bluebox.net"
|
6
|
+
include HTTParty
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def query(partial, request)
|
10
|
+
url = "#{@api_url}#{partial}"
|
11
|
+
response = get(url)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(config_file)
|
16
|
+
@config_file = config_file
|
17
|
+
@debug = false
|
18
|
+
end
|
19
|
+
|
20
|
+
def config
|
21
|
+
@config ||= Config.new(@config_file)
|
22
|
+
end
|
23
|
+
|
24
|
+
def load_credentials
|
25
|
+
@@credentials = {
|
26
|
+
:bluebox_customer_id => self.config["bluebox_customer_id"],
|
27
|
+
:bluebox_api_key => self.config["bluebox_api_key"]
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def debug!
|
32
|
+
@debug = true
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.help
|
36
|
+
puts "test"
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.geturl(partial, opts={})
|
40
|
+
url = "#{API_URL}#{partial}"
|
41
|
+
format :json
|
42
|
+
response = get(url)
|
43
|
+
if @debug
|
44
|
+
puts "Response Code: #{response.code}"
|
45
|
+
puts "Response RAW: #{response}"
|
46
|
+
end
|
47
|
+
response
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.posturl
|
51
|
+
# alternatively:
|
52
|
+
# raise NotImplementedError, "bla"
|
53
|
+
puts "bla"
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.puturl
|
57
|
+
# alternatively:
|
58
|
+
# raise NotImplementedError, "bla"
|
59
|
+
puts "bla"
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.lb_advanced
|
63
|
+
choose do |menu|
|
64
|
+
puts "Load Balancer API - http://bit.ly/ucbpDF"
|
65
|
+
puts "----------------------------------------"
|
66
|
+
menu.prompt = "Which Objects Would You Like? "
|
67
|
+
|
68
|
+
menu.choices(:applications) {BBGAPI::LB_Applications.menulist}
|
69
|
+
menu.choices(:services) {BBGAPI::LB_Services.menulist}
|
70
|
+
menu.choices(:backends) {BBGAPI::LB_Backends.menulist}
|
71
|
+
menu.choices(:machines)
|
72
|
+
menu.choices(:exit) {exit 0}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.blocks_advanced
|
77
|
+
choose do |menu|
|
78
|
+
puts "Load Balancer API - http://bit.ly/ucbpDF"
|
79
|
+
puts "----------------------------------------"
|
80
|
+
menu.prompt = "Which Objects Would You Like? "
|
81
|
+
|
82
|
+
menu.choices(:blocks) {BBGAPI::Blocks.menulist}
|
83
|
+
menu.choices(:templates) {BBGAPI::Blocks_Templates.menulist}
|
84
|
+
menu.choices(:products) {BBGAPI::Blocks_Products.menulist}
|
85
|
+
menu.choices(:exit) {exit 0}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def parseopt(type="",action="",id="")
|
90
|
+
ssh_key_file = File.new("#{ENV['HOME']}/.ssh/id_rsa.pub", "r")
|
91
|
+
keyfile = ssh_key_file.gets
|
92
|
+
self.class.basic_auth config[:bluebox_customer_id], config[:bluebox_api_key]
|
93
|
+
|
94
|
+
case type
|
95
|
+
when "lb"
|
96
|
+
choose do |menu|
|
97
|
+
puts "Load Balancer API - http://bit.ly/ucbpDF"
|
98
|
+
puts "----------------------------------------"
|
99
|
+
menu.prompt = "Easy or Advanced Mode? "
|
100
|
+
menu.choices(:open_documentation) {system("open", "http://bit.ly/ucbpDF")} #fuck windows anyway
|
101
|
+
menu.choices(:easy_mode) {BBGAPI::LB_Easy.menulist}
|
102
|
+
menu.choices(:advanced_mode) {BBGAPI::Client.lb_advanced}
|
103
|
+
menu.choices(:exit) {exit 0}
|
104
|
+
puts "\n"
|
105
|
+
end
|
106
|
+
when "blocks"
|
107
|
+
choose do |menu|
|
108
|
+
puts "Blocks API - http://bit.ly/v9FtWW"
|
109
|
+
puts "----------------------------------------"
|
110
|
+
menu.prompt = "Easy or Advanced Mode? "
|
111
|
+
menu.choices(:open_documentation) {system("open", "http://bit.ly/v9FtWW")} #fuck windows anyway
|
112
|
+
menu.choices(:easy_mode) {BBGAPI::LB_Easy.menulist}
|
113
|
+
menu.choices(:advanced_mode) {BBGAPI::Client.blocks_advanced}
|
114
|
+
menu.choices(:exit) {exit 0}
|
115
|
+
puts "\n"
|
116
|
+
end
|
117
|
+
when "servers"
|
118
|
+
choose do |menu|
|
119
|
+
puts "Servers API - http://bit.ly/uDd6wQ"
|
120
|
+
puts "----------------------------------------"
|
121
|
+
menu.prompt = "Which Objects Would You Like? "
|
122
|
+
menu.choices(:open_documentation) {system("open", "http://bit.ly/uDd6wQ")} #fuck windows anyway
|
123
|
+
menu.choices(:list) {BBGAPI::Servers.list}
|
124
|
+
menu.choices(:exit) {exit 0}
|
125
|
+
end
|
126
|
+
when "help"
|
127
|
+
help
|
128
|
+
else
|
129
|
+
"Invalid --api option, try --help"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#
|
2
|
+
# Thin wrapper for a YAML config file, whose interface is a Hash
|
3
|
+
# Probably could have subclassed Hash but for simplicity's sake,
|
4
|
+
# here we are.
|
5
|
+
#
|
6
|
+
|
7
|
+
module BBGAPI
|
8
|
+
class Config
|
9
|
+
|
10
|
+
# Constructor
|
11
|
+
# Try to load the config file and fall back to making one
|
12
|
+
def initialize(config_path)
|
13
|
+
# This somewhat violates the separation of concern as
|
14
|
+
# the Config class probably shouldn't have to deal with
|
15
|
+
# the user, but it maintains the original code intent.
|
16
|
+
@config_path = config_path
|
17
|
+
@config = {}
|
18
|
+
load || create
|
19
|
+
end
|
20
|
+
|
21
|
+
# Load a YAML config file
|
22
|
+
# * +config_path+ :: config file path
|
23
|
+
def load
|
24
|
+
begin
|
25
|
+
@config = YAML.load_file(@config_path)
|
26
|
+
rescue
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Save a YAML config file
|
32
|
+
# * +config_path+ :: config file path
|
33
|
+
def save
|
34
|
+
File.open(@config_path, 'w') do |out|
|
35
|
+
out.write(@config.to_yaml)
|
36
|
+
end
|
37
|
+
puts "Config file written, please rerun the app"
|
38
|
+
end
|
39
|
+
|
40
|
+
# Make a YAML config file
|
41
|
+
# * +config+ :: config file path
|
42
|
+
def create
|
43
|
+
puts "Blue Box Config File Not Found, let's create one..."
|
44
|
+
bbg_cust_id = ask("BBG Customer ID: ") { |q| q.default = "none" }
|
45
|
+
bbg_api_key = ask("BBG API Key: ") { |q| q.default = "none" }
|
46
|
+
|
47
|
+
puts "#{bbg_cust_id}:#{bbg_api_key}"
|
48
|
+
|
49
|
+
@config = {
|
50
|
+
'bluebox_customer_id' => bbg_cust_id,
|
51
|
+
'bluebox_api_key' => bbg_api_key
|
52
|
+
}
|
53
|
+
save
|
54
|
+
end
|
55
|
+
|
56
|
+
# A quick read accessor for the +@config+ hash
|
57
|
+
def [](key)
|
58
|
+
@config[key.to_s]
|
59
|
+
end
|
60
|
+
|
61
|
+
# A quick write accessor for the +@config+ hash
|
62
|
+
def []=(key, value)
|
63
|
+
@config[key.to_s] = value
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
module BBGAPI
|
3
|
+
class LB_Applications
|
4
|
+
|
5
|
+
def self.menulist
|
6
|
+
choose do |menu|
|
7
|
+
puts "Load Balancer Applications"
|
8
|
+
puts "----------------------------------------"
|
9
|
+
menu.prompt = "Which Action?"
|
10
|
+
|
11
|
+
menu.choices(:list) {self.list}
|
12
|
+
menu.choices(:create) {self.tbi}
|
13
|
+
menu.choices(:update) {self.tbi}
|
14
|
+
menu.choices(:delete) {self.tbi}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.list
|
19
|
+
partial = '/api/lb_applications'
|
20
|
+
api_response = BBGAPI::Client.geturl(partial,"")
|
21
|
+
apps = []
|
22
|
+
api_response.each {|x|
|
23
|
+
apps << {"name" => "#{x["name"]}","id" => "#{x["id"]}"}
|
24
|
+
puts "\n"
|
25
|
+
puts "Name: #{x["name"]}"
|
26
|
+
puts "ID: #{x["id"]}"
|
27
|
+
puts "Description: #{x["description"]}"
|
28
|
+
puts "External IP: #{x["ip_v4"]}"
|
29
|
+
puts "Internal IP: #{x["source_ip_v4"]}"
|
30
|
+
puts "Created: #{x["created"]}"
|
31
|
+
}
|
32
|
+
puts "\n"
|
33
|
+
|
34
|
+
choose do |menu|
|
35
|
+
menu.prompt = "Which App Should I Set as Default?"
|
36
|
+
apps.each {|k|
|
37
|
+
menu.choices(k["name"]) {self.set_app(k["id"])}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.get_app
|
43
|
+
return @@current_app
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.set_app (appid="")
|
47
|
+
@@current_app = appid
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.only_name_id
|
51
|
+
partial = '/api/lb_applications'
|
52
|
+
api_response = BBGAPI::Client.geturl(partial,"")
|
53
|
+
apps = []
|
54
|
+
api_response.each {|x|
|
55
|
+
apps << {"name" => "#{x["name"]}","id" => "#{x["id"]}"}
|
56
|
+
}
|
57
|
+
return apps
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.tbi
|
61
|
+
puts "This is not yet implemented"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module BBGAPI
|
2
|
+
class LB_Backends
|
3
|
+
|
4
|
+
def self.menulist
|
5
|
+
choose do |menu|
|
6
|
+
puts "Load Balancer Backends"
|
7
|
+
puts "----------------------------------------"
|
8
|
+
menu.prompt = "Which Action?"
|
9
|
+
menu.choices(:list) {self.list}
|
10
|
+
menu.choices(:create) {self.tbi}
|
11
|
+
menu.choices(:update) {self.tbi}
|
12
|
+
menu.choices(:delete) {self.tbi}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.recurse
|
17
|
+
apps = BBGAPI::LB_Applications.only_name_id
|
18
|
+
choose do |menu|
|
19
|
+
menu.prompt = "Which Application?"
|
20
|
+
apps.each {|k|
|
21
|
+
menu.choices(k["name"]) {
|
22
|
+
BBGAPI::LB_Applications.set_app(k["id"])
|
23
|
+
cur_app = k["id"]
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
services = BBGAPI::LB_Services.only_name_id
|
29
|
+
choose do |menu|
|
30
|
+
menu.prompt = "Which Service?"
|
31
|
+
services.each {|k|
|
32
|
+
menu.choices(k["name"]) {
|
33
|
+
BBGAPI::LB_Services.set_service(k["id"])
|
34
|
+
cur_service = k["id"]
|
35
|
+
}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.list
|
41
|
+
begin
|
42
|
+
cur_app = BBGAPI::LB_Applications.get_app
|
43
|
+
cur_service = BBGAPI::LB_Services.get_service
|
44
|
+
rescue
|
45
|
+
self.recurse
|
46
|
+
cur_app = BBGAPI::LB_Applications.get_app
|
47
|
+
cur_service = BBGAPI::LB_Services.get_service
|
48
|
+
end
|
49
|
+
|
50
|
+
partial = "/api/lb_services/#{cur_service}/lb_backends"
|
51
|
+
api_response = BBGAPI::Client.geturl(partial,"")
|
52
|
+
api_response.each {|x|
|
53
|
+
puts "\n"
|
54
|
+
puts "Name: #{x["backend_name"]}"
|
55
|
+
puts "ID: #{x["id"]}"
|
56
|
+
puts "Alive Check: #{x["monitoring_url"]}"
|
57
|
+
puts "Check Interval: #{x["check_interval"]}"
|
58
|
+
nodes = x["lb_machines"].sort_by {|var| var["hostname"]}
|
59
|
+
nodes.each {|y|
|
60
|
+
puts "App: #{y["hostname"]}"
|
61
|
+
}
|
62
|
+
}
|
63
|
+
puts "\n"
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def self.raw
|
68
|
+
begin
|
69
|
+
cur_app = BBGAPI::LB_Applications.get_app
|
70
|
+
cur_service = BBGAPI::LB_Services.get_service
|
71
|
+
rescue
|
72
|
+
self.recurse
|
73
|
+
cur_app = BBGAPI::LB_Applications.get_app
|
74
|
+
cur_service = BBGAPI::LB_Services.get_service
|
75
|
+
end
|
76
|
+
|
77
|
+
partial = "/api/lb_services/#{cur_service}/lb_backends"
|
78
|
+
api_response = BBGAPI::Client.geturl(partial,"")
|
79
|
+
return api_response
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.tbi
|
83
|
+
puts "This is not yet implemented"
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module BBGAPI
|
2
|
+
class LB_Easy
|
3
|
+
|
4
|
+
|
5
|
+
def self.menulist
|
6
|
+
choose do |menu|
|
7
|
+
puts "Load Balancer Easy Functions"
|
8
|
+
puts "----------------------------------------"
|
9
|
+
menu.prompt = "Which Action?"
|
10
|
+
|
11
|
+
menu.choices(:get_haproxy_login) {self.haproxy_login}
|
12
|
+
menu.choices(:find_machines_in_pool) {self.machines_in_pool}
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.haproxy_login
|
18
|
+
haproxy = BBGAPI::LB_Services.haproxyinfo
|
19
|
+
puts "-----Needs improvement but should work for now"
|
20
|
+
haproxy.each {|x|
|
21
|
+
puts "#{x["name"]} - URL: #{x["status_url"]} #{x["status_username"]}:#{x["status_password"]} "
|
22
|
+
}
|
23
|
+
puts "------------------"
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.machines_in_pool
|
27
|
+
nodes = BBGAPI::LB_Backends.raw
|
28
|
+
puts "\nNodes in Pool:\n"
|
29
|
+
nodes.first["lb_machines"].each {|x| puts "#{x["hostname"]}"}
|
30
|
+
puts "\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module BBGAPI
|
2
|
+
class LB_Services
|
3
|
+
|
4
|
+
def self.menulist
|
5
|
+
choose do |menu|
|
6
|
+
puts "Load Balancer Services"
|
7
|
+
puts "----------------------------------------"
|
8
|
+
menu.prompt = "Which Action?"
|
9
|
+
menu.choices(:list) {self.list}
|
10
|
+
menu.choices(:create) {self.tbi}
|
11
|
+
menu.choices(:update) {self.tbi}
|
12
|
+
menu.choices(:delete) {self.tbi}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get_service
|
17
|
+
return @@current_service
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.set_service (serviceid="")
|
21
|
+
@@current_service = serviceid
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.recurse
|
25
|
+
apps = BBGAPI::LB_Applications.only_name_id
|
26
|
+
choose do |menu|
|
27
|
+
menu.prompt = "Which Application?"
|
28
|
+
apps.each {|k|
|
29
|
+
menu.choices(k["name"]) {
|
30
|
+
BBGAPI::LB_Applications.set_app(k["id"])
|
31
|
+
cur_app = k["id"]
|
32
|
+
}
|
33
|
+
}
|
34
|
+
end
|
35
|
+
return BBGAPI::LB_Applications.get_app
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.list
|
39
|
+
begin
|
40
|
+
cur_app = BBGAPI::LB_Applications.get_app
|
41
|
+
rescue
|
42
|
+
cur_app = self.recurse
|
43
|
+
end
|
44
|
+
|
45
|
+
partial = "/api/lb_applications/#{cur_app}/lb_services"
|
46
|
+
api_response = BBGAPI::Client.geturl(partial,"")
|
47
|
+
api_response.each {|x|
|
48
|
+
puts "\n"
|
49
|
+
puts "Name: #{x["name"]}"
|
50
|
+
puts "ID: #{x["id"]}"
|
51
|
+
puts "Description: #{x["description"]}"
|
52
|
+
puts "Port: #{x["port"]}"
|
53
|
+
puts "Service Type: #{x["service_type"]}"
|
54
|
+
puts "Status URL: #{x["status_url"]}"
|
55
|
+
puts "Status User: #{x["status_username"]}"
|
56
|
+
puts "Status Pass: #{x["status_password"]}"
|
57
|
+
puts "Created: #{x["created"]}"
|
58
|
+
}
|
59
|
+
puts "\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.only_name_id
|
63
|
+
begin
|
64
|
+
cur_app = BBGAPI::LB_Applications.get_app
|
65
|
+
rescue
|
66
|
+
cur_app = self.recurse
|
67
|
+
end
|
68
|
+
|
69
|
+
partial = "/api/lb_applications/#{cur_app}/lb_services"
|
70
|
+
api_response = BBGAPI::Client.geturl(partial,"")
|
71
|
+
services = []
|
72
|
+
api_response.each {|x|
|
73
|
+
services << {"name" => "#{x["name"]}","id" => "#{x["id"]}"}
|
74
|
+
}
|
75
|
+
return services
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.haproxyinfo
|
79
|
+
begin
|
80
|
+
cur_app = BBGAPI::LB_Applications.get_app
|
81
|
+
rescue
|
82
|
+
cur_app = self.recurse
|
83
|
+
end
|
84
|
+
|
85
|
+
partial = "/api/lb_applications/#{cur_app}/lb_services"
|
86
|
+
api_response = BBGAPI::Client.geturl(partial,"")
|
87
|
+
haproxy = []
|
88
|
+
api_response.each {|x|
|
89
|
+
haproxy << {"name" => "#{x["name"]}","status_url" => "#{x["status_url"]}","status_username" => "#{x["status_username"]}","status_password" => "#{x["status_password"]}"}
|
90
|
+
}
|
91
|
+
return haproxy
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.tbi
|
95
|
+
puts "This is not yet implemented"
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module BBGAPI
|
2
|
+
class Servers
|
3
|
+
|
4
|
+
def self.menulist
|
5
|
+
choose do |menu|
|
6
|
+
puts "Servers"
|
7
|
+
puts "----------------------------------------"
|
8
|
+
menu.prompt = "Which Action?"
|
9
|
+
|
10
|
+
menu.choices(:list) {self.list}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.list
|
15
|
+
partial = '/api/servers'
|
16
|
+
api_response = BBGAPI::Client.geturl(partial,"")
|
17
|
+
nodes = api_response.sort_by {|var| var["hostname"]}
|
18
|
+
nodes.each {|x|
|
19
|
+
puts "\n"
|
20
|
+
puts "Name: #{x["hostname"]}"
|
21
|
+
puts "ID: #{x["id"]}"
|
22
|
+
puts "Description: #{x["description"]}"
|
23
|
+
puts "IP: #{x["ips"].first["address"]}"
|
24
|
+
puts "Status: #{x["status"]}"
|
25
|
+
}
|
26
|
+
puts "\n"
|
27
|
+
|
28
|
+
choose do |menu|
|
29
|
+
menu.prompt = "Would you like to list extended information?"
|
30
|
+
|
31
|
+
menu.choices(:yes) {self.fulllist}
|
32
|
+
menu.choices(:no)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.fulllist
|
37
|
+
partial = '/api/servers'
|
38
|
+
api_response = BBGAPI::Client.geturl(partial,"")
|
39
|
+
nodes = api_response.sort_by {|var| var["hostname"]}
|
40
|
+
nodes.each {|x|
|
41
|
+
puts "\n"
|
42
|
+
puts "Name: #{x["hostname"]}"
|
43
|
+
puts "ID: #{x["id"]}"
|
44
|
+
puts "Description: #{x["description"]}"
|
45
|
+
puts "IP: #{x["ips"].first["address"]}"
|
46
|
+
puts "Status: #{x["status"]}"
|
47
|
+
puts "CPU: #{x["cpu"]}"
|
48
|
+
puts "Memory: #{x["memory"]}"
|
49
|
+
puts "Storage: #{x["storage"]}"
|
50
|
+
puts "Load Balancers:"
|
51
|
+
x["lb_applications"].each {|y|
|
52
|
+
puts y["lb_application_name"]
|
53
|
+
}
|
54
|
+
}
|
55
|
+
puts "\n"
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/bbgapi.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'highline'
|
4
|
+
require 'highline/import'
|
5
|
+
require 'httparty'
|
6
|
+
require 'yaml'
|
7
|
+
require 'bbgapi/client'
|
8
|
+
require 'bbgapi/config'
|
9
|
+
require 'bbgapi/lb_applications'
|
10
|
+
require 'bbgapi/lb_backends'
|
11
|
+
require 'bbgapi/lb_services'
|
12
|
+
require 'bbgapi/lb_easy'
|
13
|
+
require 'bbgapi/servers'
|
14
|
+
require 'bbgapi/blocks'
|
15
|
+
require 'bbgapi/blocks_products'
|
16
|
+
require 'bbgapi/blocks_templates'
|
data/lib/bbgcli.rb
ADDED
data/rebuild.sh
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bbgcli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pete Shima
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-03 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: trollop
|
16
|
+
requirement: &2157983860 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2157983860
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: httparty
|
27
|
+
requirement: &2157983320 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2157983320
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: highline
|
38
|
+
requirement: &2157982780 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2157982780
|
47
|
+
description: An interactive cli for the blue box api in ruby
|
48
|
+
email:
|
49
|
+
- pete@kingofweb.com
|
50
|
+
executables:
|
51
|
+
- bbgcli
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- bbgcli.gemspec
|
60
|
+
- bin/bbgcli
|
61
|
+
- lib/bbgapi.rb
|
62
|
+
- lib/bbgapi/blocks.rb
|
63
|
+
- lib/bbgapi/blocks_products.rb
|
64
|
+
- lib/bbgapi/blocks_templates.rb
|
65
|
+
- lib/bbgapi/client.rb
|
66
|
+
- lib/bbgapi/config.rb
|
67
|
+
- lib/bbgapi/lb_applications.rb
|
68
|
+
- lib/bbgapi/lb_backends.rb
|
69
|
+
- lib/bbgapi/lb_easy.rb
|
70
|
+
- lib/bbgapi/lb_services.rb
|
71
|
+
- lib/bbgapi/servers.rb
|
72
|
+
- lib/bbgcli.rb
|
73
|
+
- rebuild.sh
|
74
|
+
homepage: https://github.com/petey5king/bbgcli
|
75
|
+
licenses: []
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project: bbgcli
|
94
|
+
rubygems_version: 1.8.11
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: An interactive cli for the blue box api
|
98
|
+
test_files: []
|