bbgcli 0.0.2 → 0.0.3

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/README.md CHANGED
@@ -6,25 +6,59 @@ This is a command line interface for the blue box api.
6
6
  Installing
7
7
  -------
8
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
9
+ gem install bbgcli
13
10
 
14
11
  Running
15
12
  -------
16
13
 
17
- cd bbgcli
18
- ruby bbgcli --api <opts here>
14
+ bbgcli --api <lb|servers|blocks>
19
15
 
20
- Initial code only allows for --api lb
16
+ Setup
17
+ -------
18
+
19
+ To setup bbcli with your blue box api credentials just run the app.
20
+
21
+ bash$ bbgcli --api lb
22
+ Blue Box Config File Not Found, let's create one...
23
+ BBG Customer ID: |none| <enter customer id here>
24
+ BBG API Key: |none| <enter api key here>
25
+ Config file written, please rerun the app
26
+
27
+ Interactive interface
28
+ -------
29
+ bash$ bbgcli --api lb
30
+ Load Balancer API - http://bit.ly/ucbpDF
31
+ ----------------------------------------
21
32
 
33
+ 1. open_documentation
34
+ 2. easy_mode
35
+ 3. advanced_mode
36
+ 4. exit
37
+ Easy or Advanced Mode?
38
+
39
+ Advanced Mode:
40
+
41
+ Load Balancer API - http://bit.ly/ucbpDF
42
+ ----------------------------------------
43
+ 1. applications
44
+ 2. services
45
+ 3. backends
46
+ 4. machines
47
+ 5. exit
48
+
49
+ And More!
50
+
51
+ Version 0.0.2
52
+ -------
53
+ * Added initial blocks code
54
+ * Added initial servers code which is complete
55
+ * Added easy mode and advanced mode
22
56
 
23
57
  Todo
24
58
  ----
25
59
 
26
60
  * Finish load balancer commands other than list
27
- * Start the servers api code
28
- * Start the blocks api code
61
+ * Finish blocks commands other than list
29
62
  * Remember default ids in yaml
30
63
  * Find a way to query the api url less for load concerns/speed
64
+ * Safety checks against production
data/bin/bbgcli CHANGED
@@ -4,27 +4,15 @@ require 'bbgcli'
4
4
  require 'trollop'
5
5
 
6
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
7
  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
8
  opt :debug, "Debug Mode", :default => false
21
9
  end
22
10
 
23
- Trollop::die :api, "You must specify an API" if opts[:api] == ""
11
+ Trollop::die :api, "You must specify an --api parameter" if !opts[:api]
24
12
 
25
- client = BBGAPI::Client.new("#{ENV['HOME']}/bluebox.yaml")
13
+ client = BBGAPI::Client.new("#{ENV['HOME']}/.bbgcli")
26
14
  client.parseopt(opts[:api],opts[:action])
27
15
 
28
- for i in 0..5
16
+ for i in 0..25
29
17
  client.parseopt(opts[:api],opts[:action])
30
18
  end
data/lib/bbgapi/blocks.rb CHANGED
@@ -7,8 +7,7 @@ module BBGAPI
7
7
  menu.prompt = "Which Action?"
8
8
 
9
9
  menu.choices(:list) {self.list}
10
- menu.choices(:create) {self.tbi}
11
- menu.choices(:update) {self.tbi}
10
+ menu.choices(:create) {self.create}
12
11
  menu.choices(:delete) {self.tbi}
13
12
  end
14
13
  end
@@ -32,11 +31,70 @@ module BBGAPI
32
31
 
33
32
  end
34
33
 
34
+ def self.raw
35
+ partial = '/api/blocks'
36
+ api_response = BBGAPI::Client.geturl(partial,"")
37
+ return api_response
38
+ end
39
+
40
+ def self.productmenu
41
+ products = BBGAPI::Blocks_Products.raw
42
+ choose do |menu|
43
+ menu.prompt = "Which Product Would You Like?"
44
+ products.each {|product|
45
+ menu.choices(product["description"]) {return product["id"]}
46
+ }
47
+ end
48
+ end
49
+
50
+ def self.templatemenu
51
+ templates = BBGAPI::Blocks_Templates.raw
52
+ choose do |menu|
53
+ menu.prompt = "Which Template Would You Like?"
54
+ templates.each {|template|
55
+ menu.choices(template["description"]) {return template["id"]}
56
+ }
57
+ end
58
+ end
59
+
60
+ def self.create
61
+ productid = self.productmenu
62
+ templateid = self.templatemenu
63
+ ssh_key_file = File.new("#{ENV['HOME']}/.ssh/id_rsa.pub", "r")
64
+ keyfile = ssh_key_file.gets
65
+ hostname = ask("Hostname: ")
35
66
 
