bbgcli 0.0.3 → 0.0.4

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/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2011 Pete Shima
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md CHANGED
@@ -1,13 +1,19 @@
1
1
  Summary
2
2
  ======
3
3
 
4
- This is a command line interface for the blue box api.
4
+ This is a command line interface for the blue box api. This is currently used in production but use at your own risk!
5
5
 
6
6
  Installing
7
7
  -------
8
8
 
9
9
  gem install bbgcli
10
10
 
11
+ Upgrading
12
+ -------
13
+
14
+ rm ~/.bbgcli (or move somewhere for key backup)
15
+ gem install bbgcli
16
+
11
17
  Running
12
18
  -------
13
19
 
@@ -48,6 +54,25 @@ Interactive interface
48
54
 
49
55
  And More!
50
56
 
57
+
58
+ Version 0.0.4
59
+ -------
60
+ * Blocks API listing now shows formatted output
61
+ * New server creation on blocks now prompts for ssh, bootstrap and load balancer additions after server startup
62
+ * Bootstrap and load balancer additions require specific files present on machine and executes them remotely. Examples to be provided later.
63
+ * Gemspec updated to include new net:ssh requirement
64
+ * Fixed server sleep time to actually be 5 minutes before boot. 3 minutes would typically fail.
65
+
66
+
67
+ Version 0.0.3
68
+ -------
69
+ * Create and delete load balancer applications
70
+ * Create and delete load balancer services
71
+ * Fixed showing help if no command line options are given
72
+ * Create blocks from templates
73
+ * Create templates from VPS or Blocks
74
+
75
+
51
76
  Version 0.0.2
52
77
  -------
53
78
  * Added initial blocks code
@@ -58,7 +83,11 @@ Todo
58
83
  ----
59
84
 
60
85
  * Finish load balancer commands other than list
86
+ * More error checking
61
87
  * Finish blocks commands other than list
62
88
  * Remember default ids in yaml
89
+ * Add additional configuration options for noting production setups and prompt user for initial config
63
90
  * Find a way to query the api url less for load concerns/speed
64
91
  * Safety checks against production
92
+
93
+
@@ -21,5 +21,6 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency "trollop"
22
22
  s.add_dependency "httparty"
23
23
  s.add_dependency "highline"
24
+ s.add_dependency "net-ssh"
24
25
 
25
26
  end
data/bin/bbgcli CHANGED
@@ -10,7 +10,9 @@ end
10
10
 
11
11
  Trollop::die :api, "You must specify an --api parameter" if !opts[:api]
12
12
 
13
- client = BBGAPI::Client.new("#{ENV['HOME']}/.bbgcli")
13
+ configpath="#{ENV['HOME']}/.bbgcli"
14
+
15
+ client = BBGAPI::Client.new(configpath)
14
16
  client.parseopt(opts[:api],opts[:action])
15
17
 
16
18
  for i in 0..25
@@ -4,6 +4,7 @@ require 'highline'
4
4
  require 'highline/import'
5
5
  require 'httparty'
6
6
  require 'yaml'
7
+ require 'net/ssh'
7
8
  require 'bbgapi/client'
8
9
  require 'bbgapi/config'
9
10
  require 'bbgapi/lb_applications'
@@ -15,19 +15,28 @@ module BBGAPI
15
15
  def self.list
16
16
  partial = '/api/blocks'
17
17
  api_response = BBGAPI::Client.geturl(partial,"")
18
- pp api_response
19
- # apps = []
20
- # api_response.each {|x|
21
- # apps << {"name" => "#{x["name"]}","id" => "#{x["id"]}"}
22
- # puts "\n"
23
- # puts "Name: #{x["name"]}"
24
- # puts "ID: #{x["id"]}"
25
- # puts "Description: #{x["description"]}"
26
- # puts "External IP: #{x["ip_v4"]}"
27
- # puts "Internal IP: #{x["source_ip_v4"]}"
28
- # puts "Created: #{x["created"]}"
29
- # }
30
- # puts "\n"
18
+
19
+ api_response.each {|x|
20
+ puts "\n"
21
+ puts "Name: #{x["hostname"]}"
22
+ puts "ID: #{x["id"]}"
23
+ puts "External IP: #{x["ips"].first["address"]}"
24
+ if !x["lb_applications"].empty?
25
+ puts "LB App: #{x["lb_applications"].first["lb_application_name"]}"
26
+ end
27
+ }
28
+ puts "\n"
29
+
30
+ end
31
+
32
+ def self.find_id_from_name
33
+ partial = '/api/blocks'
34
+ api_response = BBGAPI::Client.geturl(partial,"")
35
+
36
+ machines=api_response.first["lb_machines"]
37
+ hostname = "#{id}.c45451"
38
+ srv = machines.find_all{|item| item["hostname"] == hostname }
39
+ srv_id = srv.first["id"]
31
40
 