67
+ options = { :body => {
68
+ :product => productid,
69
+ :template => templateid,
70
+ :ssh_public_key => keyfile,
71
+ :hostname => hostname
72
+ } }
73
+
74
+ partial = '/api/blocks'
75
+ api_response = BBGAPI::Client.posturl(partial,options)
76
+ if api_response.code == 200
77
+ puts "Name: #{api_response["hostname"]}"
78
+ puts "IP: #{api_response["ips"].first["address"]}"
79
+ puts "Status: #{api_response["status"]}"
80
+ puts "\n"
81
+ choose do |menu|
82
+ menu.prompt = "Do you want to ssh to this new server?"
83
+ menu.choices(:yes) {
84
+ puts "sleeping 5 minutes" # really 3 minutes but will feel like 5.
85
+ sleep 180
86
+ system("open", "ssh://deploy@#{api_response["ips"].first["address"]}")
87
+ }
88
+ menu.choices(:no)
89
+ end
90
+ else
91
+ puts "Recieved a #{api_response.code} to the request"
92
+ end
93
+ end
36
94
 
37
95
 
38
96
  def self.tbi
39
- puts "This is not yet implemented"
97
+ puts "This is not yet implemented\n"
40
98
  end
41
99
 
42
100
  end
@@ -26,7 +26,11 @@ module BBGAPI
26
26
  puts "\n"
27
27
  end
28
28
 
29
-
29
+ def self.raw
30
+ partial = '/api/block_products'
31
+ api_response = BBGAPI::Client.geturl(partial,"")
32
+ return api_response
33
+ end
30
34
 
31
35
 
32
36
  def self.tbi
@@ -7,7 +7,7 @@ module BBGAPI
7
7
  menu.prompt = "Which Action?"
8
8
 
9
9
  menu.choices(:list) {self.list}
10
- menu.choices(:create) {self.tbi}
10
+ menu.choices(:create) {self.create}
11
11
  menu.choices(:update) {self.tbi}
12
12
  menu.choices(:delete) {self.tbi}
13
13
  end
@@ -41,6 +41,50 @@ module BBGAPI
41
41
 
42
42
  end
43
43
 
44
+ def self.blocksmenu
45
+ choose do |menu|
46
+ menu.prompt = "Are you templating a VPS or a Block?"
47
+
48
+ menu.choices(:vps) {
49
+ vpslist = BBGAPI::Servers.raw
50
+ choose do |vpsmenu|
51
+ vpsmenu.prompt = "Which VPS?"
52
+ vpslist.each {|vps|
53
+ vpsmenu.choices(vps["hostname"]) {return vps["id"]}
54
+ }
55
+ end
56
+ }
57
+ menu.choices(:block) {
58
+ vpslist = BBGAPI::Blocks.raw
59
+ choose do |vpsmenu|
60
+ vpsmenu.prompt = "Which Block?"
61
+ vpslist.each {|vps|
62
+ vpsmenu.choices(vps["hostname"]) {return vps["id"]}
63
+ }
64
+ end
65
+ }
66
+ end
67
+ end
68
+
69
+ def self.create
70
+ blockid = self.blocksmenu
71
+
72
+ options = { :body => {
73
+ :id => blockid
74
+ } }
75
+
76
+ partial = '/api/block_templates'
77
+ api_response = BBGAPI::Client.posturl(partial,options)
78
+ puts "#{api_response["text"]}"
79
+ end
80
+
81
+ def self.raw
82
+ partial = '/api/block_templates'
83
+ api_response = BBGAPI::Client.geturl(partial,"")
84
+ sorted = api_response.sort_by {|a| a["created"]}.reverse
85
+ return sorted
86
+ end
87
+
44
88
  def self.tbi
45
89
  puts "This is not yet implemented"
46
90
  end
data/lib/bbgapi/client.rb CHANGED
@@ -38,8 +38,22 @@ module BBGAPI
38
38
 
39
39
  def self.geturl(partial, opts={})
40
40
  url = "#{API_URL}#{partial}"
41
- format :json
41
+
42
42
  response = get(url)