32
41
  end
33
42
 
@@ -78,17 +87,57 @@ module BBGAPI
78
87
  puts "IP: #{api_response["ips"].first["address"]}"
79
88
  puts "Status: #{api_response["status"]}"
80
89
  puts "\n"
90
+ puts "Sleeping 5 minutes while server boots up"
91
+ sleep 300
81
92
  choose do |menu|
82
93
  menu.prompt = "Do you want to ssh to this new server?"
83
94
  menu.choices(:yes) {
84
- puts "sleeping 5 minutes" # really 3 minutes but will feel like 5.
85
- sleep 180
86
95
  system("open", "ssh://deploy@#{api_response["ips"].first["address"]}")
87
96
  }
88
97
  menu.choices(:no)
89
98
  end
99
+ choose do |menu|
100
+ menu.prompt = "Do you want to bootstrap this new server?"
101
+ menu.choices(:yes) {
102
+
103
+ ssh_host = api_response["ips"].first["address"]
104
+ ssh_user = 'deploy'
105
+
106
+ begin
107
+ Net::SSH.start( ssh_host, ssh_user ) do|ssh|
108
+ output = ssh.exec('sudo chmod +x /root/bootstrap.sh && sudo /root/bootstrap.sh')
109
+ puts output
110
+ end
111
+ rescue Net::SSH::HostKeyMismatch => e
112
+ puts "remembering new key: #{e.fingerprint}"
113
+ e.remember_host!
114
+ retry
115
+ end
116
+ }
117
+ menu.choices(:no)
118
+ end
119
+ choose do |menu|
120
+ menu.prompt = "Do you want to add this machine to a load balanced pool?"
121
+ menu.choices(:yes) {
122
+
123
+ ssh_host = api_response["ips"].first["address"]
124
+ ssh_user = 'deploy'
125
+
126
+ begin
127
+ Net::SSH.start( ssh_host, ssh_user ) do|ssh|
128
+ output = ssh.exec('sudo chmod +x /root/tools/lb_add.sh && sudo /root/tools/lb_add.sh autoadd')
129
+ puts output
130
+ end
131
+ rescue Net::SSH::HostKeyMismatch => e
132
+ puts "remembering new key: #{e.fingerprint}"
133
+ e.remember_host!
134
+ retry
135
+ end
136
+ }
137
+ menu.choices(:no)
138
+ end
90
139
  else
91
- puts "Recieved a #{api_response.code} to the request"
140
+ #puts "Recieved a #{api_response.code} to the request"
92
141
  end
93
142
  end
94
143
 
@@ -1,5 +1,7 @@
1
1
 
2
2
  module BBGAPI
3
+ @dnssuffix = '.blueboxgrid.com'
4
+
3
5
  class Client
4
6
 
5
7
  API_URL = "https://boxpanel.bluebox.net"
@@ -28,6 +30,10 @@ module BBGAPI
28
30
  }
29
31
  end
30
32
 
33
+ # def self.configload
34
+ # configload = Config.new(@config_file)
35
+ # end
36
+
31
37
  def debug!
32
38
  @debug = true
33
39
  end
@@ -41,7 +47,7 @@ module BBGAPI
41
47
 
42
48
  response = get(url)
43
49
 
44
- puts response.code
50
+ #puts response.code
45
51
 
46
52
  if response.code == 401
47
53
  puts "Access denied. Bad Customer Number or API Key."
@@ -118,7 +124,7 @@ module BBGAPI
118
124
  puts "----------------------------------------"