43
+
44
+ puts response.code
45
+
46
+ if response.code == 401
47
+ puts "Access denied. Bad Customer Number or API Key."
48
+ exit 0
49
+ end
50
+
51
+ if response.code != 200
52
+ puts "Response code is #{response.code}"
53
+ puts response
54
+ exit 0
55
+ end
56
+
43
57
  if @debug
44
58
  puts "Response Code: #{response.code}"
45
59
  puts "Response RAW: #{response}"
@@ -47,12 +61,18 @@ module BBGAPI
47
61
  response
48
62
  end
49
63
 
50
- def self.posturl
51
- # alternatively:
52
- # raise NotImplementedError, "bla"
53
- puts "bla"
64
+ def self.posturl(partial, opts={})
65
+ url = "#{API_URL}#{partial}"
66
+ response = post(url,opts)
67
+ return response
54
68
  end
55
69
 
70
+ def self.deleteurl(partial)
71
+ url = "#{API_URL}#{partial}"
72
+ response = delete(url)
73
+ return response
74
+ end
75
+
56
76
  def self.puturl
57
77
  # alternatively:
58
78
  # raise NotImplementedError, "bla"
data/lib/bbgapi/config.rb CHANGED
@@ -35,6 +35,7 @@ module BBGAPI
35
35
  out.write(@config.to_yaml)
36
36
  end
37
37
  puts "Config file written, please rerun the app"
38
+ exit 0
38
39
  end
39
40
 
40
41
  # Make a YAML config file
@@ -9,9 +9,9 @@ module BBGAPI
9
9
  menu.prompt = "Which Action?"
10
10
 
11
11
  menu.choices(:list) {self.list}
12
- menu.choices(:create) {self.tbi}
12
+ menu.choices(:create) {self.create}
13
13
  menu.choices(:update) {self.tbi}
14
- menu.choices(:delete) {self.tbi}
14
+ menu.choices(:delete) {self.delete}
15
15
  end
16
16
  end
17
17
 
@@ -30,15 +30,46 @@ module BBGAPI
30
30
  puts "Created: #{x["created"]}"
31
31
  }
32
32
  puts "\n"
33
+ end
34
+
35
+ def self.create
36
+ app_name = ask("Specify a name for the new app: ")
37
+ options = { :body => {
38
+ :name => app_name
39
+ } }
40
+ partial = '/api/lb_applications'
41
+ api_response = BBGAPI::Client.posturl(partial,options)
42
+ puts "App Created!"
43
+ puts "Name: #{api_response["name"]}"
44
+ puts "ID: #{api_response["id"]}"
45
+ puts "External IP: #{api_response["ip_v4"]}"
46
+ puts "Internal IP: #{api_response["source_ip"]}"
47
+ end
33
48
 
49
+ def self.delete
50
+ raw_apps = self.raw
34
51
  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"])}
52
+ menu.prompt = "Which App To Delete?"
53
+ raw_apps.each {|app|
54
+ menu.choices(app["name"]) {self.delete_confirm(app["name"],app["id"])}
38
55
  }
39
56
  end
40
57
  end
41
58
 
59
+ def self.delete_confirm(name,id)
60
+ choose do |menu|
61
+ menu.prompt = "Are you sure you want to delete app #{name}?"
62
+
63
+ menu.choices(:yes) {
64
+ partial = "/api/lb_applications/#{id}"
65
+ api_response = BBGAPI::Client.deleteurl(partial)
66
+ pp api_response
67
+ }
68
+ menu.choices(:no)
69
+ end
70
+
71
+ end
72
+
42
73
  def self.get_app
43
74
  return @@current_app
44
75
  end
@@ -47,6 +78,12 @@ module BBGAPI
47
78
  @@current_app = appid
48
79
  end
49
80
 
81
+ def self.raw
82
+ partial = '/api/lb_applications'
83
+ api_response = BBGAPI::Client.geturl(partial,"")
84
+ return api_response
85
+ end
86
+
50
87
  def self.only_name_id
51
88
  partial = '/api/lb_applications'
52
89
  api_response = BBGAPI::Client.geturl(partial,"")
@@ -7,7 +7,6 @@ module BBGAPI
7
7
  puts "----------------------------------------"
8
8
  menu.prompt = "Which Action?"
9
9
  menu.choices(:list) {self.list}
10
- menu.choices(:create) {self.tbi}
11
10
  menu.choices(:update) {self.tbi}
12
11
  menu.choices(:delete) {self.tbi}
13
12
  end
@@ -63,7 +62,6 @@ module BBGAPI
63
62
  puts "\n"