119
125
  menu.prompt = "Easy or Advanced Mode? "
120
126
  menu.choices(:open_documentation) {system("open", "http://bit.ly/ucbpDF")} #fuck windows anyway
121
- menu.choices(:easy_mode) {BBGAPI::LB_Easy.menulist}
127
+ menu.choices(:easy_mode) {BBGAPI::LB_Easy.menulist(self.config)}
122
128
  menu.choices(:advanced_mode) {BBGAPI::Client.lb_advanced}
123
129
  menu.choices(:exit) {exit 0}
124
130
  puts "\n"
@@ -62,6 +62,12 @@ module BBGAPI
62
62
  puts "\n"
63
63
  end
64
64
 
65
+
66
+ def self.add_from_bootstrap(serverid,lbid)
67
+ puts "Server ID:#{serverid}"
68
+ puts "LB ID:#{lbid}"
69
+ end
70
+
65
71
  def self.raw
66
72
  begin
67
73
  cur_app = BBGAPI::LB_Applications.get_app
@@ -1,8 +1,10 @@
1
1
  module BBGAPI
2
2
  class LB_Easy
3
3
 
4
-
5
- def self.menulist
4
+ def self.menulist(config)
5
+ @@config = config
6
+ #["bluebox_customer_id"]
7
+ puts BBGAPI.dnssuffix
6
8
  choose do |menu|
7
9
  puts "Load Balancer Easy Functions"
8
10
  puts "----------------------------------------"
@@ -10,6 +12,7 @@ module BBGAPI
10
12
 
11
13
  menu.choices(:get_haproxy_login) {self.haproxy_login}
12
14
  menu.choices(:find_machines_in_pool) {self.machines_in_pool}
15
+ menu.choices(:remove_machine_in_pool) {self.remove_machine_in_pool}
13
16
 
14
17
  end
15
18
  end
@@ -30,6 +33,10 @@ module BBGAPI
30
33
  puts "\n"
31
34
  end
32
35
 
36
+ def self.remove_machine_in_pool
37
+ puts "Not yet implemented."
38
+ end
39
+
33
40
 
34
41
  end
35
42
  end
@@ -19,9 +19,9 @@ module BBGAPI
19
19
  puts "\n"
20
20
  puts "Name: #{x["hostname"]}"
21
21
  puts "ID: #{x["id"]}"
22
- puts "Description: #{x["description"]}"
23
- puts "IP: #{x["ips"].first["address"]}"
24
- puts "Status: #{x["status"]}"
22
+ if not x["description"].to_s.empty?
23
+ puts "Description: #{x["description"]}"
24
+ end
25
25
  }
26
26
  puts "\n"
27
27
 
@@ -2,5 +2,5 @@
2
2
  require 'bbgapi'
3
3
 
4
4
  module Bbgcli
5
- VERSION = "0.0.3"
5
+ VERSION = "0.0.4"
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.3.gem
3
+ gem install bbgcli-0.0.4.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.3
4
+ version: 0.0.4
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-08 00:00:00.000000000Z
12
+ date: 2012-01-03 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trollop
16
- requirement: &2167305860 !ruby/object:Gem::Requirement
16
+ requirement: &2159544380 !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: *2167305860
24
+ version_requirements: *2159544380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &2167305360 !ruby/object:Gem::Requirement
27
+ requirement: &2159543860 !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: *2167305360
35
+ version_requirements: *2159543860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: highline
38
- requirement: &2167304920 !ruby/object:Gem::Requirement
38
+ requirement: &2159543260 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,18 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2167304920
46
+ version_requirements: *2159543260
47
+ - !ruby/object:Gem::Dependency
48
+ name: net-ssh
49
+ requirement: &2159542700 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *2159542700
47
58
  description: An interactive cli for the blue box api in ruby
48
59
  email:
49
60
  - pete@kingofweb.com
@@ -54,6 +65,7 @@ extra_rdoc_files: []
54
65
  files:
55
66
  - .gitignore
56
67
  - Gemfile
68
+ - LICENSE
57
69
  - README.md
58
70
  - Rakefile
59
71
  - bbgcli.gemspec