64
63
  end
65
64
 
66
-
67
65
  def self.raw
68
66
  begin
69
67
  cur_app = BBGAPI::LB_Applications.get_app
@@ -59,6 +59,59 @@ module BBGAPI
59
59
  puts "\n"
60
60
  end
61
61
 
62
+ def self.create
63
+ begin
64
+ cur_app = BBGAPI::LB_Applications.get_app
65
+ rescue
66
+ cur_app = self.recurse
67
+ end
68
+
69
+ choose do |menu|
70
+ menu.prompt = "HTTP or HTTPS?"
71
+ menu.choices(:http) {service_type="http"}
72
+ menu.choices(:https) {service_type="https"}
73
+ end
74
+
75
+ options = { :body => {
76
+ :service_type => service_type
77
+ } }
78
+
79
+ partial = "/api/lb_applications/#{cur_app}/lb_services"
80
+ api_response = BBGAPI::Client.posturl(partial,options)
81
+ pp api_response
82
+ #puts "Name: #{api_response["name"]}"
83
+
84
+ puts "\n"
85
+ end
86
+
87
+ def self.delete
88
+ raw_services = self.raw
89
+ choose do |menu|
90
+ menu.prompt = "Which Service To Delete?"
91
+ raw_services.each {|service|
92
+ menu.choices(service["name"]) {self.delete_confirm(service["name"],service["id"])}
93
+ }
94
+ end
95
+ end
96
+
97
+ def self.delete_confirm(name,id)
98
+ begin
99
+ cur_app = BBGAPI::LB_Applications.get_app
100
+ rescue
101
+ cur_app = self.recurse
102
+ end
103
+
104
+ choose do |menu|
105
+ menu.prompt = "Are you sure you want to delete service #{name}?"
106
+ menu.choices(:yes) {
107
+ partial = "/api/lb_applications/#{cur_app}/lb_services/#{id}"
108
+ api_response = BBGAPI::Client.deleteurl(partial)
109
+ pp api_response
110
+ }
111
+ menu.choices(:no)
112
+ end
113
+ end
114
+
62
115
  def self.only_name_id
63
116
  begin
64
117
  cur_app = BBGAPI::LB_Applications.get_app
@@ -75,6 +128,19 @@ module BBGAPI
75
128
  return services
76
129
  end
77
130
 
131
+ def self.raw
132
+ begin
133
+ cur_app = BBGAPI::LB_Applications.get_app
134
+ rescue
135
+ cur_app = self.recurse
136
+ end
137
+
138
+ partial = "/api/lb_applications/#{cur_app}/lb_services"
139
+ api_response = BBGAPI::Client.geturl(partial,"")
140
+ return api_response
141
+ end
142
+
143
+
78
144
  def self.haproxyinfo
79
145
  begin
80
146
  cur_app = BBGAPI::LB_Applications.get_app
@@ -33,6 +33,13 @@ module BBGAPI
33
33
  end
34
34
  end
35
35
 
36
+ def self.raw
37
+ partial = '/api/servers'
38
+ api_response = BBGAPI::Client.geturl(partial,"")
39
+ nodes = api_response.sort_by {|var| var["hostname"]}
40
+ return nodes
41
+ end
42
+
36
43
  def self.fulllist
37
44
  partial = '/api/servers'
38
45
  api_response = BBGAPI::Client.geturl(partial,"")
data/lib/bbgcli.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  require 'bbgapi'
3
3
 
4
4
  module Bbgcli
5
- VERSION = "0.0.2"
5
+ VERSION = "0.0.3"
6
6
  end
data/rebuild.sh CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/bin/bash
2
2
  gem build bbgcli.gemspec
3
- gem install bbgcli-0.0.2.gem
3
+ gem install bbgcli-0.0.3.gem
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbgcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-03 00:00:00.000000000Z
12
+ date: 2011-11-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trollop
16
- requirement: &2157983860 !ruby/object:Gem::Requirement
16
+ requirement: &2167305860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2157983860
24
+ version_requirements: *2167305860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &2157983320 !ruby/object:Gem::Requirement
27
+ requirement: &2167305360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2157983320
35
+ version_requirements: *2167305360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: highline
38
- requirement: &2157982780 !ruby/object:Gem::Requirement
38
+ requirement: &2167304920 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2157982780
46
+ version_requirements: *2167304920
47
47
  description: An interactive cli for the blue box api in ruby
48
48
  email:
49
49
  - pete@kingofweb.com